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 78718fdee09d1e41a3ce392f57db6072901cc5ec..4527b763d140d01f23ec7509b50ccafd481c8092 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
| @@ -443,12 +443,36 @@ void GDataWapiFeedLoader::LoadFromServer( |
| const FindEntryCallback& entry_found_callback, |
| const LoadDocumentFeedCallback& feed_load_callback) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DVLOG(1) << "LoadFeedFromServer"; |
|
satorux1
2012/08/10 18:14:34
remove this?
kochi
2012/08/13 09:08:39
Done.
|
| // |feed_list| will contain the list of all collected feed updates that |
| // we will receive through calls of DocumentsService::GetDocuments(). |
| 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, |
| @@ -625,6 +649,106 @@ 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_%ld.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); |
| + //feed->largest_changestamp_ = params->root_feed_changestamp; |
| + 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); |
| +} |
| + |
| void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( |
| base::WeakPtr<GetDocumentsUiState> ui_state) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |