OLD | NEW |
---|---|
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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 // Gets the cache state of file corresponding to |resource_id| and |md5| if it | 261 // Gets the cache state of file corresponding to |resource_id| and |md5| if it |
262 // exists on disk. | 262 // exists on disk. |
263 // Initializes cache if it has not been initialized. | 263 // Initializes cache if it has not been initialized. |
264 // Upon completion, |callback| is invoked on the thread where this method was | 264 // Upon completion, |callback| is invoked on the thread where this method was |
265 // called with the cache state if file exists in cache or CACHE_STATE_NONE | 265 // called with the cache state if file exists in cache or CACHE_STATE_NONE |
266 // otherwise. | 266 // otherwise. |
267 void GetCacheState(const std::string& resource_id, | 267 void GetCacheState(const std::string& resource_id, |
268 const std::string& md5, | 268 const std::string& md5, |
269 const GetCacheStateCallback& callback); | 269 const GetCacheStateCallback& callback); |
270 | 270 |
271 // Finds file object by |file_path| and returns its |file_info|. | 271 // Finds file object by |file_path| and returns its |file_info| and optionally |
272 // Returns true if file was found. | 272 // its |resource_id|, |md5| and |content_url| properties. Returns true if file |
273 // was found. | |
273 bool GetFileInfoFromPath(const FilePath& gdata_file_path, | 274 bool GetFileInfoFromPath(const FilePath& gdata_file_path, |
274 base::PlatformFileInfo* file_info); | 275 base::PlatformFileInfo* file_info, |
276 std::string* resource_id, | |
277 std::string* md5, | |
278 GURL* content_url); | |
satorux1
2012/03/20 04:51:17
Having four output parameters looks unclean. Canno
zel
2012/03/20 05:24:25
Then I have to copy way more than I really want ev
satorux1
2012/03/20 05:35:14
I see. Then we could define two separate functions
| |
275 | 279 |
276 // Returns the tmp sub-directory under gdata cache directory, i.e. | 280 // Returns the tmp sub-directory under gdata cache directory, i.e. |
277 // <user_profile_dir>/GCache/v1/tmp | 281 // <user_profile_dir>/GCache/v1/tmp |
278 FilePath GetGDataCacheTmpDirectory() { | 282 FilePath GetGDataCacheTmpDirectory() { |
279 return cache_paths_[CACHE_TYPE_TMP]; | 283 return cache_paths_[CACHE_TYPE_TMP]; |
280 } | 284 } |
281 | 285 |
282 // Fetches the user's Account Metadata to find out current quota information | 286 // Fetches the user's Account Metadata to find out current quota information |
283 // and returns it to the callback. | 287 // and returns it to the callback. |
284 void GetAvailableSpace(const GetAvailableSpaceCallback& callback); | 288 void GetAvailableSpace(const GetAvailableSpaceCallback& callback); |
(...skipping 29 matching lines...) Expand all Loading... | |
314 const FileOperationCallback& callback); | 318 const FileOperationCallback& callback); |
315 ~CreateDirectoryParams(); | 319 ~CreateDirectoryParams(); |
316 | 320 |
317 const FilePath created_directory_path; | 321 const FilePath created_directory_path; |
318 const FilePath target_directory_path; | 322 const FilePath target_directory_path; |
319 const bool is_exclusive; | 323 const bool is_exclusive; |
320 const bool is_recursive; | 324 const bool is_recursive; |
321 FileOperationCallback callback; | 325 FileOperationCallback callback; |
322 }; | 326 }; |
323 | 327 |
328 // Defines set of parameters passed to intermediate callbacks during | |
329 // execution of GetFile() method. | |
330 struct GetFileFromCacheParams { | |
331 GetFileFromCacheParams(const FilePath& virtual_file_path, | |
332 const FilePath& local_tmp_path, | |
333 const GURL& content_url, | |
334 const std::string& resource_id, | |
335 const std::string& md5, | |
336 scoped_refptr<base::MessageLoopProxy> proxy, | |
337 const GetFileCallback& callback); | |
338 ~GetFileFromCacheParams(); | |
339 | |
340 FilePath virtual_file_path; | |
341 FilePath local_tmp_path; | |
342 GURL content_url; | |
343 std::string resource_id; | |
344 std::string md5; | |
345 scoped_refptr<base::MessageLoopProxy> proxy; | |
346 const GetFileCallback callback; | |
347 }; | |
348 | |
324 // Callback similar to FileOperationCallback but with a given | 349 // Callback similar to FileOperationCallback but with a given |
325 // |file_path|. | 350 // |file_path|. |
326 typedef base::Callback<void(base::PlatformFileError error, | 351 typedef base::Callback<void(base::PlatformFileError error, |
327 const FilePath& file_path)> | 352 const FilePath& file_path)> |
328 FilePathUpdateCallback; | 353 FilePathUpdateCallback; |
329 | 354 |
330 GDataFileSystem(Profile* profile, | 355 GDataFileSystem(Profile* profile, |
331 DocumentsServiceInterface* documents_service); | 356 DocumentsServiceInterface* documents_service); |
332 virtual ~GDataFileSystem(); | 357 virtual ~GDataFileSystem(); |
333 | 358 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 const GURL& document_url); | 474 const GURL& document_url); |
450 | 475 |
451 // Callback for handling directory create requests. | 476 // Callback for handling directory create requests. |
452 void OnCreateDirectoryCompleted( | 477 void OnCreateDirectoryCompleted( |
453 const CreateDirectoryParams& params, | 478 const CreateDirectoryParams& params, |
454 GDataErrorCode status, | 479 GDataErrorCode status, |
455 scoped_ptr<base::Value> created_entry); | 480 scoped_ptr<base::Value> created_entry); |
456 | 481 |
457 // Callback for handling file downloading requests. | 482 // Callback for handling file downloading requests. |
458 void OnFileDownloaded( | 483 void OnFileDownloaded( |
459 const GetFileCallback& callback, | 484 const GetFileFromCacheParams& params, |
460 GDataErrorCode status, | 485 GDataErrorCode status, |
461 const GURL& content_url, | 486 const GURL& content_url, |
462 const FilePath& temp_file); | 487 const FilePath& downloaded_file_path); |
488 | |
489 // Callback for handling internal StoreToCache() calls after downloading | |
490 // file content. | |
491 void OnDownloadStoredToCache(base::PlatformFileError error, | |
492 const std::string& resource_id, | |
493 const std::string& md5); | |
463 | 494 |
464 // Callback for handling file upload initialization requests. | 495 // Callback for handling file upload initialization requests. |
465 void OnUploadLocationReceived( | 496 void OnUploadLocationReceived( |
466 const InitiateUploadCallback& callback, | 497 const InitiateUploadCallback& callback, |
467 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 498 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
468 GDataErrorCode code, | 499 GDataErrorCode code, |
469 const GURL& upload_location); | 500 const GURL& upload_location); |
470 | 501 |
471 // Callback for handling file upload resume requests. | 502 // Callback for handling file upload resume requests. |
472 void OnResumeUpload(const ResumeUploadCallback& callback, | 503 void OnResumeUpload(const ResumeUploadCallback& callback, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 // The functionalities of GData blob cache include: | 600 // The functionalities of GData blob cache include: |
570 // - stores downloaded gdata files on disk, indexed by the resource_id and md5 | 601 // - stores downloaded gdata files on disk, indexed by the resource_id and md5 |
571 // of the gdata file. | 602 // of the gdata file. |
572 // - provides absolute path for files to be cached or cached. | 603 // - provides absolute path for files to be cached or cached. |
573 // - updates the cached file on disk after user has edited it locally | 604 // - updates the cached file on disk after user has edited it locally |
574 // - handles eviction when disk runs out of space | 605 // - handles eviction when disk runs out of space |
575 // - uploads dirty files to gdata server. | 606 // - uploads dirty files to gdata server. |
576 // - etc. | 607 // - etc. |
577 | 608 |
578 // Returns absolute path of the file if it were cached or to be cached. | 609 // Returns absolute path of the file if it were cached or to be cached. |
579 FilePath GetCacheFilePath(const std::string& resource_id, | 610 FilePath GetCacheFilePath(const std::string& resource_id, |
satorux1
2012/03/20 04:51:17
is_local is not documented. what is this for?
zel
2012/03/20 05:24:25
switched to self-describing enum instead.
| |
580 const std::string& md5, | 611 const std::string& md5, |
581 CacheSubdir subdir_id, | 612 CacheSubdir subdir_id, |
582 bool is_local); | 613 bool is_local); |
583 | 614 |
584 // Stores |source_path| corresponding to |resource_id| and |md5| to cache. | 615 // Stores |source_path| corresponding to |resource_id| and |md5| to cache. |
585 // Initializes cache if it has not been initialized. | 616 // Initializes cache if it has not been initialized. |
586 // Upon completion, |callback| is invoked on the thread where this method was | 617 // Upon completion, |callback| is invoked on the thread where this method was |
587 // called. | 618 // called. |
588 // TODO(kuan): When URLFetcher can save response to a specified file (as | |
589 // opposed to only temporary file currently), remove |source_path| parameter. | |
590 void StoreToCache(const std::string& resource_id, | 619 void StoreToCache(const std::string& resource_id, |
591 const std::string& md5, | 620 const std::string& md5, |
592 const FilePath& source_path, | 621 const FilePath& source_path, |
593 const CacheOperationCallback& callback); | 622 const CacheOperationCallback& callback); |
594 | 623 |
595 // Checks if file corresponding to |resource_id| and |md5| exist on disk and | 624 // Checks if file corresponding to |resource_id| and |md5| exist on disk and |
596 // can be accessed i.e. not corrupted by previous file operations that didn't | 625 // can be accessed i.e. not corrupted by previous file operations that didn't |
597 // complete for whatever reasons. | 626 // complete for whatever reasons. |
598 // Initializes cache if it has not been initialized. | 627 // Initializes cache if it has not been initialized. |
599 // Upon completion, |callback| is invoked on the thread where this method was | 628 // Upon completion, |callback| is invoked on the thread where this method was |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
685 mode_t mode_bits, | 714 mode_t mode_bits, |
686 const CacheOperationCallback& callback); | 715 const CacheOperationCallback& callback); |
687 | 716 |
688 // Helper function for OnFilePinned() and OnFileUnpinned(). | 717 // Helper function for OnFilePinned() and OnFileUnpinned(). |
689 void OnCacheStatusModified(base::PlatformFileError error, | 718 void OnCacheStatusModified(base::PlatformFileError error, |
690 const std::string& resource_id, | 719 const std::string& resource_id, |
691 const std::string& md5, | 720 const std::string& md5, |
692 mode_t mode_bits, | 721 mode_t mode_bits, |
693 const CacheOperationCallback& callback); | 722 const CacheOperationCallback& callback); |
694 | 723 |
724 // Helper function for internally handling responses from GetFromCache() | |
725 // calls during processing of GetFile() request. | |
726 void OnGetFileFromCache(const GetFileFromCacheParams& params, | |
727 base::PlatformFileError error, | |
728 const std::string& resource_id, | |
729 const std::string& md5, | |
730 const FilePath& gdata_file_path, | |
731 const FilePath& cache_file_path); | |
732 | |
695 // Callback for GetCacheState that gets cache state of file corresponding to | 733 // Callback for GetCacheState that gets cache state of file corresponding to |
696 // |resource_id| and |md5|. | 734 // |resource_id| and |md5|. |
697 void OnGetCacheState(const std::string& resource_id, | 735 void OnGetCacheState(const std::string& resource_id, |
698 const std::string& md5, | 736 const std::string& md5, |
699 const GetCacheStateCallback& callback); | 737 const GetCacheStateCallback& callback); |
700 | 738 |
701 // Cache internal helper functions. | 739 // Cache internal helper functions. |
702 | 740 |
703 void GetFromCacheInternal(const std::string& resource_id, | 741 void GetFromCacheInternal(const std::string& resource_id, |
704 const std::string& md5, | 742 const std::string& md5, |
705 const FilePath& gdata_file_path, | 743 const FilePath& gdata_file_path, |
706 const GetFromCacheCallback& callback); | 744 const GetFromCacheCallback& callback); |
707 | 745 |
708 // Unsafe (unlocked) version of InitializeCacheIfnecessary method. | 746 // Unsafe (unlocked) version of InitializeCacheIfnecessary method. |
709 void UnsafeInitializeCacheIfNecessary(); | 747 void UnsafeInitializeCacheIfNecessary(); |
710 | 748 |
711 // Helper function used to perform file search on the calling thread of | 749 // Helper function used to perform file search on the calling thread of |
712 // FindFileByPath() request. | 750 // FindFileByPath() request. |
713 void FindFileByPathOnCallingThread(const FilePath& search_file_path, | 751 void FindFileByPathOnCallingThread(const FilePath& search_file_path, |
714 const FindFileCallback& callback); | 752 const FindFileCallback& callback); |
715 | 753 |
716 scoped_ptr<GDataRootDirectory> root_; | 754 scoped_ptr<GDataRootDirectory> root_; |
717 | 755 |
718 base::Lock lock_; | 756 base::Lock lock_; |
719 | 757 |
720 // The profile hosts the GDataFileSystem. | 758 // The profile hosts the GDataFileSystem. |
721 Profile* profile_; | 759 Profile* profile_; |
722 | 760 |
723 // The document service for the GDataFileSystem. | 761 // The document service for the GDataFileSystem. |
724 scoped_ptr<DocumentsServiceInterface> documents_service_; | 762 scoped_ptr<DocumentsServiceInterface> documents_service_; |
725 | 763 |
726 // File content uploader. | 764 // File content uploader. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 virtual ~GDataFileSystemFactory(); | 806 virtual ~GDataFileSystemFactory(); |
769 | 807 |
770 // ProfileKeyedServiceFactory: | 808 // ProfileKeyedServiceFactory: |
771 virtual ProfileKeyedService* BuildServiceInstanceFor( | 809 virtual ProfileKeyedService* BuildServiceInstanceFor( |
772 Profile* profile) const OVERRIDE; | 810 Profile* profile) const OVERRIDE; |
773 }; | 811 }; |
774 | 812 |
775 } // namespace gdata | 813 } // namespace gdata |
776 | 814 |
777 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 815 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
OLD | NEW |