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