Replace FileUtilProxy with FileProxy in renderer_host/pepper
BUG=322664
Review URL: https://codereview.chromium.org/252583007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270781 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: 0ccbf04f0245accae86ec8b9f6f7e1061ba28e1d
diff --git a/base/files/file_proxy.cc b/base/files/file_proxy.cc
index fa04d7c..291b98d 100644
--- a/base/files/file_proxy.cc
+++ b/base/files/file_proxy.cc
@@ -265,10 +265,19 @@
return file_.IsValid();
}
+void FileProxy::SetFile(File file) {
+ DCHECK(!file_.IsValid());
+ file_ = file.Pass();
+}
+
File FileProxy::TakeFile() {
return file_.Pass();
}
+PlatformFile FileProxy::GetPlatformFile() const {
+ return file_.GetPlatformFile();
+}
+
bool FileProxy::Close(const StatusCallback& callback) {
DCHECK(file_.IsValid());
GenericFileHelper* helper = new GenericFileHelper(this, file_.Pass());
@@ -347,9 +356,4 @@
Bind(&GenericFileHelper::Reply, Owned(helper), callback));
}
-void FileProxy::SetFile(File file) {
- DCHECK(!file_.IsValid());
- file_ = file.Pass();
-}
-
} // namespace base
diff --git a/base/files/file_proxy.h b/base/files/file_proxy.h
index 3c834f6..f990d04 100644
--- a/base/files/file_proxy.h
+++ b/base/files/file_proxy.h
@@ -33,12 +33,9 @@
// In other words, having a sequence like
//
// proxy.Write(...);
-// delete proxy;
+// proxy.Write(...);
//
-// will keep the file valid during the Write operation but will cause the file
-// to be closed in the current thread, when the operation finishes. If Close is
-// called right away after Write, the second call will fail because there is an
-// operation in progress.
+// means the second Write will always fail.
class BASE_EXPORT FileProxy : public SupportsWeakPtr<FileProxy> {
public:
// This callback is used by methods that report only an error code. It is
@@ -88,8 +85,14 @@
// length to simulate a new file), and false otherwise.
bool created() const { return file_.created(); }
+ // Claims ownership of |file|. It is an error to call this method when
+ // IsValid() returns true.
+ void SetFile(File file);
+
File TakeFile();
+ PlatformFile GetPlatformFile() const;
+
// Proxies File::Close. The callback can be null.
// This returns false if task posting to |task_runner| has failed.
bool Close(const StatusCallback& callback);
@@ -127,7 +130,6 @@
private:
friend class FileHelper;
- void SetFile(File file);
TaskRunner* task_runner() { return task_runner_.get(); }
scoped_refptr<TaskRunner> task_runner_;
diff --git a/base/files/file_proxy_unittest.cc b/base/files/file_proxy_unittest.cc
index 7748923..d44beb9 100644
--- a/base/files/file_proxy_unittest.cc
+++ b/base/files/file_proxy_unittest.cc
@@ -207,6 +207,20 @@
EXPECT_TRUE(base::DeleteFile(path_, false));
}
+TEST_F(FileProxyTest, SetAndTake) {
+ File file(test_path(), File::FLAG_CREATE | File::FLAG_READ);
+ ASSERT_TRUE(file.IsValid());
+ FileProxy proxy(file_task_runner());
+ EXPECT_FALSE(proxy.IsValid());
+ proxy.SetFile(file.Pass());
+ EXPECT_TRUE(proxy.IsValid());
+ EXPECT_FALSE(file.IsValid());
+
+ file = proxy.TakeFile();
+ EXPECT_FALSE(proxy.IsValid());
+ EXPECT_TRUE(file.IsValid());
+}
+
TEST_F(FileProxyTest, GetInfo) {
// Setup.
ASSERT_EQ(4, base::WriteFile(test_path(), "test", 4));