OLD | NEW |
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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // Adds |entry| to |results|. Runs |callback| with |results| when | 394 // Adds |entry| to |results|. Runs |callback| with |results| when |
395 // |run_callback| is true. When |entry| is not present in our local file system | 395 // |run_callback| is true. When |entry| is not present in our local file system |
396 // snapshot, it is not added to |results|. Instead, |entry_skipped_callback| is | 396 // snapshot, it is not added to |results|. Instead, |entry_skipped_callback| is |
397 // called. | 397 // called. |
398 void AddEntryToSearchResults( | 398 void AddEntryToSearchResults( |
399 std::vector<SearchResultInfo>* results, | 399 std::vector<SearchResultInfo>* results, |
400 const SearchCallback& callback, | 400 const SearchCallback& callback, |
401 const base::Closure& entry_skipped_callback, | 401 const base::Closure& entry_skipped_callback, |
402 GDataFileError error, | 402 GDataFileError error, |
403 bool run_callback, | 403 bool run_callback, |
| 404 const GURL& next_feed, |
404 GDataEntry* entry) { | 405 GDataEntry* entry) { |
405 // If a result is not present in our local file system snapshot, invoke | 406 // If a result is not present in our local file system snapshot, invoke |
406 // |entry_skipped_callback| and refreshes the snapshot with delta feed. | 407 // |entry_skipped_callback| and refreshes the snapshot with delta feed. |
407 // For example, this may happen if the entry has recently been added to the | 408 // For example, this may happen if the entry has recently been added to the |
408 // drive (and we still haven't received its delta feed). | 409 // drive (and we still haven't received its delta feed). |
409 if (entry) { | 410 if (entry) { |
410 const bool is_directory = entry->AsGDataDirectory() != NULL; | 411 const bool is_directory = entry->AsGDataDirectory() != NULL; |
411 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); | 412 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); |
412 } else { | 413 } else { |
413 if (!entry_skipped_callback.is_null()) | 414 if (!entry_skipped_callback.is_null()) |
414 entry_skipped_callback.Run(); | 415 entry_skipped_callback.Run(); |
415 } | 416 } |
416 | 417 |
417 if (run_callback) { | 418 if (run_callback) { |
418 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); | 419 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); |
419 if (!callback.is_null()) | 420 if (!callback.is_null()) |
420 callback.Run(error, result_vec.Pass()); | 421 callback.Run(error, next_feed, result_vec.Pass()); |
421 } | 422 } |
422 } | 423 } |
423 | 424 |
424 // Runs task on UI thread. | 425 // Runs task on UI thread. |
425 void RunTaskOnUIThread(const base::Closure& task) { | 426 void RunTaskOnUIThread(const base::Closure& task) { |
426 RunTaskOnThread( | 427 RunTaskOnThread( |
427 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), task); | 428 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), task); |
428 } | 429 } |
429 | 430 |
430 // RelayCallback relays arguments for callback running on the given thread. | 431 // RelayCallback relays arguments for callback running on the given thread. |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1016 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1016 | 1017 |
1017 GDataFileError error = GDataToGDataFileError(status); | 1018 GDataFileError error = GDataToGDataFileError(status); |
1018 if (error != GDATA_FILE_OK) { | 1019 if (error != GDATA_FILE_OK) { |
1019 // Get changes starting from the next changestamp from what we have locally. | 1020 // Get changes starting from the next changestamp from what we have locally. |
1020 LoadFromServer(initial_origin, | 1021 LoadFromServer(initial_origin, |
1021 local_changestamp + 1, 0, | 1022 local_changestamp + 1, 0, |
1022 true, /* should_fetch_multiple_feeds */ | 1023 true, /* should_fetch_multiple_feeds */ |
1023 search_file_path, | 1024 search_file_path, |
1024 std::string() /* no search query */, | 1025 std::string() /* no search query */, |
| 1026 GURL(), /* feed not explicitly set */ |
1025 std::string() /* no directory resource ID */, | 1027 std::string() /* no directory resource ID */, |
1026 callback, | 1028 callback, |
1027 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, | 1029 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
1028 weak_ptr_factory_.GetWeakPtr())); | 1030 weak_ptr_factory_.GetWeakPtr())); |
1029 return; | 1031 return; |
1030 } | 1032 } |
1031 | 1033 |
1032 scoped_ptr<AccountMetadataFeed> account_metadata; | 1034 scoped_ptr<AccountMetadataFeed> account_metadata; |
1033 if (feed_data.get()) { | 1035 if (feed_data.get()) { |
1034 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); | 1036 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); |
1035 #ifndef NDEBUG | 1037 #ifndef NDEBUG |
1036 // Save account metadata feed for analysis. | 1038 // Save account metadata feed for analysis. |
1037 const FilePath path = | 1039 const FilePath path = |
1038 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( | 1040 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( |
1039 kAccountMetadataFile); | 1041 kAccountMetadataFile); |
1040 PostBlockingPoolSequencedTask( | 1042 PostBlockingPoolSequencedTask( |
1041 FROM_HERE, | 1043 FROM_HERE, |
1042 blocking_task_runner_, | 1044 blocking_task_runner_, |
1043 base::Bind(&SaveFeedOnBlockingPoolForDebugging, | 1045 base::Bind(&SaveFeedOnBlockingPoolForDebugging, |
1044 path, base::Passed(&feed_data))); | 1046 path, base::Passed(&feed_data))); |
1045 #endif | 1047 #endif |
1046 } | 1048 } |
1047 | 1049 |
1048 if (!account_metadata.get()) { | 1050 if (!account_metadata.get()) { |
1049 LoadFromServer(initial_origin, | 1051 LoadFromServer(initial_origin, |
1050 local_changestamp + 1, 0, | 1052 local_changestamp + 1, 0, |
1051 true, /* should_fetch_multiple_feeds */ | 1053 true, /* should_fetch_multiple_feeds */ |
1052 search_file_path, | 1054 search_file_path, |
1053 std::string() /* no search query */, | 1055 std::string() /* no search query */, |
| 1056 GURL(), /* feed not explicitly set */ |
1054 std::string() /* no directory resource ID */, | 1057 std::string() /* no directory resource ID */, |
1055 callback, | 1058 callback, |
1056 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, | 1059 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
1057 weak_ptr_factory_.GetWeakPtr())); | 1060 weak_ptr_factory_.GetWeakPtr())); |
1058 return; | 1061 return; |
1059 } | 1062 } |
1060 | 1063 |
1061 webapps_registry_->UpdateFromFeed(account_metadata.get()); | 1064 webapps_registry_->UpdateFromFeed(account_metadata.get()); |
1062 | 1065 |
1063 bool changes_detected = true; | 1066 bool changes_detected = true; |
(...skipping 20 matching lines...) Expand all Loading... |
1084 return; | 1087 return; |
1085 } | 1088 } |
1086 | 1089 |
1087 // Load changes from the server. | 1090 // Load changes from the server. |
1088 LoadFromServer(initial_origin, | 1091 LoadFromServer(initial_origin, |
1089 local_changestamp > 0 ? local_changestamp + 1 : 0, | 1092 local_changestamp > 0 ? local_changestamp + 1 : 0, |
1090 account_metadata->largest_changestamp(), | 1093 account_metadata->largest_changestamp(), |
1091 true, /* should_fetch_multiple_feeds */ | 1094 true, /* should_fetch_multiple_feeds */ |
1092 search_file_path, | 1095 search_file_path, |
1093 std::string() /* no search query */, | 1096 std::string() /* no search query */, |
| 1097 GURL(), /* feed not explicitly set */ |
1094 std::string() /* no directory resource ID */, | 1098 std::string() /* no directory resource ID */, |
1095 callback, | 1099 callback, |
1096 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, | 1100 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
1097 weak_ptr_factory_.GetWeakPtr())); | 1101 weak_ptr_factory_.GetWeakPtr())); |
1098 } | 1102 } |
1099 | 1103 |
1100 void GDataWapiFeedLoader::LoadFromServer( | 1104 void GDataWapiFeedLoader::LoadFromServer( |
1101 ContentOrigin initial_origin, | 1105 ContentOrigin initial_origin, |
1102 int start_changestamp, | 1106 int start_changestamp, |
1103 int root_feed_changestamp, | 1107 int root_feed_changestamp, |
1104 bool should_fetch_multiple_feeds, | 1108 bool should_fetch_multiple_feeds, |
1105 const FilePath& search_file_path, | 1109 const FilePath& search_file_path, |
1106 const std::string& search_query, | 1110 const std::string& search_query, |
| 1111 const GURL& feed_to_load, |
1107 const std::string& directory_resource_id, | 1112 const std::string& directory_resource_id, |
1108 const FindEntryCallback& entry_found_callback, | 1113 const FindEntryCallback& entry_found_callback, |
1109 const LoadDocumentFeedCallback& feed_load_callback) { | 1114 const LoadDocumentFeedCallback& feed_load_callback) { |
1110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1111 | 1116 |
1112 // |feed_list| will contain the list of all collected feed updates that | 1117 // |feed_list| will contain the list of all collected feed updates that |
1113 // we will receive through calls of DocumentsService::GetDocuments(). | 1118 // we will receive through calls of DocumentsService::GetDocuments(). |
1114 scoped_ptr<std::vector<DocumentFeed*> > feed_list( | 1119 scoped_ptr<std::vector<DocumentFeed*> > feed_list( |
1115 new std::vector<DocumentFeed*>); | 1120 new std::vector<DocumentFeed*>); |
1116 const base::TimeTicks start_time = base::TimeTicks::Now(); | 1121 const base::TimeTicks start_time = base::TimeTicks::Now(); |
1117 documents_service_->GetDocuments( | 1122 documents_service_->GetDocuments( |
1118 GURL(), // root feed start. | 1123 feed_to_load, |
1119 start_changestamp, | 1124 start_changestamp, |
1120 search_query, | 1125 search_query, |
1121 directory_resource_id, | 1126 directory_resource_id, |
1122 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, | 1127 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, |
1123 weak_ptr_factory_.GetWeakPtr(), | 1128 weak_ptr_factory_.GetWeakPtr(), |
1124 initial_origin, | 1129 initial_origin, |
1125 feed_load_callback, | 1130 feed_load_callback, |
1126 base::Owned(new GetDocumentsParams(start_changestamp, | 1131 base::Owned(new GetDocumentsParams(start_changestamp, |
1127 root_feed_changestamp, | 1132 root_feed_changestamp, |
1128 feed_list.release(), | 1133 feed_list.release(), |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2400 return; | 2405 return; |
2401 } | 2406 } |
2402 | 2407 |
2403 feed_loader_->LoadFromServer( | 2408 feed_loader_->LoadFromServer( |
2404 directory_service_->origin(), | 2409 directory_service_->origin(), |
2405 0, // Not delta feed. | 2410 0, // Not delta feed. |
2406 0, // Not used. | 2411 0, // Not used. |
2407 true, // multiple feeds | 2412 true, // multiple feeds |
2408 file_path, | 2413 file_path, |
2409 std::string(), // No search query | 2414 std::string(), // No search query |
| 2415 GURL(), /* feed not explicitly set */ |
2410 entry_proto->resource_id(), | 2416 entry_proto->resource_id(), |
2411 FindEntryCallback(), // Not used. | 2417 FindEntryCallback(), // Not used. |
2412 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, | 2418 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, |
2413 ui_weak_ptr_)); | 2419 ui_weak_ptr_)); |
2414 } | 2420 } |
2415 | 2421 |
2416 void GDataFileSystem::OnRequestDirectoryRefresh( | 2422 void GDataFileSystem::OnRequestDirectoryRefresh( |
2417 GetDocumentsParams* params, | 2423 GetDocumentsParams* params, |
2418 GDataFileError error) { | 2424 GDataFileError error) { |
2419 DCHECK(params); | 2425 DCHECK(params); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2722 } | 2728 } |
2723 } | 2729 } |
2724 | 2730 |
2725 void GDataFileSystem::OnSearch(const SearchCallback& callback, | 2731 void GDataFileSystem::OnSearch(const SearchCallback& callback, |
2726 GetDocumentsParams* params, | 2732 GetDocumentsParams* params, |
2727 GDataFileError error) { | 2733 GDataFileError error) { |
2728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2729 | 2735 |
2730 if (error != GDATA_FILE_OK) { | 2736 if (error != GDATA_FILE_OK) { |
2731 if (!callback.is_null()) | 2737 if (!callback.is_null()) |
2732 callback.Run(error, scoped_ptr<std::vector<SearchResultInfo> >()); | 2738 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >()); |
2733 return; | 2739 return; |
2734 } | 2740 } |
2735 | 2741 |
2736 // The search results will be returned using virtual directory. | 2742 // The search results will be returned using virtual directory. |
2737 // The directory is not really part of the file system, so it has no parent or | 2743 // The directory is not really part of the file system, so it has no parent or |
2738 // root. | 2744 // root. |
2739 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); | 2745 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); |
2740 | 2746 |
2741 DCHECK_EQ(1u, params->feed_list->size()); | 2747 DCHECK_EQ(1u, params->feed_list->size()); |
2742 DocumentFeed* feed = params->feed_list->at(0); | 2748 DocumentFeed* feed = params->feed_list->at(0); |
2743 | 2749 |
| 2750 // TODO(tbarzic): Limit total number of returned results for the query. |
| 2751 GURL next_feed; |
| 2752 feed->GetNextFeedURL(&next_feed); |
| 2753 |
2744 if (feed->entries().empty()) { | 2754 if (feed->entries().empty()) { |
2745 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); | 2755 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); |
2746 if (!callback.is_null()) | 2756 if (!callback.is_null()) |
2747 callback.Run(error, result_vec.Pass()); | 2757 callback.Run(error, next_feed, result_vec.Pass()); |
2748 return; | 2758 return; |
2749 } | 2759 } |
2750 | 2760 |
2751 // Go through all entires generated by the feed and add them to the search | 2761 // Go through all entires generated by the feed and add them to the search |
2752 // result directory. | 2762 // result directory. |
2753 for (size_t i = 0; i < feed->entries().size(); ++i) { | 2763 for (size_t i = 0; i < feed->entries().size(); ++i) { |
2754 DocumentEntry* doc = const_cast<DocumentEntry*>(feed->entries()[i]); | 2764 DocumentEntry* doc = const_cast<DocumentEntry*>(feed->entries()[i]); |
2755 scoped_ptr<GDataEntry> entry( | 2765 scoped_ptr<GDataEntry> entry( |
2756 GDataEntry::FromDocumentEntry(NULL, doc, directory_service_.get())); | 2766 GDataEntry::FromDocumentEntry(NULL, doc, directory_service_.get())); |
2757 | 2767 |
(...skipping 16 matching lines...) Expand all Loading... |
2774 // We will need information about result entry to create info for callback. | 2784 // We will need information about result entry to create info for callback. |
2775 // We can't use |entry| anymore, so we have to refetch entry from file | 2785 // We can't use |entry| anymore, so we have to refetch entry from file |
2776 // system. Also, |entry| doesn't have file path set before |RefreshFile| | 2786 // system. Also, |entry| doesn't have file path set before |RefreshFile| |
2777 // call, so we can't get file path from there. | 2787 // call, so we can't get file path from there. |
2778 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, | 2788 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, |
2779 base::Bind(&AddEntryToSearchResults, | 2789 base::Bind(&AddEntryToSearchResults, |
2780 results, | 2790 results, |
2781 callback, | 2791 callback, |
2782 base::Bind(&GDataFileSystem::CheckForUpdates, ui_weak_ptr_), | 2792 base::Bind(&GDataFileSystem::CheckForUpdates, ui_weak_ptr_), |
2783 error, | 2793 error, |
2784 i+1 == feed->entries().size())); | 2794 i+1 == feed->entries().size(), |
| 2795 next_feed)); |
2785 } | 2796 } |
2786 } | 2797 } |
2787 | 2798 |
2788 void GDataFileSystem::Search(const std::string& search_query, | 2799 void GDataFileSystem::Search(const std::string& search_query, |
| 2800 const GURL& next_feed, |
2789 const SearchCallback& callback) { | 2801 const SearchCallback& callback) { |
2790 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2791 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2803 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2792 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, | 2804 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, |
2793 ui_weak_ptr_, | 2805 ui_weak_ptr_, |
2794 search_query, | 2806 search_query, |
| 2807 next_feed, |
2795 CreateRelayCallback(callback))); | 2808 CreateRelayCallback(callback))); |
2796 } | 2809 } |
2797 | 2810 |
2798 void GDataFileSystem::SearchAsyncOnUIThread( | 2811 void GDataFileSystem::SearchAsyncOnUIThread( |
2799 const std::string& search_query, | 2812 const std::string& search_query, |
| 2813 const GURL& next_feed, |
2800 const SearchCallback& callback) { | 2814 const SearchCallback& callback) { |
2801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2802 scoped_ptr<std::vector<DocumentFeed*> > feed_list( | 2816 scoped_ptr<std::vector<DocumentFeed*> > feed_list( |
2803 new std::vector<DocumentFeed*>); | 2817 new std::vector<DocumentFeed*>); |
2804 | 2818 |
2805 ContentOrigin initial_origin = directory_service_->origin(); | 2819 ContentOrigin initial_origin = directory_service_->origin(); |
2806 feed_loader_->LoadFromServer( | 2820 feed_loader_->LoadFromServer( |
2807 initial_origin, | 2821 initial_origin, |
2808 0, 0, // We don't use change stamps when fetching search | 2822 0, 0, // We don't use change stamps when fetching search |
2809 // data; we always fetch the whole result feed. | 2823 // data; we always fetch the whole result feed. |
2810 false, // Stop fetching search results after first feed | 2824 false, // Stop fetching search results after first feed |
2811 // chunk to avoid displaying huge number of search | 2825 // chunk to avoid displaying huge number of search |
2812 // results (especially since we don't cache them). | 2826 // results (especially since we don't cache them). |
2813 FilePath(), // Not used. | 2827 FilePath(), // Not used. |
2814 search_query, | 2828 search_query, |
| 2829 next_feed, |
2815 std::string(), // No directory resource ID. | 2830 std::string(), // No directory resource ID. |
2816 FindEntryCallback(), // Not used. | 2831 FindEntryCallback(), // Not used. |
2817 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback)); | 2832 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback)); |
2818 } | 2833 } |
2819 | 2834 |
2820 void GDataWapiFeedLoader::OnGetDocuments( | 2835 void GDataWapiFeedLoader::OnGetDocuments( |
2821 ContentOrigin initial_origin, | 2836 ContentOrigin initial_origin, |
2822 const LoadDocumentFeedCallback& callback, | 2837 const LoadDocumentFeedCallback& callback, |
2823 GetDocumentsParams* params, | 2838 GetDocumentsParams* params, |
2824 base::TimeTicks start_time, | 2839 base::TimeTicks start_time, |
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4168 } | 4183 } |
4169 | 4184 |
4170 PlatformFileInfoProto entry_file_info; | 4185 PlatformFileInfoProto entry_file_info; |
4171 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4186 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
4172 *entry_proto->mutable_file_info() = entry_file_info; | 4187 *entry_proto->mutable_file_info() = entry_file_info; |
4173 if (!callback.is_null()) | 4188 if (!callback.is_null()) |
4174 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4189 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
4175 } | 4190 } |
4176 | 4191 |
4177 } // namespace gdata | 4192 } // namespace gdata |
OLD | NEW |