| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/file_system_file_util_proxy.h" | 5 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "webkit/fileapi/file_system_context.h" | 9 #include "webkit/fileapi/file_system_context.h" |
| 10 #include "webkit/fileapi/file_system_file_util.h" | 10 #include "webkit/fileapi/file_system_file_util.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 origin_message_loop_proxy_->PostTask( | 64 origin_message_loop_proxy_->PostTask( |
| 65 FROM_HERE, base::Bind(&MessageLoopRelay::RunCallback, this)); | 65 FROM_HERE, base::Bind(&MessageLoopRelay::RunCallback, this)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 68 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
| 69 base::PlatformFileError error_code_; | 69 base::PlatformFileError error_code_; |
| 70 fileapi::FileSystemOperationContext context_; | 70 fileapi::FileSystemOperationContext context_; |
| 71 fileapi::FileSystemFileUtil* file_util_; | 71 fileapi::FileSystemFileUtil* file_util_; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 class RelayWithStatusCallback : public MessageLoopRelay { | |
| 75 public: | |
| 76 RelayWithStatusCallback( | |
| 77 const fileapi::FileSystemOperationContext& context, | |
| 78 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | |
| 79 : MessageLoopRelay(context), | |
| 80 callback_(callback) { | |
| 81 // It is OK for callback to be NULL. | |
| 82 } | |
| 83 | |
| 84 protected: | |
| 85 virtual void RunCallback() { | |
| 86 // The caller may not have been interested in the result. | |
| 87 if (!callback_.is_null()) | |
| 88 callback_.Run(error_code()); | |
| 89 } | |
| 90 | |
| 91 private: | |
| 92 fileapi::FileSystemFileUtilProxy::StatusCallback callback_; | |
| 93 }; | |
| 94 | |
| 95 class RelayEnsureFileExists : public MessageLoopRelay { | 74 class RelayEnsureFileExists : public MessageLoopRelay { |
| 96 public: | 75 public: |
| 97 RelayEnsureFileExists( | 76 RelayEnsureFileExists( |
| 98 const fileapi::FileSystemOperationContext& context, | 77 const fileapi::FileSystemOperationContext& context, |
| 99 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 78 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 100 const FilePath& file_path, | 79 const FilePath& file_path, |
| 101 const fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback& | 80 const fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback& |
| 102 callback) | 81 callback) |
| 103 : MessageLoopRelay(context), | 82 : MessageLoopRelay(context), |
| 104 message_loop_proxy_(message_loop_proxy), | 83 message_loop_proxy_(message_loop_proxy), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 119 } | 98 } |
| 120 | 99 |
| 121 private: | 100 private: |
| 122 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 101 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 123 FilePath file_path_; | 102 FilePath file_path_; |
| 124 fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback callback_; | 103 fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback callback_; |
| 125 bool created_; | 104 bool created_; |
| 126 }; | 105 }; |
| 127 | 106 |
| 128 | 107 |
| 129 class RelayGetLocalPath : public MessageLoopRelay { | |
| 130 public: | |
| 131 RelayGetLocalPath( | |
| 132 const fileapi::FileSystemOperationContext& context, | |
| 133 const FilePath& virtual_path, | |
| 134 fileapi::FileSystemFileUtilProxy::GetLocalPathCallback* callback) | |
| 135 : MessageLoopRelay(context), | |
| 136 callback_(callback), | |
| 137 virtual_path_(virtual_path) { | |
| 138 DCHECK(callback); | |
| 139 } | |
| 140 | |
| 141 protected: | |
| 142 virtual void RunWork() { | |
| 143 set_error_code(file_util()->GetLocalFilePath( | |
| 144 context(), virtual_path_, &local_path_)); | |
| 145 } | |
| 146 | |
| 147 virtual void RunCallback() { | |
| 148 callback_->Run(error_code(), local_path_); | |
| 149 delete callback_; | |
| 150 } | |
| 151 | |
| 152 private: | |
| 153 fileapi::FileSystemFileUtilProxy::GetLocalPathCallback* callback_; | |
| 154 FilePath virtual_path_; | |
| 155 FilePath local_path_; | |
| 156 }; | |
| 157 | |
| 158 class RelayGetFileInfo : public MessageLoopRelay { | 108 class RelayGetFileInfo : public MessageLoopRelay { |
| 159 public: | 109 public: |
| 160 RelayGetFileInfo( | 110 RelayGetFileInfo( |
| 161 const fileapi::FileSystemOperationContext& context, | 111 const fileapi::FileSystemOperationContext& context, |
| 162 const FilePath& file_path, | 112 const FilePath& file_path, |
| 163 const fileapi::FileSystemFileUtilProxy::GetFileInfoCallback& callback) | 113 const fileapi::FileSystemFileUtilProxy::GetFileInfoCallback& callback) |
| 164 : MessageLoopRelay(context), | 114 : MessageLoopRelay(context), |
| 165 callback_(callback), | 115 callback_(callback), |
| 166 file_path_(file_path) { | 116 file_path_(file_path) { |
| 167 DCHECK_EQ(false, callback.is_null()); | 117 DCHECK_EQ(false, callback.is_null()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 virtual void RunCallback() { | 155 virtual void RunCallback() { |
| 206 callback_.Run(error_code(), entries_); | 156 callback_.Run(error_code(), entries_); |
| 207 } | 157 } |
| 208 | 158 |
| 209 private: | 159 private: |
| 210 fileapi::FileSystemFileUtilProxy::ReadDirectoryCallback callback_; | 160 fileapi::FileSystemFileUtilProxy::ReadDirectoryCallback callback_; |
| 211 FilePath file_path_; | 161 FilePath file_path_; |
| 212 std::vector<base::FileUtilProxy::Entry> entries_; | 162 std::vector<base::FileUtilProxy::Entry> entries_; |
| 213 }; | 163 }; |
| 214 | 164 |
| 215 class RelayCreateDirectory : public RelayWithStatusCallback { | |
| 216 public: | |
| 217 RelayCreateDirectory( | |
| 218 const fileapi::FileSystemOperationContext& context, | |
| 219 const FilePath& file_path, | |
| 220 bool exclusive, | |
| 221 bool recursive, | |
| 222 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | |
| 223 : RelayWithStatusCallback(context, callback), | |
| 224 file_path_(file_path), | |
| 225 exclusive_(exclusive), | |
| 226 recursive_(recursive) { | |
| 227 } | |
| 228 | |
| 229 protected: | |
| 230 virtual void RunWork() { | |
| 231 set_error_code(file_util()->CreateDirectory( | |
| 232 context(), file_path_, exclusive_, recursive_)); | |
| 233 } | |
| 234 | |
| 235 private: | |
| 236 FilePath file_path_; | |
| 237 bool exclusive_; | |
| 238 bool recursive_; | |
| 239 }; | |
| 240 | |
| 241 class RelayCopy : public RelayWithStatusCallback { | |
| 242 public: | |
| 243 RelayCopy(const fileapi::FileSystemOperationContext& context, | |
| 244 const FilePath& src_file_path, | |
| 245 const FilePath& dest_file_path, | |
| 246 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | |
| 247 : RelayWithStatusCallback(context, callback), | |
| 248 src_file_path_(src_file_path), | |
| 249 dest_file_path_(dest_file_path) { | |
| 250 } | |
| 251 | |
| 252 protected: | |
| 253 virtual void RunWork() { | |
| 254 set_error_code(file_util()->Copy( | |
| 255 context(), src_file_path_, dest_file_path_)); | |
| 256 } | |
| 257 | |
| 258 private: | |
| 259 FilePath src_file_path_; | |
| 260 FilePath dest_file_path_; | |
| 261 }; | |
| 262 | |
| 263 class RelayMove : public RelayWithStatusCallback { | |
| 264 public: | |
| 265 RelayMove(const fileapi::FileSystemOperationContext& context, | |
| 266 const FilePath& src_file_path, | |
| 267 const FilePath& dest_file_path, | |
| 268 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | |
| 269 : RelayWithStatusCallback(context, callback), | |
| 270 src_file_path_(src_file_path), | |
| 271 dest_file_path_(dest_file_path) { | |
| 272 } | |
| 273 | |
| 274 protected: | |
| 275 virtual void RunWork() { | |
| 276 set_error_code(file_util()->Move( | |
| 277 context(), src_file_path_, dest_file_path_)); | |
| 278 } | |
| 279 | |
| 280 private: | |
| 281 FilePath src_file_path_; | |
| 282 FilePath dest_file_path_; | |
| 283 }; | |
| 284 | |
| 285 class RelayDelete : public RelayWithStatusCallback { | |
| 286 public: | |
| 287 RelayDelete(const fileapi::FileSystemOperationContext& context, | |
| 288 const FilePath& file_path, | |
| 289 bool recursive, | |
| 290 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | |
| 291 : RelayWithStatusCallback(context, callback), | |
| 292 file_path_(file_path), | |
| 293 recursive_(recursive) { | |
| 294 } | |
| 295 | |
| 296 protected: | |
| 297 virtual void RunWork() { | |
| 298 set_error_code(file_util()->Delete(context(), file_path_, recursive_)); | |
| 299 } | |
| 300 | |
| 301 private: | |
| 302 FilePath file_path_; | |
| 303 bool recursive_; | |
| 304 }; | |
| 305 | |
| 306 class RelayTouchFilePath : public RelayWithStatusCallback { | |
| 307 public: | |
| 308 RelayTouchFilePath( | |
| 309 const fileapi::FileSystemOperationContext& context, | |
| 310 const FilePath& file_path, | |
| 311 const base::Time& last_access_time, | |
| 312 const base::Time& last_modified_time, | |
| 313 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | |
| 314 : RelayWithStatusCallback(context, callback), | |
| 315 file_path_(file_path), | |
| 316 last_access_time_(last_access_time), | |
| 317 last_modified_time_(last_modified_time) { | |
| 318 } | |
| 319 | |
| 320 protected: | |
| 321 virtual void RunWork() { | |
| 322 set_error_code(file_util()->Touch( | |
| 323 context(), file_path_, last_access_time_, last_modified_time_)); | |
| 324 } | |
| 325 | |
| 326 private: | |
| 327 FilePath file_path_; | |
| 328 base::Time last_access_time_; | |
| 329 base::Time last_modified_time_; | |
| 330 }; | |
| 331 | |
| 332 class RelayTruncate : public RelayWithStatusCallback { | |
| 333 public: | |
| 334 RelayTruncate( | |
| 335 const fileapi::FileSystemOperationContext& context, | |
| 336 const FilePath& file_path, | |
| 337 int64 length, | |
| 338 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | |
| 339 : RelayWithStatusCallback(context, callback), | |
| 340 file_path_(file_path), | |
| 341 length_(length) { | |
| 342 } | |
| 343 | |
| 344 protected: | |
| 345 virtual void RunWork() { | |
| 346 set_error_code(file_util()->Truncate(context(), file_path_, length_)); | |
| 347 } | |
| 348 | |
| 349 private: | |
| 350 FilePath file_path_; | |
| 351 int64 length_; | |
| 352 }; | |
| 353 | |
| 354 bool Start(const tracked_objects::Location& from_here, | 165 bool Start(const tracked_objects::Location& from_here, |
| 355 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 166 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 356 scoped_refptr<MessageLoopRelay> relay) { | 167 scoped_refptr<MessageLoopRelay> relay) { |
| 357 return relay->Start(message_loop_proxy, from_here); | 168 return relay->Start(message_loop_proxy, from_here); |
| 358 } | 169 } |
| 359 | 170 |
| 360 } // namespace | 171 } // namespace |
| 361 | 172 |
| 362 namespace fileapi { | 173 namespace fileapi { |
| 363 | 174 |
| 364 // static | 175 // static |
| 365 bool FileSystemFileUtilProxy::EnsureFileExists( | 176 bool FileSystemFileUtilProxy::EnsureFileExists( |
| 366 const FileSystemOperationContext& context, | 177 const FileSystemOperationContext& context, |
| 367 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 178 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 368 const FilePath& file_path, | 179 const FilePath& file_path, |
| 369 const EnsureFileExistsCallback& callback) { | 180 const EnsureFileExistsCallback& callback) { |
| 370 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( | 181 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( |
| 371 context, message_loop_proxy, file_path, callback)); | 182 context, message_loop_proxy, file_path, callback)); |
| 372 } | 183 } |
| 373 | 184 |
| 374 // static | 185 // static |
| 375 bool FileSystemFileUtilProxy::GetLocalPath( | |
| 376 const FileSystemOperationContext& context, | |
| 377 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 378 const FilePath& virtual_path, | |
| 379 GetLocalPathCallback* callback) { | |
| 380 return Start(FROM_HERE, message_loop_proxy, | |
| 381 new RelayGetLocalPath(context, virtual_path, callback)); | |
| 382 } | |
| 383 | |
| 384 // static | |
| 385 bool FileSystemFileUtilProxy::GetFileInfo( | 186 bool FileSystemFileUtilProxy::GetFileInfo( |
| 386 const FileSystemOperationContext& context, | 187 const FileSystemOperationContext& context, |
| 387 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 188 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 388 const FilePath& file_path, | 189 const FilePath& file_path, |
| 389 const GetFileInfoCallback& callback) { | 190 const GetFileInfoCallback& callback) { |
| 390 return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo(context, | 191 return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo(context, |
| 391 file_path, callback)); | 192 file_path, callback)); |
| 392 } | 193 } |
| 393 | 194 |
| 394 // static | 195 // static |
| 395 bool FileSystemFileUtilProxy::ReadDirectory( | 196 bool FileSystemFileUtilProxy::ReadDirectory( |
| 396 const FileSystemOperationContext& context, | 197 const FileSystemOperationContext& context, |
| 397 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 198 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 398 const FilePath& file_path, | 199 const FilePath& file_path, |
| 399 const ReadDirectoryCallback& callback) { | 200 const ReadDirectoryCallback& callback) { |
| 400 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory(context, | 201 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory(context, |
| 401 file_path, callback)); | 202 file_path, callback)); |
| 402 } | 203 } |
| 403 | 204 |
| 404 // static | |
| 405 bool FileSystemFileUtilProxy::CreateDirectory( | |
| 406 const FileSystemOperationContext& context, | |
| 407 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 408 const FilePath& file_path, | |
| 409 bool exclusive, | |
| 410 bool recursive, | |
| 411 const StatusCallback& callback) { | |
| 412 return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory( | |
| 413 context, file_path, exclusive, recursive, callback)); | |
| 414 } | |
| 415 | |
| 416 // static | |
| 417 bool FileSystemFileUtilProxy::Copy( | |
| 418 const FileSystemOperationContext& context, | |
| 419 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 420 const FilePath& src_file_path, | |
| 421 const FilePath& dest_file_path, | |
| 422 const StatusCallback& callback) { | |
| 423 return Start(FROM_HERE, message_loop_proxy, | |
| 424 new RelayCopy(context, src_file_path, dest_file_path, | |
| 425 callback)); | |
| 426 } | |
| 427 | |
| 428 // static | |
| 429 bool FileSystemFileUtilProxy::Move( | |
| 430 const FileSystemOperationContext& context, | |
| 431 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 432 const FilePath& src_file_path, | |
| 433 const FilePath& dest_file_path, | |
| 434 const StatusCallback& callback) { | |
| 435 return Start(FROM_HERE, message_loop_proxy, | |
| 436 new RelayMove(context, src_file_path, dest_file_path, | |
| 437 callback)); | |
| 438 } | |
| 439 | |
| 440 // static | |
| 441 bool FileSystemFileUtilProxy::Delete( | |
| 442 const FileSystemOperationContext& context, | |
| 443 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 444 const FilePath& file_path, | |
| 445 bool recursive, | |
| 446 const StatusCallback& callback) { | |
| 447 return Start(FROM_HERE, message_loop_proxy, | |
| 448 new RelayDelete(context, file_path, recursive, callback)); | |
| 449 } | |
| 450 | |
| 451 // static | |
| 452 bool FileSystemFileUtilProxy::Touch( | |
| 453 const FileSystemOperationContext& context, | |
| 454 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 455 const FilePath& file_path, | |
| 456 const base::Time& last_access_time, | |
| 457 const base::Time& last_modified_time, | |
| 458 const StatusCallback& callback) { | |
| 459 return Start(FROM_HERE, message_loop_proxy, | |
| 460 new RelayTouchFilePath(context, file_path, last_access_time, | |
| 461 last_modified_time, callback)); | |
| 462 } | |
| 463 | |
| 464 // static | |
| 465 bool FileSystemFileUtilProxy::Truncate( | |
| 466 const FileSystemOperationContext& context, | |
| 467 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 468 const FilePath& path, | |
| 469 int64 length, | |
| 470 const StatusCallback& callback) { | |
| 471 return Start(FROM_HERE, message_loop_proxy, | |
| 472 new RelayTruncate(context, path, length, callback)); | |
| 473 } | |
| 474 | |
| 475 } // namespace fileapi | 205 } // namespace fileapi |
| OLD | NEW |