Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/file_util_proxy.h" | 5 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 6 | 6 |
| 7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 8 | 8 #include "webkit/fileapi/file_system_context.h" |
| 9 // TODO(jianli): Move the code from anonymous namespace to base namespace so | 9 #include "webkit/fileapi/file_system_file_util.h" |
| 10 // that all of the base:: prefixes would be unnecessary. | 10 #include "webkit/fileapi/file_system_operation_context.h" |
| 11 namespace { | |
| 12 | 11 |
| 13 namespace { | 12 namespace { |
| 14 | 13 |
| 15 // Performs common checks for move and copy. | |
| 16 // This also removes the destination directory if it's non-empty and all other | |
| 17 // checks are passed (so that the copy/move correctly overwrites the | |
| 18 // destination). | |
| 19 static base::PlatformFileError PerformCommonCheckAndPreparationForMoveAndCopy( | |
| 20 const FilePath& src_file_path, | |
| 21 const FilePath& dest_file_path) { | |
| 22 // Exits earlier if the source path does not exist. | |
| 23 if (!file_util::PathExists(src_file_path)) | |
| 24 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 25 | |
| 26 // The parent of the |dest_file_path| does not exist. | |
| 27 if (!file_util::DirectoryExists(dest_file_path.DirName())) | |
| 28 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 29 | |
| 30 // It is an error to try to copy/move an entry into its child. | |
| 31 if (src_file_path.IsParent(dest_file_path)) | |
| 32 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
| 33 | |
| 34 // Now it is ok to return if the |dest_file_path| does not exist. | |
| 35 if (!file_util::PathExists(dest_file_path)) | |
| 36 return base::PLATFORM_FILE_OK; | |
| 37 | |
| 38 // |src_file_path| exists and is a directory. | |
| 39 // |dest_file_path| exists and is a file. | |
| 40 bool src_is_directory = file_util::DirectoryExists(src_file_path); | |
| 41 bool dest_is_directory = file_util::DirectoryExists(dest_file_path); | |
| 42 if (src_is_directory && !dest_is_directory) | |
| 43 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
| 44 | |
| 45 // |src_file_path| exists and is a file. | |
| 46 // |dest_file_path| exists and is a directory. | |
| 47 if (!src_is_directory && dest_is_directory) | |
| 48 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | |
| 49 | |
| 50 // It is an error to copy/move an entry into the same path. | |
| 51 if (src_file_path.value() == dest_file_path.value()) | |
| 52 return base::PLATFORM_FILE_ERROR_EXISTS; | |
| 53 | |
| 54 if (dest_is_directory) { | |
| 55 // It is an error to copy/move an entry to a non-empty directory. | |
| 56 // Otherwise the copy/move attempt must overwrite the destination, but | |
| 57 // the file_util's Copy or Move method doesn't perform overwrite | |
| 58 // on all platforms, so we delete the destination directory here. | |
| 59 // TODO(kinuko): may be better to change the file_util::{Copy,Move}. | |
| 60 if (!file_util::Delete(dest_file_path, false /* recursive */)) { | |
| 61 if (!file_util::IsDirectoryEmpty(dest_file_path)) | |
| 62 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | |
| 63 return base::PLATFORM_FILE_ERROR_FAILED; | |
| 64 } | |
| 65 } | |
| 66 return base::PLATFORM_FILE_OK; | |
| 67 } | |
| 68 | |
| 69 } // anonymous namespace | |
| 70 | |
| 71 class MessageLoopRelay | 14 class MessageLoopRelay |
| 72 : public base::RefCountedThreadSafe<MessageLoopRelay> { | 15 : public base::RefCountedThreadSafe<MessageLoopRelay> { |
| 73 public: | 16 public: |
| 74 MessageLoopRelay() | 17 explicit MessageLoopRelay(fileapi::FileSystemOperationContext* context) |
|
kinuko
2011/02/22 12:20:58
Can we add a comment about who owns the context?
(
| |
| 75 : origin_message_loop_proxy_( | 18 : origin_message_loop_proxy_( |
| 76 base::MessageLoopProxy::CreateForCurrentThread()), | 19 base::MessageLoopProxy::CreateForCurrentThread()), |
| 77 error_code_(base::PLATFORM_FILE_OK) { | 20 error_code_(base::PLATFORM_FILE_OK), |
| 21 context_(context) { | |
| 78 } | 22 } |
| 79 | 23 |
| 80 bool Start(scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 24 bool Start(scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 81 const tracked_objects::Location& from_here) { | 25 const tracked_objects::Location& from_here) { |
| 82 return message_loop_proxy->PostTask( | 26 return message_loop_proxy->PostTask( |
| 83 from_here, | 27 from_here, |
| 84 NewRunnableMethod(this, &MessageLoopRelay::ProcessOnTargetThread)); | 28 NewRunnableMethod(this, &MessageLoopRelay::ProcessOnTargetThread)); |
| 85 } | 29 } |
| 86 | 30 |
| 87 protected: | 31 protected: |
| 88 friend class base::RefCountedThreadSafe<MessageLoopRelay>; | 32 friend class base::RefCountedThreadSafe<MessageLoopRelay>; |
| 89 virtual ~MessageLoopRelay() {} | 33 virtual ~MessageLoopRelay() {} |
| 90 | 34 |
| 91 // Called to perform work on the FILE thread. | 35 // Called to perform work on the FILE thread. |
| 92 virtual void RunWork() = 0; | 36 virtual void RunWork() = 0; |
| 93 | 37 |
| 94 // Called to notify the callback on the origin thread. | 38 // Called to notify the callback on the origin thread. |
| 95 virtual void RunCallback() = 0; | 39 virtual void RunCallback() = 0; |
| 96 | 40 |
| 97 void set_error_code(base::PlatformFileError error_code) { | 41 void set_error_code(base::PlatformFileError error_code) { |
| 98 error_code_ = error_code; | 42 error_code_ = error_code; |
| 99 } | 43 } |
| 100 | 44 |
| 101 base::PlatformFileError error_code() const { | 45 base::PlatformFileError error_code() const { |
| 102 return error_code_; | 46 return error_code_; |
| 103 } | 47 } |
| 104 | 48 |
| 49 fileapi::FileSystemOperationContext* context() { | |
| 50 return context_; | |
| 51 } | |
| 52 fileapi::FileSystemFileUtil* file_system_file_util() { | |
| 53 return context_->file_system_context()->file_system_file_util(); | |
| 54 } | |
| 55 | |
| 105 private: | 56 private: |
| 106 void ProcessOnTargetThread() { | 57 void ProcessOnTargetThread() { |
| 107 RunWork(); | 58 RunWork(); |
| 108 origin_message_loop_proxy_->PostTask( | 59 origin_message_loop_proxy_->PostTask( |
| 109 FROM_HERE, | 60 FROM_HERE, |
| 110 NewRunnableMethod(this, &MessageLoopRelay::RunCallback)); | 61 NewRunnableMethod(this, &MessageLoopRelay::RunCallback)); |
| 111 } | 62 } |
| 112 | 63 |
| 113 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 64 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
| 114 base::PlatformFileError error_code_; | 65 base::PlatformFileError error_code_; |
| 66 fileapi::FileSystemOperationContext* context_; | |
| 115 }; | 67 }; |
| 116 | 68 |
| 117 class RelayCreateOrOpen : public MessageLoopRelay { | 69 class RelayCreateOrOpen : public MessageLoopRelay { |
| 118 public: | 70 public: |
| 119 RelayCreateOrOpen( | 71 RelayCreateOrOpen( |
| 72 fileapi::FileSystemOperationContext* context, | |
| 120 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 73 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 121 const FilePath& file_path, | 74 const FilePath& file_path, |
| 122 int file_flags, | 75 int file_flags, |
| 123 base::FileUtilProxy::CreateOrOpenCallback* callback) | 76 fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback* callback) |
| 124 : message_loop_proxy_(message_loop_proxy), | 77 : MessageLoopRelay(context), |
| 78 message_loop_proxy_(message_loop_proxy), | |
| 125 file_path_(file_path), | 79 file_path_(file_path), |
| 126 file_flags_(file_flags), | 80 file_flags_(file_flags), |
| 127 callback_(callback), | 81 callback_(callback), |
| 128 file_handle_(base::kInvalidPlatformFileValue), | 82 file_handle_(base::kInvalidPlatformFileValue), |
| 129 created_(false) { | 83 created_(false) { |
| 130 DCHECK(callback); | 84 DCHECK(callback); |
| 131 } | 85 } |
| 132 | 86 |
| 133 protected: | 87 protected: |
| 134 virtual ~RelayCreateOrOpen() { | 88 virtual ~RelayCreateOrOpen() { |
| 135 if (file_handle_ != base::kInvalidPlatformFileValue) | 89 if (file_handle_ != base::kInvalidPlatformFileValue) |
| 136 base::FileUtilProxy::Close(message_loop_proxy_, file_handle_, NULL); | 90 base::FileUtilProxy::Close(message_loop_proxy_, file_handle_, NULL); |
|
Dai Mikurube (google.com)
2011/02/22 08:18:04
It should be :
fileapi::FileSystemFileUtilProxy::C
Dai Mikurube (google.com)
2011/02/22 10:13:53
It was opposite to the correct way. Revert it. Fil
kinuko
2011/02/22 11:13:39
I think the Close here should be fixed too.
Dai Mikurube (google.com)
2011/02/22 11:25:16
We should not use fileapi::FileSystemFileUtilProxy
kinuko
2011/02/22 12:20:58
Ah I see (here and your other comment). But calli
| |
| 137 } | 91 } |
| 138 | 92 |
| 139 virtual void RunWork() { | 93 virtual void RunWork() { |
| 140 if (!file_util::DirectoryExists(file_path_.DirName())) { | 94 set_error_code( |
| 141 // If its parent does not exist, should return NOT_FOUND error. | 95 file_system_file_util()->CreateOrOpen( |
| 142 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 96 context(), file_path_, file_flags_, &file_handle_, &created_)); |
| 143 return; | |
| 144 } | |
| 145 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; | |
| 146 file_handle_ = base::CreatePlatformFile(file_path_, file_flags_, | |
| 147 &created_, &error_code); | |
| 148 set_error_code(error_code); | |
| 149 } | 97 } |
| 150 | 98 |
| 151 virtual void RunCallback() { | 99 virtual void RunCallback() { |
| 152 callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), | 100 callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), |
| 153 created_); | 101 created_); |
| 154 delete callback_; | 102 delete callback_; |
| 155 } | 103 } |
| 156 | 104 |
| 157 private: | 105 private: |
| 158 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 106 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 159 FilePath file_path_; | 107 FilePath file_path_; |
| 160 int file_flags_; | 108 int file_flags_; |
| 161 base::FileUtilProxy::CreateOrOpenCallback* callback_; | 109 fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback* callback_; |
| 162 base::PlatformFile file_handle_; | 110 base::PlatformFile file_handle_; |
| 163 bool created_; | 111 bool created_; |
| 164 }; | 112 }; |
| 165 | 113 |
| 166 class RelayCreateTemporary : public MessageLoopRelay { | |
| 167 public: | |
| 168 RelayCreateTemporary( | |
| 169 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | |
| 170 base::FileUtilProxy::CreateTemporaryCallback* callback) | |
| 171 : message_loop_proxy_(message_loop_proxy), | |
| 172 callback_(callback), | |
| 173 file_handle_(base::kInvalidPlatformFileValue) { | |
| 174 DCHECK(callback); | |
| 175 } | |
| 176 | |
| 177 protected: | |
| 178 virtual ~RelayCreateTemporary() { | |
| 179 if (file_handle_ != base::kInvalidPlatformFileValue) | |
| 180 base::FileUtilProxy::Close(message_loop_proxy_, file_handle_, NULL); | |
| 181 } | |
| 182 | |
| 183 virtual void RunWork() { | |
| 184 // TODO(darin): file_util should have a variant of CreateTemporaryFile | |
| 185 // that returns a FilePath and a PlatformFile. | |
| 186 file_util::CreateTemporaryFile(&file_path_); | |
| 187 | |
| 188 // Use a fixed set of flags that are appropriate for writing to a temporary | |
| 189 // file from the IO thread using a net::FileStream. | |
| 190 int file_flags = | |
| 191 base::PLATFORM_FILE_CREATE_ALWAYS | | |
| 192 base::PLATFORM_FILE_WRITE | | |
| 193 base::PLATFORM_FILE_ASYNC | | |
| 194 base::PLATFORM_FILE_TEMPORARY; | |
| 195 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; | |
| 196 file_handle_ = base::CreatePlatformFile(file_path_, file_flags, | |
| 197 NULL, &error_code); | |
| 198 set_error_code(error_code); | |
| 199 } | |
| 200 | |
| 201 virtual void RunCallback() { | |
| 202 callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), | |
| 203 file_path_); | |
| 204 delete callback_; | |
| 205 } | |
| 206 | |
| 207 private: | |
| 208 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
| 209 base::FileUtilProxy::CreateTemporaryCallback* callback_; | |
| 210 base::PlatformFile file_handle_; | |
| 211 FilePath file_path_; | |
| 212 }; | |
| 213 | |
| 214 class RelayWithStatusCallback : public MessageLoopRelay { | 114 class RelayWithStatusCallback : public MessageLoopRelay { |
| 215 public: | 115 public: |
| 216 explicit RelayWithStatusCallback( | 116 RelayWithStatusCallback( |
| 217 base::FileUtilProxy::StatusCallback* callback) | 117 fileapi::FileSystemOperationContext* context, |
| 218 : callback_(callback) { | 118 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 119 : MessageLoopRelay(context), | |
| 120 callback_(callback) { | |
| 219 // It is OK for callback to be NULL. | 121 // It is OK for callback to be NULL. |
| 220 } | 122 } |
| 221 | 123 |
| 222 protected: | 124 protected: |
| 223 virtual void RunCallback() { | 125 virtual void RunCallback() { |
| 224 // The caller may not have been interested in the result. | 126 // The caller may not have been interested in the result. |
| 225 if (callback_) { | 127 if (callback_) { |
| 226 callback_->Run(error_code()); | 128 callback_->Run(error_code()); |
| 227 delete callback_; | 129 delete callback_; |
| 228 } | 130 } |
| 229 } | 131 } |
| 230 | 132 |
| 231 private: | 133 private: |
| 232 base::FileUtilProxy::StatusCallback* callback_; | 134 fileapi::FileSystemFileUtilProxy::StatusCallback* callback_; |
| 233 }; | 135 }; |
| 234 | 136 |
| 235 class RelayClose : public RelayWithStatusCallback { | 137 class RelayClose : public RelayWithStatusCallback { |
| 236 public: | 138 public: |
| 237 RelayClose(base::PlatformFile file_handle, | 139 RelayClose(fileapi::FileSystemOperationContext* context, |
| 238 base::FileUtilProxy::StatusCallback* callback) | 140 base::PlatformFile file_handle, |
| 239 : RelayWithStatusCallback(callback), | 141 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 142 : RelayWithStatusCallback(context, callback), | |
| 240 file_handle_(file_handle) { | 143 file_handle_(file_handle) { |
| 241 } | 144 } |
| 242 | 145 |
| 243 protected: | 146 protected: |
| 244 virtual void RunWork() { | 147 virtual void RunWork() { |
| 245 if (!base::ClosePlatformFile(file_handle_)) | 148 set_error_code( |
| 246 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | 149 file_system_file_util()->Close(context(), file_handle_)); |
| 247 } | 150 } |
| 248 | 151 |
| 249 private: | 152 private: |
| 250 base::PlatformFile file_handle_; | 153 base::PlatformFile file_handle_; |
| 251 }; | 154 }; |
| 252 | 155 |
| 253 class RelayEnsureFileExists : public MessageLoopRelay { | 156 class RelayEnsureFileExists : public MessageLoopRelay { |
| 254 public: | 157 public: |
| 255 RelayEnsureFileExists( | 158 RelayEnsureFileExists( |
| 159 fileapi::FileSystemOperationContext* context, | |
| 256 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 160 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 257 const FilePath& file_path, | 161 const FilePath& file_path, |
| 258 base::FileUtilProxy::EnsureFileExistsCallback* callback) | 162 fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback* callback) |
| 259 : message_loop_proxy_(message_loop_proxy), | 163 : MessageLoopRelay(context), |
| 164 message_loop_proxy_(message_loop_proxy), | |
| 260 file_path_(file_path), | 165 file_path_(file_path), |
| 261 callback_(callback), | 166 callback_(callback), |
| 262 created_(false) { | 167 created_(false) { |
| 263 DCHECK(callback); | 168 DCHECK(callback); |
| 264 } | 169 } |
| 265 | 170 |
| 266 protected: | 171 protected: |
| 267 virtual void RunWork() { | 172 virtual void RunWork() { |
| 268 if (!file_util::DirectoryExists(file_path_.DirName())) { | 173 set_error_code( |
| 269 // If its parent does not exist, should return NOT_FOUND error. | 174 file_system_file_util()->EnsureFileExists( |
| 270 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 175 context(), file_path_, &created_)); |
| 271 return; | |
| 272 } | |
| 273 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; | |
| 274 // Tries to create the |file_path_| exclusively. This should fail | |
| 275 // with PLATFORM_FILE_ERROR_EXISTS if the path already exists. | |
| 276 base::PlatformFile handle = base::CreatePlatformFile( | |
| 277 file_path_, | |
| 278 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ, | |
| 279 &created_, &error_code); | |
| 280 if (error_code == base::PLATFORM_FILE_ERROR_EXISTS) { | |
| 281 // Make sure created_ is false. | |
| 282 created_ = false; | |
| 283 error_code = base::PLATFORM_FILE_OK; | |
| 284 } | |
| 285 if (handle != base::kInvalidPlatformFileValue) | |
| 286 base::ClosePlatformFile(handle); | |
| 287 set_error_code(error_code); | |
| 288 } | 176 } |
| 289 | 177 |
| 290 virtual void RunCallback() { | 178 virtual void RunCallback() { |
| 291 callback_->Run(error_code(), created_); | 179 callback_->Run(error_code(), created_); |
| 292 delete callback_; | 180 delete callback_; |
| 293 } | 181 } |
| 294 | 182 |
| 295 private: | 183 private: |
| 296 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 184 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 297 FilePath file_path_; | 185 FilePath file_path_; |
| 298 base::FileUtilProxy::EnsureFileExistsCallback* callback_; | 186 fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback* callback_; |
| 299 bool created_; | 187 bool created_; |
| 300 }; | 188 }; |
| 301 | 189 |
| 302 class RelayDelete : public RelayWithStatusCallback { | 190 class RelayGetFileInfo : public MessageLoopRelay { |
| 303 public: | 191 public: |
| 304 RelayDelete(const FilePath& file_path, | 192 RelayGetFileInfo( |
| 305 bool recursive, | 193 fileapi::FileSystemOperationContext* context, |
| 306 base::FileUtilProxy::StatusCallback* callback) | 194 const FilePath& file_path, |
| 307 : RelayWithStatusCallback(callback), | 195 fileapi::FileSystemFileUtilProxy::GetFileInfoCallback* callback) |
| 308 file_path_(file_path), | 196 : MessageLoopRelay(context), |
| 309 recursive_(recursive) { | 197 callback_(callback), |
| 198 file_path_(file_path) { | |
| 199 DCHECK(callback); | |
| 310 } | 200 } |
| 311 | 201 |
| 312 protected: | 202 protected: |
| 313 virtual void RunWork() { | 203 virtual void RunWork() { |
| 314 if (!file_util::PathExists(file_path_)) { | 204 set_error_code( |
| 315 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 205 file_system_file_util()->GetFileInfo( |
| 316 return; | 206 context(), file_path_, &file_info_)); |
| 317 } | 207 } |
| 318 if (!file_util::Delete(file_path_, recursive_)) { | 208 |
| 319 if (!recursive_ && !file_util::IsDirectoryEmpty(file_path_)) { | 209 virtual void RunCallback() { |
| 320 set_error_code(base::PLATFORM_FILE_ERROR_NOT_EMPTY); | 210 callback_->Run(error_code(), file_info_); |
| 321 return; | 211 delete callback_; |
| 322 } | |
| 323 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 324 } | |
| 325 } | 212 } |
| 326 | 213 |
| 327 private: | 214 private: |
| 215 fileapi::FileSystemFileUtilProxy::GetFileInfoCallback* callback_; | |
| 328 FilePath file_path_; | 216 FilePath file_path_; |
| 329 bool recursive_; | 217 base::PlatformFileInfo file_info_; |
| 330 }; | |
| 331 | |
| 332 class RelayCopy : public RelayWithStatusCallback { | |
| 333 public: | |
| 334 RelayCopy(const FilePath& src_file_path, | |
| 335 const FilePath& dest_file_path, | |
| 336 base::FileUtilProxy::StatusCallback* callback) | |
| 337 : RelayWithStatusCallback(callback), | |
| 338 src_file_path_(src_file_path), | |
| 339 dest_file_path_(dest_file_path) { | |
| 340 } | |
| 341 | |
| 342 protected: | |
| 343 virtual void RunWork() { | |
| 344 set_error_code(PerformCommonCheckAndPreparationForMoveAndCopy( | |
| 345 src_file_path_, dest_file_path_)); | |
| 346 if (error_code() != base::PLATFORM_FILE_OK) | |
| 347 return; | |
| 348 if (!file_util::CopyDirectory(src_file_path_, dest_file_path_, | |
| 349 true /* recursive */)) | |
| 350 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 351 } | |
| 352 | |
| 353 private: | |
| 354 FilePath src_file_path_; | |
| 355 FilePath dest_file_path_; | |
| 356 }; | |
| 357 | |
| 358 class RelayMove : public RelayWithStatusCallback { | |
| 359 public: | |
| 360 RelayMove(const FilePath& src_file_path, | |
| 361 const FilePath& dest_file_path, | |
| 362 base::FileUtilProxy::StatusCallback* callback) | |
| 363 : RelayWithStatusCallback(callback), | |
| 364 src_file_path_(src_file_path), | |
| 365 dest_file_path_(dest_file_path) { | |
| 366 } | |
| 367 | |
| 368 protected: | |
| 369 virtual void RunWork() { | |
| 370 set_error_code(PerformCommonCheckAndPreparationForMoveAndCopy( | |
| 371 src_file_path_, dest_file_path_)); | |
| 372 if (error_code() != base::PLATFORM_FILE_OK) | |
| 373 return; | |
| 374 if (!file_util::Move(src_file_path_, dest_file_path_)) | |
| 375 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 376 } | |
| 377 | |
| 378 private: | |
| 379 FilePath src_file_path_; | |
| 380 FilePath dest_file_path_; | |
| 381 }; | |
| 382 | |
| 383 class RelayCreateDirectory : public RelayWithStatusCallback { | |
| 384 public: | |
| 385 RelayCreateDirectory( | |
| 386 const FilePath& file_path, | |
| 387 bool exclusive, | |
| 388 bool recursive, | |
| 389 base::FileUtilProxy::StatusCallback* callback) | |
| 390 : RelayWithStatusCallback(callback), | |
| 391 file_path_(file_path), | |
| 392 exclusive_(exclusive), | |
| 393 recursive_(recursive) { | |
| 394 } | |
| 395 | |
| 396 protected: | |
| 397 virtual void RunWork() { | |
| 398 bool path_exists = file_util::PathExists(file_path_); | |
| 399 // If parent dir of file doesn't exist. | |
| 400 if (!recursive_ && !file_util::PathExists(file_path_.DirName())) { | |
| 401 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); | |
| 402 return; | |
| 403 } | |
| 404 if (exclusive_ && path_exists) { | |
| 405 set_error_code(base::PLATFORM_FILE_ERROR_EXISTS); | |
| 406 return; | |
| 407 } | |
| 408 // If file exists at the path. | |
| 409 if (path_exists && !file_util::DirectoryExists(file_path_)) { | |
| 410 set_error_code(base::PLATFORM_FILE_ERROR_EXISTS); | |
| 411 return; | |
| 412 } | |
| 413 if (!file_util::CreateDirectory(file_path_)) | |
| 414 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 415 } | |
| 416 | |
| 417 private: | |
| 418 FilePath file_path_; | |
| 419 bool exclusive_; | |
| 420 bool recursive_; | |
| 421 }; | 218 }; |
| 422 | 219 |
| 423 class RelayReadDirectory : public MessageLoopRelay { | 220 class RelayReadDirectory : public MessageLoopRelay { |
| 424 public: | 221 public: |
| 425 RelayReadDirectory(const FilePath& file_path, | 222 RelayReadDirectory( |
| 426 base::FileUtilProxy::ReadDirectoryCallback* callback) | 223 fileapi::FileSystemOperationContext* context, |
| 427 : callback_(callback), file_path_(file_path) { | 224 const FilePath& file_path, |
| 225 fileapi::FileSystemFileUtilProxy::ReadDirectoryCallback* callback) | |
| 226 : MessageLoopRelay(context), | |
| 227 callback_(callback), file_path_(file_path) { | |
| 428 DCHECK(callback); | 228 DCHECK(callback); |
| 429 } | 229 } |
| 430 | 230 |
| 431 protected: | 231 protected: |
| 432 virtual void RunWork() { | 232 virtual void RunWork() { |
| 433 // TODO(kkanetkar): Implement directory read in multiple chunks. | 233 // TODO(kkanetkar): Implement directory read in multiple chunks. |
| 434 if (!file_util::DirectoryExists(file_path_)) { | 234 set_error_code( |
| 435 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 235 file_system_file_util()->ReadDirectory( |
| 436 return; | 236 context(), file_path_, &entries_)); |
| 437 } | |
| 438 | |
| 439 file_util::FileEnumerator file_enum( | |
| 440 file_path_, false, static_cast<file_util::FileEnumerator::FILE_TYPE>( | |
| 441 file_util::FileEnumerator::FILES | | |
| 442 file_util::FileEnumerator::DIRECTORIES)); | |
| 443 FilePath current; | |
| 444 while (!(current = file_enum.Next()).empty()) { | |
| 445 base::FileUtilProxy::Entry entry; | |
| 446 file_util::FileEnumerator::FindInfo info; | |
| 447 file_enum.GetFindInfo(&info); | |
| 448 entry.is_directory = file_enum.IsDirectory(info); | |
| 449 // This will just give the entry's name instead of entire path | |
| 450 // if we use current.value(). | |
| 451 entry.name = file_util::FileEnumerator::GetFilename(info).value(); | |
| 452 entries_.push_back(entry); | |
| 453 } | |
| 454 } | 237 } |
| 455 | 238 |
| 456 virtual void RunCallback() { | 239 virtual void RunCallback() { |
| 457 callback_->Run(error_code(), entries_); | 240 callback_->Run(error_code(), entries_); |
| 458 delete callback_; | 241 delete callback_; |
| 459 } | 242 } |
| 460 | 243 |
| 461 private: | 244 private: |
| 462 base::FileUtilProxy::ReadDirectoryCallback* callback_; | 245 fileapi::FileSystemFileUtilProxy::ReadDirectoryCallback* callback_; |
| 463 FilePath file_path_; | 246 FilePath file_path_; |
| 464 std::vector<base::FileUtilProxy::Entry> entries_; | 247 std::vector<fileapi::FileSystemFileUtilProxy::Entry> entries_; |
| 465 }; | 248 }; |
| 466 | 249 |
| 467 class RelayGetFileInfo : public MessageLoopRelay { | 250 class RelayCreateDirectory : public RelayWithStatusCallback { |
| 468 public: | 251 public: |
| 469 RelayGetFileInfo(const FilePath& file_path, | 252 RelayCreateDirectory( |
| 470 base::FileUtilProxy::GetFileInfoCallback* callback) | 253 fileapi::FileSystemOperationContext* context, |
| 471 : callback_(callback), | 254 const FilePath& file_path, |
| 472 file_path_(file_path) { | 255 bool exclusive, |
| 473 DCHECK(callback); | 256 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 257 : RelayWithStatusCallback(context, callback), | |
| 258 file_path_(file_path), | |
| 259 exclusive_(exclusive) { | |
| 474 } | 260 } |
| 475 | 261 |
| 476 protected: | 262 protected: |
| 477 virtual void RunWork() { | 263 virtual void RunWork() { |
| 478 if (!file_util::PathExists(file_path_)) { | 264 set_error_code( |
| 479 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 265 file_system_file_util()->CreateDirectory( |
| 480 return; | 266 context(), file_path_, exclusive_)); |
| 481 } | |
| 482 if (!file_util::GetFileInfo(file_path_, &file_info_)) | |
| 483 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 484 } | |
| 485 | |
| 486 virtual void RunCallback() { | |
| 487 callback_->Run(error_code(), file_info_); | |
| 488 delete callback_; | |
| 489 } | 267 } |
| 490 | 268 |
| 491 private: | 269 private: |
| 492 base::FileUtilProxy::GetFileInfoCallback* callback_; | |
| 493 FilePath file_path_; | 270 FilePath file_path_; |
| 494 base::PlatformFileInfo file_info_; | 271 bool exclusive_; |
| 495 }; | 272 }; |
| 496 | 273 |
| 497 class RelayGetFileInfoFromPlatformFile : public MessageLoopRelay { | 274 class RelayCopy : public RelayWithStatusCallback { |
| 498 public: | 275 public: |
| 499 RelayGetFileInfoFromPlatformFile( | 276 RelayCopy(fileapi::FileSystemOperationContext* context, |
| 500 base::PlatformFile file, | 277 const FilePath& src_file_path, |
| 501 base::FileUtilProxy::GetFileInfoCallback* callback) | 278 const FilePath& dest_file_path, |
| 502 : callback_(callback), | 279 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 503 file_(file) { | 280 : RelayWithStatusCallback(context, callback), |
| 504 DCHECK(callback); | 281 src_file_path_(src_file_path), |
| 282 dest_file_path_(dest_file_path) { | |
| 505 } | 283 } |
| 506 | 284 |
| 507 protected: | 285 protected: |
| 508 virtual void RunWork() { | 286 virtual void RunWork() { |
| 509 if (!base::GetPlatformFileInfo(file_, &file_info_)) | 287 set_error_code( |
| 510 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | 288 file_system_file_util()->Copy( |
| 511 } | 289 context(), src_file_path_, dest_file_path_)); |
| 512 | |
| 513 virtual void RunCallback() { | |
| 514 callback_->Run(error_code(), file_info_); | |
| 515 delete callback_; | |
| 516 } | 290 } |
| 517 | 291 |
| 518 private: | 292 private: |
| 519 base::FileUtilProxy::GetFileInfoCallback* callback_; | 293 FilePath src_file_path_; |
| 520 base::PlatformFile file_; | 294 FilePath dest_file_path_; |
| 521 base::PlatformFileInfo file_info_; | |
| 522 }; | 295 }; |
| 523 | 296 |
| 524 class RelayRead : public MessageLoopRelay { | 297 class RelayMove : public RelayWithStatusCallback { |
| 525 public: | 298 public: |
| 526 RelayRead(base::PlatformFile file, | 299 RelayMove(fileapi::FileSystemOperationContext* context, |
| 527 int64 offset, | 300 const FilePath& src_file_path, |
| 528 int bytes_to_read, | 301 const FilePath& dest_file_path, |
| 529 base::FileUtilProxy::ReadCallback* callback) | 302 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 530 : file_(file), | 303 : RelayWithStatusCallback(context, callback), |
| 531 offset_(offset), | 304 src_file_path_(src_file_path), |
| 532 buffer_(new char[bytes_to_read]), | 305 dest_file_path_(dest_file_path) { |
| 533 bytes_to_read_(bytes_to_read), | |
| 534 callback_(callback), | |
| 535 bytes_read_(0) { | |
| 536 } | 306 } |
| 537 | 307 |
| 538 protected: | 308 protected: |
| 539 virtual void RunWork() { | 309 virtual void RunWork() { |
| 540 bytes_read_ = base::ReadPlatformFile(file_, offset_, buffer_.get(), | 310 set_error_code( |
| 541 bytes_to_read_); | 311 file_system_file_util()->Move( |
| 542 if (bytes_read_ < 0) | 312 context(), src_file_path_, dest_file_path_)); |
| 543 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 544 } | |
| 545 | |
| 546 virtual void RunCallback() { | |
| 547 if (callback_) { | |
| 548 callback_->Run(error_code(), buffer_.get(), bytes_read_); | |
| 549 delete callback_; | |
| 550 } | |
| 551 } | 313 } |
| 552 | 314 |
| 553 private: | 315 private: |
| 554 base::PlatformFile file_; | 316 FilePath src_file_path_; |
| 555 int64 offset_; | 317 FilePath dest_file_path_; |
| 556 scoped_array<char> buffer_; | |
| 557 int bytes_to_read_; | |
| 558 base::FileUtilProxy::ReadCallback* callback_; | |
| 559 int bytes_read_; | |
| 560 }; | 318 }; |
| 561 | 319 |
| 562 class RelayWrite : public MessageLoopRelay { | 320 class RelayDelete : public RelayWithStatusCallback { |
| 563 public: | 321 public: |
| 564 RelayWrite(base::PlatformFile file, | 322 RelayDelete(fileapi::FileSystemOperationContext* context, |
| 565 int64 offset, | 323 const FilePath& file_path, |
| 566 const char* buffer, | 324 bool recursive, |
| 567 int bytes_to_write, | 325 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 568 base::FileUtilProxy::WriteCallback* callback) | 326 : RelayWithStatusCallback(context, callback), |
| 569 : file_(file), | 327 file_path_(file_path), |
| 570 offset_(offset), | 328 recursive_(recursive) { |
| 571 buffer_(new char[bytes_to_write]), | |
| 572 bytes_to_write_(bytes_to_write), | |
| 573 callback_(callback) { | |
| 574 memcpy(buffer_.get(), buffer, bytes_to_write); | |
| 575 } | 329 } |
| 576 | 330 |
| 577 protected: | 331 protected: |
| 578 virtual void RunWork() { | 332 virtual void RunWork() { |
| 579 bytes_written_ = base::WritePlatformFile(file_, offset_, buffer_.get(), | 333 set_error_code( |
| 580 bytes_to_write_); | 334 file_system_file_util()->Delete( |
| 581 if (bytes_written_ < 0) | 335 context(), file_path_, recursive_)); |
| 582 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 583 } | |
| 584 | |
| 585 virtual void RunCallback() { | |
| 586 if (callback_) { | |
| 587 callback_->Run(error_code(), bytes_written_); | |
| 588 delete callback_; | |
| 589 } | |
| 590 } | 336 } |
| 591 | 337 |
| 592 private: | 338 private: |
| 593 base::PlatformFile file_; | 339 FilePath file_path_; |
| 594 int64 offset_; | 340 bool recursive_; |
| 595 scoped_array<char> buffer_; | |
| 596 int bytes_to_write_; | |
| 597 base::FileUtilProxy::WriteCallback* callback_; | |
| 598 int bytes_written_; | |
| 599 }; | |
| 600 | |
| 601 class RelayTouch : public RelayWithStatusCallback { | |
| 602 public: | |
| 603 RelayTouch(base::PlatformFile file, | |
| 604 const base::Time& last_access_time, | |
| 605 const base::Time& last_modified_time, | |
| 606 base::FileUtilProxy::StatusCallback* callback) | |
| 607 : RelayWithStatusCallback(callback), | |
| 608 file_(file), | |
| 609 last_access_time_(last_access_time), | |
| 610 last_modified_time_(last_modified_time) { | |
| 611 } | |
| 612 | |
| 613 protected: | |
| 614 virtual void RunWork() { | |
| 615 if (!base::TouchPlatformFile(file_, last_access_time_, last_modified_time_)) | |
| 616 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 617 } | |
| 618 | |
| 619 private: | |
| 620 base::PlatformFile file_; | |
| 621 base::Time last_access_time_; | |
| 622 base::Time last_modified_time_; | |
| 623 }; | 341 }; |
| 624 | 342 |
| 625 class RelayTouchFilePath : public RelayWithStatusCallback { | 343 class RelayTouchFilePath : public RelayWithStatusCallback { |
| 626 public: | 344 public: |
| 627 RelayTouchFilePath(const FilePath& file_path, | 345 RelayTouchFilePath(fileapi::FileSystemOperationContext* context, |
| 346 const FilePath& file_path, | |
| 628 const base::Time& last_access_time, | 347 const base::Time& last_access_time, |
| 629 const base::Time& last_modified_time, | 348 const base::Time& last_modified_time, |
| 630 base::FileUtilProxy::StatusCallback* callback) | 349 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 631 : RelayWithStatusCallback(callback), | 350 : RelayWithStatusCallback(context, callback), |
| 632 file_path_(file_path), | 351 file_path_(file_path), |
| 633 last_access_time_(last_access_time), | 352 last_access_time_(last_access_time), |
| 634 last_modified_time_(last_modified_time) { | 353 last_modified_time_(last_modified_time) { |
| 635 } | 354 } |
| 636 | 355 |
| 637 protected: | 356 protected: |
| 638 virtual void RunWork() { | 357 virtual void RunWork() { |
| 639 if (!file_util::TouchFile( | 358 set_error_code( |
| 640 file_path_, last_access_time_, last_modified_time_)) | 359 file_system_file_util()->Touch( |
| 641 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | 360 context(), file_path_, last_access_time_, last_modified_time_)); |
| 642 } | 361 } |
| 643 | 362 |
| 644 private: | 363 private: |
| 645 FilePath file_path_; | 364 FilePath file_path_; |
| 646 base::Time last_access_time_; | 365 base::Time last_access_time_; |
| 647 base::Time last_modified_time_; | 366 base::Time last_modified_time_; |
| 648 }; | 367 }; |
| 649 | 368 |
| 650 class RelayTruncatePlatformFile : public RelayWithStatusCallback { | 369 class RelayTruncate : public RelayWithStatusCallback { |
| 651 public: | 370 public: |
| 652 RelayTruncatePlatformFile(base::PlatformFile file, | 371 RelayTruncate(fileapi::FileSystemOperationContext* context, |
| 653 int64 length, | 372 const FilePath& file_path, |
| 654 base::FileUtilProxy::StatusCallback* callback) | 373 int64 length, |
| 655 : RelayWithStatusCallback(callback), | 374 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 656 file_(file), | 375 : RelayWithStatusCallback(context, callback), |
| 376 file_path_(file_path), | |
| 657 length_(length) { | 377 length_(length) { |
| 658 } | 378 } |
| 659 | 379 |
| 660 protected: | 380 protected: |
| 661 virtual void RunWork() { | 381 virtual void RunWork() { |
| 662 if (!base::TruncatePlatformFile(file_, length_)) | 382 set_error_code( |
| 663 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | 383 file_system_file_util()->Truncate(context(), file_path_, length_)); |
| 664 } | 384 } |
| 665 | 385 |
| 666 private: | 386 private: |
| 667 base::PlatformFile file_; | 387 FilePath file_path_; |
| 668 int64 length_; | 388 int64 length_; |
| 669 }; | 389 }; |
| 670 | 390 |
| 671 class RelayTruncate : public RelayWithStatusCallback { | |
| 672 public: | |
| 673 RelayTruncate(const FilePath& path, | |
| 674 int64 length, | |
| 675 base::FileUtilProxy::StatusCallback* callback) | |
| 676 : RelayWithStatusCallback(callback), | |
| 677 path_(path), | |
| 678 length_(length) { | |
| 679 } | |
| 680 | |
| 681 protected: | |
| 682 virtual void RunWork() { | |
| 683 base::PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 684 base::PlatformFile file = | |
| 685 base::CreatePlatformFile( | |
| 686 path_, | |
| 687 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | |
| 688 NULL, | |
| 689 &error_code); | |
| 690 if (error_code != base::PLATFORM_FILE_OK) { | |
| 691 set_error_code(error_code); | |
| 692 return; | |
| 693 } | |
| 694 if (!base::TruncatePlatformFile(file, length_)) | |
| 695 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 696 base::ClosePlatformFile(file); | |
| 697 } | |
| 698 | |
| 699 private: | |
| 700 FilePath path_; | |
| 701 int64 length_; | |
| 702 }; | |
| 703 | |
| 704 class RelayFlush : public RelayWithStatusCallback { | |
| 705 public: | |
| 706 RelayFlush(base::PlatformFile file, | |
| 707 base::FileUtilProxy::StatusCallback* callback) | |
| 708 : RelayWithStatusCallback(callback), | |
| 709 file_(file) { | |
| 710 } | |
| 711 | |
| 712 protected: | |
| 713 virtual void RunWork() { | |
| 714 if (!base::FlushPlatformFile(file_)) | |
| 715 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
| 716 } | |
| 717 | |
| 718 private: | |
| 719 base::PlatformFile file_; | |
| 720 }; | |
| 721 | |
| 722 bool Start(const tracked_objects::Location& from_here, | 391 bool Start(const tracked_objects::Location& from_here, |
| 723 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 392 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 724 scoped_refptr<MessageLoopRelay> relay) { | 393 scoped_refptr<MessageLoopRelay> relay) { |
| 725 return relay->Start(message_loop_proxy, from_here); | 394 return relay->Start(message_loop_proxy, from_here); |
| 726 } | 395 } |
| 727 | 396 |
| 728 } // namespace | 397 } // namespace |
| 729 | 398 |
| 730 namespace base { | 399 namespace fileapi { |
| 731 | 400 |
| 732 // static | 401 // static |
| 733 bool FileUtilProxy::CreateOrOpen( | 402 bool FileSystemFileUtilProxy::CreateOrOpen( |
| 403 FileSystemOperationContext* context, | |
| 734 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 404 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 735 const FilePath& file_path, int file_flags, | 405 const FilePath& file_path, int file_flags, |
| 736 CreateOrOpenCallback* callback) { | 406 CreateOrOpenCallback* callback) { |
| 737 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen( | 407 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(context, |
| 738 message_loop_proxy, file_path, file_flags, callback)); | 408 message_loop_proxy, file_path, file_flags, callback)); |
| 739 } | 409 } |
| 740 | 410 |
| 741 // static | 411 // static |
| 742 bool FileUtilProxy::CreateTemporary( | 412 bool FileSystemFileUtilProxy::Close( |
| 413 FileSystemOperationContext* context, | |
| 743 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 414 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 744 CreateTemporaryCallback* callback) { | 415 base::PlatformFile file_handle, |
| 416 StatusCallback* callback) { | |
| 745 return Start(FROM_HERE, message_loop_proxy, | 417 return Start(FROM_HERE, message_loop_proxy, |
| 746 new RelayCreateTemporary(message_loop_proxy, callback)); | 418 new RelayClose(context, file_handle, callback)); |
| 747 } | 419 } |
| 748 | 420 |
| 749 // static | 421 // static |
| 750 bool FileUtilProxy::Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 422 bool FileSystemFileUtilProxy::EnsureFileExists( |
| 751 base::PlatformFile file_handle, | 423 FileSystemOperationContext* context, |
| 752 StatusCallback* callback) { | |
| 753 return Start(FROM_HERE, message_loop_proxy, | |
| 754 new RelayClose(file_handle, callback)); | |
| 755 } | |
| 756 | |
| 757 // static | |
| 758 bool FileUtilProxy::EnsureFileExists( | |
| 759 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 424 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 760 const FilePath& file_path, | 425 const FilePath& file_path, |
| 761 EnsureFileExistsCallback* callback) { | 426 EnsureFileExistsCallback* callback) { |
| 762 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( | 427 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( |
| 763 message_loop_proxy, file_path, callback)); | 428 context, message_loop_proxy, file_path, callback)); |
| 764 } | 429 } |
| 765 | 430 |
| 766 // Retrieves the information about a file. It is invalid to pass NULL for the | 431 // Retrieves the information about a file. It is invalid to pass NULL for the |
| 767 // callback. | 432 // callback. |
| 768 bool FileUtilProxy::GetFileInfo( | 433 bool FileSystemFileUtilProxy::GetFileInfo( |
| 434 FileSystemOperationContext* context, | |
| 769 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 435 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 770 const FilePath& file_path, | 436 const FilePath& file_path, |
| 771 GetFileInfoCallback* callback) { | 437 GetFileInfoCallback* callback) { |
| 772 return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo( | 438 return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo(context, |
| 773 file_path, callback)); | 439 file_path, callback)); |
| 774 } | 440 } |
| 775 | 441 |
| 776 // static | 442 // static |
| 777 bool FileUtilProxy::GetFileInfoFromPlatformFile( | 443 bool FileSystemFileUtilProxy::ReadDirectory( |
| 778 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 444 FileSystemOperationContext* context, |
| 779 PlatformFile file, | |
| 780 GetFileInfoCallback* callback) { | |
| 781 return Start(FROM_HERE, message_loop_proxy, | |
| 782 new RelayGetFileInfoFromPlatformFile(file, callback)); | |
| 783 } | |
| 784 | |
| 785 // static | |
| 786 bool FileUtilProxy::ReadDirectory( | |
| 787 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 445 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 788 const FilePath& file_path, | 446 const FilePath& file_path, |
| 789 ReadDirectoryCallback* callback) { | 447 ReadDirectoryCallback* callback) { |
| 790 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory( | 448 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory(context, |
| 791 file_path, callback)); | 449 file_path, callback)); |
| 792 } | 450 } |
| 793 | 451 |
| 794 // static | 452 // static |
| 795 bool FileUtilProxy::CreateDirectory( | 453 bool FileSystemFileUtilProxy::CreateDirectory( |
| 454 FileSystemOperationContext* context, | |
| 796 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 455 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 797 const FilePath& file_path, | 456 const FilePath& file_path, |
| 798 bool exclusive, | 457 bool exclusive, |
| 799 bool recursive, | |
| 800 StatusCallback* callback) { | 458 StatusCallback* callback) { |
| 801 return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory( | 459 return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory( |
| 802 file_path, exclusive, recursive, callback)); | 460 context, file_path, exclusive, callback)); |
| 803 } | 461 } |
| 804 | 462 |
| 805 // static | 463 // static |
| 806 bool FileUtilProxy::Copy(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 464 bool FileSystemFileUtilProxy::Copy( |
| 807 const FilePath& src_file_path, | 465 FileSystemOperationContext* context, |
| 808 const FilePath& dest_file_path, | 466 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 809 StatusCallback* callback) { | 467 const FilePath& src_file_path, |
| 468 const FilePath& dest_file_path, | |
| 469 StatusCallback* callback) { | |
| 810 return Start(FROM_HERE, message_loop_proxy, | 470 return Start(FROM_HERE, message_loop_proxy, |
| 811 new RelayCopy(src_file_path, dest_file_path, callback)); | 471 new RelayCopy(context, src_file_path, dest_file_path, |
| 472 callback)); | |
| 812 } | 473 } |
| 813 | 474 |
| 814 // static | 475 // static |
| 815 bool FileUtilProxy::Move(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 476 bool FileSystemFileUtilProxy::Move( |
| 816 const FilePath& src_file_path, | 477 FileSystemOperationContext* context, |
| 817 const FilePath& dest_file_path, | 478 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 818 StatusCallback* callback) { | 479 const FilePath& src_file_path, |
| 480 const FilePath& dest_file_path, | |
| 481 StatusCallback* callback) { | |
| 819 return Start(FROM_HERE, message_loop_proxy, | 482 return Start(FROM_HERE, message_loop_proxy, |
| 820 new RelayMove(src_file_path, dest_file_path, callback)); | 483 new RelayMove(context, src_file_path, dest_file_path, |
| 484 callback)); | |
| 821 } | 485 } |
| 822 | 486 |
| 823 // static | 487 // static |
| 824 bool FileUtilProxy::Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 488 bool FileSystemFileUtilProxy::Delete( |
| 825 const FilePath& file_path, | 489 FileSystemOperationContext* context, |
| 826 bool recursive, | 490 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 827 StatusCallback* callback) { | 491 const FilePath& file_path, |
| 492 bool recursive, | |
| 493 StatusCallback* callback) { | |
| 828 return Start(FROM_HERE, message_loop_proxy, | 494 return Start(FROM_HERE, message_loop_proxy, |
| 829 new RelayDelete(file_path, recursive, callback)); | 495 new RelayDelete(context, file_path, recursive, callback)); |
| 830 } | 496 } |
| 831 | 497 |
| 832 // static | 498 // static |
| 833 bool FileUtilProxy::RecursiveDelete( | 499 bool FileSystemFileUtilProxy::Touch( |
| 834 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 500 FileSystemOperationContext* context, |
| 835 const FilePath& file_path, | |
| 836 StatusCallback* callback) { | |
| 837 return Start(FROM_HERE, message_loop_proxy, | |
| 838 new RelayDelete(file_path, true, callback)); | |
| 839 } | |
| 840 | |
| 841 // static | |
| 842 bool FileUtilProxy::Read( | |
| 843 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 844 PlatformFile file, | |
| 845 int64 offset, | |
| 846 int bytes_to_read, | |
| 847 ReadCallback* callback) { | |
| 848 return Start(FROM_HERE, message_loop_proxy, | |
| 849 new RelayRead(file, offset, bytes_to_read, callback)); | |
| 850 } | |
| 851 | |
| 852 // static | |
| 853 bool FileUtilProxy::Write( | |
| 854 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 855 PlatformFile file, | |
| 856 int64 offset, | |
| 857 const char* buffer, | |
| 858 int bytes_to_write, | |
| 859 WriteCallback* callback) { | |
| 860 return Start(FROM_HERE, message_loop_proxy, | |
| 861 new RelayWrite(file, offset, buffer, bytes_to_write, callback)); | |
| 862 } | |
| 863 | |
| 864 // static | |
| 865 bool FileUtilProxy::Touch( | |
| 866 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 867 PlatformFile file, | |
| 868 const base::Time& last_access_time, | |
| 869 const base::Time& last_modified_time, | |
| 870 StatusCallback* callback) { | |
| 871 return Start(FROM_HERE, message_loop_proxy, | |
| 872 new RelayTouch(file, last_access_time, last_modified_time, | |
| 873 callback)); | |
| 874 } | |
| 875 | |
| 876 // static | |
| 877 bool FileUtilProxy::Touch( | |
| 878 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 501 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 879 const FilePath& file_path, | 502 const FilePath& file_path, |
| 880 const base::Time& last_access_time, | 503 const base::Time& last_access_time, |
| 881 const base::Time& last_modified_time, | 504 const base::Time& last_modified_time, |
| 882 StatusCallback* callback) { | 505 StatusCallback* callback) { |
| 883 return Start(FROM_HERE, message_loop_proxy, | 506 return Start(FROM_HERE, message_loop_proxy, |
| 884 new RelayTouchFilePath(file_path, last_access_time, | 507 new RelayTouchFilePath(context, file_path, last_access_time, |
| 885 last_modified_time, callback)); | 508 last_modified_time, callback)); |
| 886 } | 509 } |
| 887 | 510 |
| 888 // static | 511 // static |
| 889 bool FileUtilProxy::Truncate( | 512 bool FileSystemFileUtilProxy::Truncate( |
| 890 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 513 FileSystemOperationContext* context, |
| 891 PlatformFile file, | |
| 892 int64 length, | |
| 893 StatusCallback* callback) { | |
| 894 return Start(FROM_HERE, message_loop_proxy, | |
| 895 new RelayTruncatePlatformFile(file, length, callback)); | |
| 896 } | |
| 897 | |
| 898 // static | |
| 899 bool FileUtilProxy::Truncate( | |
| 900 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 514 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 901 const FilePath& path, | 515 const FilePath& path, |
| 902 int64 length, | 516 int64 length, |
| 903 StatusCallback* callback) { | 517 StatusCallback* callback) { |
| 904 return Start(FROM_HERE, message_loop_proxy, | 518 return Start(FROM_HERE, message_loop_proxy, |
| 905 new RelayTruncate(path, length, callback)); | 519 new RelayTruncate(context, path, length, callback)); |
| 906 } | 520 } |
| 907 | 521 |
| 908 // static | 522 } // namespace fileapi |
| 909 bool FileUtilProxy::Flush( | |
| 910 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 911 PlatformFile file, | |
| 912 StatusCallback* callback) { | |
| 913 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); | |
| 914 } | |
| 915 | |
| 916 } // namespace base | |
| OLD | NEW |