dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/file_util_proxy.h" |
| 6 | |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 7 | #include "base/message_loop_proxy.h" |
| 8 | |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 9 | // TODO(jianli): Move the code from anonymous namespace to base namespace so |
| 10 | // that all of the base:: prefixes would be unnecessary. |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 11 | namespace { |
| 12 | |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 13 | namespace { |
| 14 | |
| 15 | // Performs common checks for move and copy. |
| 16 | // This also removes the destination directory if it's non-empty and all other |
kinuko@chromium.org | 850eb6d | 2010-10-15 09:37:34 +0900 | [diff] [blame] | 17 | // checks are passed (so that the copy/move correctly overwrites the |
| 18 | // destination). |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 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 | |
kkanetkar@chromium.org | 4871068 | 2010-11-03 05:36:52 +0900 | [diff] [blame^] | 69 | } // anonymous namespace |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 70 | |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 71 | class MessageLoopRelay |
| 72 | : public base::RefCountedThreadSafe<MessageLoopRelay> { |
| 73 | public: |
| 74 | MessageLoopRelay() |
| 75 | : origin_message_loop_proxy_( |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 76 | base::MessageLoopProxy::CreateForCurrentThread()), |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 77 | error_code_(base::PLATFORM_FILE_OK) { |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 78 | } |
| 79 | |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 80 | bool Start(scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 81 | const tracked_objects::Location& from_here) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 82 | return message_loop_proxy->PostTask( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 83 | from_here, |
| 84 | NewRunnableMethod(this, &MessageLoopRelay::ProcessOnTargetThread)); |
| 85 | } |
| 86 | |
| 87 | protected: |
| 88 | friend class base::RefCountedThreadSafe<MessageLoopRelay>; |
| 89 | virtual ~MessageLoopRelay() {} |
| 90 | |
| 91 | // Called to perform work on the FILE thread. |
| 92 | virtual void RunWork() = 0; |
| 93 | |
| 94 | // Called to notify the callback on the origin thread. |
| 95 | virtual void RunCallback() = 0; |
| 96 | |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 97 | void set_error_code(base::PlatformFileError error_code) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 98 | error_code_ = error_code; |
| 99 | } |
| 100 | |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 101 | base::PlatformFileError error_code() const { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 102 | return error_code_; |
| 103 | } |
| 104 | |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 105 | private: |
| 106 | void ProcessOnTargetThread() { |
| 107 | RunWork(); |
| 108 | origin_message_loop_proxy_->PostTask( |
| 109 | FROM_HERE, |
| 110 | NewRunnableMethod(this, &MessageLoopRelay::RunCallback)); |
| 111 | } |
| 112 | |
| 113 | scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 114 | base::PlatformFileError error_code_; |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | class RelayCreateOrOpen : public MessageLoopRelay { |
| 118 | public: |
| 119 | RelayCreateOrOpen( |
| 120 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 121 | const FilePath& file_path, |
| 122 | int file_flags, |
| 123 | base::FileUtilProxy::CreateOrOpenCallback* callback) |
| 124 | : message_loop_proxy_(message_loop_proxy), |
| 125 | file_path_(file_path), |
| 126 | file_flags_(file_flags), |
| 127 | callback_(callback), |
| 128 | file_handle_(base::kInvalidPlatformFileValue), |
| 129 | created_(false) { |
| 130 | DCHECK(callback); |
| 131 | } |
| 132 | |
| 133 | protected: |
| 134 | virtual ~RelayCreateOrOpen() { |
| 135 | if (file_handle_ != base::kInvalidPlatformFileValue) |
| 136 | base::FileUtilProxy::Close(message_loop_proxy_, file_handle_, NULL); |
| 137 | } |
| 138 | |
| 139 | virtual void RunWork() { |
kinuko@chromium.org | af334b2 | 2010-10-12 11:17:14 +0900 | [diff] [blame] | 140 | if (!file_util::DirectoryExists(file_path_.DirName())) { |
| 141 | // If its parent does not exist, should return NOT_FOUND error. |
| 142 | set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 143 | return; |
| 144 | } |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 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); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | virtual void RunCallback() { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 152 | callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), |
| 153 | created_); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 154 | delete callback_; |
| 155 | } |
| 156 | |
| 157 | private: |
| 158 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 159 | FilePath file_path_; |
| 160 | int file_flags_; |
| 161 | base::FileUtilProxy::CreateOrOpenCallback* callback_; |
| 162 | base::PlatformFile file_handle_; |
| 163 | bool created_; |
| 164 | }; |
| 165 | |
| 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; |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 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); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | virtual void RunCallback() { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 202 | callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), |
| 203 | file_path_); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 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 { |
| 215 | public: |
| 216 | explicit RelayWithStatusCallback( |
| 217 | base::FileUtilProxy::StatusCallback* callback) |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 218 | : callback_(callback) { |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 219 | // It is OK for callback to be NULL. |
| 220 | } |
| 221 | |
| 222 | protected: |
| 223 | virtual void RunCallback() { |
| 224 | // The caller may not have been interested in the result. |
| 225 | if (callback_) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 226 | callback_->Run(error_code()); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 227 | delete callback_; |
| 228 | } |
| 229 | } |
| 230 | |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 231 | private: |
| 232 | base::FileUtilProxy::StatusCallback* callback_; |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | class RelayClose : public RelayWithStatusCallback { |
| 236 | public: |
| 237 | RelayClose(base::PlatformFile file_handle, |
| 238 | base::FileUtilProxy::StatusCallback* callback) |
| 239 | : RelayWithStatusCallback(callback), |
| 240 | file_handle_(file_handle) { |
| 241 | } |
| 242 | |
| 243 | protected: |
| 244 | virtual void RunWork() { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 245 | if (!base::ClosePlatformFile(file_handle_)) |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 246 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | private: |
| 250 | base::PlatformFile file_handle_; |
| 251 | }; |
| 252 | |
kinuko@chromium.org | 850eb6d | 2010-10-15 09:37:34 +0900 | [diff] [blame] | 253 | class RelayEnsureFileExists : public MessageLoopRelay { |
| 254 | public: |
| 255 | RelayEnsureFileExists( |
| 256 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 257 | const FilePath& file_path, |
| 258 | base::FileUtilProxy::EnsureFileExistsCallback* callback) |
| 259 | : message_loop_proxy_(message_loop_proxy), |
| 260 | file_path_(file_path), |
| 261 | callback_(callback), |
| 262 | created_(false) { |
| 263 | DCHECK(callback); |
| 264 | } |
| 265 | |
| 266 | protected: |
| 267 | virtual void RunWork() { |
| 268 | if (!file_util::DirectoryExists(file_path_.DirName())) { |
| 269 | // If its parent does not exist, should return NOT_FOUND error. |
| 270 | set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 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 | } |
| 289 | |
| 290 | virtual void RunCallback() { |
| 291 | callback_->Run(error_code(), created_); |
| 292 | delete callback_; |
| 293 | } |
| 294 | |
| 295 | private: |
| 296 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 297 | FilePath file_path_; |
| 298 | base::FileUtilProxy::EnsureFileExistsCallback* callback_; |
| 299 | bool created_; |
| 300 | }; |
| 301 | |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 302 | class RelayDelete : public RelayWithStatusCallback { |
| 303 | public: |
| 304 | RelayDelete(const FilePath& file_path, |
| 305 | bool recursive, |
| 306 | base::FileUtilProxy::StatusCallback* callback) |
| 307 | : RelayWithStatusCallback(callback), |
| 308 | file_path_(file_path), |
| 309 | recursive_(recursive) { |
| 310 | } |
| 311 | |
| 312 | protected: |
| 313 | virtual void RunWork() { |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 314 | if (!file_util::PathExists(file_path_)) { |
| 315 | set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 316 | return; |
| 317 | } |
| 318 | if (!file_util::Delete(file_path_, recursive_)) { |
| 319 | if (!recursive_ && !file_util::IsDirectoryEmpty(file_path_)) { |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 320 | set_error_code(base::PLATFORM_FILE_ERROR_NOT_EMPTY); |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 321 | return; |
| 322 | } |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 323 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 324 | } |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | private: |
| 328 | FilePath file_path_; |
| 329 | bool recursive_; |
| 330 | }; |
| 331 | |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 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() { |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 344 | set_error_code(PerformCommonCheckAndPreparationForMoveAndCopy( |
| 345 | src_file_path_, dest_file_path_)); |
| 346 | if (error_code() != base::PLATFORM_FILE_OK) |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 347 | return; |
kinuko@chromium.org | 31583c3 | 2010-10-07 06:44:35 +0900 | [diff] [blame] | 348 | if (!file_util::CopyDirectory(src_file_path_, dest_file_path_, |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 349 | true /* recursive */)) |
kinuko@chromium.org | 31583c3 | 2010-10-07 06:44:35 +0900 | [diff] [blame] | 350 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 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() { |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 370 | set_error_code(PerformCommonCheckAndPreparationForMoveAndCopy( |
| 371 | src_file_path_, dest_file_path_)); |
| 372 | if (error_code() != base::PLATFORM_FILE_OK) |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 373 | return; |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 374 | if (!file_util::Move(src_file_path_, dest_file_path_)) |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 375 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 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, |
kinuko@chromium.org | c483d79 | 2010-09-08 09:50:41 +0900 | [diff] [blame] | 388 | bool recursive, |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 389 | base::FileUtilProxy::StatusCallback* callback) |
| 390 | : RelayWithStatusCallback(callback), |
| 391 | file_path_(file_path), |
kinuko@chromium.org | c483d79 | 2010-09-08 09:50:41 +0900 | [diff] [blame] | 392 | exclusive_(exclusive), |
| 393 | recursive_(recursive) { |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 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. |
kinuko@chromium.org | c483d79 | 2010-09-08 09:50:41 +0900 | [diff] [blame] | 400 | if (!recursive_ && !file_util::PathExists(file_path_.DirName())) { |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 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_; |
kinuko@chromium.org | c483d79 | 2010-09-08 09:50:41 +0900 | [diff] [blame] | 420 | bool recursive_; |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 421 | }; |
| 422 | |
| 423 | class RelayReadDirectory : public MessageLoopRelay { |
| 424 | public: |
| 425 | RelayReadDirectory(const FilePath& file_path, |
| 426 | base::FileUtilProxy::ReadDirectoryCallback* callback) |
| 427 | : callback_(callback), file_path_(file_path) { |
| 428 | DCHECK(callback); |
| 429 | } |
| 430 | |
| 431 | protected: |
| 432 | virtual void RunWork() { |
| 433 | // TODO(kkanetkar): Implement directory read in multiple chunks. |
| 434 | if (!file_util::DirectoryExists(file_path_)) { |
| 435 | set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 436 | return; |
| 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()) { |
kkanetkar@chromium.org | 4871068 | 2010-11-03 05:36:52 +0900 | [diff] [blame^] | 445 | base::FileUtilProxy::Entry entry; |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 446 | file_util::FileEnumerator::FindInfo info; |
| 447 | file_enum.GetFindInfo(&info); |
kinuko@chromium.org | 83604d1 | 2010-09-03 07:28:49 +0900 | [diff] [blame] | 448 | entry.is_directory = file_enum.IsDirectory(info); |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 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 | } |
| 455 | |
| 456 | virtual void RunCallback() { |
| 457 | callback_->Run(error_code(), entries_); |
| 458 | delete callback_; |
| 459 | } |
| 460 | |
| 461 | private: |
| 462 | base::FileUtilProxy::ReadDirectoryCallback* callback_; |
| 463 | FilePath file_path_; |
kkanetkar@chromium.org | 4871068 | 2010-11-03 05:36:52 +0900 | [diff] [blame^] | 464 | std::vector<base::FileUtilProxy::Entry> entries_; |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 465 | }; |
| 466 | |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 467 | class RelayGetFileInfo : public MessageLoopRelay { |
| 468 | public: |
| 469 | RelayGetFileInfo(const FilePath& file_path, |
| 470 | base::FileUtilProxy::GetFileInfoCallback* callback) |
| 471 | : callback_(callback), |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 472 | file_path_(file_path) { |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 473 | DCHECK(callback); |
| 474 | } |
| 475 | |
| 476 | protected: |
| 477 | virtual void RunWork() { |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 478 | if (!file_util::PathExists(file_path_)) { |
| 479 | set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 480 | return; |
| 481 | } |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 482 | if (!file_util::GetFileInfo(file_path_, &file_info_)) |
| 483 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | virtual void RunCallback() { |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame] | 487 | callback_->Run(error_code(), file_info_); |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 488 | delete callback_; |
| 489 | } |
| 490 | |
| 491 | private: |
| 492 | base::FileUtilProxy::GetFileInfoCallback* callback_; |
| 493 | FilePath file_path_; |
dumi@chromium.org | 97ae261 | 2010-09-03 11:28:37 +0900 | [diff] [blame] | 494 | base::PlatformFileInfo file_info_; |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 495 | }; |
| 496 | |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 497 | class RelayGetFileInfoFromPlatformFile : public MessageLoopRelay { |
| 498 | public: |
| 499 | RelayGetFileInfoFromPlatformFile( |
| 500 | base::PlatformFile file, |
| 501 | base::FileUtilProxy::GetFileInfoCallback* callback) |
| 502 | : callback_(callback), |
| 503 | file_(file) { |
| 504 | DCHECK(callback); |
| 505 | } |
| 506 | |
| 507 | protected: |
| 508 | virtual void RunWork() { |
| 509 | if (!base::GetPlatformFileInfo(file_, &file_info_)) |
| 510 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
| 511 | } |
| 512 | |
| 513 | virtual void RunCallback() { |
| 514 | callback_->Run(error_code(), file_info_); |
| 515 | delete callback_; |
| 516 | } |
| 517 | |
| 518 | private: |
| 519 | base::FileUtilProxy::GetFileInfoCallback* callback_; |
| 520 | base::PlatformFile file_; |
| 521 | base::PlatformFileInfo file_info_; |
| 522 | }; |
| 523 | |
| 524 | class RelayRead : public MessageLoopRelay { |
| 525 | public: |
| 526 | RelayRead(base::PlatformFile file, |
| 527 | int64 offset, |
| 528 | char* buffer, |
| 529 | int bytes_to_read, |
| 530 | base::FileUtilProxy::ReadWriteCallback* callback) |
| 531 | : file_(file), |
| 532 | offset_(offset), |
| 533 | buffer_(buffer), |
| 534 | bytes_to_read_(bytes_to_read), |
| 535 | callback_(callback), |
| 536 | bytes_read_(0) { |
| 537 | } |
| 538 | |
| 539 | protected: |
| 540 | virtual void RunWork() { |
| 541 | bytes_read_ = base::ReadPlatformFile(file_, offset_, buffer_, |
| 542 | bytes_to_read_); |
| 543 | if (bytes_read_ < 0) |
| 544 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
| 545 | } |
| 546 | |
| 547 | virtual void RunCallback() { |
| 548 | if (callback_) { |
| 549 | callback_->Run(error_code(), bytes_read_); |
| 550 | delete callback_; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | private: |
| 555 | base::PlatformFile file_; |
| 556 | int64 offset_; |
| 557 | char* buffer_; |
| 558 | int bytes_to_read_; |
| 559 | base::FileUtilProxy::ReadWriteCallback* callback_; |
| 560 | int bytes_read_; |
| 561 | }; |
| 562 | |
| 563 | class RelayWrite : public MessageLoopRelay { |
| 564 | public: |
| 565 | RelayWrite(base::PlatformFile file, |
ericu@google.com | 6a65222 | 2010-10-05 11:26:47 +0900 | [diff] [blame] | 566 | int64 offset, |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 567 | const char* buffer, |
| 568 | int bytes_to_write, |
| 569 | base::FileUtilProxy::ReadWriteCallback* callback) |
| 570 | : file_(file), |
| 571 | offset_(offset), |
| 572 | buffer_(buffer), |
| 573 | bytes_to_write_(bytes_to_write), |
| 574 | callback_(callback) { |
| 575 | } |
| 576 | |
| 577 | protected: |
| 578 | virtual void RunWork() { |
| 579 | bytes_written_ = base::WritePlatformFile(file_, offset_, buffer_, |
| 580 | bytes_to_write_); |
| 581 | if (bytes_written_ < 0) |
| 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 | } |
| 591 | |
| 592 | private: |
| 593 | base::PlatformFile file_; |
| 594 | int64 offset_; |
| 595 | const char* buffer_; |
| 596 | int bytes_to_write_; |
| 597 | base::FileUtilProxy::ReadWriteCallback* 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 | }; |
| 624 | |
dumi@chromium.org | 12c2e2b | 2010-09-24 10:09:32 +0900 | [diff] [blame] | 625 | class RelayTouchFilePath : public RelayWithStatusCallback { |
| 626 | public: |
| 627 | RelayTouchFilePath(const FilePath& file_path, |
| 628 | const base::Time& last_access_time, |
| 629 | const base::Time& last_modified_time, |
| 630 | base::FileUtilProxy::StatusCallback* callback) |
| 631 | : RelayWithStatusCallback(callback), |
evan@chromium.org | d719ede | 2010-09-25 05:07:41 +0900 | [diff] [blame] | 632 | file_path_(file_path), |
dumi@chromium.org | 12c2e2b | 2010-09-24 10:09:32 +0900 | [diff] [blame] | 633 | last_access_time_(last_access_time), |
| 634 | last_modified_time_(last_modified_time) { |
| 635 | } |
| 636 | |
| 637 | protected: |
| 638 | virtual void RunWork() { |
| 639 | if (!file_util::TouchFile( |
| 640 | file_path_, last_access_time_, last_modified_time_)) |
| 641 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
| 642 | } |
| 643 | |
| 644 | private: |
| 645 | FilePath file_path_; |
| 646 | base::Time last_access_time_; |
| 647 | base::Time last_modified_time_; |
| 648 | }; |
| 649 | |
ericu@google.com | 6a65222 | 2010-10-05 11:26:47 +0900 | [diff] [blame] | 650 | class RelayTruncatePlatformFile : public RelayWithStatusCallback { |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 651 | public: |
ericu@google.com | 6a65222 | 2010-10-05 11:26:47 +0900 | [diff] [blame] | 652 | RelayTruncatePlatformFile(base::PlatformFile file, |
| 653 | int64 length, |
| 654 | base::FileUtilProxy::StatusCallback* callback) |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 655 | : RelayWithStatusCallback(callback), |
| 656 | file_(file), |
| 657 | length_(length) { |
| 658 | } |
| 659 | |
| 660 | protected: |
| 661 | virtual void RunWork() { |
| 662 | if (!base::TruncatePlatformFile(file_, length_)) |
| 663 | set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
| 664 | } |
| 665 | |
| 666 | private: |
| 667 | base::PlatformFile file_; |
| 668 | int64 length_; |
| 669 | }; |
| 670 | |
ericu@google.com | 6a65222 | 2010-10-05 11:26:47 +0900 | [diff] [blame] | 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 | |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 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 | |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 722 | bool Start(const tracked_objects::Location& from_here, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 723 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 724 | scoped_refptr<MessageLoopRelay> relay) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 725 | return relay->Start(message_loop_proxy, from_here); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | } // namespace |
| 729 | |
| 730 | namespace base { |
| 731 | |
| 732 | // static |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 733 | bool FileUtilProxy::CreateOrOpen( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 734 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 735 | const FilePath& file_path, int file_flags, |
| 736 | CreateOrOpenCallback* callback) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 737 | return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen( |
kinuko@chromium.org | 850eb6d | 2010-10-15 09:37:34 +0900 | [diff] [blame] | 738 | message_loop_proxy, file_path, file_flags, callback)); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | // static |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 742 | bool FileUtilProxy::CreateTemporary( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 743 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 744 | CreateTemporaryCallback* callback) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 745 | return Start(FROM_HERE, message_loop_proxy, |
| 746 | new RelayCreateTemporary(message_loop_proxy, callback)); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | // static |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 750 | bool FileUtilProxy::CreateDirectory( |
| 751 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 752 | const FilePath& file_path, |
| 753 | bool exclusive, |
kinuko@chromium.org | c483d79 | 2010-09-08 09:50:41 +0900 | [diff] [blame] | 754 | bool recursive, |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 755 | StatusCallback* callback) { |
| 756 | return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory( |
kinuko@chromium.org | c483d79 | 2010-09-08 09:50:41 +0900 | [diff] [blame] | 757 | file_path, exclusive, recursive, callback)); |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | // static |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 761 | bool FileUtilProxy::Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 762 | base::PlatformFile file_handle, |
| 763 | StatusCallback* callback) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 764 | return Start(FROM_HERE, message_loop_proxy, |
| 765 | new RelayClose(file_handle, callback)); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | // static |
kinuko@chromium.org | 850eb6d | 2010-10-15 09:37:34 +0900 | [diff] [blame] | 769 | bool FileUtilProxy::EnsureFileExists( |
| 770 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 771 | const FilePath& file_path, |
| 772 | EnsureFileExistsCallback* callback) { |
| 773 | return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( |
| 774 | message_loop_proxy, file_path, callback)); |
| 775 | } |
| 776 | |
| 777 | // static |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 778 | bool FileUtilProxy::Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 779 | const FilePath& file_path, |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 780 | bool recursive, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 781 | StatusCallback* callback) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 782 | return Start(FROM_HERE, message_loop_proxy, |
kinuko@chromium.org | 1a07804 | 2010-10-07 17:35:09 +0900 | [diff] [blame] | 783 | new RelayDelete(file_path, recursive, callback)); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | // static |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 787 | bool FileUtilProxy::Copy(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 788 | const FilePath& src_file_path, |
| 789 | const FilePath& dest_file_path, |
| 790 | StatusCallback* callback) { |
| 791 | return Start(FROM_HERE, message_loop_proxy, |
| 792 | new RelayCopy(src_file_path, dest_file_path, callback)); |
| 793 | } |
| 794 | |
| 795 | // static |
| 796 | bool FileUtilProxy::Move(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 797 | const FilePath& src_file_path, |
| 798 | const FilePath& dest_file_path, |
| 799 | StatusCallback* callback) { |
| 800 | return Start(FROM_HERE, message_loop_proxy, |
| 801 | new RelayMove(src_file_path, dest_file_path, callback)); |
| 802 | } |
| 803 | |
| 804 | // static |
| 805 | bool FileUtilProxy::ReadDirectory( |
| 806 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 807 | const FilePath& file_path, |
| 808 | ReadDirectoryCallback* callback) { |
| 809 | return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory( |
| 810 | file_path, callback)); |
| 811 | } |
| 812 | |
| 813 | // Retrieves the information about a file. It is invalid to pass NULL for the |
| 814 | // callback. |
| 815 | bool FileUtilProxy::GetFileInfo( |
| 816 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 817 | const FilePath& file_path, |
| 818 | GetFileInfoCallback* callback) { |
| 819 | return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo( |
| 820 | file_path, callback)); |
| 821 | } |
| 822 | |
| 823 | // static |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 824 | bool FileUtilProxy::RecursiveDelete( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 825 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 826 | const FilePath& file_path, |
| 827 | StatusCallback* callback) { |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 828 | return Start(FROM_HERE, message_loop_proxy, |
| 829 | new RelayDelete(file_path, true, callback)); |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 830 | } |
| 831 | |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 832 | // static |
| 833 | bool FileUtilProxy::GetFileInfoFromPlatformFile( |
| 834 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 835 | PlatformFile file, |
| 836 | GetFileInfoCallback* callback) { |
| 837 | return Start(FROM_HERE, message_loop_proxy, |
| 838 | new RelayGetFileInfoFromPlatformFile(file, callback)); |
| 839 | } |
| 840 | |
| 841 | // static |
| 842 | bool FileUtilProxy::Read( |
| 843 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 844 | PlatformFile file, |
| 845 | int64 offset, |
| 846 | char* buffer, |
| 847 | int bytes_to_read, |
| 848 | ReadWriteCallback* callback) { |
| 849 | return Start(FROM_HERE, message_loop_proxy, |
| 850 | new RelayRead(file, offset, buffer, bytes_to_read, callback)); |
| 851 | } |
| 852 | |
| 853 | // static |
| 854 | bool FileUtilProxy::Write( |
| 855 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 856 | PlatformFile file, |
| 857 | int64 offset, |
| 858 | const char* buffer, |
| 859 | int bytes_to_write, |
| 860 | ReadWriteCallback* callback) { |
| 861 | return Start(FROM_HERE, message_loop_proxy, |
| 862 | new RelayWrite(file, offset, buffer, bytes_to_write, callback)); |
| 863 | } |
| 864 | |
| 865 | // static |
| 866 | bool FileUtilProxy::Touch( |
| 867 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 868 | PlatformFile file, |
| 869 | const base::Time& last_access_time, |
| 870 | const base::Time& last_modified_time, |
| 871 | StatusCallback* callback) { |
| 872 | return Start(FROM_HERE, message_loop_proxy, |
| 873 | new RelayTouch(file, last_access_time, last_modified_time, |
| 874 | callback)); |
| 875 | } |
| 876 | |
| 877 | // static |
dumi@chromium.org | 12c2e2b | 2010-09-24 10:09:32 +0900 | [diff] [blame] | 878 | bool FileUtilProxy::Touch( |
| 879 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 880 | const FilePath& file_path, |
| 881 | const base::Time& last_access_time, |
| 882 | const base::Time& last_modified_time, |
| 883 | StatusCallback* callback) { |
| 884 | return Start(FROM_HERE, message_loop_proxy, |
| 885 | new RelayTouchFilePath(file_path, last_access_time, |
| 886 | last_modified_time, callback)); |
| 887 | } |
| 888 | |
| 889 | // static |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 890 | bool FileUtilProxy::Truncate( |
| 891 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 892 | PlatformFile file, |
ericu@google.com | 6a65222 | 2010-10-05 11:26:47 +0900 | [diff] [blame] | 893 | int64 length, |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 894 | StatusCallback* callback) { |
| 895 | return Start(FROM_HERE, message_loop_proxy, |
ericu@google.com | 6a65222 | 2010-10-05 11:26:47 +0900 | [diff] [blame] | 896 | new RelayTruncatePlatformFile(file, length, callback)); |
| 897 | } |
| 898 | |
| 899 | // static |
| 900 | bool FileUtilProxy::Truncate( |
| 901 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 902 | const FilePath& path, |
| 903 | int64 length, |
| 904 | StatusCallback* callback) { |
| 905 | return Start(FROM_HERE, message_loop_proxy, |
| 906 | new RelayTruncate(path, length, callback)); |
dumi@chromium.org | 2391598 | 2010-09-10 12:01:14 +0900 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | // static |
| 910 | bool FileUtilProxy::Flush( |
| 911 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 912 | PlatformFile file, |
| 913 | StatusCallback* callback) { |
| 914 | return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); |
| 915 | } |
| 916 | |
kkanetkar@chromium.org | 3a3bdea | 2010-09-02 12:43:36 +0900 | [diff] [blame] | 917 | } // namespace base |