Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system.h
blob7d091abf65f383a48293ee9c3178b65507b1a0d7
1 // Copyright (c) 2012 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_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h"
16 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h"
17 #include "chrome/browser/chromeos/drive/file_system_interface.h"
18 #include "google_apis/drive/drive_api_error_codes.h"
20 class PrefService;
22 namespace base {
23 class SequencedTaskRunner;
24 } // namespace base
26 namespace google_apis {
27 class AboutResource;
28 class ResourceEntry;
29 } // namespace google_apis
31 namespace drive {
32 struct ClientContext;
33 class EventLogger;
34 class FileCacheEntry;
35 class FileSystemObserver;
36 class JobScheduler;
38 namespace internal {
39 class AboutResourceLoader;
40 class ChangeListLoader;
41 class DirectoryLoader;
42 class FileCache;
43 class LoaderController;
44 class ResourceMetadata;
45 class SyncClient;
46 } // namespace internal
48 namespace file_system {
49 class CopyOperation;
50 class CreateDirectoryOperation;
51 class CreateFileOperation;
52 class DownloadOperation;
53 class GetFileForSavingOperation;
54 class MoveOperation;
55 class OpenFileOperation;
56 class RemoveOperation;
57 class SearchOperation;
58 class SetPropertyOperation;
59 class TouchOperation;
60 class TruncateOperation;
61 } // namespace file_system
63 // The production implementation of FileSystemInterface.
64 class FileSystem : public FileSystemInterface,
65 public internal::ChangeListLoaderObserver,
66 public file_system::OperationDelegate {
67 public:
68 FileSystem(PrefService* pref_service,
69 EventLogger* logger,
70 internal::FileCache* cache,
71 JobScheduler* scheduler,
72 internal::ResourceMetadata* resource_metadata,
73 base::SequencedTaskRunner* blocking_task_runner,
74 base::SingleThreadTaskRunner* file_task_runner,
75 const base::FilePath& temporary_file_directory);
76 ~FileSystem() override;
78 // FileSystemInterface overrides.
79 void AddObserver(FileSystemObserver* observer) override;
80 void RemoveObserver(FileSystemObserver* observer) override;
81 void CheckForUpdates() override;
82 void Search(const std::string& search_query,
83 const GURL& next_link,
84 const SearchCallback& callback) override;
85 void SearchMetadata(const std::string& query,
86 int options,
87 int at_most_num_matches,
88 const SearchMetadataCallback& callback) override;
89 void SearchByHashes(const std::set<std::string>& hashes,
90 const SearchByHashesCallback& callback) override;
91 void TransferFileFromLocalToRemote(
92 const base::FilePath& local_src_file_path,
93 const base::FilePath& remote_dest_file_path,
94 const FileOperationCallback& callback) override;
95 void OpenFile(const base::FilePath& file_path,
96 OpenMode open_mode,
97 const std::string& mime_type,
98 const OpenFileCallback& callback) override;
99 void Copy(const base::FilePath& src_file_path,
100 const base::FilePath& dest_file_path,
101 bool preserve_last_modified,
102 const FileOperationCallback& callback) override;
103 void Move(const base::FilePath& src_file_path,
104 const base::FilePath& dest_file_path,
105 const FileOperationCallback& callback) override;
106 void Remove(const base::FilePath& file_path,
107 bool is_recursive,
108 const FileOperationCallback& callback) override;
109 void CreateDirectory(const base::FilePath& directory_path,
110 bool is_exclusive,
111 bool is_recursive,
112 const FileOperationCallback& callback) override;
113 void CreateFile(const base::FilePath& file_path,
114 bool is_exclusive,
115 const std::string& mime_type,
116 const FileOperationCallback& callback) override;
117 void TouchFile(const base::FilePath& file_path,
118 const base::Time& last_access_time,
119 const base::Time& last_modified_time,
120 const FileOperationCallback& callback) override;
121 void TruncateFile(const base::FilePath& file_path,
122 int64 length,
123 const FileOperationCallback& callback) override;
124 void Pin(const base::FilePath& file_path,
125 const FileOperationCallback& callback) override;
126 void Unpin(const base::FilePath& file_path,
127 const FileOperationCallback& callback) override;
128 void GetFile(const base::FilePath& file_path,
129 const GetFileCallback& callback) override;
130 void GetFileForSaving(const base::FilePath& file_path,
131 const GetFileCallback& callback) override;
132 base::Closure GetFileContent(
133 const base::FilePath& file_path,
134 const GetFileContentInitializedCallback& initialized_callback,
135 const google_apis::GetContentCallback& get_content_callback,
136 const FileOperationCallback& completion_callback) override;
137 void GetResourceEntry(const base::FilePath& file_path,
138 const GetResourceEntryCallback& callback) override;
139 void ReadDirectory(const base::FilePath& directory_path,
140 const ReadDirectoryEntriesCallback& entries_callback,
141 const FileOperationCallback& completion_callback) override;
142 void GetAvailableSpace(const GetAvailableSpaceCallback& callback) override;
143 void GetShareUrl(const base::FilePath& file_path,
144 const GURL& embed_origin,
145 const GetShareUrlCallback& callback) override;
146 void GetMetadata(const GetFilesystemMetadataCallback& callback) override;
147 void MarkCacheFileAsMounted(const base::FilePath& drive_file_path,
148 const MarkMountedCallback& callback) override;
149 void MarkCacheFileAsUnmounted(const base::FilePath& cache_file_path,
150 const FileOperationCallback& callback) override;
151 void AddPermission(const base::FilePath& drive_file_path,
152 const std::string& email,
153 google_apis::drive::PermissionRole role,
154 const FileOperationCallback& callback) override;
155 void SetProperty(const base::FilePath& drive_file_path,
156 google_apis::drive::Property::Visibility visibility,
157 const std::string& key,
158 const std::string& value,
159 const FileOperationCallback& callback) override;
160 void Reset(const FileOperationCallback& callback) override;
161 void GetPathFromResourceId(const std::string& resource_id,
162 const GetFilePathCallback& callback) override;
163 void FreeDiskSpaceIfNeededFor(int64 num_bytes,
164 const FreeDiskSpaceCallback& callback) override;
166 // file_system::OperationDelegate overrides.
167 void OnFileChangedByOperation(const FileChange& changed_files) override;
168 void OnEntryUpdatedByOperation(const ClientContext& context,
169 const std::string& local_id) override;
170 void OnDriveSyncError(file_system::DriveSyncErrorType type,
171 const std::string& local_id) override;
172 bool WaitForSyncComplete(const std::string& local_id,
173 const FileOperationCallback& callback) override;
175 // ChangeListLoader::Observer overrides.
176 // Used to propagate events from ChangeListLoader.
177 void OnDirectoryReloaded(const base::FilePath& directory_path) override;
178 void OnFileChanged(const FileChange& changed_files) override;
179 void OnLoadFromServerComplete() override;
180 void OnInitialLoadComplete() override;
182 // Used by tests.
183 internal::ChangeListLoader* change_list_loader_for_testing() {
184 return change_list_loader_.get();
186 internal::SyncClient* sync_client_for_testing() { return sync_client_.get(); }
188 private:
189 struct CreateDirectoryParams;
191 // Used for initialization and Reset(). (Re-)initializes sub components that
192 // need to be recreated during the reset of resource metadata and the cache.
193 void ResetComponents();
195 // Part of CreateDirectory(). Called after ReadDirectory()
196 // is called and made sure that the resource metadata is loaded.
197 void CreateDirectoryAfterRead(const CreateDirectoryParams& params,
198 FileError error);
200 void FinishPin(const FileOperationCallback& callback,
201 const std::string* local_id,
202 FileError error);
204 void FinishUnpin(const FileOperationCallback& callback,
205 const std::string* local_id,
206 FileError error);
208 // Callback for handling about resource fetch.
209 void OnGetAboutResource(
210 const GetAvailableSpaceCallback& callback,
211 google_apis::DriveApiErrorCode status,
212 scoped_ptr<google_apis::AboutResource> about_resource);
214 // Part of CheckForUpdates(). Called when
215 // ChangeListLoader::CheckForUpdates() is complete.
216 void OnUpdateChecked(FileError error);
218 // Part of GetResourceEntry().
219 // Called when ReadDirectory() is complete.
220 void GetResourceEntryAfterRead(const base::FilePath& file_path,
221 const GetResourceEntryCallback& callback,
222 FileError error);
224 // Part of GetShareUrl. Resolves the resource entry to get the resource it,
225 // and then uses it to ask for the share url. |callback| must not be null.
226 void GetShareUrlAfterGetResourceEntry(const base::FilePath& file_path,
227 const GURL& embed_origin,
228 const GetShareUrlCallback& callback,
229 ResourceEntry* entry,
230 FileError error);
231 void OnGetResourceEntryForGetShareUrl(const GetShareUrlCallback& callback,
232 google_apis::DriveApiErrorCode status,
233 const GURL& share_url);
234 // Part of AddPermission.
235 void AddPermissionAfterGetResourceEntry(
236 const std::string& email,
237 google_apis::drive::PermissionRole role,
238 const FileOperationCallback& callback,
239 ResourceEntry* entry,
240 FileError error);
242 // Part of OnDriveSyncError().
243 virtual void OnDriveSyncErrorAfterGetFilePath(
244 file_system::DriveSyncErrorType type,
245 const base::FilePath* file_path,
246 FileError error);
248 // Used to get Drive related preferences.
249 PrefService* pref_service_;
251 // Sub components owned by DriveIntegrationService.
252 EventLogger* logger_;
253 internal::FileCache* cache_;
254 JobScheduler* scheduler_;
255 internal::ResourceMetadata* resource_metadata_;
257 // Time of the last update check.
258 base::Time last_update_check_time_;
260 // Error of the last update check.
261 FileError last_update_check_error_;
263 // Used to load about resource.
264 scoped_ptr<internal::AboutResourceLoader> about_resource_loader_;
266 // Used to control ChangeListLoader.
267 scoped_ptr<internal::LoaderController> loader_controller_;
269 // The loader is used to load the change lists.
270 scoped_ptr<internal::ChangeListLoader> change_list_loader_;
272 scoped_ptr<internal::DirectoryLoader> directory_loader_;
274 scoped_ptr<internal::SyncClient> sync_client_;
276 base::ObserverList<FileSystemObserver> observers_;
278 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
279 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
281 base::FilePath temporary_file_directory_;
283 // Implementation of each file system operation.
284 scoped_ptr<file_system::CopyOperation> copy_operation_;
285 scoped_ptr<file_system::CreateDirectoryOperation> create_directory_operation_;
286 scoped_ptr<file_system::CreateFileOperation> create_file_operation_;
287 scoped_ptr<file_system::MoveOperation> move_operation_;
288 scoped_ptr<file_system::OpenFileOperation> open_file_operation_;
289 scoped_ptr<file_system::RemoveOperation> remove_operation_;
290 scoped_ptr<file_system::TouchOperation> touch_operation_;
291 scoped_ptr<file_system::TruncateOperation> truncate_operation_;
292 scoped_ptr<file_system::DownloadOperation> download_operation_;
293 scoped_ptr<file_system::SearchOperation> search_operation_;
294 scoped_ptr<file_system::GetFileForSavingOperation>
295 get_file_for_saving_operation_;
296 scoped_ptr<file_system::SetPropertyOperation> set_property_operation_;
298 base::ThreadChecker thread_checker_;
300 // Note: This should remain the last member so it'll be destroyed and
301 // invalidate the weak pointers before any other members are destroyed.
302 base::WeakPtrFactory<FileSystem> weak_ptr_factory_;
304 DISALLOW_COPY_AND_ASSIGN(FileSystem);
307 } // namespace drive
309 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_H_