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

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

Issue 10543037: gdata: Convert public synchronous functions in GDataFileSystem to asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Satoru's and Toni's concerns. Created 8 years, 6 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 #pragma once 7 #pragma once
8 8
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 10
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 // Used by GDataFileSystem::GetDocumentResourceIdOnIOThreadPool to return 119 // Used by GDataFileSystem::GetDocumentResourceIdOnIOThreadPool to return
120 // the resource ID read from a document JSON file on the local file system. 120 // the resource ID read from a document JSON file on the local file system.
121 typedef base::Callback<void(const std::string& resource_id)> 121 typedef base::Callback<void(const std::string& resource_id)>
122 GetDocumentResourceIdCallback; 122 GetDocumentResourceIdCallback;
123 123
124 // Callback for GetCacheState operation. 124 // Callback for GetCacheState operation.
125 typedef base::Callback<void(base::PlatformFileError error, 125 typedef base::Callback<void(base::PlatformFileError error,
126 int cache_state)> GetCacheStateCallback; 126 int cache_state)> GetCacheStateCallback;
127 127
128 // Helper structure used for extracting key properties from GDataFile object.
129 // TODO(satorux): Remove this as part of crosbug.com/30066
130 struct GDataFileProperties {
131 GDataFileProperties();
132 ~GDataFileProperties();
133
134 base::PlatformFileInfo file_info;
135 std::string resource_id;
136 std::string file_md5;
137 std::string mime_type;
138 GURL content_url;
139 GURL alternate_url;
140 bool is_hosted_document;
141 };
142
143 // GData file system abstraction layer. 128 // GData file system abstraction layer.
144 // The interface is defined to make GDataFileSystem mockable. 129 // The interface is defined to make GDataFileSystem mockable.
145 class GDataFileSystemInterface { 130 class GDataFileSystemInterface {
146 public: 131 public:
147 virtual ~GDataFileSystemInterface() {} 132 virtual ~GDataFileSystemInterface() {}
148 133
149 // Used to notify events on the file system. 134 // Used to notify events on the file system.
150 // All events are notified on UI thread. 135 // All events are notified on UI thread.
151 class Observer { 136 class Observer {
152 public: 137 public:
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 virtual void RequestDirectoryRefresh(const FilePath& file_path) = 0; 392 virtual void RequestDirectoryRefresh(const FilePath& file_path) = 0;
408 393
409 // Does server side content search for |search_query|. Search results will be 394 // Does server side content search for |search_query|. Search results will be
410 // returned as gdata entries in temp directory proto, and their 395 // returned as gdata entries in temp directory proto, and their
411 // title/file_name will be formatted as |<resource_id>.<original_file_name>|. 396 // title/file_name will be formatted as |<resource_id>.<original_file_name>|.
412 // 397 //
413 // Can be called from UI/IO thread. |callback| is run on the calling thread. 398 // Can be called from UI/IO thread. |callback| is run on the calling thread.
414 virtual void SearchAsync(const std::string& search_query, 399 virtual void SearchAsync(const std::string& search_query,
415 const ReadDirectoryCallback& callback) = 0; 400 const ReadDirectoryCallback& callback) = 0;
416 401
417
418 // Finds a file (not a directory) by |file_path| and returns its key
419 // |properties|. Returns true if file was found.
420 // TODO(satorux): Remove this: crosbug.com/30066.
421 virtual bool GetFileInfoByPath(const FilePath& file_path,
422 GDataFileProperties* properties) = 0;
423
424 // Returns true if the given path is under gdata cache directory, i.e. 402 // Returns true if the given path is under gdata cache directory, i.e.
425 // <user_profile_dir>/GCache/v1 403 // <user_profile_dir>/GCache/v1
426 virtual bool IsUnderGDataCacheDirectory(const FilePath& path) const = 0; 404 virtual bool IsUnderGDataCacheDirectory(const FilePath& path) const = 0;
427 405
428 // Returns the sub-directory under gdata cache directory for the given sub 406 // Returns the sub-directory under gdata cache directory for the given sub
429 // directory type. Example: <user_profile_dir>/GCache/v1/tmp 407 // directory type. Example: <user_profile_dir>/GCache/v1/tmp
430 virtual FilePath GetCacheDirectoryPath( 408 virtual FilePath GetCacheDirectoryPath(
431 GDataCache::CacheSubDirectoryType sub_dir_type) const = 0; 409 GDataCache::CacheSubDirectoryType sub_dir_type) const = 0;
432 410
433 // Returns absolute path of the file if it were cached or to be cached. 411 // Returns absolute path of the file if it were cached or to be cached.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 const FilePath& file_path, 502 const FilePath& file_path,
525 const GetEntryInfoCallback& callback) OVERRIDE; 503 const GetEntryInfoCallback& callback) OVERRIDE;
526 virtual void GetFileInfoByPathAsync( 504 virtual void GetFileInfoByPathAsync(
527 const FilePath& file_path, 505 const FilePath& file_path,
528 const GetFileInfoCallback& callback) OVERRIDE; 506 const GetFileInfoCallback& callback) OVERRIDE;
529 virtual void ReadDirectoryByPathAsync( 507 virtual void ReadDirectoryByPathAsync(
530 const FilePath& file_path, 508 const FilePath& file_path,
531 const ReadDirectoryCallback& callback) OVERRIDE; 509 const ReadDirectoryCallback& callback) OVERRIDE;
532 virtual void RequestDirectoryRefresh( 510 virtual void RequestDirectoryRefresh(
533 const FilePath& file_path) OVERRIDE; 511 const FilePath& file_path) OVERRIDE;
534 virtual bool GetFileInfoByPath(const FilePath& file_path,
535 GDataFileProperties* properties) OVERRIDE;
536 virtual bool IsUnderGDataCacheDirectory(const FilePath& path) const OVERRIDE; 512 virtual bool IsUnderGDataCacheDirectory(const FilePath& path) const OVERRIDE;
537 virtual FilePath GetCacheDirectoryPath( 513 virtual FilePath GetCacheDirectoryPath(
538 GDataCache::CacheSubDirectoryType sub_dir_type) const OVERRIDE; 514 GDataCache::CacheSubDirectoryType sub_dir_type) const OVERRIDE;
539 virtual FilePath GetCacheFilePath( 515 virtual FilePath GetCacheFilePath(
540 const std::string& resource_id, 516 const std::string& resource_id,
541 const std::string& md5, 517 const std::string& md5,
542 GDataCache::CacheSubDirectoryType sub_dir_type, 518 GDataCache::CacheSubDirectoryType sub_dir_type,
543 CachedFileOrigin file_orign) const OVERRIDE; 519 CachedFileOrigin file_orign) const OVERRIDE;
544 virtual void GetAvailableSpace( 520 virtual void GetAvailableSpace(
545 const GetAvailableSpaceCallback& callback) OVERRIDE; 521 const GetAvailableSpaceCallback& callback) OVERRIDE;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // Initiates transfer of |local_file_path| to |remote_dest_file_path|. 688 // Initiates transfer of |local_file_path| to |remote_dest_file_path|.
713 // |local_file_path| must be a regular file (i.e. not a hosted document) from 689 // |local_file_path| must be a regular file (i.e. not a hosted document) from
714 // the local file system, |remote_dest_file_path| is the virtual destination 690 // the local file system, |remote_dest_file_path| is the virtual destination
715 // path within gdata file system. 691 // path within gdata file system.
716 // 692 //
717 // Must be called from *UI* thread. |callback| is run on the calling thread. 693 // Must be called from *UI* thread. |callback| is run on the calling thread.
718 void TransferRegularFile(const FilePath& local_file_path, 694 void TransferRegularFile(const FilePath& local_file_path,
719 const FilePath& remote_dest_file_path, 695 const FilePath& remote_dest_file_path,
720 const FileOperationCallback& callback); 696 const FileOperationCallback& callback);
721 697
698 // Invoked upon completion of GetFileInfoByPathAsync initiated by
699 // GetFileByPath. It then continues to invoke GetResolvedFileByPath.
700 void OnGetFileInfoCompleteForGetFileByPath(
701 const FilePath& file_path,
702 const GetFileCallback& get_file_callback,
703 const GetDownloadDataCallback& get_download_data_callback,
704 base::PlatformFileError error,
705 scoped_ptr<GDataFileProto> file_info);
722 // Invoked upon completion of GetFileInfoByPathAsync initiated by OpenFile. 706 // Invoked upon completion of GetFileInfoByPathAsync initiated by OpenFile.
723 // It then continues to invoke GetFileByPath and processed to 707 // It then continues to invoke GetResolvedFileByPath and proceeds to
724 // OnGetFileCompleteForOpenFile. 708 // OnGetFileCompleteForOpenFile.
725 void OnGetFileInfoCompleteForOpenFile(const FilePath& file_path, 709 void OnGetFileInfoCompleteForOpenFile(const FilePath& file_path,
726 const OpenFileCallback& callback, 710 const OpenFileCallback& callback,
727 base::PlatformFileError error, 711 base::PlatformFileError error,
728 scoped_ptr<GDataFileProto> file_info); 712 scoped_ptr<GDataFileProto> file_info);
729 // Invoked upon completion of GetFileInfoByPathAsync initiated by CloseFile. 713 // Invoked upon completion of GetFileInfoByPathAsync initiated by CloseFile.
730 // It then continues to invoke GetFileByPath and processed to 714 // It then continues to invoke CommitDirtyInCache and proceeds to
731 // OnGetFileCompleteForCloseFile. 715 // OnCommitDirtyInCacheCompleteForCloseFile.
732 void OnGetFileInfoCompleteForCloseFile(const FilePath& file_path, 716 void OnGetFileInfoCompleteForCloseFile(const FilePath& file_path,
733 const CloseFileCallback& callback, 717 const CloseFileCallback& callback,
734 base::PlatformFileError error, 718 base::PlatformFileError error,
735 scoped_ptr<GDataFileProto> file_info); 719 scoped_ptr<GDataFileProto> file_info);
736 720
737 // Invoked upon completion of GetFileByPath initiated by Copy. If 721 // Invoked upon completion of GetFileByPath initiated by Copy. If
738 // GetFileByPath reports no error, calls TransferRegularFile to transfer 722 // GetFileByPath reports no error, calls TransferRegularFile to transfer
739 // |local_file_path| to |remote_dest_file_path|. 723 // |local_file_path| to |remote_dest_file_path|.
740 // 724 //
741 // Can be called from UI/IO thread. |callback| is run on the calling thread. 725 // Can be called from UI/IO thread. |callback| is run on the calling thread.
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 // Called when an entry is found for ReadDirectoryByPathAsync(). 1423 // Called when an entry is found for ReadDirectoryByPathAsync().
1440 void OnReadDirectory(const ReadDirectoryCallback& callback, 1424 void OnReadDirectory(const ReadDirectoryCallback& callback,
1441 base::PlatformFileError error, 1425 base::PlatformFileError error,
1442 GDataEntry* entry); 1426 GDataEntry* entry);
1443 1427
1444 // Finds file info by using virtual |file_path|. This call will also 1428 // Finds file info by using virtual |file_path|. This call will also
1445 // retrieve and refresh file system content from server and disk cache. 1429 // retrieve and refresh file system content from server and disk cache.
1446 void FindEntryByPathAsyncOnUIThread(const FilePath& search_file_path, 1430 void FindEntryByPathAsyncOnUIThread(const FilePath& search_file_path,
1447 const FindEntryCallback& callback); 1431 const FindEntryCallback& callback);
1448 1432
1433 // Gets |file_path| from the file system after the file info is already
1434 // resolved with GetFileInfoByPathAsync(). This function is called by
1435 // OnGetFileInfoCompleteForGetFileByPath and OnGetFileInfoCompleteForOpenFile.
1436 void GetResolvedFileByPath(
1437 const FilePath& file_path,
1438 const GetFileCallback& get_file_callback,
1439 const GetDownloadDataCallback& get_download_data_callback,
1440 base::PlatformFileError error,
1441 const GDataFileProto* file_proto);
1442
1449 // The following functions are used to forward calls to asynchronous public 1443 // The following functions are used to forward calls to asynchronous public
1450 // member functions to UI thread. 1444 // member functions to UI thread.
1451 void SearchAsyncOnUIThread(const std::string& search_query, 1445 void SearchAsyncOnUIThread(const std::string& search_query,
1452 const ReadDirectoryCallback& callback); 1446 const ReadDirectoryCallback& callback);
1453 void OpenFileOnUIThread(const FilePath& file_path, 1447 void OpenFileOnUIThread(const FilePath& file_path,
1454 const OpenFileCallback& callback); 1448 const OpenFileCallback& callback);
1455 void CloseFileOnUIThread(const FilePath& file_path, 1449 void CloseFileOnUIThread(const FilePath& file_path,
1456 const CloseFileCallback& callback); 1450 const CloseFileCallback& callback);
1457 void CopyOnUIThread(const FilePath& src_file_path, 1451 void CopyOnUIThread(const FilePath& src_file_path,
1458 const FilePath& dest_file_path, 1452 const FilePath& dest_file_path,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 }; 1558 };
1565 1559
1566 // Sets the free disk space getter for testing. 1560 // Sets the free disk space getter for testing.
1567 // The existing getter is deleted. 1561 // The existing getter is deleted.
1568 void SetFreeDiskSpaceGetterForTesting( 1562 void SetFreeDiskSpaceGetterForTesting(
1569 FreeDiskSpaceGetterInterface* getter); 1563 FreeDiskSpaceGetterInterface* getter);
1570 1564
1571 } // namespace gdata 1565 } // namespace gdata
1572 1566
1573 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ 1567 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698