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 "base/file_util_proxy.h" | 5 #include "base/file_util_proxy.h" |
6 | 6 |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 | 8 |
9 // TODO(jianli): Move the code from anonymous namespace to base namespace so | 9 // TODO(jianli): Move the code from anonymous namespace to base namespace so |
10 // that all of the base:: prefixes would be unnecessary. | 10 // that all of the base:: prefixes would be unnecessary. |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 414 } |
415 | 415 |
416 private: | 416 private: |
417 FilePath file_path_; | 417 FilePath file_path_; |
418 bool exclusive_; | 418 bool exclusive_; |
419 bool recursive_; | 419 bool recursive_; |
420 }; | 420 }; |
421 | 421 |
422 class RelayReadDirectory : public MessageLoopRelay { | 422 class RelayReadDirectory : public MessageLoopRelay { |
423 public: | 423 public: |
424 RelayReadDirectory(const FilePath& file_path, | 424 RelayReadDirectory( |
425 base::FileUtilProxy::ReadDirectoryCallback* callback) | 425 const FilePath& file_path, |
426 : callback_(callback), file_path_(file_path) { | 426 const base::FileUtilProxy::ReadDirectoryCallback& callback) |
427 DCHECK(callback); | 427 : callback_(callback), |
| 428 file_path_(file_path) { |
| 429 DCHECK_EQ(false, callback.is_null()); |
428 } | 430 } |
429 | 431 |
430 protected: | 432 protected: |
431 virtual void RunWork() { | 433 virtual void RunWork() { |
432 // TODO(kkanetkar): Implement directory read in multiple chunks. | 434 // TODO(kkanetkar): Implement directory read in multiple chunks. |
433 if (!file_util::DirectoryExists(file_path_)) { | 435 if (!file_util::DirectoryExists(file_path_)) { |
434 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 436 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
435 return; | 437 return; |
436 } | 438 } |
437 | 439 |
(...skipping 11 matching lines...) Expand all Loading... |
449 // if we use current.value(). | 451 // if we use current.value(). |
450 entry.name = file_util::FileEnumerator::GetFilename(info).value(); | 452 entry.name = file_util::FileEnumerator::GetFilename(info).value(); |
451 entry.size = file_util::FileEnumerator::GetFilesize(info); | 453 entry.size = file_util::FileEnumerator::GetFilesize(info); |
452 entry.last_modified_time = | 454 entry.last_modified_time = |
453 file_util::FileEnumerator::GetLastModifiedTime(info); | 455 file_util::FileEnumerator::GetLastModifiedTime(info); |
454 entries_.push_back(entry); | 456 entries_.push_back(entry); |
455 } | 457 } |
456 } | 458 } |
457 | 459 |
458 virtual void RunCallback() { | 460 virtual void RunCallback() { |
459 callback_->Run(error_code(), entries_); | 461 callback_.Run(error_code(), entries_); |
460 delete callback_; | |
461 } | 462 } |
462 | 463 |
463 private: | 464 private: |
464 base::FileUtilProxy::ReadDirectoryCallback* callback_; | 465 base::FileUtilProxy::ReadDirectoryCallback callback_; |
465 FilePath file_path_; | 466 FilePath file_path_; |
466 std::vector<base::FileUtilProxy::Entry> entries_; | 467 std::vector<base::FileUtilProxy::Entry> entries_; |
467 }; | 468 }; |
468 | 469 |
469 class RelayGetFileInfo : public MessageLoopRelay { | 470 class RelayGetFileInfo : public MessageLoopRelay { |
470 public: | 471 public: |
471 RelayGetFileInfo(const FilePath& file_path, | 472 RelayGetFileInfo(const FilePath& file_path, |
472 const base::FileUtilProxy::GetFileInfoCallback& callback) | 473 const base::FileUtilProxy::GetFileInfoCallback& callback) |
473 : callback_(callback), | 474 : callback_(callback), |
474 file_path_(file_path) { | 475 file_path_(file_path) { |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 PlatformFile file, | 784 PlatformFile file, |
784 const GetFileInfoCallback& callback) { | 785 const GetFileInfoCallback& callback) { |
785 return Start(FROM_HERE, message_loop_proxy, | 786 return Start(FROM_HERE, message_loop_proxy, |
786 new RelayGetFileInfoFromPlatformFile(file, callback)); | 787 new RelayGetFileInfoFromPlatformFile(file, callback)); |
787 } | 788 } |
788 | 789 |
789 // static | 790 // static |
790 bool FileUtilProxy::ReadDirectory( | 791 bool FileUtilProxy::ReadDirectory( |
791 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 792 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
792 const FilePath& file_path, | 793 const FilePath& file_path, |
793 ReadDirectoryCallback* callback) { | 794 const ReadDirectoryCallback& callback) { |
794 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory( | 795 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory( |
795 file_path, callback)); | 796 file_path, callback)); |
796 } | 797 } |
797 | 798 |
798 // static | 799 // static |
799 bool FileUtilProxy::CreateDirectory( | 800 bool FileUtilProxy::CreateDirectory( |
800 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 801 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
801 const FilePath& file_path, | 802 const FilePath& file_path, |
802 bool exclusive, | 803 bool exclusive, |
803 bool recursive, | 804 bool recursive, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 | 920 |
920 // static | 921 // static |
921 bool FileUtilProxy::Flush( | 922 bool FileUtilProxy::Flush( |
922 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 923 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
923 PlatformFile file, | 924 PlatformFile file, |
924 StatusCallback* callback) { | 925 StatusCallback* callback) { |
925 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); | 926 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); |
926 } | 927 } |
927 | 928 |
928 } // namespace base | 929 } // namespace base |
OLD | NEW |