Retry: Bind: Merge FileUtilProxy and FileSystemFileUtilProxy: Delete/Touch/Truncate/Copy/Move

Original reviewed issue is: http://codereview.chromium.org/8424007/

BUG=none
TEST=test_shell:*File*

Review URL: http://codereview.chromium.org/8508001

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


CrOS-Libchrome-Original-Commit: 4412cd0412701e21ff00eb7e3394a57c95171b36
diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc
index 4c79465..9b51d34 100644
--- a/base/file_util_proxy.cc
+++ b/base/file_util_proxy.cc
@@ -176,19 +176,6 @@
   DISALLOW_COPY_AND_ASSIGN(CreateTemporaryHelper);
 };
 
-PlatformFileError DeleteHelper(const FilePath& file_path, bool recursive) {
-  if (!file_util::PathExists(file_path)) {
-    return PLATFORM_FILE_ERROR_NOT_FOUND;
-  }
-  if (!file_util::Delete(file_path, recursive)) {
-    if (!recursive && !file_util::IsDirectoryEmpty(file_path)) {
-      return PLATFORM_FILE_ERROR_NOT_EMPTY;
-    }
-    return PLATFORM_FILE_ERROR_FAILED;
-  }
-  return PLATFORM_FILE_OK;
-}
-
 class GetFileInfoHelper {
  public:
   GetFileInfoHelper()
@@ -297,6 +284,19 @@
   return PLATFORM_FILE_OK;
 }
 
+PlatformFileError DeleteAdapter(const FilePath& file_path, bool recursive) {
+  if (!file_util::PathExists(file_path)) {
+    return PLATFORM_FILE_ERROR_NOT_FOUND;
+  }
+  if (!file_util::Delete(file_path, recursive)) {
+    if (!recursive && !file_util::IsDirectoryEmpty(file_path)) {
+      return PLATFORM_FILE_ERROR_NOT_EMPTY;
+    }
+    return PLATFORM_FILE_ERROR_FAILED;
+  }
+  return PLATFORM_FILE_OK;
+}
+
 }  // namespace
 
 // static
@@ -367,10 +367,10 @@
                            const FilePath& file_path,
                            bool recursive,
                            const StatusCallback& callback) {
-  return PostTaskAndReplyWithStatus<PlatformFileError>(
+  return RelayFileTask(
       message_loop_proxy, FROM_HERE,
-      Bind(&DeleteHelper, file_path, recursive), callback,
-      new PlatformFileError);
+      Bind(&DeleteAdapter, file_path, recursive),
+      callback);
 }
 
 // static
@@ -378,10 +378,10 @@
     scoped_refptr<MessageLoopProxy> message_loop_proxy,
     const FilePath& file_path,
     const StatusCallback& callback) {
-  return PostTaskAndReplyWithStatus<PlatformFileError>(
+  return RelayFileTask(
       message_loop_proxy, FROM_HERE,
-      Bind(&DeleteHelper, file_path, true /* recursive */), callback,
-      new PlatformFileError);
+      Bind(&DeleteAdapter, file_path, true /* recursive */),
+      callback);
 }
 
 // static
@@ -472,6 +472,19 @@
 }
 
 // static
+bool FileUtilProxy::RelayFileTask(
+    scoped_refptr<MessageLoopProxy> message_loop_proxy,
+    const tracked_objects::Location& from_here,
+    const FileTask& file_task,
+    const StatusCallback& callback) {
+  PlatformFileError* result = new PlatformFileError;
+  return message_loop_proxy->PostTaskAndReply(
+      from_here,
+      ReturnAsParam(file_task, result),
+      ReplyHelper(callback, Owned(result)));
+}
+
+// static
 bool FileUtilProxy::RelayCreateOrOpen(
     scoped_refptr<MessageLoopProxy> message_loop_proxy,
     const CreateOrOpenTask& open_task,
diff --git a/base/file_util_proxy.h b/base/file_util_proxy.h
index 15a3e82..1cde1ce 100644
--- a/base/file_util_proxy.h
+++ b/base/file_util_proxy.h
@@ -53,6 +53,7 @@
 
   typedef Callback<PlatformFileError(PlatformFile*, bool*)> CreateOrOpenTask;
   typedef Callback<PlatformFileError(PlatformFile)> CloseTask;
+  typedef Callback<PlatformFileError(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
@@ -168,6 +169,12 @@
       const StatusCallback& callback);
 
   // Relay helpers.
+  static bool RelayFileTask(
+      scoped_refptr<MessageLoopProxy> message_loop_proxy,
+      const tracked_objects::Location& from_here,
+      const FileTask& task,
+      const StatusCallback& callback);
+
   static bool RelayCreateOrOpen(
       scoped_refptr<MessageLoopProxy> message_loop_proxy,
       const CreateOrOpenTask& open_task,