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

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

Issue 10274002: Add gdata content search (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed satorux's comments Created 8 years, 7 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 const GetFileInfoCallback& callback) = 0; 334 const GetFileInfoCallback& callback) = 0;
335 335
336 // Finds and reads a directory by |file_path|. This call will also retrieve 336 // Finds and reads a directory by |file_path|. This call will also retrieve
337 // and refresh file system content from server and disk cache. 337 // and refresh file system content from server and disk cache.
338 // 338 //
339 // Can be called from UI/IO thread. |callback| is run on the calling thread. 339 // Can be called from UI/IO thread. |callback| is run on the calling thread.
340 virtual void ReadDirectoryByPathAsync( 340 virtual void ReadDirectoryByPathAsync(
341 const FilePath& file_path, 341 const FilePath& file_path,
342 const ReadDirectoryCallback& callback) = 0; 342 const ReadDirectoryCallback& callback) = 0;
343 343
344 // Does server side content search for |search_query|. Search results will be
345 // returned as gdata entries in temp directory proto, and their
346 // title/file_name will be formatted as |<resource_id>.<original_file_name>|.
347 //
348 // Can be called from UI/IO thread. |callback| is run on calling thread.
Ben Chan 2012/05/03 22:47:39 nit: for consistency, "run on calling thread" ->
tbarzic 2012/05/03 23:56:17 Done.
349 virtual void GetEntriesByQueryAsync(
350 const std::string& search_query,
351 const ReadDirectoryCallback& callback) = 0;
352
353
344 // Finds a file (not a directory) by |file_path| and returns its key 354 // Finds a file (not a directory) by |file_path| and returns its key
345 // |properties|. Returns true if file was found. 355 // |properties|. Returns true if file was found.
346 // TODO(satorux): Remove this: crosbug.com/30066. 356 // TODO(satorux): Remove this: crosbug.com/30066.
347 virtual bool GetFileInfoByPath(const FilePath& file_path, 357 virtual bool GetFileInfoByPath(const FilePath& file_path,
348 GDataFileProperties* properties) = 0; 358 GDataFileProperties* properties) = 0;
349 359
350 // Returns true if the given path is under gdata cache directory, i.e. 360 // Returns true if the given path is under gdata cache directory, i.e.
351 // <user_profile_dir>/GCache/v1 361 // <user_profile_dir>/GCache/v1
352 virtual bool IsUnderGDataCacheDirectory(const FilePath& path) const = 0; 362 virtual bool IsUnderGDataCacheDirectory(const FilePath& path) const = 0;
353 363
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 DocumentsServiceInterface* documents_service); 406 DocumentsServiceInterface* documents_service);
397 virtual ~GDataFileSystem(); 407 virtual ~GDataFileSystem();
398 408
399 // GDataFileSystem overrides. 409 // GDataFileSystem overrides.
400 virtual void Initialize() OVERRIDE; 410 virtual void Initialize() OVERRIDE;
401 virtual void AddObserver(Observer* observer) OVERRIDE; 411 virtual void AddObserver(Observer* observer) OVERRIDE;
402 virtual void RemoveObserver(Observer* observer) OVERRIDE; 412 virtual void RemoveObserver(Observer* observer) OVERRIDE;
403 virtual void Authenticate(const AuthStatusCallback& callback) OVERRIDE; 413 virtual void Authenticate(const AuthStatusCallback& callback) OVERRIDE;
404 virtual void FindEntryByResourceIdSync(const std::string& resource_id, 414 virtual void FindEntryByResourceIdSync(const std::string& resource_id,
405 FindEntryDelegate* delegate) OVERRIDE; 415 FindEntryDelegate* delegate) OVERRIDE;
416 virtual void GetEntriesByQueryAsync(
zel 2012/05/03 22:57:56 Get<Something>ByQuery is called Search :) Please
tbarzic 2012/05/03 23:56:17 Done.
417 const std::string& search_query,
418 const ReadDirectoryCallback& callback) OVERRIDE;
406 virtual void TransferFile(const FilePath& local_file_path, 419 virtual void TransferFile(const FilePath& local_file_path,
407 const FilePath& remote_dest_file_path, 420 const FilePath& remote_dest_file_path,
408 const FileOperationCallback& callback) OVERRIDE; 421 const FileOperationCallback& callback) OVERRIDE;
409 virtual void Copy(const FilePath& src_file_path, 422 virtual void Copy(const FilePath& src_file_path,
410 const FilePath& dest_file_path, 423 const FilePath& dest_file_path,
411 const FileOperationCallback& callback) OVERRIDE; 424 const FileOperationCallback& callback) OVERRIDE;
412 virtual void Move(const FilePath& src_file_path, 425 virtual void Move(const FilePath& src_file_path,
413 const FilePath& dest_file_path, 426 const FilePath& dest_file_path,
414 const FileOperationCallback& callback) OVERRIDE; 427 const FileOperationCallback& callback) OVERRIDE;
415 virtual void Remove(const FilePath& file_path, 428 virtual void Remove(const FilePath& file_path,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 std::string mime_type; 553 std::string mime_type;
541 const GetFileCallback get_file_callback; 554 const GetFileCallback get_file_callback;
542 const GetDownloadDataCallback get_download_data_callback; 555 const GetDownloadDataCallback get_download_data_callback;
543 }; 556 };
544 557
545 // Defines set of parameters sent to callback OnGetDocuments(). 558 // Defines set of parameters sent to callback OnGetDocuments().
546 struct GetDocumentsParams { 559 struct GetDocumentsParams {
547 GetDocumentsParams(int start_changestamp, 560 GetDocumentsParams(int start_changestamp,
548 int root_feed_changestamp, 561 int root_feed_changestamp,
549 std::vector<DocumentFeed*>* feed_list, 562 std::vector<DocumentFeed*>* feed_list,
563 bool should_fetch_multiple_feeds,
550 const FilePath& search_file_path, 564 const FilePath& search_file_path,
565 const std::string& search_query,
551 const FindEntryCallback& callback); 566 const FindEntryCallback& callback);
552 ~GetDocumentsParams(); 567 ~GetDocumentsParams();
553 568
554 // Changestamps are positive numbers in increasing order. The difference 569 // Changestamps are positive numbers in increasing order. The difference
555 // between two changestamps is proportional equal to number of items in 570 // between two changestamps is proportional equal to number of items in
556 // delta feed between them - bigger the difference, more likely bigger 571 // delta feed between them - bigger the difference, more likely bigger
557 // number of items in delta feeds. 572 // number of items in delta feeds.
558 int start_changestamp; 573 int start_changestamp;
559 int root_feed_changestamp; 574 int root_feed_changestamp;
560 scoped_ptr<std::vector<DocumentFeed*> > feed_list; 575 scoped_ptr<std::vector<DocumentFeed*> > feed_list;
576 // Should we stop after getting first feed chunk, even if there is more
577 // data.
578 bool should_fetch_multiple_feeds;
561 FilePath search_file_path; 579 FilePath search_file_path;
580 std::string search_query;
562 FindEntryCallback callback; 581 FindEntryCallback callback;
563 }; 582 };
564 583
565 typedef std::map<std::string /* resource_id */, GDataEntry*> 584 typedef std::map<std::string /* resource_id */, GDataEntry*>
566 FileResourceIdMap; 585 FileResourceIdMap;
567 586
568 // Callback similar to FileOperationCallback but with a given |file_path|. 587 // Callback similar to FileOperationCallback but with a given |file_path|.
569 typedef base::Callback<void(base::PlatformFileError error, 588 typedef base::Callback<void(base::PlatformFileError error,
570 const FilePath& file_path)> 589 const FilePath& file_path)>
571 FilePathUpdateCallback; 590 FilePathUpdateCallback;
572 591
592 // Callback run as a response to LoadFeedFromServer.
593 typedef base::Callback<void(GetDocumentsParams* params,
594 base::PlatformFileError error)>
595 LoadDocumentFeedCallback;
596
573 // Finds entry object by |file_path| and returns the entry object. 597 // Finds entry object by |file_path| and returns the entry object.
574 // Returns NULL if it does not find the entry. 598 // Returns NULL if it does not find the entry.
575 GDataEntry* GetGDataEntryByPath(const FilePath& file_path); 599 GDataEntry* GetGDataEntryByPath(const FilePath& file_path);
576 600
577 // Inits cache directory paths in the provided root. 601 // Inits cache directory paths in the provided root.
578 // Should be called before cache is initialized. 602 // Should be called before cache is initialized.
579 void SetCachePaths(const FilePath& root_path); 603 void SetCachePaths(const FilePath& root_path);
580 604
581 // Initiates upload operation of file defined with |file_name|, 605 // Initiates upload operation of file defined with |file_name|,
582 // |content_type| and |content_length|. The operation will place the newly 606 // |content_type| and |content_length|. The operation will place the newly
(...skipping 14 matching lines...) Expand all
597 // TODO(satorux,achuith): Remove this: crosbug.com/29943 621 // TODO(satorux,achuith): Remove this: crosbug.com/29943
598 void ResumeUpload(const ResumeUploadParams& params, 622 void ResumeUpload(const ResumeUploadParams& params,
599 const ResumeFileUploadCallback& callback); 623 const ResumeFileUploadCallback& callback);
600 624
601 // Converts document feed from gdata service into DirectoryInfo. On failure, 625 // Converts document feed from gdata service into DirectoryInfo. On failure,
602 // returns NULL and fills in |error| with an appropriate value. 626 // returns NULL and fills in |error| with an appropriate value.
603 GDataDirectory* ParseGDataFeed(GDataErrorCode status, 627 GDataDirectory* ParseGDataFeed(GDataErrorCode status,
604 base::Value* data, 628 base::Value* data,
605 base::PlatformFileError *error); 629 base::PlatformFileError *error);
606 630
631 // Callback passed to |LoadFeedFromServer| from |GetEntriesByQueryAsync|
632 // method.
633 // |callback| is that should be run with data received from
634 // |LoadFeedFromServer|.
635 // |params| params used for getting document feed for content search.
636 // |status| was |LoadFeedFromServer| successfull.
Ben Chan 2012/05/03 22:47:39 typo: successfull?
tbarzic 2012/05/03 23:56:17 Done.
637 void OnGetEntriesByQuery(const ReadDirectoryCallback& callback,
638 GetDocumentsParams* params,
639 base::PlatformFileError status);
640
607 // Initiates transfer of |local_file_path| with |resource_id| to 641 // Initiates transfer of |local_file_path| with |resource_id| to
608 // |remote_dest_file_path|. |local_file_path| must be a file from the local 642 // |remote_dest_file_path|. |local_file_path| must be a file from the local
609 // file system, |remote_dest_file_path| is the virtual destination path within 643 // file system, |remote_dest_file_path| is the virtual destination path within
610 // gdata file system. If |resource_id| is a non-empty string, the transfer is 644 // gdata file system. If |resource_id| is a non-empty string, the transfer is
611 // handled by CopyDocumentToDirectory. Otherwise, the transfer is handled by 645 // handled by CopyDocumentToDirectory. Otherwise, the transfer is handled by
612 // TransferRegularFile. 646 // TransferRegularFile.
613 // 647 //
614 // Must be called from *UI* thread. |callback| is run on the calling thread. 648 // Must be called from *UI* thread. |callback| is run on the calling thread.
615 void TransferFileForResourceId(const FilePath& local_file_path, 649 void TransferFileForResourceId(const FilePath& local_file_path,
616 const FilePath& remote_dest_file_path, 650 const FilePath& remote_dest_file_path,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 base::PlatformFileError error, 706 base::PlatformFileError error,
673 const FilePath& file_path); 707 const FilePath& file_path);
674 708
675 // Removes file under |file_path| from in-memory snapshot of the file system. 709 // Removes file under |file_path| from in-memory snapshot of the file system.
676 // |resource_id| contains the resource id of the removed file if it was a 710 // |resource_id| contains the resource id of the removed file if it was a
677 // file. 711 // file.
678 // Return PLATFORM_FILE_OK if successful. 712 // Return PLATFORM_FILE_OK if successful.
679 base::PlatformFileError RemoveEntryFromGData(const FilePath& file_path, 713 base::PlatformFileError RemoveEntryFromGData(const FilePath& file_path,
680 std::string* resource_id); 714 std::string* resource_id);
681 715
682 // Callback for handling feed content fetching while searching for file info. 716 // Callback for handling response from |GDataDocumentsService::GetDocuments|.
683 // This callback is invoked after async feed fetch operation that was 717 // Invokes |callback| when done.
684 // invoked by StartDirectoryRefresh() completes. This callback will update 718 void OnGetDocuments(const LoadDocumentFeedCallback& callback,
685 // the content of the refreshed directory object and continue initially 719 GetDocumentsParams* params,
686 // started FindEntryByPath() request.
687 void OnGetDocuments(GetDocumentsParams* params,
688 GDataErrorCode status, 720 GDataErrorCode status,
689 scoped_ptr<base::Value> data); 721 scoped_ptr<base::Value> data);
690 722
691 // A pass-through callback used for bridging from 723 // A pass-through callback used for bridging from
692 // FilePathUpdateCallback to FileOperationCallback. 724 // FilePathUpdateCallback to FileOperationCallback.
693 void OnFilePathUpdated(const FileOperationCallback& cllback, 725 void OnFilePathUpdated(const FileOperationCallback& cllback,
694 base::PlatformFileError error, 726 base::PlatformFileError error,
695 const FilePath& file_path); 727 const FilePath& file_path);
696 728
697 // Callback for handling resource rename attempt. 729 // Callback for handling resource rename attempt.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 const FilePath& search_file_path, 878 const FilePath& search_file_path,
847 const FindEntryCallback& callback, 879 const FindEntryCallback& callback,
848 GDataErrorCode error, 880 GDataErrorCode error,
849 scoped_ptr<base::Value> feed_data); 881 scoped_ptr<base::Value> feed_data);
850 882
851 // Starts root feed load from the server. Value of |start_changestamp| 883 // Starts root feed load from the server. Value of |start_changestamp|
852 // determines the type of feed to load - 0 means root feed, every other 884 // determines the type of feed to load - 0 means root feed, every other
853 // value would trigger delta feed. 885 // value would trigger delta feed.
854 // In the case of loading the root feed we use |root_feed_changestamp| as its 886 // In the case of loading the root feed we use |root_feed_changestamp| as its
855 // initial changestamp value since it does not come with that info. 887 // initial changestamp value since it does not come with that info.
856 // If successful, it will try to find the file upon retrieval completion. 888 // When done |load_feed_callback| is invoked.
889 // |entry_found_callback| is used only when this is invoked while searching
890 // for file info, and is used in |load_feed_callback|. If successful, it will
891 // try to find the file upon retrieval completion.
892 // |should_fetch_multiple_feeds| is true iff don't want to stop feed loading
893 // after we retrieve first feed chunk.
894 // If invoked as a part of content search, query will be set in
895 // |search_query|.
857 void LoadFeedFromServer(int start_changestamp, 896 void LoadFeedFromServer(int start_changestamp,
858 int root_feed_changestamp, 897 int root_feed_changestamp,
898 bool should_fetch_multiple_feeds,
859 const FilePath& search_file_path, 899 const FilePath& search_file_path,
860 const FindEntryCallback& callback); 900 const std::string& search_query,
901 const FindEntryCallback& entry_found_callback,
902 const LoadDocumentFeedCallback& load_feed_callback);
903
904 // Callback for handling feed content fetching while searching for file info.
905 // This callback is invoked after async feed fetch operation that was
906 // invoked by StartDirectoryRefresh() completes. This callback will update
907 // the content of the refreshed directory object and continue initially
908 // started FindEntryByPath() request.
909 void OnFeedFromServerLoaded(GetDocumentsParams* params,
910 base::PlatformFileError status);
861 911
862 // Starts root feed load from the cache. If successful, it will try to find 912 // Starts root feed load from the cache. If successful, it will try to find
863 // the file upon retrieval completion. In addition to that, it will 913 // the file upon retrieval completion. In addition to that, it will
864 // initate retrieval of the root feed from the server if 914 // initate retrieval of the root feed from the server if
865 // |should_load_from_server| is set. 915 // |should_load_from_server| is set.
866 void LoadRootFeedFromCache(bool should_load_from_server, 916 void LoadRootFeedFromCache(bool should_load_from_server,
867 const FilePath& search_file_path, 917 const FilePath& search_file_path,
868 const FindEntryCallback& callback); 918 const FindEntryCallback& callback);
869 919
870 // Callback for handling root directory refresh from the cache. 920 // Callback for handling root directory refresh from the cache.
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 base::PlatformFileError error, 1280 base::PlatformFileError error,
1231 const std::string& resource_id, 1281 const std::string& resource_id,
1232 const std::string& md5); 1282 const std::string& md5);
1233 1283
1234 // Changes state of hosted documents visibility, triggers directory refresh. 1284 // Changes state of hosted documents visibility, triggers directory refresh.
1235 void SetHideHostedDocuments(bool hide); 1285 void SetHideHostedDocuments(bool hide);
1236 1286
1237 // Initializes preference change observer. 1287 // Initializes preference change observer.
1238 void InitializePreferenceObserver(); 1288 void InitializePreferenceObserver();
1239 1289
1290 // Tests if we are allowed to create new directory in the provided directory.
1291 bool ShouldCreateDirectory(const FilePath& directory_path);
1292
1240 // Called when an entry is found for GetEntryInfoByPathAsync(). 1293 // Called when an entry is found for GetEntryInfoByPathAsync().
1241 void OnGetEntryInfo(const GetEntryInfoCallback& callback, 1294 void OnGetEntryInfo(const GetEntryInfoCallback& callback,
1242 base::PlatformFileError error, 1295 base::PlatformFileError error,
1243 const FilePath& entry_path, 1296 const FilePath& entry_path,
1244 GDataEntry* entry); 1297 GDataEntry* entry);
1245 1298
1246 // Called when an entry is found for GetFileInfoByPathAsync(). 1299 // Called when an entry is found for GetFileInfoByPathAsync().
1247 void OnGetFileInfo(const GetFileInfoCallback& callback, 1300 void OnGetFileInfo(const GetFileInfoCallback& callback,
1248 base::PlatformFileError error, 1301 base::PlatformFileError error,
1249 const FilePath& directory_path, 1302 const FilePath& directory_path,
1250 GDataEntry* entry); 1303 GDataEntry* entry);
1251 1304
1252 // Called when an entry is found for ReadDirectoryByPathAsync(). 1305 // Called when an entry is found for ReadDirectoryByPathAsync().
1253 void OnReadDirectory(const ReadDirectoryCallback& callback, 1306 void OnReadDirectory(const ReadDirectoryCallback& callback,
1254 base::PlatformFileError error, 1307 base::PlatformFileError error,
1255 const FilePath& directory_path, 1308 const FilePath& directory_path,
1256 GDataEntry* entry); 1309 GDataEntry* entry);
1257 1310
1258 // Finds file info by using virtual |file_path|. This call will also 1311 // Finds file info by using virtual |file_path|. This call will also
1259 // retrieve and refresh file system content from server and disk cache. 1312 // retrieve and refresh file system content from server and disk cache.
1260 void FindEntryByPathAsyncOnUIThread(const FilePath& search_file_path, 1313 void FindEntryByPathAsyncOnUIThread(const FilePath& search_file_path,
1261 const FindEntryCallback& callback); 1314 const FindEntryCallback& callback);
1262 1315
1263 // The following functions are used to forward calls to asynchronous public 1316 // The following functions are used to forward calls to asynchronous public
1264 // member functions to UI thread. 1317 // member functions to UI thread.
1318 void GetEntriesByQueryAsyncOnUIThread(const std::string& search_query,
1319 const ReadDirectoryCallback& callback);
1265 void CopyOnUIThread(const FilePath& src_file_path, 1320 void CopyOnUIThread(const FilePath& src_file_path,
1266 const FilePath& dest_file_path, 1321 const FilePath& dest_file_path,
1267 const FileOperationCallback& callback); 1322 const FileOperationCallback& callback);
1268 void MoveOnUIThread(const FilePath& src_file_path, 1323 void MoveOnUIThread(const FilePath& src_file_path,
1269 const FilePath& dest_file_path, 1324 const FilePath& dest_file_path,
1270 const FileOperationCallback& callback); 1325 const FileOperationCallback& callback);
1271 void RemoveOnUIThread(const FilePath& file_path, 1326 void RemoveOnUIThread(const FilePath& file_path,
1272 bool is_recursive, 1327 bool is_recursive,
1273 const FileOperationCallback& callback); 1328 const FileOperationCallback& callback);
1274 void CreateDirectoryOnUIThread(const FilePath& directory_path, 1329 void CreateDirectoryOnUIThread(const FilePath& directory_path,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 }; 1419 };
1365 1420
1366 // Sets the free disk space getter for testing. 1421 // Sets the free disk space getter for testing.
1367 // The existing getter is deleted. 1422 // The existing getter is deleted.
1368 void SetFreeDiskSpaceGetterForTesting( 1423 void SetFreeDiskSpaceGetterForTesting(
1369 FreeDiskSpaceGetterInterface* getter); 1424 FreeDiskSpaceGetterInterface* getter);
1370 1425
1371 } // namespace gdata 1426 } // namespace gdata
1372 1427
1373 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ 1428 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698