OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/observer_list.h" | |
16 #include "base/platform_file.h" | |
17 #include "base/timer.h" | |
18 #include "chrome/browser/api/prefs/pref_change_registrar.h" | |
19 #include "chrome/browser/chromeos/gdata/drive_cache.h" | |
20 #include "chrome/browser/chromeos/gdata/drive_resource_metadata.h" | |
21 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | |
22 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" | |
23 #include "chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h" | |
24 #include "chrome/browser/chromeos/gdata/gdata_wapi_feed_processor.h" | |
25 #include "content/public/browser/notification_observer.h" | |
26 | |
27 namespace base { | |
28 class SequencedTaskRunner; | |
29 } | |
30 | |
31 namespace gdata { | |
32 | |
33 class DriveServiceInterface; | |
34 class DriveWebAppsRegistryInterface; | |
35 class GDataUploaderInterface; | |
36 class GDataWapiFeedLoader; | |
37 struct UploadFileInfo; | |
38 | |
39 // The production implementation of GDataFileSystemInterface. | |
40 class GDataFileSystem : public GDataFileSystemInterface, | |
41 public GDataWapiFeedLoader::Observer, | |
42 public content::NotificationObserver { | |
43 public: | |
44 GDataFileSystem(Profile* profile, | |
45 DriveCache* cache, | |
46 DriveServiceInterface* drive_service, | |
47 GDataUploaderInterface* uploader, | |
48 DriveWebAppsRegistryInterface* webapps_registry, | |
49 base::SequencedTaskRunner* blocking_task_runner); | |
50 virtual ~GDataFileSystem(); | |
51 | |
52 // GDataFileSystem overrides. | |
53 virtual void Initialize() OVERRIDE; | |
54 virtual void AddObserver( | |
55 GDataFileSystemInterface::Observer* observer) OVERRIDE; | |
56 virtual void RemoveObserver( | |
57 GDataFileSystemInterface::Observer* observer) OVERRIDE; | |
58 virtual void StartUpdates() OVERRIDE; | |
59 virtual void StopUpdates() OVERRIDE; | |
60 virtual void NotifyFileSystemMounted() OVERRIDE; | |
61 virtual void NotifyFileSystemToBeUnmounted() OVERRIDE; | |
62 virtual void CheckForUpdates() OVERRIDE; | |
63 virtual void GetEntryInfoByResourceId( | |
64 const std::string& resource_id, | |
65 const GetEntryInfoWithFilePathCallback& callback) OVERRIDE; | |
66 virtual void Search(const std::string& search_query, | |
67 const GURL& next_feed, | |
68 const SearchCallback& callback) OVERRIDE; | |
69 virtual void TransferFileFromRemoteToLocal( | |
70 const FilePath& remote_src_file_path, | |
71 const FilePath& local_dest_file_path, | |
72 const FileOperationCallback& callback) OVERRIDE; | |
73 virtual void TransferFileFromLocalToRemote( | |
74 const FilePath& local_src_file_path, | |
75 const FilePath& remote_dest_file_path, | |
76 const FileOperationCallback& callback) OVERRIDE; | |
77 virtual void OpenFile(const FilePath& file_path, | |
78 const OpenFileCallback& callback) OVERRIDE; | |
79 virtual void CloseFile(const FilePath& file_path, | |
80 const FileOperationCallback& callback) OVERRIDE; | |
81 virtual void Copy(const FilePath& src_file_path, | |
82 const FilePath& dest_file_path, | |
83 const FileOperationCallback& callback) OVERRIDE; | |
84 virtual void Move(const FilePath& src_file_path, | |
85 const FilePath& dest_file_path, | |
86 const FileOperationCallback& callback) OVERRIDE; | |
87 virtual void Remove(const FilePath& file_path, | |
88 bool is_recursive, | |
89 const FileOperationCallback& callback) OVERRIDE; | |
90 virtual void CreateDirectory(const FilePath& directory_path, | |
91 bool is_exclusive, | |
92 bool is_recursive, | |
93 const FileOperationCallback& callback) OVERRIDE; | |
94 virtual void CreateFile(const FilePath& file_path, | |
95 bool is_exclusive, | |
96 const FileOperationCallback& callback) OVERRIDE; | |
97 virtual void GetFileByPath( | |
98 const FilePath& file_path, | |
99 const GetFileCallback& get_file_callback, | |
100 const GetContentCallback& get_content_callback) OVERRIDE; | |
101 virtual void GetFileByResourceId( | |
102 const std::string& resource_id, | |
103 const GetFileCallback& get_file_callback, | |
104 const GetContentCallback& get_content_callback) OVERRIDE; | |
105 virtual void UpdateFileByResourceId( | |
106 const std::string& resource_id, | |
107 const FileOperationCallback& callback) OVERRIDE; | |
108 virtual void GetEntryInfoByPath( | |
109 const FilePath& file_path, | |
110 const GetEntryInfoCallback& callback) OVERRIDE; | |
111 virtual void ReadDirectoryByPath( | |
112 const FilePath& file_path, | |
113 const ReadDirectoryWithSettingCallback& callback) OVERRIDE; | |
114 virtual void RequestDirectoryRefresh( | |
115 const FilePath& file_path) OVERRIDE; | |
116 virtual void GetAvailableSpace( | |
117 const GetAvailableSpaceCallback& callback) OVERRIDE; | |
118 virtual void AddUploadedFile(UploadMode upload_mode, | |
119 const FilePath& virtual_dir_path, | |
120 scoped_ptr<DocumentEntry> entry, | |
121 const FilePath& file_content_path, | |
122 DriveCache::FileOperationType cache_operation, | |
123 const base::Closure& callback) OVERRIDE; | |
124 virtual void UpdateEntryData(const std::string& resource_id, | |
125 const std::string& md5, | |
126 scoped_ptr<DocumentEntry> entry, | |
127 const FilePath& file_content_path, | |
128 const base::Closure& callback) OVERRIDE; | |
129 | |
130 // content::NotificationObserver implementation. | |
131 virtual void Observe(int type, | |
132 const content::NotificationSource& source, | |
133 const content::NotificationDetails& details) OVERRIDE; | |
134 | |
135 // GDataWapiFeedLoader::Observer overrides. | |
136 // Used to propagate events from GDataWapiFeedLoader. | |
137 virtual void OnDirectoryChanged(const FilePath& directory_path) OVERRIDE; | |
138 virtual void OnDocumentFeedFetched(int num_accumulated_entries) OVERRIDE; | |
139 virtual void OnFeedFromServerLoaded() OVERRIDE; | |
140 | |
141 // Used in tests to load the root feed from the cache. | |
142 void LoadRootFeedFromCacheForTesting(); | |
143 | |
144 // Used in tests to update the file system from |feed_list|. | |
145 // See also the comment at GDataWapiFeedLoader::UpdateFromFeed(). | |
146 DriveFileError UpdateFromFeedForTesting( | |
147 const std::vector<DocumentFeed*>& feed_list, | |
148 int64 start_changestamp, | |
149 int64 root_feed_changestamp); | |
150 | |
151 private: | |
152 friend class GDataFileSystemTest; | |
153 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | |
154 FindFirstMissingParentDirectory); | |
155 | |
156 // Defines possible search results of FindFirstMissingParentDirectory(). | |
157 enum FindMissingDirectoryResult { | |
158 // Target directory found, it's not a directory. | |
159 FOUND_INVALID, | |
160 // Found missing directory segment while searching for given directory. | |
161 FOUND_MISSING, | |
162 // Found target directory, it already exists. | |
163 DIRECTORY_ALREADY_PRESENT, | |
164 }; | |
165 | |
166 // Defines set of parameters passes to intermediate callbacks during | |
167 // execution of CreateDirectory() method. | |
168 struct CreateDirectoryParams; | |
169 | |
170 // Defines set of parameters passed to an intermediate callback | |
171 // OnGetFileCompleteForOpen, during execution of OpenFile() method. | |
172 struct GetFileCompleteForOpenParams; | |
173 | |
174 // Defines set of parameters passed to intermediate callbacks during | |
175 // execution of GetFileByPath() method. | |
176 struct GetFileFromCacheParams; | |
177 | |
178 // Struct used for StartFileUploadOnUIThread(). | |
179 struct StartFileUploadParams; | |
180 | |
181 // Struct used for AddUploadedFile. | |
182 struct AddUploadedFileParams; | |
183 | |
184 // Callback passed to |LoadFeedFromServer| from |Search| method. | |
185 // |callback| is that should be run with data received from | |
186 // |LoadFeedFromServer|. | |
187 // |params| params used for getting document feed for content search. | |
188 // |error| error code returned by |LoadFeedFromServer|. | |
189 void OnSearch(const SearchCallback& callback, | |
190 GetDocumentsParams* params, | |
191 DriveFileError error); | |
192 | |
193 // Part of TransferFileFromLocalToRemote(). Called after | |
194 // GetEntryInfoByPath() is complete. | |
195 void TransferFileFromLocalToRemoteAfterGetEntryInfo( | |
196 const FilePath& local_src_file_path, | |
197 const FilePath& remote_dest_file_path, | |
198 const FileOperationCallback& callback, | |
199 DriveFileError error, | |
200 scoped_ptr<DriveEntryProto> entry_proto); | |
201 | |
202 // Initiates transfer of |local_file_path| with |resource_id| to | |
203 // |remote_dest_file_path|. |local_file_path| must be a file from the local | |
204 // file system, |remote_dest_file_path| is the virtual destination path within | |
205 // gdata file system. If |resource_id| is a non-empty string, the transfer is | |
206 // handled by CopyDocumentToDirectory. Otherwise, the transfer is handled by | |
207 // TransferRegularFile. | |
208 // | |
209 // Must be called from *UI* thread. |callback| is run on the calling thread. | |
210 // |callback| must not be null. | |
211 void TransferFileForResourceId(const FilePath& local_file_path, | |
212 const FilePath& remote_dest_file_path, | |
213 const FileOperationCallback& callback, | |
214 std::string* resource_id); | |
215 | |
216 // Initiates transfer of |local_file_path| to |remote_dest_file_path|. | |
217 // |local_file_path| must be a regular file (i.e. not a hosted document) from | |
218 // the local file system, |remote_dest_file_path| is the virtual destination | |
219 // path within gdata file system. | |
220 // | |
221 // Must be called from *UI* thread. |callback| is run on the calling thread. | |
222 void TransferRegularFile(const FilePath& local_file_path, | |
223 const FilePath& remote_dest_file_path, | |
224 const FileOperationCallback& callback); | |
225 | |
226 // Invoked during the process of CreateFile. | |
227 // First, FindEntryByPathAsyncOnUIThread is called and the result is returned | |
228 // to OnGetEntryInfoForCreateFile. By using the information, CreateFile deals | |
229 // with the cases when an entry already existed at the path. If there was no | |
230 // entry, a new empty file is uploaded, and when it finishes | |
231 // DidUploadForCreateBrandNewFile does the final clean up. | |
232 // |callback| must not be null. | |
233 void OnGetEntryInfoForCreateFile(const FilePath& file_path, | |
234 bool is_exclusive, | |
235 const FileOperationCallback& callback, | |
236 DriveFileError result, | |
237 scoped_ptr<DriveEntryProto> entry_proto); | |
238 void DoUploadForCreateBrandNewFile(const FilePath& remote_path, | |
239 FilePath* local_path, | |
240 const FileOperationCallback& callback); | |
241 void DidUploadForCreateBrandNewFile(const FilePath& local_path, | |
242 const FileOperationCallback& callback, | |
243 DriveFileError result); | |
244 | |
245 // Invoked upon completion of GetEntryInfoByPath initiated by | |
246 // GetFileByPath. It then continues to invoke GetResolvedFileByPath. | |
247 void OnGetEntryInfoCompleteForGetFileByPath( | |
248 const FilePath& file_path, | |
249 const GetFileCallback& get_file_callback, | |
250 const GetContentCallback& get_content_callback, | |
251 DriveFileError error, | |
252 scoped_ptr<DriveEntryProto> file_info); | |
253 | |
254 // Invoked upon completion of GetEntryInfoByPath initiated by OpenFile. | |
255 // It then continues to invoke GetResolvedFileByPath and proceeds to | |
256 // OnGetFileCompleteForOpenFile. | |
257 void OnGetEntryInfoCompleteForOpenFile( | |
258 const FilePath& file_path, | |
259 const OpenFileCallback& callback, | |
260 DriveFileError error, | |
261 scoped_ptr<DriveEntryProto> file_info); | |
262 | |
263 // Invoked at the last step of OpenFile. It removes |file_path| from the | |
264 // current set of opened files if |result| is an error, and then invokes the | |
265 // |callback| function. | |
266 void OnOpenFileFinished(const FilePath& file_path, | |
267 const OpenFileCallback& callback, | |
268 DriveFileError result, | |
269 const FilePath& cache_file_path); | |
270 | |
271 // Invoked during the process of CloseFile. What is done here is as follows: | |
272 // 1) Gets resource_id and md5 of the entry at |file_path|. | |
273 // 2) Commits the modification to the cache system. | |
274 // 3) Removes the |file_path| from the remembered set of opened files. | |
275 // 4) Invokes the user-supplied |callback|. | |
276 // |callback| must not be null. | |
277 void CloseFileOnUIThreadAfterGetEntryInfo( | |
278 const FilePath& file_path, | |
279 const FileOperationCallback& callback, | |
280 DriveFileError error, | |
281 scoped_ptr<DriveEntryProto> entry_proto); | |
282 void CloseFileOnUIThreadAfterCommitDirtyInCache( | |
283 const FileOperationCallback& callback, | |
284 DriveFileError error, | |
285 const std::string& resource_id, | |
286 const std::string& md5); | |
287 void CloseFileOnUIThreadFinalize(const FilePath& file_path, | |
288 const FileOperationCallback& callback, | |
289 DriveFileError result); | |
290 | |
291 // Invoked upon completion of GetFileByPath initiated by Copy. If | |
292 // GetFileByPath reports no error, calls TransferRegularFile to transfer | |
293 // |local_file_path| to |remote_dest_file_path|. | |
294 // | |
295 // Can be called from UI thread. |callback| is run on the calling thread. | |
296 void OnGetFileCompleteForCopy(const FilePath& remote_dest_file_path, | |
297 const FileOperationCallback& callback, | |
298 DriveFileError error, | |
299 const FilePath& local_file_path, | |
300 const std::string& unused_mime_type, | |
301 DriveFileType file_type); | |
302 | |
303 // Invoked upon completion of GetFileByPath initiated by | |
304 // TransferFileFromRemoteToLocal. If GetFileByPath reports no error, calls | |
305 // CopyLocalFileOnBlockingPool to copy |local_file_path| to | |
306 // |local_dest_file_path|. | |
307 // | |
308 // Can be called from UI thread. |callback| is run on the calling thread. | |
309 // |callback| must not be null. | |
310 void OnGetFileCompleteForTransferFile(const FilePath& local_dest_file_path, | |
311 const FileOperationCallback& callback, | |
312 DriveFileError error, | |
313 const FilePath& local_file_path, | |
314 const std::string& unused_mime_type, | |
315 DriveFileType file_type); | |
316 | |
317 // Invoked upon completion of GetFileByPath initiated by OpenFile. If | |
318 // GetFileByPath is successful, calls MarkDirtyInCache to mark the cache | |
319 // file as dirty for the file identified by |file_info.resource_id| and | |
320 // |file_info.md5|. | |
321 // | |
322 // Can be called from UI thread. |callback| is run on the calling thread. | |
323 void OnGetFileCompleteForOpenFile( | |
324 const OpenFileCallback& callback, | |
325 const GetFileCompleteForOpenParams& file_info, | |
326 DriveFileError error, | |
327 const FilePath& file_path, | |
328 const std::string& mime_type, | |
329 DriveFileType file_type); | |
330 | |
331 // Copies a document with |resource_id| to the directory at |dir_path| | |
332 // and names the copied document as |new_name|. | |
333 // | |
334 // Can be called from UI thread. |callback| is run on the calling thread. | |
335 // |callback| must not be null. | |
336 void CopyDocumentToDirectory(const FilePath& dir_path, | |
337 const std::string& resource_id, | |
338 const FilePath::StringType& new_name, | |
339 const FileOperationCallback& callback); | |
340 | |
341 // Renames a file or directory at |file_path| to |new_name| in the same | |
342 // directory. |callback| will receive the new file path if the operation is | |
343 // successful. If the new name already exists in the same directory, the file | |
344 // name is uniquified by adding a parenthesized serial number like | |
345 // "foo (2).txt" | |
346 // | |
347 // Can be called from UI thread. |callback| is run on the calling thread. | |
348 // |callback| must not be null. | |
349 void Rename(const FilePath& file_path, | |
350 const FilePath::StringType& new_name, | |
351 const FileMoveCallback& callback); | |
352 | |
353 // Part of Rename(). Called after GetEntryInfoByPath() is complete. | |
354 void RenameAfterGetEntryInfo(const FilePath& file_path, | |
355 const FilePath::StringType& new_name, | |
356 const FileMoveCallback& callback, | |
357 DriveFileError error, | |
358 scoped_ptr<DriveEntryProto> entry_proto); | |
359 | |
360 // Moves a file or directory at |file_path| in the root directory to | |
361 // another directory at |dir_path|. This function does nothing if | |
362 // |dir_path| points to the root directory. | |
363 // | |
364 // Can be called from UI thread. |callback| is run on the calling thread. | |
365 // |callback| must not be null. | |
366 void MoveEntryFromRootDirectory(const FilePath& dir_path, | |
367 const FileOperationCallback& callback, | |
368 DriveFileError error, | |
369 const FilePath& file_path); | |
370 | |
371 // Part of MoveEntryFromRootDirectory(). Called after | |
372 // GetEntryInfoPairByPaths() is complete. |callback| must not be null. | |
373 void MoveEntryFromRootDirectoryAfterGetEntryInfoPair( | |
374 const FileOperationCallback& callback, | |
375 scoped_ptr<EntryInfoPairResult> result); | |
376 | |
377 // Part of RemoveEntryFromNonRootDirectory(). Called after | |
378 // GetEntryInfoPairByPaths() is complete. |callback| must not be null. | |
379 void RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( | |
380 const FileMoveCallback& callback, | |
381 scoped_ptr<EntryInfoPairResult> result); | |
382 | |
383 // Removes a file or directory at |file_path| from the current directory if | |
384 // it's not in the root directory. This essentially moves an entry to the | |
385 // root directory on the server side. | |
386 // | |
387 // Can be called from UI thread. |callback| is run on the calling thread. | |
388 // |callback| must not be null. | |
389 void RemoveEntryFromNonRootDirectory(const FileMoveCallback& callback, | |
390 DriveFileError error, | |
391 const FilePath& file_path); | |
392 | |
393 // Removes file under |file_path| on the client side. | |
394 // |resource_id| contains the resource id of the removed file if it was a | |
395 // file. | |
396 // Return PLATFORM_FILE_OK if successful. | |
397 DriveFileError RemoveEntryLocally(const FilePath& file_path, | |
398 std::string* resource_id); | |
399 | |
400 // A pass-through callback used for bridging from | |
401 // FileMoveCallback to FileOperationCallback. | |
402 void OnFilePathUpdated(const FileOperationCallback& cllback, | |
403 DriveFileError error, | |
404 const FilePath& file_path); | |
405 | |
406 // Invoked upon completion of MarkDirtyInCache initiated by OpenFile. Invokes | |
407 // |callback| with |cache_file_path|, which is the path of the cache file | |
408 // ready for modification. | |
409 // | |
410 // Must be called on UI thread. | |
411 void OnMarkDirtyInCacheCompleteForOpenFile(const OpenFileCallback& callback, | |
412 DriveFileError error, | |
413 const std::string& resource_id, | |
414 const std::string& md5, | |
415 const FilePath& cache_file_path); | |
416 | |
417 // Callback for handling document copy attempt. | |
418 // |callback| must not be null. | |
419 void OnCopyDocumentCompleted(const FilePath& dir_path, | |
420 const FileOperationCallback& callback, | |
421 GDataErrorCode status, | |
422 scoped_ptr<base::Value> data); | |
423 | |
424 // Callback for handling an attempt to move a file or directory from the | |
425 // root directory to another directory on the server side. This function | |
426 // moves |entry| to the root directory on the client side with | |
427 // DriveResourceMetadata::MoveEntryToDirectory(). | |
428 // | |
429 // |callback| must not be null. | |
430 void OnMoveEntryFromRootDirectoryCompleted( | |
431 const FileOperationCallback& callback, | |
432 const FilePath& file_path, | |
433 const FilePath& dir_path, | |
434 GDataErrorCode status, | |
435 const GURL& document_url); | |
436 | |
437 // Callback for handling account metadata fetch. | |
438 void OnGetAvailableSpace(const GetAvailableSpaceCallback& callback, | |
439 GDataErrorCode status, | |
440 scoped_ptr<base::Value> data); | |
441 | |
442 // Callback for handling Drive V2 about resource fetch. | |
443 void OnGetAboutResource(const GetAvailableSpaceCallback& callback, | |
444 GDataErrorCode status, | |
445 scoped_ptr<base::Value> data); | |
446 | |
447 // Callback for handling document remove attempt. | |
448 void OnRemovedDocument(const FileOperationCallback& callback, | |
449 const FilePath& file_path, | |
450 GDataErrorCode status, | |
451 const GURL& document_url); | |
452 | |
453 // Callback for handling directory create requests. | |
454 void OnCreateDirectoryCompleted(const CreateDirectoryParams& params, | |
455 GDataErrorCode status, | |
456 scoped_ptr<base::Value> created_entry); | |
457 | |
458 // Callback for handling file downloading requests. | |
459 void OnFileDownloaded(const GetFileFromCacheParams& params, | |
460 GDataErrorCode status, | |
461 const GURL& content_url, | |
462 const FilePath& downloaded_file_path); | |
463 | |
464 // Unpins file if cache entry is pinned. | |
465 void UnpinIfPinned(const std::string& resource_id, | |
466 const std::string& md5, | |
467 bool success, | |
468 const DriveCacheEntry& cache_entry); | |
469 | |
470 // Similar to OnFileDownloaded() but takes |has_enough_space| so we report | |
471 // an error in case we don't have enough disk space. | |
472 void OnFileDownloadedAndSpaceChecked(const GetFileFromCacheParams& params, | |
473 GDataErrorCode status, | |
474 const GURL& content_url, | |
475 const FilePath& downloaded_file_path, | |
476 bool* has_enough_space); | |
477 | |
478 // Callback for handling internal StoreToCache() calls after downloading | |
479 // file content. | |
480 void OnDownloadStoredToCache(DriveFileError error, | |
481 const std::string& resource_id, | |
482 const std::string& md5); | |
483 | |
484 // Callback for handling resource rename attempt. Renames a file or | |
485 // directory at |file_path| on the client side. | |
486 // |callback| must not be null. | |
487 void RenameEntryLocally(const FilePath& file_path, | |
488 const FilePath::StringType& new_name, | |
489 const FileMoveCallback& callback, | |
490 GDataErrorCode status, | |
491 const GURL& document_url); | |
492 | |
493 // Callback for handling an attempt to remove a file or directory from | |
494 // another directory. Moves a file or directory at |file_path| to root on | |
495 // the client side. | |
496 // |callback| must not be null. | |
497 void MoveEntryToRootDirectoryLocally(const FileMoveCallback& callback, | |
498 const FilePath& file_path, | |
499 const FilePath& dir_path, | |
500 GDataErrorCode status, | |
501 const GURL& document_url); | |
502 | |
503 // Removes a file or directory under |file_path| on the client side and the | |
504 // corresponding file from cache if it exists. Returns PLATFORM_FILE_OK if | |
505 // successful. | |
506 DriveFileError RemoveEntryAndCacheLocally(const FilePath& file_path); | |
507 | |
508 // Callback when an entry is moved to another directory on the client side. | |
509 // Notifies the directory change and runs |callback|. | |
510 // |callback| may be null. | |
511 void NotifyAndRunFileMoveCallback( | |
512 const FileMoveCallback& callback, | |
513 DriveFileError error, | |
514 const FilePath& moved_file_path); | |
515 | |
516 // Callback when an entry is moved to another directory on the client side. | |
517 // Notifies the directory change and runs |callback|. | |
518 // |callback| must not be null. | |
519 void NotifyAndRunFileOperationCallback( | |
520 const FileOperationCallback& callback, | |
521 DriveFileError error, | |
522 const FilePath& moved_file_path); | |
523 | |
524 // FileMoveCallback for directory changes. | |
525 void OnDirectoryChangeFileMoveCallback( | |
526 DriveFileError error, | |
527 const FilePath& directory_path); | |
528 | |
529 // Callback for GetEntryByResourceIdAsync. | |
530 // Removes stale entry upon upload of file. | |
531 void RemoveStaleEntryOnUpload(const std::string& resource_id, | |
532 DriveDirectory* parent_dir, | |
533 const FileMoveCallback& callback, | |
534 DriveEntry* existing_entry); | |
535 | |
536 // Continues to add an uploaded file after existing entry has been deleted. | |
537 void ContinueAddUploadedFile(AddUploadedFileParams* params, | |
538 DriveFileError error, | |
539 const FilePath& file_path); | |
540 | |
541 // Adds the uploaded file to the cache. | |
542 void AddUploadedFileToCache(AddUploadedFileParams* params, | |
543 DriveFileError error, | |
544 const FilePath& file_path); | |
545 | |
546 // Converts |entry_value| into GFileDocument instance and adds it | |
547 // to virtual file system at |directory_path|. | |
548 DriveFileError AddNewDirectory(const FilePath& directory_path, | |
549 base::Value* entry_value); | |
550 | |
551 // Given non-existing |directory_path|, finds the first missing parent | |
552 // directory of |directory_path|. | |
553 FindMissingDirectoryResult FindFirstMissingParentDirectory( | |
554 const FilePath& directory_path, | |
555 GURL* last_dir_content_url, | |
556 FilePath* first_missing_parent_path); | |
557 | |
558 // Callback for handling results of ReloadFeedFromServerIfNeeded() initiated | |
559 // from CheckForUpdates(). This callback checks whether feed is successfully | |
560 // reloaded, and in case of failure, restores the content origin of the root | |
561 // directory. | |
562 void OnUpdateChecked(ContentOrigin initial_origin, | |
563 DriveFileError error); | |
564 | |
565 // Notifies that the initial load is finished and runs |callback|. | |
566 // |callback| must not be null. | |
567 void NotifyInitialLoadFinishedAndRun(const FileOperationCallback& callback, | |
568 DriveFileError error); | |
569 | |
570 // Helper function that completes bookkeeping tasks related to | |
571 // completed file transfer. | |
572 void OnTransferCompleted(const FileOperationCallback& callback, | |
573 DriveFileError error, | |
574 scoped_ptr<UploadFileInfo> upload_file_info); | |
575 | |
576 // Kicks off file upload once it receives |file_size| and |content_type|. | |
577 void StartFileUploadOnUIThread(const StartFileUploadParams& params, | |
578 DriveFileError* error, | |
579 int64* file_size, | |
580 std::string* content_type); | |
581 | |
582 // Part of StartFileUploadOnUIThread(). Called after GetEntryInfoByPath() | |
583 // is complete. | |
584 void StartFileUploadOnUIThreadAfterGetEntryInfo( | |
585 const StartFileUploadParams& params, | |
586 int64 file_size, | |
587 std::string content_type, | |
588 DriveFileError error, | |
589 scoped_ptr<DriveEntryProto> entry_proto); | |
590 | |
591 // Cache intermediate callbacks, that run on calling thread, for above cache | |
592 // tasks that were run on blocking pool. | |
593 | |
594 // Helper function for internally handling responses from | |
595 // GetFileFromCacheByResourceIdAndMd5() calls during processing of | |
596 // GetFileByPath() request. | |
597 void OnGetFileFromCache(const GetFileFromCacheParams& params, | |
598 DriveFileError error, | |
599 const std::string& resource_id, | |
600 const std::string& md5, | |
601 const FilePath& cache_file_path); | |
602 | |
603 // Callback for |drive_service_->GetDocumentEntry|. | |
604 // It is called before file download. If GetDocumentEntry was successful, | |
605 // file download procedure is started for the file. The file is downloaded | |
606 // from the content url extracted from the fetched metadata to | |
607 // |cache_file_path|. Also, available space checks are done using file size | |
608 // from the fetched metadata. | |
609 void OnGetDocumentEntry(const FilePath& cache_file_path, | |
610 const GetFileFromCacheParams& params, | |
611 GDataErrorCode status, | |
612 scoped_ptr<base::Value> data); | |
613 | |
614 // Starts downloading a file if we have enough disk space indicated by | |
615 // |has_enough_space|. | |
616 void StartDownloadFileIfEnoughSpace(const GetFileFromCacheParams& params, | |
617 const GURL& content_url, | |
618 const FilePath& cache_file_path, | |
619 bool* has_enough_space); | |
620 | |
621 // Changes state of hosted documents visibility, triggers directory refresh. | |
622 void SetHideHostedDocuments(bool hide); | |
623 | |
624 // Initializes preference change observer. | |
625 void InitializePreferenceObserver(); | |
626 | |
627 // Part of GetEntryInfoByPathOnUIThread() | |
628 // 1) Called when the feed is loaded. | |
629 // 2) Called when an entry is found. | |
630 // |callback| must not be null. | |
631 void GetEntryInfoByPathOnUIThreadAfterLoad( | |
632 const FilePath& file_path, | |
633 const GetEntryInfoCallback& callback, | |
634 DriveFileError error); | |
635 void GetEntryInfoByPathOnUIThreadAfterGetEntry( | |
636 const GetEntryInfoCallback& callback, | |
637 DriveFileError error, | |
638 scoped_ptr<DriveEntryProto> entry_proto); | |
639 | |
640 // Part of ReadDirectoryByPathOnUIThread() | |
641 // 1) Called when the feed is loaded. | |
642 // 2) Called when an entry is found. | |
643 // |callback| must not be null. | |
644 void ReadDirectoryByPathOnUIThreadAfterLoad( | |
645 const FilePath& file_path, | |
646 const ReadDirectoryWithSettingCallback& callback, | |
647 DriveFileError error); | |
648 void ReadDirectoryByPathOnUIThreadAfterRead( | |
649 const ReadDirectoryWithSettingCallback& callback, | |
650 DriveFileError error, | |
651 scoped_ptr<DriveEntryProtoVector> entries); | |
652 | |
653 // Loads the feed from the cache or the server if not yet loaded. Runs | |
654 // |callback| upon the completion with the error code. | |
655 // |callback| must not be null. | |
656 void LoadFeedIfNeeded(const FileOperationCallback& callback); | |
657 | |
658 // Gets |file_path| from the file system after the file info is already | |
659 // resolved with GetEntryInfoByPath(). This function is called by | |
660 // OnGetEntryInfoCompleteForGetFileByPath and | |
661 // OnGetEntryInfoCompleteForOpenFile. | |
662 void GetResolvedFileByPath( | |
663 const FilePath& file_path, | |
664 const GetFileCallback& get_file_callback, | |
665 const GetContentCallback& get_content_callback, | |
666 DriveFileError error, | |
667 const DriveEntryProto* entry_proto); | |
668 | |
669 // Part of UpdateFileByResourceId(). Called when | |
670 // DriveDirectory::GetEntryInfoByResourceId() is complete. | |
671 // |callback| must not be null. | |
672 void UpdateFileByEntryInfo( | |
673 const FileOperationCallback& callback, | |
674 DriveFileError error, | |
675 const FilePath& /* drive_file_path */, | |
676 scoped_ptr<DriveEntryProto> entry_proto); | |
677 | |
678 // Part of UpdateFileByResourceId(). | |
679 // Called when DriveCache::GetFileOnUIThread() is completed for | |
680 // UpdateFileByResourceId(). | |
681 // |callback| must not be null. | |
682 void OnGetFileCompleteForUpdateFile(const FileOperationCallback& callback, | |
683 DriveFileError error, | |
684 const std::string& resource_id, | |
685 const std::string& md5, | |
686 const FilePath& cache_file_path); | |
687 | |
688 // Part of UpdateFileByResourceId(). | |
689 // Callback for getting the size of the cache file in the blocking pool. | |
690 // |callback| must not be null. | |
691 void OnGetFileSizeCompleteForUpdateFile(const FileOperationCallback& callback, | |
692 const std::string& resource_id, | |
693 const FilePath& cache_file_path, | |
694 DriveFileError* error, | |
695 int64* file_size); | |
696 | |
697 // Part of UpdateFileByResourceId(). | |
698 // Callback for GDataRootDirectory::GetEntryByResourceIdAsync. | |
699 // |callback| must not be null. | |
700 void OnGetFileCompleteForUpdateFileByEntry( | |
701 const FileOperationCallback& callback, | |
702 int64 file_size, | |
703 const FilePath& cache_file_path, | |
704 DriveFileError error, | |
705 const FilePath& drive_file_path, | |
706 scoped_ptr<DriveEntryProto> entry_proto); | |
707 | |
708 // Part of UpdateFileByResourceId(). | |
709 // Called when GDataUploader::UploadUpdatedFile() is completed for | |
710 // UpdateFileByResourceId(). | |
711 // |callback| must not be null. | |
712 void OnUpdatedFileUploaded(const FileOperationCallback& callback, | |
713 DriveFileError error, | |
714 scoped_ptr<UploadFileInfo> upload_file_info); | |
715 | |
716 // The following functions are used to forward calls to asynchronous public | |
717 // member functions to UI thread. | |
718 void SearchAsyncOnUIThread(const std::string& search_query, | |
719 const GURL& next_feed, | |
720 const SearchCallback& callback); | |
721 void OpenFileOnUIThread(const FilePath& file_path, | |
722 const OpenFileCallback& callback); | |
723 void CloseFileOnUIThread(const FilePath& file_path, | |
724 const FileOperationCallback& callback); | |
725 void CopyOnUIThread(const FilePath& src_file_path, | |
726 const FilePath& dest_file_path, | |
727 const FileOperationCallback& callback); | |
728 void MoveOnUIThread(const FilePath& src_file_path, | |
729 const FilePath& dest_file_path, | |
730 const FileOperationCallback& callback); | |
731 void RemoveOnUIThread(const FilePath& file_path, | |
732 bool is_recursive, | |
733 const FileOperationCallback& callback); | |
734 void CreateDirectoryOnUIThread(const FilePath& directory_path, | |
735 bool is_exclusive, | |
736 bool is_recursive, | |
737 const FileOperationCallback& callback); | |
738 void CreateFileOnUIThread(const FilePath& file_path, | |
739 bool is_exclusive, | |
740 const FileOperationCallback& callback); | |
741 void GetFileByPathOnUIThread( | |
742 const FilePath& file_path, | |
743 const GetFileCallback& get_file_callback, | |
744 const GetContentCallback& get_content_callback); | |
745 void GetFileByResourceIdOnUIThread( | |
746 const std::string& resource_id, | |
747 const GetFileCallback& get_file_callback, | |
748 const GetContentCallback& get_content_callback); | |
749 void GetFileByEntryOnUIThread( | |
750 const GetFileCallback& get_file_callback, | |
751 const GetContentCallback& get_content_callback, | |
752 DriveEntry* entry); | |
753 void GetEntryInfoByEntryOnUIThread( | |
754 const GetEntryInfoWithFilePathCallback& callback, | |
755 DriveEntry* entry); | |
756 void UpdateFileByResourceIdOnUIThread(const std::string& resource_id, | |
757 const FileOperationCallback& callback); | |
758 void GetEntryInfoByPathOnUIThread(const FilePath& file_path, | |
759 const GetEntryInfoCallback& callback); | |
760 void GetEntryInfoByResourceIdOnUIThread( | |
761 const std::string& resource_id, | |
762 const GetEntryInfoWithFilePathCallback& callback); | |
763 void ReadDirectoryByPathOnUIThread( | |
764 const FilePath& file_path, | |
765 const ReadDirectoryWithSettingCallback& callback); | |
766 void RequestDirectoryRefreshOnUIThread(const FilePath& file_path); | |
767 void OnRequestDirectoryRefresh(const FilePath& directory_path, | |
768 GetDocumentsParams* params, | |
769 DriveFileError error); | |
770 void GetAvailableSpaceOnUIThread(const GetAvailableSpaceCallback& callback); | |
771 void AddUploadedFileOnUIThread(UploadMode upload_mode, | |
772 const FilePath& virtual_dir_path, | |
773 scoped_ptr<DocumentEntry> entry, | |
774 const FilePath& file_content_path, | |
775 DriveCache::FileOperationType cache_operation, | |
776 const base::Closure& callback); | |
777 void UpdateEntryDataOnUIThread(const std::string& resource_id, | |
778 const std::string& md5, | |
779 scoped_ptr<DocumentEntry> entry, | |
780 const FilePath& file_content_path, | |
781 const base::Closure& callback); | |
782 | |
783 // Part of CopyOnUIThread(). Called after GetEntryInfoPairByPaths() is | |
784 // complete. |callback| must not be null. | |
785 void CopyOnUIThreadAfterGetEntryInfoPair( | |
786 const FilePath& dest_file_path, | |
787 const FileOperationCallback& callback, | |
788 scoped_ptr<EntryInfoPairResult> result); | |
789 | |
790 // Part of MoveOnUIThread(). Called after GetEntryInfoPairByPaths() is | |
791 // complete. |callback| must not be null. | |
792 void MoveOnUIThreadAfterGetEntryInfoPair( | |
793 const FilePath& dest_file_path, | |
794 const FileOperationCallback& callback, | |
795 scoped_ptr<EntryInfoPairResult> result); | |
796 | |
797 // Part of RemoveOnUIThread(). Called after GetEntryInfoByPath() is | |
798 // complete. | |
799 void RemoveOnUIThreadAfterGetEntryInfo( | |
800 const FilePath& file_path, | |
801 bool is_recursive, | |
802 const FileOperationCallback& callback, | |
803 DriveFileError error, | |
804 scoped_ptr<DriveEntryProto> entry_proto); | |
805 | |
806 // Part of RequestDirectoryRefreshOnUIThread(). Called after | |
807 // GetEntryInfoByPath() is complete. | |
808 void RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo( | |
809 const FilePath& file_path, | |
810 DriveFileError error, | |
811 scoped_ptr<DriveEntryProto> entry_proto); | |
812 | |
813 // Part of GetEntryByResourceId and GetEntryByPath. Checks whether there is a | |
814 // local dirty cache for the entry, and if there is, replace the | |
815 // PlatformFileInfo part of the |entry_proto| with the locally modified info. | |
816 // |callback| must not be null. | |
817 void CheckLocalModificationAndRun(scoped_ptr<DriveEntryProto> entry_proto, | |
818 const GetEntryInfoCallback& callback); | |
819 void CheckLocalModificationAndRunAfterGetCacheEntry( | |
820 scoped_ptr<DriveEntryProto> entry_proto, | |
821 const GetEntryInfoCallback& callback, | |
822 bool success, | |
823 const DriveCacheEntry& cache_entry); | |
824 void CheckLocalModificationAndRunAfterGetCacheFile( | |
825 scoped_ptr<DriveEntryProto> entry_proto, | |
826 const GetEntryInfoCallback& callback, | |
827 DriveFileError error, | |
828 const std::string& resource_id, | |
829 const std::string& md5, | |
830 const FilePath& local_cache_path); | |
831 void CheckLocalModificationAndRunAfterGetFileInfo( | |
832 scoped_ptr<DriveEntryProto> entry_proto, | |
833 const GetEntryInfoCallback& callback, | |
834 base::PlatformFileInfo* file_info, | |
835 bool* get_file_info_result); | |
836 | |
837 // All members should be accessed only on UI thread. Do not post tasks to | |
838 // other threads with base::Unretained(this). | |
839 scoped_ptr<DriveResourceMetadata> resource_metadata_; | |
840 | |
841 // The profile hosts the GDataFileSystem via GDataSystemService. | |
842 Profile* profile_; | |
843 | |
844 // The cache owned by GDataSystemService. | |
845 DriveCache* cache_; | |
846 | |
847 // The uploader owned by GDataSystemService. | |
848 GDataUploaderInterface* uploader_; | |
849 | |
850 // The document service owned by GDataSystemService. | |
851 DriveServiceInterface* drive_service_; | |
852 | |
853 // The webapps registry owned by GDataSystemService. | |
854 DriveWebAppsRegistryInterface* webapps_registry_; | |
855 | |
856 // Periodic timer for checking updates. | |
857 base::Timer update_timer_; | |
858 | |
859 // True if hosted documents should be hidden. | |
860 bool hide_hosted_docs_; | |
861 | |
862 // The set of paths opened by OpenFile but not yet closed by CloseFile. | |
863 std::set<FilePath> open_files_; | |
864 | |
865 scoped_ptr<PrefChangeRegistrar> pref_registrar_; | |
866 | |
867 // The loader is used to load the feeds. | |
868 scoped_ptr<GDataWapiFeedLoader> feed_loader_; | |
869 | |
870 ObserverList<GDataFileSystemInterface::Observer> observers_; | |
871 | |
872 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
873 | |
874 // WeakPtrFactory and WeakPtr bound to the UI thread. | |
875 // Note: These should remain the last member so they'll be destroyed and | |
876 // invalidate the weak pointers before any other members are destroyed. | |
877 base::WeakPtrFactory<GDataFileSystem> ui_weak_ptr_factory_; | |
878 // Unlike other classes, we need this as we need this to redirect a task | |
879 // from IO thread to UI thread. | |
880 base::WeakPtr<GDataFileSystem> ui_weak_ptr_; | |
881 }; | |
882 | |
883 } // namespace gdata | |
884 | |
885 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | |
OLD | NEW |