OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_GET_FILE_FOR_SAVING_OPERATION_
H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_GET_FILE_FOR_SAVING_OPERATION_
H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 12 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 13 |
| 14 namespace base { |
| 15 class FilePath; |
| 16 class SequencedTaskRunner; |
| 17 } // namespace base |
| 18 |
| 19 namespace drive { |
| 20 namespace internal { |
| 21 class FileCache; |
| 22 class FileWriteWatcher; |
| 23 class ResourceMetadata; |
| 24 } // namespace internal |
| 25 |
| 26 class JobScheduler; |
| 27 class ResourceEntry; |
| 28 |
| 29 namespace file_system { |
| 30 |
| 31 class CreateFileOperation; |
| 32 class DownloadOperation; |
| 33 class OperationObserver; |
| 34 |
| 35 // Implements GetFileForSaving() operation that prepares a local cache for |
| 36 // a Drive file whose next modification is monitored and notified to the |
| 37 // OperationObserver. |
| 38 // TODO(kinaba): crbug.com/269424: we might want to monitor all the changes |
| 39 // to the cache directory, not just the one immediately after the save dialog. |
| 40 class GetFileForSavingOperation { |
| 41 public: |
| 42 GetFileForSavingOperation(base::SequencedTaskRunner* blocking_task_runner, |
| 43 OperationObserver* observer, |
| 44 JobScheduler* scheduler, |
| 45 internal::ResourceMetadata* metadata, |
| 46 internal::FileCache* cache, |
| 47 const base::FilePath& temporary_file_directory); |
| 48 ~GetFileForSavingOperation(); |
| 49 |
| 50 // Makes sure that |file_path| in the file system is available in the local |
| 51 // cache, and marks it as dirty. The next modification to the cache file is |
| 52 // watched and is automatically notified to the observer. If the entry is not |
| 53 // present in the file system, it is created. |
| 54 void GetFileForSaving(const base::FilePath& file_path, |
| 55 const GetFileCallback& callback); |
| 56 |
| 57 internal::FileWriteWatcher* file_write_watcher_for_testing() { |
| 58 return file_write_watcher_.get(); |
| 59 } |
| 60 |
| 61 private: |
| 62 void GetFileForSavingAfterCreate(const base::FilePath& file_path, |
| 63 const GetFileCallback& callback, |
| 64 FileError error); |
| 65 void GetFileForSavingAfterDownload(const GetFileCallback& callback, |
| 66 FileError error, |
| 67 const base::FilePath& cache_path, |
| 68 scoped_ptr<ResourceEntry> entry); |
| 69 void GetFileForSavingAfterMarkDirty(const GetFileCallback& callback, |
| 70 const base::FilePath& cache_path, |
| 71 scoped_ptr<ResourceEntry> entry, |
| 72 FileError error); |
| 73 void GetFileForSavingAfterWatch(const GetFileCallback& callback, |
| 74 const base::FilePath& cache_path, |
| 75 scoped_ptr<ResourceEntry> entry, |
| 76 bool success); |
| 77 |
| 78 scoped_ptr<CreateFileOperation> create_file_operation_; |
| 79 scoped_ptr<DownloadOperation> download_operation_; |
| 80 scoped_ptr<internal::FileWriteWatcher> file_write_watcher_; |
| 81 internal::FileCache* cache_; |
| 82 |
| 83 // Note: This should remain the last member so it'll be destroyed and |
| 84 // invalidate the weak pointers before any other members are destroyed. |
| 85 base::WeakPtrFactory<GetFileForSavingOperation> weak_ptr_factory_; |
| 86 DISALLOW_COPY_AND_ASSIGN(GetFileForSavingOperation); |
| 87 }; |
| 88 |
| 89 } // namespace file_system |
| 90 } // namespace drive |
| 91 |
| 92 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_GET_FILE_FOR_SAVING_OPERATI
ON_H_ |
OLD | NEW |