| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/file_system_file_util_proxy.h" | 5 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "webkit/fileapi/cross_file_util_helper.h" | 10 #include "webkit/fileapi/cross_file_util_helper.h" |
| 11 #include "webkit/fileapi/file_system_file_util.h" | 11 #include "webkit/fileapi/file_system_file_util.h" |
| 12 #include "webkit/fileapi/file_system_operation_context.h" | 12 #include "webkit/fileapi/file_system_operation_context.h" |
| 13 | 13 |
| 14 namespace fileapi { | 14 namespace fileapi { |
| 15 | 15 |
| 16 using base::Bind; | 16 using base::Bind; |
| 17 using base::Callback; | 17 using base::Callback; |
| 18 using base::Owned; | 18 using base::Owned; |
| 19 using base::PlatformFileError; | 19 using base::PlatformFileError; |
| 20 using base::Unretained; | 20 using base::Unretained; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 typedef fileapi::FileSystemFileUtilProxy Proxy; | 24 typedef fileapi::FileSystemFileUtilProxy Proxy; |
| 25 | 25 |
| 26 class CopyOrMoveHelper { | |
| 27 public: | |
| 28 CopyOrMoveHelper(CrossFileUtilHelper* helper) | |
| 29 : helper_(helper), | |
| 30 error_(base::PLATFORM_FILE_OK) {} | |
| 31 ~CopyOrMoveHelper() {} | |
| 32 | |
| 33 void RunWork() { | |
| 34 error_ = helper_->DoWork(); | |
| 35 } | |
| 36 | |
| 37 void Reply(const Proxy::StatusCallback& callback) { | |
| 38 if (!callback.is_null()) | |
| 39 callback.Run(error_); | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 scoped_ptr<CrossFileUtilHelper> helper_; | |
| 44 base::PlatformFileError error_; | |
| 45 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveHelper); | |
| 46 }; | |
| 47 | |
| 48 class EnsureFileExistsHelper { | 26 class EnsureFileExistsHelper { |
| 49 public: | 27 public: |
| 50 EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK), created_(false) {} | 28 EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK), created_(false) {} |
| 51 | 29 |
| 52 void RunWork(FileSystemFileUtil* file_util, | 30 void RunWork(FileSystemFileUtil* file_util, |
| 53 FileSystemOperationContext* context, | 31 FileSystemOperationContext* context, |
| 54 const FileSystemPath& path) { | 32 const FileSystemPath& path) { |
| 55 error_ = file_util->EnsureFileExists(context, path, &created_); | 33 error_ = file_util->EnsureFileExists(context, path, &created_); |
| 56 } | 34 } |
| 57 | 35 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 124 |
| 147 // static | 125 // static |
| 148 bool FileSystemFileUtilProxy::Copy( | 126 bool FileSystemFileUtilProxy::Copy( |
| 149 MessageLoopProxy* message_loop_proxy, | 127 MessageLoopProxy* message_loop_proxy, |
| 150 FileSystemOperationContext* context, | 128 FileSystemOperationContext* context, |
| 151 FileSystemFileUtil* src_util, | 129 FileSystemFileUtil* src_util, |
| 152 FileSystemFileUtil* dest_util, | 130 FileSystemFileUtil* dest_util, |
| 153 const FileSystemPath& src_path, | 131 const FileSystemPath& src_path, |
| 154 const FileSystemPath& dest_path, | 132 const FileSystemPath& dest_path, |
| 155 const StatusCallback& callback) { | 133 const StatusCallback& callback) { |
| 156 CopyOrMoveHelper* helper = new CopyOrMoveHelper( | 134 CrossFileUtilHelper* helper = |
| 157 new CrossFileUtilHelper( | 135 new CrossFileUtilHelper( |
| 158 context, src_util, dest_util, src_path, dest_path, | 136 context, src_util, dest_util, src_path, dest_path, |
| 159 CrossFileUtilHelper::OPERATION_COPY)); | 137 CrossFileUtilHelper::OPERATION_COPY); |
| 160 return message_loop_proxy->PostTaskAndReply( | 138 |
| 161 FROM_HERE, | 139 return base::FileUtilProxy::RelayFileTask( |
| 162 Bind(&CopyOrMoveHelper::RunWork, Unretained(helper)), | 140 message_loop_proxy, FROM_HERE, |
| 163 Bind(&CopyOrMoveHelper::Reply, Owned(helper), callback)); | 141 Bind(&CrossFileUtilHelper::DoWork, Owned(helper)), |
| 142 callback); |
| 164 } | 143 } |
| 165 | 144 |
| 166 // static | 145 // static |
| 167 bool FileSystemFileUtilProxy::Move( | 146 bool FileSystemFileUtilProxy::Move( |
| 168 MessageLoopProxy* message_loop_proxy, | 147 MessageLoopProxy* message_loop_proxy, |
| 169 FileSystemOperationContext* context, | 148 FileSystemOperationContext* context, |
| 170 FileSystemFileUtil* src_util, | 149 FileSystemFileUtil* src_util, |
| 171 FileSystemFileUtil* dest_util, | 150 FileSystemFileUtil* dest_util, |
| 172 const FileSystemPath& src_path, | 151 const FileSystemPath& src_path, |
| 173 const FileSystemPath& dest_path, | 152 const FileSystemPath& dest_path, |
| 174 const StatusCallback& callback) { | 153 const StatusCallback& callback) { |
| 175 CopyOrMoveHelper* helper = new CopyOrMoveHelper( | 154 CrossFileUtilHelper* helper = |
| 176 new CrossFileUtilHelper( | 155 new CrossFileUtilHelper( |
| 177 context, src_util, dest_util, src_path, dest_path, | 156 context, src_util, dest_util, src_path, dest_path, |
| 178 CrossFileUtilHelper::OPERATION_MOVE)); | 157 CrossFileUtilHelper::OPERATION_MOVE); |
| 179 return message_loop_proxy->PostTaskAndReply( | 158 return base::FileUtilProxy::RelayFileTask( |
| 180 FROM_HERE, | 159 message_loop_proxy, FROM_HERE, |
| 181 Bind(&CopyOrMoveHelper::RunWork, Unretained(helper)), | 160 Bind(&CrossFileUtilHelper::DoWork, Owned(helper)), |
| 182 Bind(&CopyOrMoveHelper::Reply, Owned(helper), callback)); | 161 callback); |
| 183 } | 162 } |
| 184 | 163 |
| 185 // static | 164 // static |
| 186 bool FileSystemFileUtilProxy::EnsureFileExists( | 165 bool FileSystemFileUtilProxy::EnsureFileExists( |
| 187 MessageLoopProxy* message_loop_proxy, | 166 MessageLoopProxy* message_loop_proxy, |
| 188 FileSystemOperationContext* context, | 167 FileSystemOperationContext* context, |
| 189 FileSystemFileUtil* file_util, | 168 FileSystemFileUtil* file_util, |
| 190 const FileSystemPath& path, | 169 const FileSystemPath& path, |
| 191 const EnsureFileExistsCallback& callback) { | 170 const EnsureFileExistsCallback& callback) { |
| 192 EnsureFileExistsHelper* helper = new EnsureFileExistsHelper; | 171 EnsureFileExistsHelper* helper = new EnsureFileExistsHelper; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 int64 length, | 248 int64 length, |
| 270 const StatusCallback& callback) { | 249 const StatusCallback& callback) { |
| 271 return base::FileUtilProxy::RelayFileTask( | 250 return base::FileUtilProxy::RelayFileTask( |
| 272 message_loop_proxy, FROM_HERE, | 251 message_loop_proxy, FROM_HERE, |
| 273 base::Bind(&FileSystemFileUtil::Truncate, base::Unretained(file_util), | 252 base::Bind(&FileSystemFileUtil::Truncate, base::Unretained(file_util), |
| 274 context, path, length), | 253 context, path, length), |
| 275 callback); | 254 callback); |
| 276 } | 255 } |
| 277 | 256 |
| 278 } // namespace fileapi | 257 } // namespace fileapi |
| OLD | NEW |