return cached_about_resource_.get();
}
- // Gets the about resource from the cache or the server. If the cache is
- // availlavle, just runs |callback| with the cached about resource. If not,
- // calls |UpdateAboutResource| passing |callback|.
+ // Gets the 'latest' about resource and asynchronously runs |callback|. I.e.,
+ // 1) If the last call to UpdateAboutResource call is in-flight, wait for it.
+ // 2) Otherwise, if the resource is cached, just returns the cached value.
+ // 3) If neither of the above hold, queries the API server by calling
+ // |UpdateAboutResource|.
void GetAboutResource(const google_apis::AboutResourceCallback& callback);
// Gets the about resource from the server, and caches it if successful. This
// function calls JobScheduler::GetAboutResource internally. The cache will be
// used in |GetAboutResource|.
- void UpdateAboutResource(
- const google_apis::AboutResourceCallback& callback);
+ void UpdateAboutResource(const google_apis::AboutResourceCallback& callback);
private:
// Part of UpdateAboutResource().
// This function should be called when the latest about resource is being
- // fetched from the server. The retrieved about resoure is cloned, and one is
- // cached and the other is passed to |callback|.
+ // fetched from the server. The retrieved about resource is cloned, and one is
+ // cached and the other is passed to callbacks associated with |task_id|.
void UpdateAboutResourceAfterGetAbout(
- const google_apis::AboutResourceCallback& callback,
+ int task_id,
google_apis::GDataErrorCode status,
scoped_ptr<google_apis::AboutResource> about_resource);
JobScheduler* scheduler_;
scoped_ptr<google_apis::AboutResource> cached_about_resource_;
+
+ // Identifier to denote the latest UpdateAboutResource call.
+ int current_update_task_id_;
+ // Mapping from each UpdateAboutResource task ID to the corresponding
+ // callbacks. Note that there will be multiple callbacks for a single task
+ // when GetAboutResource is called before the task completes.
+ std::map<int, std::vector<google_apis::AboutResourceCallback> >
+ pending_callbacks_;
+
base::WeakPtrFactory<AboutResourceLoader> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AboutResourceLoader);
};
// ChangeListLoader is used to load the change list, the full resource list,
-// and directory contents, from WAPI (codename for Documents List API)
-// or Google Drive API. The class also updates the resource metadata with
-// the change list loaded from the server.
+// and directory contents, from Google Drive API. The class also updates the
+// resource metadata with the change list loaded from the server.
//
// Note that the difference between "resource list" and "change list" is
// subtle hence the two words are often used interchangeably. To be precise,
// Flushes the callbacks for change list loading and all directory loading.
void OnChangeListLoadComplete(FileError error);
+ // Called when the loading about_resource_loader_->UpdateAboutResource is
+ // completed.
+ void OnAboutResourceUpdated(google_apis::GDataErrorCode error,
+ scoped_ptr<google_apis::AboutResource> resource);
+
// ================= Implementation for change list loading =================
// Part of LoadFromServerIfNeeded().