Index: chrome/browser/chromeos/drive/change_list_loader.cc |
diff --git a/chrome/browser/chromeos/drive/change_list_loader.cc b/chrome/browser/chromeos/drive/change_list_loader.cc |
index 6c46f7f439f9280cc4c4c3d8ca6f0dc3f6cc0add..5ecd19e7db2b19f00ecce0bced2c017fa7d733a6 100644 |
--- a/chrome/browser/chromeos/drive/change_list_loader.cc |
+++ b/chrome/browser/chromeos/drive/change_list_loader.cc |
@@ -209,6 +209,7 @@ void LoaderController::Unlock() { |
AboutResourceLoader::AboutResourceLoader(JobScheduler* scheduler) |
: scheduler_(scheduler), |
+ current_update_task_id_(-1), |
weak_ptr_factory_(this) { |
} |
@@ -219,6 +220,12 @@ void AboutResourceLoader::GetAboutResource( |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DCHECK(!callback.is_null()); |
+ // If the latest UpdateAboutResource task is still running. Wait for it, |
+ if (pending_callbacks_.count(current_update_task_id_)) { |
+ pending_callbacks_[current_update_task_id_].push_back(callback); |
+ return; |
+ } |
+ |
if (cached_about_resource_) { |
base::MessageLoopProxy::current()->PostTask( |
FROM_HERE, |
@@ -237,34 +244,47 @@ void AboutResourceLoader::UpdateAboutResource( |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DCHECK(!callback.is_null()); |
+ ++current_update_task_id_; |
+ pending_callbacks_[current_update_task_id_].push_back(callback); |
+ |
scheduler_->GetAboutResource( |
base::Bind(&AboutResourceLoader::UpdateAboutResourceAfterGetAbout, |
weak_ptr_factory_.GetWeakPtr(), |
- callback)); |
+ current_update_task_id_)); |
} |
void AboutResourceLoader::UpdateAboutResourceAfterGetAbout( |
- const google_apis::AboutResourceCallback& callback, |
+ int task_id, |
google_apis::GDataErrorCode status, |
scoped_ptr<google_apis::AboutResource> about_resource) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DCHECK(!callback.is_null()); |
FileError error = GDataToFileError(status); |
- if (error == FILE_ERROR_OK) { |
- if (cached_about_resource_ && |
- cached_about_resource_->largest_change_id() > |
- about_resource->largest_change_id()) { |
- LOG(WARNING) << "Local cached about resource is fresher than server, " |
- << "local = " << cached_about_resource_->largest_change_id() |
- << ", server = " << about_resource->largest_change_id(); |
- } |
+ const std::vector<google_apis::AboutResourceCallback> callbacks = |
+ pending_callbacks_[task_id]; |
+ pending_callbacks_.erase(task_id); |
- cached_about_resource_.reset( |
- new google_apis::AboutResource(*about_resource)); |
+ if (error != FILE_ERROR_OK) { |
+ for (size_t i = 0; i < callbacks.size(); ++i) |
+ callbacks[i].Run(status, scoped_ptr<google_apis::AboutResource>()); |
+ return; |
} |
- callback.Run(status, about_resource.Pass()); |
+ // Updates the cache when the resource is successfully obtained. |
+ if (cached_about_resource_ && |
+ cached_about_resource_->largest_change_id() > |
+ about_resource->largest_change_id()) { |
+ LOG(WARNING) << "Local cached about resource is fresher than server, " |
+ << "local = " << cached_about_resource_->largest_change_id() |
+ << ", server = " << about_resource->largest_change_id(); |
+ } |
+ cached_about_resource_.reset(new google_apis::AboutResource(*about_resource)); |
+ |
+ for (size_t i = 0; i < callbacks.size(); ++i) { |
+ callbacks[i].Run( |
+ status, |
+ make_scoped_ptr(new google_apis::AboutResource(*about_resource))); |
+ } |
} |
ChangeListLoader::ChangeListLoader( |