Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.h

Issue 9742002: Wired GDataFileSystem::GetFile() method with internal cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_
7 7
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 private: 103 private:
104 // FindFileDelegate overrides. 104 // FindFileDelegate overrides.
105 virtual void OnDone(base::PlatformFileError error, 105 virtual void OnDone(base::PlatformFileError error,
106 const FilePath& directory_path, 106 const FilePath& directory_path,
107 GDataFileBase* file) OVERRIDE; 107 GDataFileBase* file) OVERRIDE;
108 108
109 // File entry that was found. 109 // File entry that was found.
110 GDataFileBase* file_; 110 GDataFileBase* file_;
111 }; 111 };
112 112
113 // Helper structure used for extracting key properties from GDataFile object.
114 struct GDataFileProperties {
115 GDataFileProperties();
116 ~GDataFileProperties();
117
118 base::PlatformFileInfo file_info;
119 std::string resource_id;
120 std::string file_md5;
121 GURL content_url;
122 GURL edit_url;
123 bool is_hosted_document;
124 };
125
113 // GData file system abstraction layer. 126 // GData file system abstraction layer.
114 // The interface is defined to make GDataFileSystem mockable. 127 // The interface is defined to make GDataFileSystem mockable.
115 class GDataFileSystemInterface { 128 class GDataFileSystemInterface {
116 public: 129 public:
117 virtual ~GDataFileSystemInterface() {} 130 virtual ~GDataFileSystemInterface() {}
118 131
119 // Used to notify events on the file system. 132 // Used to notify events on the file system.
120 class Observer { 133 class Observer {
121 public: 134 public:
122 // Trigerred when a file has been pinned, after the cache state is 135 // Trigerred when a file has been pinned, after the cache state is
(...skipping 11 matching lines...) Expand all
134 147
135 // Enum defining GCache subdirectory location. 148 // Enum defining GCache subdirectory location.
136 enum CacheSubdir { // This indexes into |cache_paths_| vector. 149 enum CacheSubdir { // This indexes into |cache_paths_| vector.
137 CACHE_TYPE_META = 0, 150 CACHE_TYPE_META = 0,
138 CACHE_TYPE_PINNED, 151 CACHE_TYPE_PINNED,
139 CACHE_TYPE_OUTGOING, 152 CACHE_TYPE_OUTGOING,
140 CACHE_TYPE_PERSISTENT, 153 CACHE_TYPE_PERSISTENT,
141 CACHE_TYPE_TMP, 154 CACHE_TYPE_TMP,
142 }; 155 };
143 156
157 // Enum defining origin of a cached file.
158 enum CachedFileOrigin {
159 CACHED_FILE_FROM_SERVER = 0,
160 CACHED_FILE_LOCALLY_MODIFIED,
161 };
162
144 // Authenticates the user by fetching the auth token as 163 // Authenticates the user by fetching the auth token as
145 // needed. |callback| will be run with the error code and the auth 164 // needed. |callback| will be run with the error code and the auth
146 // token, on the thread this function is run. 165 // token, on the thread this function is run.
147 // 166 //
148 // Must be called on UI thread. 167 // Must be called on UI thread.
149 virtual void Authenticate(const AuthStatusCallback& callback) = 0; 168 virtual void Authenticate(const AuthStatusCallback& callback) = 0;
150 169
151 // Finds file info by using virtual |file_path|. This call will also 170 // Finds file info by using virtual |file_path|. This call will also
152 // retrieve and refresh file system content from server and disk cache. 171 // retrieve and refresh file system content from server and disk cache.
153 // 172 //
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // Gets the cache state of file corresponding to |resource_id| and |md5| if it 284 // Gets the cache state of file corresponding to |resource_id| and |md5| if it
266 // exists on disk. 285 // exists on disk.
267 // Initializes cache if it has not been initialized. 286 // Initializes cache if it has not been initialized.
268 // Upon completion, |callback| is invoked on the thread where this method was 287 // Upon completion, |callback| is invoked on the thread where this method was
269 // called with the cache state if file exists in cache or CACHE_STATE_NONE 288 // called with the cache state if file exists in cache or CACHE_STATE_NONE
270 // otherwise. 289 // otherwise.
271 virtual void GetCacheState(const std::string& resource_id, 290 virtual void GetCacheState(const std::string& resource_id,
272 const std::string& md5, 291 const std::string& md5,
273 const GetCacheStateCallback& callback) = 0; 292 const GetCacheStateCallback& callback) = 0;
274 293
275 // Finds file object by |file_path| and returns its |file_info|. 294 // Finds file object by |file_path| and returns its key |properties|.
276 // Returns true if file was found. 295 // Returns true if file was found.
277 virtual bool GetFileInfoFromPath(const FilePath& gdata_file_path, 296 virtual bool GetFileInfoFromPath(const FilePath& gdata_file_path,
278 base::PlatformFileInfo* file_info) = 0; 297 GDataFileProperties* properties) = 0;
279 298
280 // Returns the tmp sub-directory under gdata cache directory, i.e. 299 // Returns the tmp sub-directory under gdata cache directory, i.e.
281 // <user_profile_dir>/GCache/v1/tmp 300 // <user_profile_dir>/GCache/v1/tmp
282 virtual FilePath GetGDataCacheTmpDirectory() = 0; 301 virtual FilePath GetGDataCacheTmpDirectory() = 0;
283 302
284 // Fetches the user's Account Metadata to find out current quota information 303 // Fetches the user's Account Metadata to find out current quota information
285 // and returns it to the callback. 304 // and returns it to the callback.
286 virtual void GetAvailableSpace(const GetAvailableSpaceCallback& callback) = 0; 305 virtual void GetAvailableSpace(const GetAvailableSpaceCallback& callback) = 0;
287 }; 306 };
288 307
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 GetProgressStatusList() OVERRIDE; 342 GetProgressStatusList() OVERRIDE;
324 virtual bool CancelOperation(const FilePath& file_path) OVERRIDE; 343 virtual bool CancelOperation(const FilePath& file_path) OVERRIDE;
325 virtual void AddOperationObserver( 344 virtual void AddOperationObserver(
326 GDataOperationRegistry::Observer* observer) OVERRIDE; 345 GDataOperationRegistry::Observer* observer) OVERRIDE;
327 virtual void RemoveOperationObserver( 346 virtual void RemoveOperationObserver(
328 GDataOperationRegistry::Observer* observer) OVERRIDE; 347 GDataOperationRegistry::Observer* observer) OVERRIDE;
329 virtual void GetCacheState(const std::string& resource_id, 348 virtual void GetCacheState(const std::string& resource_id,
330 const std::string& md5, 349 const std::string& md5,
331 const GetCacheStateCallback& callback) OVERRIDE; 350 const GetCacheStateCallback& callback) OVERRIDE;
332 virtual bool GetFileInfoFromPath(const FilePath& gdata_file_path, 351 virtual bool GetFileInfoFromPath(const FilePath& gdata_file_path,
333 base::PlatformFileInfo* file_info) OVERRIDE; 352 GDataFileProperties* properties) OVERRIDE;
334 virtual FilePath GetGDataCacheTmpDirectory() OVERRIDE; 353 virtual FilePath GetGDataCacheTmpDirectory() OVERRIDE;
335 virtual void GetAvailableSpace( 354 virtual void GetAvailableSpace(
336 const GetAvailableSpaceCallback& callback) OVERRIDE; 355 const GetAvailableSpaceCallback& callback) OVERRIDE;
337 356
338 private: 357 private:
339 friend class GDataUploader; 358 friend class GDataUploader;
340 friend class GDataFileSystemFactory; 359 friend class GDataFileSystemFactory;
341 friend class GDataFileSystemTest; 360 friend class GDataFileSystemTest;
342 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, 361 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest,
343 FindFirstMissingParentDirectory); 362 FindFirstMissingParentDirectory);
(...skipping 22 matching lines...) Expand all
366 const FileOperationCallback& callback); 385 const FileOperationCallback& callback);
367 ~CreateDirectoryParams(); 386 ~CreateDirectoryParams();
368 387
369 const FilePath created_directory_path; 388 const FilePath created_directory_path;
370 const FilePath target_directory_path; 389 const FilePath target_directory_path;
371 const bool is_exclusive; 390 const bool is_exclusive;
372 const bool is_recursive; 391 const bool is_recursive;
373 FileOperationCallback callback; 392 FileOperationCallback callback;
374 }; 393 };
375 394
395 // Defines set of parameters passed to intermediate callbacks during
396 // execution of GetFile() method.
397 struct GetFileFromCacheParams {
398 GetFileFromCacheParams(const FilePath& virtual_file_path,
399 const FilePath& local_tmp_path,
400 const GURL& content_url,
401 const std::string& resource_id,
402 const std::string& md5,
403 scoped_refptr<base::MessageLoopProxy> proxy,
404 const GetFileCallback& callback);
405 ~GetFileFromCacheParams();
406
407 FilePath virtual_file_path;
408 FilePath local_tmp_path;
409 GURL content_url;
410 std::string resource_id;
411 std::string md5;
412 scoped_refptr<base::MessageLoopProxy> proxy;
413 const GetFileCallback callback;
414 };
415
376 // Callback similar to FileOperationCallback but with a given 416 // Callback similar to FileOperationCallback but with a given
377 // |file_path|. 417 // |file_path|.
378 typedef base::Callback<void(base::PlatformFileError error, 418 typedef base::Callback<void(base::PlatformFileError error,
379 const FilePath& file_path)> 419 const FilePath& file_path)>
380 FilePathUpdateCallback; 420 FilePathUpdateCallback;
381 421
382 GDataFileSystem(Profile* profile, 422 GDataFileSystem(Profile* profile,
383 DocumentsServiceInterface* documents_service, 423 DocumentsServiceInterface* documents_service,
384 GDataSyncClientInterface* sync_client); 424 GDataSyncClientInterface* sync_client);
385 virtual ~GDataFileSystem(); 425 virtual ~GDataFileSystem();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 const GURL& document_url); 552 const GURL& document_url);
513 553
514 // Callback for handling directory create requests. 554 // Callback for handling directory create requests.
515 void OnCreateDirectoryCompleted( 555 void OnCreateDirectoryCompleted(
516 const CreateDirectoryParams& params, 556 const CreateDirectoryParams& params,
517 GDataErrorCode status, 557 GDataErrorCode status,
518 scoped_ptr<base::Value> created_entry); 558 scoped_ptr<base::Value> created_entry);
519 559
520 // Callback for handling file downloading requests. 560 // Callback for handling file downloading requests.
521 void OnFileDownloaded( 561 void OnFileDownloaded(
522 const GetFileCallback& callback, 562 const GetFileFromCacheParams& params,
523 GDataErrorCode status, 563 GDataErrorCode status,
524 const GURL& content_url, 564 const GURL& content_url,
525 const FilePath& temp_file); 565 const FilePath& downloaded_file_path);
566
567 // Callback for handling internal StoreToCache() calls after downloading
568 // file content.
569 void OnDownloadStoredToCache(base::PlatformFileError error,
570 const std::string& resource_id,
571 const std::string& md5);
526 572
527 // Callback for handling file upload initialization requests. 573 // Callback for handling file upload initialization requests.
528 void OnUploadLocationReceived( 574 void OnUploadLocationReceived(
529 const InitiateUploadCallback& callback, 575 const InitiateUploadCallback& callback,
530 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 576 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
531 GDataErrorCode code, 577 GDataErrorCode code,
532 const GURL& upload_location); 578 const GURL& upload_location);
533 579
534 // Callback for handling file upload resume requests. 580 // Callback for handling file upload resume requests.
535 void OnResumeUpload(const ResumeUploadCallback& callback, 581 void OnResumeUpload(const ResumeUploadCallback& callback,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // - provides absolute path for files to be cached or cached. 681 // - provides absolute path for files to be cached or cached.
636 // - updates the cached file on disk after user has edited it locally 682 // - updates the cached file on disk after user has edited it locally
637 // - handles eviction when disk runs out of space 683 // - handles eviction when disk runs out of space
638 // - uploads dirty files to gdata server. 684 // - uploads dirty files to gdata server.
639 // - etc. 685 // - etc.
640 686
641 // Returns absolute path of the file if it were cached or to be cached. 687 // Returns absolute path of the file if it were cached or to be cached.
642 FilePath GetCacheFilePath(const std::string& resource_id, 688 FilePath GetCacheFilePath(const std::string& resource_id,
643 const std::string& md5, 689 const std::string& md5,
644 CacheSubdir subdir_id, 690 CacheSubdir subdir_id,
645 bool is_local); 691 CachedFileOrigin file_orign);
646 692
647 // Stores |source_path| corresponding to |resource_id| and |md5| to cache. 693 // Stores |source_path| corresponding to |resource_id| and |md5| to cache.
648 // Initializes cache if it has not been initialized. 694 // Initializes cache if it has not been initialized.
649 // Upon completion, |callback| is invoked on the thread where this method was 695 // Upon completion, |callback| is invoked on the thread where this method was
650 // called. 696 // called.
651 // TODO(kuan): When URLFetcher can save response to a specified file (as
652 // opposed to only temporary file currently), remove |source_path| parameter.
653 void StoreToCache(const std::string& resource_id, 697 void StoreToCache(const std::string& resource_id,
654 const std::string& md5, 698 const std::string& md5,
655 const FilePath& source_path, 699 const FilePath& source_path,
656 const CacheOperationCallback& callback); 700 const CacheOperationCallback& callback);
657 701
658 // Checks if file corresponding to |resource_id| and |md5| exist on disk and 702 // Checks if file corresponding to |resource_id| and |md5| exist on disk and
659 // can be accessed i.e. not corrupted by previous file operations that didn't 703 // can be accessed i.e. not corrupted by previous file operations that didn't
660 // complete for whatever reasons. 704 // complete for whatever reasons.
661 // Initializes cache if it has not been initialized. 705 // Initializes cache if it has not been initialized.
662 // Upon completion, |callback| is invoked on the thread where this method was 706 // Upon completion, |callback| is invoked on the thread where this method was
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 mode_t mode_bits, 792 mode_t mode_bits,
749 const CacheOperationCallback& callback); 793 const CacheOperationCallback& callback);
750 794
751 // Helper function for OnFilePinned() and OnFileUnpinned(). 795 // Helper function for OnFilePinned() and OnFileUnpinned().
752 void OnCacheStatusModified(base::PlatformFileError error, 796 void OnCacheStatusModified(base::PlatformFileError error,
753 const std::string& resource_id, 797 const std::string& resource_id,
754 const std::string& md5, 798 const std::string& md5,
755 mode_t mode_bits, 799 mode_t mode_bits,
756 const CacheOperationCallback& callback); 800 const CacheOperationCallback& callback);
757 801
802 // Helper function for internally handling responses from GetFromCache()
803 // calls during processing of GetFile() request.
804 void OnGetFileFromCache(const GetFileFromCacheParams& params,
805 base::PlatformFileError error,
806 const std::string& resource_id,
807 const std::string& md5,
808 const FilePath& gdata_file_path,
809 const FilePath& cache_file_path);
810
758 // Callback for GetCacheState that gets cache state of file corresponding to 811 // Callback for GetCacheState that gets cache state of file corresponding to
759 // |resource_id| and |md5|. 812 // |resource_id| and |md5|.
760 void OnGetCacheState(const std::string& resource_id, 813 void OnGetCacheState(const std::string& resource_id,
761 const std::string& md5, 814 const std::string& md5,
762 const GetCacheStateCallback& callback); 815 const GetCacheStateCallback& callback);
763 816
764 // Cache internal helper functions. 817 // Cache internal helper functions.
765 818
766 void GetFromCacheInternal(const std::string& resource_id, 819 void GetFromCacheInternal(const std::string& resource_id,
767 const std::string& md5, 820 const std::string& md5,
768 const FilePath& gdata_file_path, 821 const FilePath& gdata_file_path,
769 const GetFromCacheCallback& callback); 822 const GetFromCacheCallback& callback);
770 823
771 // Unsafe (unlocked) version of InitializeCacheIfnecessary method. 824 // Unsafe (unlocked) version of InitializeCacheIfnecessary method.
772 void UnsafeInitializeCacheIfNecessary(); 825 void UnsafeInitializeCacheIfNecessary();
773 826
774 // Helper function used to perform file search on the calling thread of 827 // Helper function used to perform file search on the calling thread of
775 // FindFileByPath() request. 828 // FindFileByPath() request.
776 void FindFileByPathOnCallingThread(const FilePath& search_file_path, 829 void FindFileByPathOnCallingThread(const FilePath& search_file_path,
777 const FindFileCallback& callback); 830 const FindFileCallback& callback);
778 831
779 scoped_ptr<GDataRootDirectory> root_; 832 scoped_ptr<GDataRootDirectory> root_;
780 833
781 base::Lock lock_; 834 base::Lock lock_;
782 835
783 // The profile hosts the GDataFileSystem. 836 // The profile hosts the GDataFileSystem.
784 Profile* profile_; 837 Profile* profile_;
785 838
786 // The document service for the GDataFileSystem. 839 // The document service for the GDataFileSystem.
787 scoped_ptr<DocumentsServiceInterface> documents_service_; 840 scoped_ptr<DocumentsServiceInterface> documents_service_;
788 841
789 // File content uploader. 842 // File content uploader.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 virtual ~GDataFileSystemFactory(); 884 virtual ~GDataFileSystemFactory();
832 885
833 // ProfileKeyedServiceFactory: 886 // ProfileKeyedServiceFactory:
834 virtual ProfileKeyedService* BuildServiceInstanceFor( 887 virtual ProfileKeyedService* BuildServiceInstanceFor(
835 Profile* profile) const OVERRIDE; 888 Profile* profile) const OVERRIDE;
836 }; 889 };
837 890
838 } // namespace gdata 891 } // namespace gdata
839 892
840 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ 893 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698