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.
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_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
13 #include "chrome/browser/chromeos/drive/file_system_interface.h"
17 class SequencedTaskRunner;
23 class FileWriteWatcher;
24 class ResourceMetadata;
25 } // namespace internal
30 namespace file_system {
32 class CreateFileOperation;
33 class DownloadOperation;
34 class OperationObserver;
36 // Implements GetFileForSaving() operation that prepares a local cache for
37 // a Drive file whose next modification is monitored and notified to the
39 // TODO(kinaba): crbug.com/269424: we might want to monitor all the changes
40 // to the cache directory, not just the one immediately after the save dialog.
41 class GetFileForSavingOperation {
43 GetFileForSavingOperation(base::SequencedTaskRunner* blocking_task_runner,
44 OperationObserver* observer,
45 JobScheduler* scheduler,
46 internal::ResourceMetadata* metadata,
47 internal::FileCache* cache,
48 const base::FilePath& temporary_file_directory);
49 ~GetFileForSavingOperation();
51 // Makes sure that |file_path| in the file system is available in the local
52 // cache, and marks it as dirty. The next modification to the cache file is
53 // watched and is automatically notified to the observer. If the entry is not
54 // present in the file system, it is created.
55 void GetFileForSaving(const base::FilePath& file_path,
56 const GetFileCallback& callback);
58 internal::FileWriteWatcher* file_write_watcher_for_testing() {
59 return file_write_watcher_.get();
63 void GetFileForSavingAfterCreate(const base::FilePath& file_path,
64 const GetFileCallback& callback,
66 void GetFileForSavingAfterDownload(const GetFileCallback& callback,
68 const base::FilePath& cache_path,
69 scoped_ptr<ResourceEntry> entry);
70 void GetFileForSavingAfterMarkDirty(const GetFileCallback& callback,
71 const base::FilePath& cache_path,
72 const std::string* local_id,
73 scoped_ptr<ResourceEntry> entry,
75 void GetFileForSavingAfterWatch(const GetFileCallback& callback,
76 const base::FilePath& cache_path,
77 scoped_ptr<ResourceEntry> entry,
79 // Called when the cache file for |local_id| is written.
80 void OnWriteEvent(const std::string& local_id);
82 scoped_ptr<CreateFileOperation> create_file_operation_;
83 scoped_ptr<DownloadOperation> download_operation_;
84 scoped_ptr<internal::FileWriteWatcher> file_write_watcher_;
85 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
86 OperationObserver* observer_;
87 internal::ResourceMetadata* metadata_;
88 internal::FileCache* cache_;
90 // Note: This should remain the last member so it'll be destroyed and
91 // invalidate the weak pointers before any other members are destroyed.
92 base::WeakPtrFactory<GetFileForSavingOperation> weak_ptr_factory_;
93 DISALLOW_COPY_AND_ASSIGN(GetFileForSavingOperation);
96 } // namespace file_system
99 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_GET_FILE_FOR_SAVING_OPERATION_H_