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

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

Issue 10634020: [FileManager] Do drive search incrementally (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit that crept up while rebasing Created 8 years, 4 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 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 } 447 }
448 448
449 // Callback for GetEntryByResourceIdAsync. 449 // Callback for GetEntryByResourceIdAsync.
450 // Adds |entry| to |results|. Runs |callback| with |results| when 450 // Adds |entry| to |results|. Runs |callback| with |results| when
451 // |run_callback| is true. 451 // |run_callback| is true.
452 void AddEntryToSearchResults( 452 void AddEntryToSearchResults(
453 std::vector<SearchResultInfo>* results, 453 std::vector<SearchResultInfo>* results,
454 const SearchCallback& callback, 454 const SearchCallback& callback,
455 GDataFileError error, 455 GDataFileError error,
456 bool run_callback, 456 bool run_callback,
457 const GURL& next_feed,
457 GDataEntry* entry) { 458 GDataEntry* entry) {
458 // If a result is not present in our local file system snapshot, ignore it. 459 // If a result is not present in our local file system snapshot, ignore it.
459 // For example, this may happen if the entry has recently been added to the 460 // For example, this may happen if the entry has recently been added to the
460 // drive (and we still haven't received its delta feed). 461 // drive (and we still haven't received its delta feed).
461 if (entry) { 462 if (entry) {
462 const bool is_directory = entry->AsGDataDirectory() != NULL; 463 const bool is_directory = entry->AsGDataDirectory() != NULL;
463 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); 464 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory));
464 } 465 }
465 466
466 if (run_callback) { 467 if (run_callback) {
467 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); 468 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results);
468 if (!callback.is_null()) 469 if (!callback.is_null())
469 callback.Run(error, result_vec.Pass()); 470 callback.Run(error, next_feed, result_vec.Pass());
470 } 471 }
471 } 472 }
472 473
473 // Runs task on UI thread. 474 // Runs task on UI thread.
474 void RunTaskOnUIThread(const base::Closure& task) { 475 void RunTaskOnUIThread(const base::Closure& task) {
475 RunTaskOnThread( 476 RunTaskOnThread(
476 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), task); 477 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), task);
477 } 478 }
478 479
479 // RelayCallback relays arguments for callback running on the given thread. 480 // RelayCallback relays arguments for callback running on the given thread.
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1006 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1006 1007
1007 GDataFileError error = GDataToGDataFileError(status); 1008 GDataFileError error = GDataToGDataFileError(status);
1008 if (error != GDATA_FILE_OK) { 1009 if (error != GDATA_FILE_OK) {
1009 // Get changes starting from the next changestamp from what we have locally. 1010 // Get changes starting from the next changestamp from what we have locally.
1010 LoadFeedFromServer(initial_origin, 1011 LoadFeedFromServer(initial_origin,
1011 local_changestamp + 1, 0, 1012 local_changestamp + 1, 0,
1012 true, /* should_fetch_multiple_feeds */ 1013 true, /* should_fetch_multiple_feeds */
1013 search_file_path, 1014 search_file_path,
1014 std::string() /* no search query */, 1015 std::string() /* no search query */,
1016 GURL(), /* feed not explicitly set */
1015 std::string() /* no directory resource ID */, 1017 std::string() /* no directory resource ID */,
1016 callback, 1018 callback,
1017 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 1019 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
1018 ui_weak_ptr_)); 1020 ui_weak_ptr_));
1019 return; 1021 return;
1020 } 1022 }
1021 1023
1022 scoped_ptr<AccountMetadataFeed> account_metadata; 1024 scoped_ptr<AccountMetadataFeed> account_metadata;
1023 if (feed_data.get()) { 1025 if (feed_data.get()) {
1024 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); 1026 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data);
1025 #ifndef NDEBUG 1027 #ifndef NDEBUG
1026 // Save account metadata feed for analysis. 1028 // Save account metadata feed for analysis.
1027 const FilePath path = 1029 const FilePath path =
1028 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( 1030 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append(
1029 kAccountMetadataFile); 1031 kAccountMetadataFile);
1030 PostBlockingPoolSequencedTask( 1032 PostBlockingPoolSequencedTask(
1031 FROM_HERE, 1033 FROM_HERE,
1032 blocking_task_runner_, 1034 blocking_task_runner_,
1033 base::Bind(&SaveFeedOnBlockingPoolForDebugging, 1035 base::Bind(&SaveFeedOnBlockingPoolForDebugging,
1034 path, base::Passed(&feed_data))); 1036 path, base::Passed(&feed_data)));
1035 #endif 1037 #endif
1036 } 1038 }
1037 1039
1038 if (!account_metadata.get()) { 1040 if (!account_metadata.get()) {
1039 LoadFeedFromServer(initial_origin, 1041 LoadFeedFromServer(initial_origin,
1040 local_changestamp + 1, 0, 1042 local_changestamp + 1, 0,
1041 true, /* should_fetch_multiple_feeds */ 1043 true, /* should_fetch_multiple_feeds */
1042 search_file_path, 1044 search_file_path,
1043 std::string() /* no search query */, 1045 std::string() /* no search query */,
1046 GURL(), /* feed not explicitly set */
1044 std::string() /* no directory resource ID */, 1047 std::string() /* no directory resource ID */,
1045 callback, 1048 callback,
1046 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 1049 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
1047 ui_weak_ptr_)); 1050 ui_weak_ptr_));
1048 return; 1051 return;
1049 } 1052 }
1050 1053
1051 webapps_registry_->UpdateFromFeed(account_metadata.get()); 1054 webapps_registry_->UpdateFromFeed(account_metadata.get());
1052 1055
1053 bool changes_detected = true; 1056 bool changes_detected = true;
(...skipping 15 matching lines...) Expand all
1069 return; 1072 return;
1070 } 1073 }
1071 1074
1072 // Load changes from the server. 1075 // Load changes from the server.
1073 LoadFeedFromServer(initial_origin, 1076 LoadFeedFromServer(initial_origin,
1074 local_changestamp > 0 ? local_changestamp + 1 : 0, 1077 local_changestamp > 0 ? local_changestamp + 1 : 0,
1075 account_metadata->largest_changestamp(), 1078 account_metadata->largest_changestamp(),
1076 true, /* should_fetch_multiple_feeds */ 1079 true, /* should_fetch_multiple_feeds */
1077 search_file_path, 1080 search_file_path,
1078 std::string() /* no search query */, 1081 std::string() /* no search query */,
1082 GURL(), /* feed not explicitly set */
1079 std::string() /* no directory resource ID */, 1083 std::string() /* no directory resource ID */,
1080 callback, 1084 callback,
1081 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 1085 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
1082 ui_weak_ptr_)); 1086 ui_weak_ptr_));
1083 } 1087 }
1084 1088
1085 void GDataFileSystem::LoadFeedFromServer( 1089 void GDataFileSystem::LoadFeedFromServer(
1086 ContentOrigin initial_origin, 1090 ContentOrigin initial_origin,
1087 int start_changestamp, 1091 int start_changestamp,
1088 int root_feed_changestamp, 1092 int root_feed_changestamp,
1089 bool should_fetch_multiple_feeds, 1093 bool should_fetch_multiple_feeds,
1090 const FilePath& search_file_path, 1094 const FilePath& search_file_path,
1091 const std::string& search_query, 1095 const std::string& search_query,
1096 const GURL& feed_to_load,
1092 const std::string& directory_resource_id, 1097 const std::string& directory_resource_id,
1093 const FindEntryCallback& entry_found_callback, 1098 const FindEntryCallback& entry_found_callback,
1094 const LoadDocumentFeedCallback& feed_load_callback) { 1099 const LoadDocumentFeedCallback& feed_load_callback) {
1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1096 1101
1097 // |feed_list| will contain the list of all collected feed updates that 1102 // |feed_list| will contain the list of all collected feed updates that
1098 // we will receive through calls of DocumentsService::GetDocuments(). 1103 // we will receive through calls of DocumentsService::GetDocuments().
1099 scoped_ptr<std::vector<DocumentFeed*> > feed_list( 1104 scoped_ptr<std::vector<DocumentFeed*> > feed_list(
1100 new std::vector<DocumentFeed*>); 1105 new std::vector<DocumentFeed*>);
1101 const base::TimeTicks start_time = base::TimeTicks::Now(); 1106 const base::TimeTicks start_time = base::TimeTicks::Now();
1102 documents_service_->GetDocuments( 1107 documents_service_->GetDocuments(
1103 GURL(), // root feed start. 1108 feed_to_load,
1104 start_changestamp, 1109 start_changestamp,
1105 search_query, 1110 search_query,
1106 directory_resource_id, 1111 directory_resource_id,
1107 base::Bind(&GDataFileSystem::OnGetDocuments, 1112 base::Bind(&GDataFileSystem::OnGetDocuments,
1108 ui_weak_ptr_, 1113 ui_weak_ptr_,
1109 initial_origin, 1114 initial_origin,
1110 feed_load_callback, 1115 feed_load_callback,
1111 base::Owned(new GetDocumentsParams(start_changestamp, 1116 base::Owned(new GetDocumentsParams(start_changestamp,
1112 root_feed_changestamp, 1117 root_feed_changestamp,
1113 feed_list.release(), 1118 feed_list.release(),
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 LOG(ERROR) << "Directory entry not found: " << file_path.value(); 2383 LOG(ERROR) << "Directory entry not found: " << file_path.value();
2379 return; 2384 return;
2380 } 2385 }
2381 2386
2382 LoadFeedFromServer(directory_service_->origin(), 2387 LoadFeedFromServer(directory_service_->origin(),
2383 0, // Not delta feed. 2388 0, // Not delta feed.
2384 0, // Not used. 2389 0, // Not used.
2385 true, // multiple feeds 2390 true, // multiple feeds
2386 file_path, 2391 file_path,
2387 std::string(), // No search query 2392 std::string(), // No search query
2393 GURL(), /* feed not explicitly set */
2388 entry_proto->resource_id(), 2394 entry_proto->resource_id(),
2389 FindEntryCallback(), // Not used. 2395 FindEntryCallback(), // Not used.
2390 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, 2396 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh,
2391 ui_weak_ptr_)); 2397 ui_weak_ptr_));
2392 } 2398 }
2393 2399
2394 void GDataFileSystem::OnRequestDirectoryRefresh( 2400 void GDataFileSystem::OnRequestDirectoryRefresh(
2395 GetDocumentsParams* params, 2401 GetDocumentsParams* params,
2396 GDataFileError error) { 2402 GDataFileError error) {
2397 DCHECK(params); 2403 DCHECK(params);
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
2708 } 2714 }
2709 } 2715 }
2710 2716
2711 void GDataFileSystem::OnSearch(const SearchCallback& callback, 2717 void GDataFileSystem::OnSearch(const SearchCallback& callback,
2712 GetDocumentsParams* params, 2718 GetDocumentsParams* params,
2713 GDataFileError error) { 2719 GDataFileError error) {
2714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2715 2721
2716 if (error != GDATA_FILE_OK) { 2722 if (error != GDATA_FILE_OK) {
2717 if (!callback.is_null()) 2723 if (!callback.is_null())
2718 callback.Run(error, scoped_ptr<std::vector<SearchResultInfo> >()); 2724 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >());
2719 return; 2725 return;
2720 } 2726 }
2721 2727
2722 // The search results will be returned using virtual directory. 2728 // The search results will be returned using virtual directory.
2723 // The directory is not really part of the file system, so it has no parent or 2729 // The directory is not really part of the file system, so it has no parent or
2724 // root. 2730 // root.
2725 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); 2731 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>());
2726 2732
2727 DCHECK_EQ(1u, params->feed_list->size()); 2733 DCHECK_EQ(1u, params->feed_list->size());
2728 DocumentFeed* feed = params->feed_list->at(0); 2734 DocumentFeed* feed = params->feed_list->at(0);
2729 2735
2736 // TODO(tbarzic): Limit total number of returned results for the query.
2737 GURL next_feed;
2738 feed->GetNextFeedURL(&next_feed);
2739
2730 if (feed->entries().empty()) { 2740 if (feed->entries().empty()) {
2731 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); 2741 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results);
2732 if (!callback.is_null()) 2742 if (!callback.is_null())
2733 callback.Run(error, result_vec.Pass()); 2743 callback.Run(error, next_feed, result_vec.Pass());
2734 return; 2744 return;
2735 } 2745 }
2736 2746
2737 // Go through all entires generated by the feed and add them to the search 2747 // Go through all entires generated by the feed and add them to the search
2738 // result directory. 2748 // result directory.
2739 for (size_t i = 0; i < feed->entries().size(); ++i) { 2749 for (size_t i = 0; i < feed->entries().size(); ++i) {
2740 DocumentEntry* doc = const_cast<DocumentEntry*>(feed->entries()[i]); 2750 DocumentEntry* doc = const_cast<DocumentEntry*>(feed->entries()[i]);
2741 scoped_ptr<GDataEntry> entry( 2751 scoped_ptr<GDataEntry> entry(
2742 GDataEntry::FromDocumentEntry(NULL, doc, directory_service_.get())); 2752 GDataEntry::FromDocumentEntry(NULL, doc, directory_service_.get()));
2743 2753
(...skipping 15 matching lines...) Expand all
2759 2769
2760 // We will need information about result entry to create info for callback. 2770 // We will need information about result entry to create info for callback.
2761 // We can't use |entry| anymore, so we have to refetch entry from file 2771 // We can't use |entry| anymore, so we have to refetch entry from file
2762 // system. Also, |entry| doesn't have file path set before |RefreshFile| 2772 // system. Also, |entry| doesn't have file path set before |RefreshFile|
2763 // call, so we can't get file path from there. 2773 // call, so we can't get file path from there.
2764 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, 2774 directory_service_->GetEntryByResourceIdAsync(entry_resource_id,
2765 base::Bind(&AddEntryToSearchResults, 2775 base::Bind(&AddEntryToSearchResults,
2766 results, 2776 results,
2767 callback, 2777 callback,
2768 error, 2778 error,
2769 i+1 == feed->entries().size())); 2779 i+1 == feed->entries().size(),
2780 next_feed));
2770 } 2781 }
2771 } 2782 }
2772 2783
2773 void GDataFileSystem::Search(const std::string& search_query, 2784 void GDataFileSystem::Search(const std::string& search_query,
2785 const GURL& next_feed,
2774 const SearchCallback& callback) { 2786 const SearchCallback& callback) {
2775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2776 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2788 BrowserThread::CurrentlyOn(BrowserThread::IO));
2777 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, 2789 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread,
2778 ui_weak_ptr_, 2790 ui_weak_ptr_,
2779 search_query, 2791 search_query,
2792 next_feed,
2780 CreateRelayCallback(callback))); 2793 CreateRelayCallback(callback)));
2781 } 2794 }
2782 2795
2783 void GDataFileSystem::SearchAsyncOnUIThread( 2796 void GDataFileSystem::SearchAsyncOnUIThread(
2784 const std::string& search_query, 2797 const std::string& search_query,
2798 const GURL& next_feed,
2785 const SearchCallback& callback) { 2799 const SearchCallback& callback) {
2786 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2787 scoped_ptr<std::vector<DocumentFeed*> > feed_list( 2801 scoped_ptr<std::vector<DocumentFeed*> > feed_list(
2788 new std::vector<DocumentFeed*>); 2802 new std::vector<DocumentFeed*>);
2789 2803
2790 ContentOrigin initial_origin = directory_service_->origin(); 2804 ContentOrigin initial_origin = directory_service_->origin();
2791 LoadFeedFromServer(initial_origin, 2805 LoadFeedFromServer(initial_origin,
2792 0, 0, // We don't use change stamps when fetching search 2806 0, 0, // We don't use change stamps when fetching search
2793 // data; we always fetch the whole result feed. 2807 // data; we always fetch the whole result feed.
2794 false, // Stop fetching search results after first feed 2808 false, // Stop fetching search results after first feed
2795 // chunk to avoid displaying huge number of search 2809 // chunk to avoid displaying huge number of search
2796 // results (especially since we don't cache them). 2810 // results (especially since we don't cache them).
2797 FilePath(), // Not used. 2811 FilePath(), // Not used.
2798 search_query, 2812 search_query,
2813 next_feed,
2799 std::string(), // No directory resource ID. 2814 std::string(), // No directory resource ID.
2800 FindEntryCallback(), // Not used. 2815 FindEntryCallback(), // Not used.
2801 base::Bind(&GDataFileSystem::OnSearch, 2816 base::Bind(&GDataFileSystem::OnSearch,
2802 ui_weak_ptr_, callback)); 2817 ui_weak_ptr_, callback));
2803 } 2818 }
2804 2819
2805 void GDataFileSystem::OnGetDocuments(ContentOrigin initial_origin, 2820 void GDataFileSystem::OnGetDocuments(ContentOrigin initial_origin,
2806 const LoadDocumentFeedCallback& callback, 2821 const LoadDocumentFeedCallback& callback,
2807 GetDocumentsParams* params, 2822 GetDocumentsParams* params,
2808 base::TimeTicks start_time, 2823 base::TimeTicks start_time,
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after
4279 } 4294 }
4280 4295
4281 PlatformFileInfoProto entry_file_info; 4296 PlatformFileInfoProto entry_file_info;
4282 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 4297 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
4283 *entry_proto->mutable_file_info() = entry_file_info; 4298 *entry_proto->mutable_file_info() = entry_file_info;
4284 if (!callback.is_null()) 4299 if (!callback.is_null())
4285 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 4300 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
4286 } 4301 }
4287 4302
4288 } // namespace gdata 4303 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698