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

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: 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
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
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 passes to intermediate callbacks during
kuan 2012/03/20 03:22:19 nit: s/passes/passed/
zel 2012/03/20 04:31:17 Done.
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
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.
490 void OnStoreToCache(base::PlatformFileError error,
kuan 2012/03/20 03:22:19 for internal StoreToCache() calls, there's already
zel 2012/03/20 04:31:17 Renamed to OnDownloadStoredToCache. We could remov
491 const std::string& resource_id,
492 const std::string& md5);
463 493
464 // Callback for handling file upload initialization requests. 494 // Callback for handling file upload initialization requests.
465 void OnUploadLocationReceived( 495 void OnUploadLocationReceived(
466 const InitiateUploadCallback& callback, 496 const InitiateUploadCallback& callback,
467 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 497 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
468 GDataErrorCode code, 498 GDataErrorCode code,
469 const GURL& upload_location); 499 const GURL& upload_location);
470 500
471 // Callback for handling file upload resume requests. 501 // Callback for handling file upload resume requests.
472 void OnResumeUpload(const ResumeUploadCallback& callback, 502 void OnResumeUpload(const ResumeUploadCallback& callback,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // Returns absolute path of the file if it were cached or to be cached. 608 // Returns absolute path of the file if it were cached or to be cached.
579 FilePath GetCacheFilePath(const std::string& resource_id, 609 FilePath GetCacheFilePath(const std::string& resource_id,
580 const std::string& md5, 610 const std::string& md5,
581 CacheSubdir subdir_id, 611 CacheSubdir subdir_id,
582 bool is_local); 612 bool is_local);
583 613
584 // Stores |source_path| corresponding to |resource_id| and |md5| to cache. 614 // Stores |source_path| corresponding to |resource_id| and |md5| to cache.
585 // Initializes cache if it has not been initialized. 615 // Initializes cache if it has not been initialized.
586 // Upon completion, |callback| is invoked on the thread where this method was 616 // Upon completion, |callback| is invoked on the thread where this method was
587 // called. 617 // 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, 618 void StoreToCache(const std::string& resource_id,
591 const std::string& md5, 619 const std::string& md5,
592 const FilePath& source_path, 620 const FilePath& source_path,
593 const CacheOperationCallback& callback); 621 const CacheOperationCallback& callback);
594 622
595 // Checks if file corresponding to |resource_id| and |md5| exist on disk and 623 // 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 624 // can be accessed i.e. not corrupted by previous file operations that didn't
597 // complete for whatever reasons. 625 // complete for whatever reasons.
598 // Initializes cache if it has not been initialized. 626 // Initializes cache if it has not been initialized.
599 // Upon completion, |callback| is invoked on the thread where this method was 627 // Upon completion, |callback| is invoked on the thread where this method was
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 mode_t mode_bits, 713 mode_t mode_bits,
686 const CacheOperationCallback& callback); 714 const CacheOperationCallback& callback);
687 715
688 // Helper function for OnFilePinned() and OnFileUnpinned(). 716 // Helper function for OnFilePinned() and OnFileUnpinned().
689 void OnCacheStatusModified(base::PlatformFileError error, 717 void OnCacheStatusModified(base::PlatformFileError error,
690 const std::string& resource_id, 718 const std::string& resource_id,
691 const std::string& md5, 719 const std::string& md5,
692 mode_t mode_bits, 720 mode_t mode_bits,
693 const CacheOperationCallback& callback); 721 const CacheOperationCallback& callback);
694 722
723 // Helper function for internally handling responses from GetFromCache()
724 // calls during processing of GetFile() request.
725 void OnGetFileFromCache(
726 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);
kuan 2012/03/20 03:22:19 nit: only 4 spaces needed for indentation.
zel 2012/03/20 04:31:17 Done.
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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698