Convert Media Galleries to use base::File

Unfortunately, this brings in changes to webkit/browser/fileapi, and once
that changes, a lot of files have to be updated.

The bright side is that most of the collateral changes are just trivial
renaming of PlatformFileError -> File::Error and PlatformFileInfo ->
File::Info

BUG=322664

Review URL: https://codereview.chromium.org/145303002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247301 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 141bcc5b660175f90a351d0b1fc412eecbeb70e6
diff --git a/base/files/file_util_proxy.cc b/base/files/file_util_proxy.cc
index 8307234..141e4e1 100644
--- a/base/files/file_util_proxy.cc
+++ b/base/files/file_util_proxy.cc
@@ -20,7 +20,7 @@
 void CallWithTranslatedParameter(const FileUtilProxy::StatusCallback& callback,
                                  bool value) {
   DCHECK(!callback.is_null());
-  callback.Run(value ? PLATFORM_FILE_OK : PLATFORM_FILE_ERROR_FAILED);
+  callback.Run(value ? File::FILE_OK : File::FILE_ERROR_FAILED);
 }
 
 // Helper classes or routines for individual methods.
@@ -32,7 +32,7 @@
         close_task_(close_task),
         file_handle_(kInvalidPlatformFileValue),
         created_(false),
-        error_(PLATFORM_FILE_OK) {}
+        error_(File::FILE_OK) {}
 
   ~CreateOrOpenHelper() {
     if (file_handle_ != kInvalidPlatformFileValue) {
@@ -56,7 +56,7 @@
   FileUtilProxy::CloseTask close_task_;
   PlatformFile file_handle_;
   bool created_;
-  PlatformFileError error_;
+  File::Error error_;
   DISALLOW_COPY_AND_ASSIGN(CreateOrOpenHelper);
 };
 
@@ -65,7 +65,7 @@
   explicit CreateTemporaryHelper(TaskRunner* task_runner)
       : task_runner_(task_runner),
         file_handle_(kInvalidPlatformFileValue),
-        error_(PLATFORM_FILE_OK) {}
+        error_(File::FILE_OK) {}
 
   ~CreateTemporaryHelper() {
     if (file_handle_ != kInvalidPlatformFileValue) {
@@ -85,8 +85,11 @@
         PLATFORM_FILE_CREATE_ALWAYS |
         additional_file_flags;
 
-    error_ = PLATFORM_FILE_OK;
-    file_handle_ = CreatePlatformFile(file_path_, file_flags, NULL, &error_);
+    error_ = File::FILE_OK;
+    // TODO(rvargas): Convert this code to use File.
+    file_handle_ =
+        CreatePlatformFile(file_path_, file_flags, NULL,
+                           reinterpret_cast<PlatformFileError*>(&error_));
   }
 
   void Reply(const FileUtilProxy::CreateTemporaryCallback& callback) {
@@ -98,28 +101,30 @@
   scoped_refptr<TaskRunner> task_runner_;
   PlatformFile file_handle_;
   FilePath file_path_;
-  PlatformFileError error_;
+  File::Error error_;
   DISALLOW_COPY_AND_ASSIGN(CreateTemporaryHelper);
 };
 
 class GetFileInfoHelper {
  public:
   GetFileInfoHelper()
-      : error_(PLATFORM_FILE_OK) {}
+      : error_(File::FILE_OK) {}
 
   void RunWorkForFilePath(const FilePath& file_path) {
     if (!PathExists(file_path)) {
-      error_ = PLATFORM_FILE_ERROR_NOT_FOUND;
+      error_ = File::FILE_ERROR_NOT_FOUND;
       return;
     }
     // TODO(rvargas): switch this file to base::File.
     if (!GetFileInfo(file_path, reinterpret_cast<File::Info*>(&file_info_)))
-      error_ = PLATFORM_FILE_ERROR_FAILED;
+      error_ = File::FILE_ERROR_FAILED;
   }
 
   void RunWorkForPlatformFile(PlatformFile file) {
-    if (!GetPlatformFileInfo(file, &file_info_))
-      error_ = PLATFORM_FILE_ERROR_FAILED;
+    if (!GetPlatformFileInfo(
+            file, reinterpret_cast<PlatformFileInfo*>(&file_info_))) {
+      error_ = File::FILE_ERROR_FAILED;
+    }
   }
 
   void Reply(const FileUtilProxy::GetFileInfoCallback& callback) {
@@ -129,8 +134,8 @@
   }
 
  private:
-  PlatformFileError error_;
-  PlatformFileInfo file_info_;
+  File::Error error_;
+  File::Info file_info_;
   DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper);
 };
 
@@ -147,8 +152,8 @@
 
   void Reply(const FileUtilProxy::ReadCallback& callback) {
     if (!callback.is_null()) {
-      PlatformFileError error =
-          (bytes_read_ < 0) ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK;
+      File::Error error =
+          (bytes_read_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK;
       callback.Run(error, buffer_.get(), bytes_read_);
     }
   }
@@ -176,8 +181,8 @@
 
   void Reply(const FileUtilProxy::WriteCallback& callback) {
     if (!callback.is_null()) {
-      PlatformFileError error =
-          (bytes_written_ < 0) ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK;
+      File::Error error =
+          (bytes_written_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK;
       callback.Run(error, bytes_written_);
     }
   }
@@ -189,38 +194,40 @@
   DISALLOW_COPY_AND_ASSIGN(WriteHelper);
 };
 
-PlatformFileError CreateOrOpenAdapter(
+File::Error CreateOrOpenAdapter(
     const FilePath& file_path, int file_flags,
     PlatformFile* file_handle, bool* created) {
   DCHECK(file_handle);
   DCHECK(created);
   if (!DirectoryExists(file_path.DirName())) {
     // If its parent does not exist, should return NOT_FOUND error.
-    return PLATFORM_FILE_ERROR_NOT_FOUND;
+    return File::FILE_ERROR_NOT_FOUND;
   }
-  PlatformFileError error = PLATFORM_FILE_OK;
-  *file_handle = CreatePlatformFile(file_path, file_flags, created, &error);
+  File::Error error = File::FILE_OK;
+  *file_handle =
+      CreatePlatformFile(file_path, file_flags, created,
+                         reinterpret_cast<PlatformFileError*>(&error));
   return error;
 }
 
-PlatformFileError CloseAdapter(PlatformFile file_handle) {
+File::Error CloseAdapter(PlatformFile file_handle) {
   if (!ClosePlatformFile(file_handle)) {
-    return PLATFORM_FILE_ERROR_FAILED;
+    return File::FILE_ERROR_FAILED;
   }
-  return PLATFORM_FILE_OK;
+  return File::FILE_OK;
 }
 
-PlatformFileError DeleteAdapter(const FilePath& file_path, bool recursive) {
+File::Error DeleteAdapter(const FilePath& file_path, bool recursive) {
   if (!PathExists(file_path)) {
-    return PLATFORM_FILE_ERROR_NOT_FOUND;
+    return File::FILE_ERROR_NOT_FOUND;
   }
   if (!base::DeleteFile(file_path, recursive)) {
     if (!recursive && !base::IsDirectoryEmpty(file_path)) {
-      return PLATFORM_FILE_ERROR_NOT_EMPTY;
+      return File::FILE_ERROR_NOT_EMPTY;
     }
-    return PLATFORM_FILE_ERROR_FAILED;
+    return File::FILE_ERROR_FAILED;
   }
-  return PLATFORM_FILE_OK;
+  return File::FILE_OK;
 }
 
 }  // namespace
diff --git a/base/files/file_util_proxy.h b/base/files/file_util_proxy.h
index bded161..846e8fb 100644
--- a/base/files/file_util_proxy.h
+++ b/base/files/file_util_proxy.h
@@ -7,6 +7,7 @@
 
 #include "base/base_export.h"
 #include "base/callback_forward.h"
+#include "base/files/file.h"
 #include "base/files/file_path.h"
 #include "base/memory/ref_counted.h"
 #include "base/platform_file.h"
@@ -26,25 +27,25 @@
   // This callback is used by methods that report only an error code.  It is
   // valid to pass a null callback to any function that takes a StatusCallback,
   // in which case the operation will complete silently.
-  typedef Callback<void(PlatformFileError)> StatusCallback;
+  typedef Callback<void(File::Error)> StatusCallback;
 
-  typedef Callback<void(PlatformFileError,
+  typedef Callback<void(File::Error,
                         PassPlatformFile,
                         bool /* created */)> CreateOrOpenCallback;
-  typedef Callback<void(PlatformFileError,
+  typedef Callback<void(File::Error,
                         PassPlatformFile,
                         const FilePath&)> CreateTemporaryCallback;
-  typedef Callback<void(PlatformFileError,
-                        const PlatformFileInfo&)> GetFileInfoCallback;
-  typedef Callback<void(PlatformFileError,
+  typedef Callback<void(File::Error,
+                        const File::Info&)> GetFileInfoCallback;
+  typedef Callback<void(File::Error,
                         const char* /* data */,
                         int /* bytes read */)> ReadCallback;
-  typedef Callback<void(PlatformFileError,
+  typedef Callback<void(File::Error,
                         int /* bytes written */)> WriteCallback;
 
-  typedef Callback<PlatformFileError(PlatformFile*, bool*)> CreateOrOpenTask;
-  typedef Callback<PlatformFileError(PlatformFile)> CloseTask;
-  typedef Callback<PlatformFileError(void)> FileTask;
+  typedef Callback<File::Error(PlatformFile*, bool*)> CreateOrOpenTask;
+  typedef Callback<File::Error(PlatformFile)> CloseTask;
+  typedef Callback<File::Error(void)> FileTask;
 
   // Creates or opens a file with the given flags. It is invalid to pass a null
   // callback. If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to
diff --git a/base/files/file_util_proxy_unittest.cc b/base/files/file_util_proxy_unittest.cc
index d01d56d..30c77d3 100644
--- a/base/files/file_util_proxy_unittest.cc
+++ b/base/files/file_util_proxy_unittest.cc
@@ -22,7 +22,7 @@
  public:
   FileUtilProxyTest()
       : file_thread_("FileUtilProxyTestFileThread"),
-        error_(PLATFORM_FILE_OK),
+        error_(File::FILE_OK),
         created_(false),
         file_(kInvalidPlatformFileValue),
         bytes_written_(-1),
@@ -38,12 +38,12 @@
       ClosePlatformFile(file_);
   }
 
-  void DidFinish(PlatformFileError error) {
+  void DidFinish(File::Error error) {
     error_ = error;
     MessageLoop::current()->QuitWhenIdle();
   }
 
-  void DidCreateOrOpen(PlatformFileError error,
+  void DidCreateOrOpen(File::Error error,
                        PassPlatformFile file,
                        bool created) {
     error_ = error;
@@ -52,7 +52,7 @@
     MessageLoop::current()->QuitWhenIdle();
   }
 
-  void DidCreateTemporary(PlatformFileError error,
+  void DidCreateTemporary(File::Error error,
                           PassPlatformFile file,
                           const FilePath& path) {
     error_ = error;
@@ -61,14 +61,14 @@
     MessageLoop::current()->QuitWhenIdle();
   }
 
-  void DidGetFileInfo(PlatformFileError error,
-                      const PlatformFileInfo& file_info) {
+  void DidGetFileInfo(File::Error error,
+                      const File::Info& file_info) {
     error_ = error;
     file_info_ = file_info;
     MessageLoop::current()->QuitWhenIdle();
   }
 
-  void DidRead(PlatformFileError error,
+  void DidRead(File::Error error,
                const char* data,
                int bytes_read) {
     error_ = error;
@@ -77,7 +77,7 @@
     MessageLoop::current()->QuitWhenIdle();
   }
 
-  void DidWrite(PlatformFileError error,
+  void DidWrite(File::Error error,
                 int bytes_written) {
     error_ = error;
     bytes_written_ = bytes_written;
@@ -106,11 +106,11 @@
   Thread file_thread_;
 
   ScopedTempDir dir_;
-  PlatformFileError error_;
+  File::Error error_;
   bool created_;
   PlatformFile file_;
   FilePath path_;
-  PlatformFileInfo file_info_;
+  File::Info file_info_;
   std::vector<char> buffer_;
   int bytes_written_;
   WeakPtrFactory<FileUtilProxyTest> weak_factory_;
@@ -124,7 +124,7 @@
       Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
   MessageLoop::current()->Run();
 
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
   EXPECT_TRUE(created_);
   EXPECT_NE(kInvalidPlatformFileValue, file_);
   EXPECT_TRUE(PathExists(test_path()));
@@ -143,7 +143,7 @@
       Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
   MessageLoop::current()->Run();
 
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
   EXPECT_FALSE(created_);
   EXPECT_NE(kInvalidPlatformFileValue, file_);
 }
@@ -155,7 +155,7 @@
       PLATFORM_FILE_OPEN | PLATFORM_FILE_READ,
       Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
   MessageLoop::current()->Run();
-  EXPECT_EQ(PLATFORM_FILE_ERROR_NOT_FOUND, error_);
+  EXPECT_EQ(File::FILE_ERROR_NOT_FOUND, error_);
   EXPECT_FALSE(created_);
   EXPECT_EQ(kInvalidPlatformFileValue, file_);
   EXPECT_FALSE(PathExists(test_path()));
@@ -177,7 +177,7 @@
       file,
       Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
   MessageLoop::current()->Run();
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
 
   // Now it should pass on all platforms.
   EXPECT_TRUE(base::Move(test_path(), test_dir_path().AppendASCII("new")));
@@ -188,7 +188,7 @@
       file_task_runner(), 0 /* additional_file_flags */,
       Bind(&FileUtilProxyTest::DidCreateTemporary, weak_factory_.GetWeakPtr()));
   MessageLoop::current()->Run();
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
   EXPECT_TRUE(PathExists(path_));
   EXPECT_NE(kInvalidPlatformFileValue, file_);
 
@@ -235,7 +235,7 @@
   MessageLoop::current()->Run();
 
   // Verify.
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
   EXPECT_EQ(expected_info.size, file_info_.size);
   EXPECT_EQ(expected_info.is_directory, file_info_.is_directory);
   EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link);
@@ -258,7 +258,7 @@
   MessageLoop::current()->Run();
 
   // Verify.
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
   EXPECT_EQ(expected_info.size, file_info_.size);
   EXPECT_EQ(expected_info.is_directory, file_info_.is_directory);
   EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link);
@@ -284,7 +284,7 @@
   MessageLoop::current()->Run();
 
   // Verify.
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
   EXPECT_EQ(expected_bytes, static_cast<int>(buffer_.size()));
   for (size_t i = 0; i < buffer_.size(); ++i) {
     EXPECT_EQ(expected_data[i], buffer_[i]);
@@ -305,7 +305,7 @@
       data_bytes,
       Bind(&FileUtilProxyTest::DidWrite, weak_factory_.GetWeakPtr()));
   MessageLoop::current()->Run();
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
   EXPECT_EQ(data_bytes, bytes_written_);
 
   // Flush the written data.  (So that the following read should always
@@ -315,7 +315,7 @@
       file,
       Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
   MessageLoop::current()->Run();
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
 
   // Verify the written data.
   char buffer[10];
@@ -338,7 +338,7 @@
       last_modified_time,
       Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
   MessageLoop::current()->Run();
-  EXPECT_EQ(PLATFORM_FILE_OK, error_);
+  EXPECT_EQ(File::FILE_OK, error_);
 
   File::Info info;
   GetFileInfo(test_path(), &info);