Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
| index 8c7828e167043a609408d23ea84f1d4730eed8f9..f4d0cc97a94ef030ae5b908ef7c449db09bb91a6 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
| @@ -464,6 +464,29 @@ void GDataWapiFeedLoader::LoadFromServer( |
| scoped_ptr<std::vector<DocumentFeed*> > feed_list( |
| new std::vector<DocumentFeed*>); |
| const base::TimeTicks start_time = base::TimeTicks::Now(); |
| + |
| + if (gdata::util::IsDriveV2ApiEnabled()) { |
| + documents_service_->GetChangelist( |
| + feed_to_load, |
| + start_changestamp, |
| + base::Bind(&GDataWapiFeedLoader::OnGetChangelist, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + initial_origin, |
| + feed_load_callback, |
| + base::Owned(new GetDocumentsParams( |
| + start_changestamp, |
| + root_feed_changestamp, |
| + feed_list.release(), |
| + should_fetch_multiple_feeds, |
| + search_file_path, |
| + search_query, |
| + directory_resource_id, |
| + entry_found_callback, |
| + NULL)), |
| + start_time)); |
| + return; |
| + } |
| + |
| documents_service_->GetDocuments( |
| feed_to_load, |
| start_changestamp, |
| @@ -640,6 +663,105 @@ void GDataWapiFeedLoader::OnGetDocuments( |
| callback.Run(params, error); |
| } |
| +void GDataWapiFeedLoader::OnGetChangelist( |
| + ContentOrigin initial_origin, |
| + const LoadDocumentFeedCallback& callback, |
| + GetDocumentsParams* params, |
| + base::TimeTicks start_time, |
| + GDataErrorCode status, |
| + scoped_ptr<base::Value> data) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + if (params->feed_list->empty()) { |
| + UMA_HISTOGRAM_TIMES("Drive.InitialFeedLoadTime", |
| + base::TimeTicks::Now() - start_time); |
| + } |
| + |
| + GDataFileError error = util::GDataToGDataFileError(status); |
| + if (error == GDATA_FILE_OK && |
| + (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) { |
| + error = GDATA_FILE_ERROR_FAILED; |
| + } |
| + |
| + if (error != GDATA_FILE_OK) { |
| + directory_service_->set_origin(initial_origin); |
| + |
| + if (!callback.is_null()) |
| + callback.Run(params, error); |
| + |
| + return; |
| + } |
| + |
| + GURL next_feed_url; |
| + scoped_ptr<ChangeList> current_feed(ChangeList::CreateFrom(*data)); |
| + if (!current_feed.get()) { |
| + if (!callback.is_null()) { |
| + callback.Run(params, GDATA_FILE_ERROR_FAILED); |
| + } |
| + return; |
| + } |
| + const bool has_next_feed = !current_feed->next_page_token().empty(); |
| + |
| +#ifndef NDEBUG |
| + // Save initial root feed for analysis. |
| + std::string file_name = |
| + base::StringPrintf("DEBUG_changelist_%" PRId64 ".json", |
| + params->start_changestamp); |
| + util::PostBlockingPoolSequencedTask( |
| + FROM_HERE, |
| + blocking_task_runner_, |
| + base::Bind(&SaveFeedOnBlockingPoolForDebugging, |
| + cache_->GetCacheDirectoryPath( |
| + GDataCache::CACHE_TYPE_META).Append(file_name), |
| + base::Passed(&data))); |
| +#endif |
| + |
| + // Add the current feed to the list of collected feeds for this directory. |
| + scoped_ptr<DocumentFeed> feed = |
| + DocumentFeed::CreateFromChangeList(*current_feed); |
| + params->feed_list->push_back(feed.release()); |
| + |
| + // Compute and notify the number of entries fetched so far. |
| + int num_accumulated_entries = 0; |
| + for (size_t i = 0; i < params->feed_list->size(); ++i) |
| + num_accumulated_entries += params->feed_list->at(i)->entries().size(); |
| + |
| + // Notify the observers that a document feed is fetched. |
| + FOR_EACH_OBSERVER(Observer, observers_, |
| + OnDocumentFeedFetched(num_accumulated_entries)); |
| + |
| + // Check if we need to collect more data to complete the directory list. |
| + if (params->should_fetch_multiple_feeds && has_next_feed) { |
| + // Kick of the remaining part of the feeds. |
| + documents_service_->GetChangelist( |
| + current_feed->next_link(), |
| + params->start_changestamp, |
| + base::Bind(&GDataWapiFeedLoader::OnGetChangelist, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + initial_origin, |
| + callback, |
| + base::Owned( |
| + new GetDocumentsParams( |
| + params->start_changestamp, |
| + params->root_feed_changestamp, |
| + params->feed_list.release(), |
| + params->should_fetch_multiple_feeds, |
| + params->search_file_path, |
| + params->search_query, |
| + params->directory_resource_id, |
| + params->callback, |
| + NULL)), |
| + start_time)); |
| + return; |
| + } |
| + |
| + UMA_HISTOGRAM_TIMES("Drive.EntireFeedLoadTime", |
| + base::TimeTicks::Now() - start_time); |
| + |
| + if (!callback.is_null()) |
| + callback.Run(params, error); |
| +} |
|
satorux1
2012/08/13 17:05:43
In OnGetDocuments, OnNotifyDocumentFeedFetched() i
kochi
2012/08/14 02:09:19
Done.
|
| + |
| void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( |
| base::WeakPtr<GetDocumentsUiState> ui_state) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |