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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 public: | 78 public: |
79 explicit AboutResourceLoader(JobScheduler* scheduler); | 79 explicit AboutResourceLoader(JobScheduler* scheduler); |
80 ~AboutResourceLoader(); | 80 ~AboutResourceLoader(); |
81 | 81 |
82 // Returns the cached about resource. | 82 // Returns the cached about resource. |
83 // NULL is returned if the cache is not available. | 83 // NULL is returned if the cache is not available. |
84 const google_apis::AboutResource* cached_about_resource() const { | 84 const google_apis::AboutResource* cached_about_resource() const { |
85 return cached_about_resource_.get(); | 85 return cached_about_resource_.get(); |
86 } | 86 } |
87 | 87 |
88 // Gets the about resource from the cache or the server. If the cache is | 88 // Gets the 'latest' about resource and asynchronously runs |callback|. I.e., |
89 // availlavle, just runs |callback| with the cached about resource. If not, | 89 // 1) If the last call to UpdateAboutResource call is in-flight, wait for it. |
90 // calls |UpdateAboutResource| passing |callback|. | 90 // 2) Otherwise, if the resource is cached, just returns the cached value. |
| 91 // 3) If neither of the above hold, queries the API server by calling |
| 92 // |UpdateAboutResource|. |
91 void GetAboutResource(const google_apis::AboutResourceCallback& callback); | 93 void GetAboutResource(const google_apis::AboutResourceCallback& callback); |
92 | 94 |
93 // Gets the about resource from the server, and caches it if successful. This | 95 // Gets the about resource from the server, and caches it if successful. This |
94 // function calls JobScheduler::GetAboutResource internally. The cache will be | 96 // function calls JobScheduler::GetAboutResource internally. The cache will be |
95 // used in |GetAboutResource|. | 97 // used in |GetAboutResource|. |
96 void UpdateAboutResource( | 98 void UpdateAboutResource(const google_apis::AboutResourceCallback& callback); |
97 const google_apis::AboutResourceCallback& callback); | |
98 | 99 |
99 private: | 100 private: |
100 // Part of UpdateAboutResource(). | 101 // Part of UpdateAboutResource(). |
101 // This function should be called when the latest about resource is being | 102 // This function should be called when the latest about resource is being |
102 // fetched from the server. The retrieved about resoure is cloned, and one is | 103 // fetched from the server. The retrieved about resource is cloned, and one is |
103 // cached and the other is passed to |callback|. | 104 // cached and the other is passed to callbacks associated with |task_id|. |
104 void UpdateAboutResourceAfterGetAbout( | 105 void UpdateAboutResourceAfterGetAbout( |
105 const google_apis::AboutResourceCallback& callback, | 106 int task_id, |
106 google_apis::GDataErrorCode status, | 107 google_apis::GDataErrorCode status, |
107 scoped_ptr<google_apis::AboutResource> about_resource); | 108 scoped_ptr<google_apis::AboutResource> about_resource); |
108 | 109 |
109 JobScheduler* scheduler_; | 110 JobScheduler* scheduler_; |
110 scoped_ptr<google_apis::AboutResource> cached_about_resource_; | 111 scoped_ptr<google_apis::AboutResource> cached_about_resource_; |
| 112 |
| 113 // Identifier to denote the latest UpdateAboutResource call. |
| 114 int current_update_task_id_; |
| 115 // Mapping from each UpdateAboutResource task ID to the corresponding |
| 116 // callbacks. Note that there will be multiple callbacks for a single task |
| 117 // when GetAboutResource is called before the task completes. |
| 118 std::map<int, std::vector<google_apis::AboutResourceCallback> > |
| 119 pending_callbacks_; |
| 120 |
111 base::WeakPtrFactory<AboutResourceLoader> weak_ptr_factory_; | 121 base::WeakPtrFactory<AboutResourceLoader> weak_ptr_factory_; |
112 DISALLOW_COPY_AND_ASSIGN(AboutResourceLoader); | 122 DISALLOW_COPY_AND_ASSIGN(AboutResourceLoader); |
113 }; | 123 }; |
114 | 124 |
115 // ChangeListLoader is used to load the change list, the full resource list, | 125 // ChangeListLoader is used to load the change list, the full resource list, |
116 // and directory contents, from WAPI (codename for Documents List API) | 126 // and directory contents, from Google Drive API. The class also updates the |
117 // or Google Drive API. The class also updates the resource metadata with | 127 // resource metadata with the change list loaded from the server. |
118 // the change list loaded from the server. | |
119 // | 128 // |
120 // Note that the difference between "resource list" and "change list" is | 129 // Note that the difference between "resource list" and "change list" is |
121 // subtle hence the two words are often used interchangeably. To be precise, | 130 // subtle hence the two words are often used interchangeably. To be precise, |
122 // "resource list" refers to metadata from the server when fetching the full | 131 // "resource list" refers to metadata from the server when fetching the full |
123 // resource metadata, or fetching directory contents, whereas "change list" | 132 // resource metadata, or fetching directory contents, whereas "change list" |
124 // refers to metadata from the server when fetching changes (delta). | 133 // refers to metadata from the server when fetching changes (delta). |
125 class ChangeListLoader { | 134 class ChangeListLoader { |
126 public: | 135 public: |
127 // Resource feed fetcher from the server. | 136 // Resource feed fetcher from the server. |
128 class FeedFetcher; | 137 class FeedFetcher; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // Note: This should remain the last member so it'll be destroyed and | 227 // Note: This should remain the last member so it'll be destroyed and |
219 // invalidate its weak pointers before any other members are destroyed. | 228 // invalidate its weak pointers before any other members are destroyed. |
220 base::WeakPtrFactory<ChangeListLoader> weak_ptr_factory_; | 229 base::WeakPtrFactory<ChangeListLoader> weak_ptr_factory_; |
221 DISALLOW_COPY_AND_ASSIGN(ChangeListLoader); | 230 DISALLOW_COPY_AND_ASSIGN(ChangeListLoader); |
222 }; | 231 }; |
223 | 232 |
224 } // namespace internal | 233 } // namespace internal |
225 } // namespace drive | 234 } // namespace drive |
226 | 235 |
227 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ | 236 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ |
OLD | NEW |