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

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

Powered by Google App Engine
This is Rietveld 408576698