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 <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // | 97 // |
98 // See comments at ChangeListProcessor::ApplyFeeds() for | 98 // See comments at ChangeListProcessor::ApplyFeeds() for |
99 // |about_resource| and |is_delta_feed|. | 99 // |about_resource| and |is_delta_feed|. |
100 // |update_finished_callback| must not be null. | 100 // |update_finished_callback| must not be null. |
101 void UpdateFromFeed(scoped_ptr<google_apis::AboutResource> about_resource, | 101 void UpdateFromFeed(scoped_ptr<google_apis::AboutResource> about_resource, |
102 ScopedVector<ChangeList> change_lists, | 102 ScopedVector<ChangeList> change_lists, |
103 bool is_delta_feed, | 103 bool is_delta_feed, |
104 const base::Closure& update_finished_callback); | 104 const base::Closure& update_finished_callback); |
105 | 105 |
106 // Indicates whether there is a feed refreshing server request is in flight. | 106 // Indicates whether there is a feed refreshing server request is in flight. |
107 bool refreshing() const { return refreshing_; } | 107 bool IsRefreshing() const; |
108 | 108 |
109 private: | 109 private: |
110 // Initiates the change list loading from the server if the local | 110 // Implementation of LoadIfNeeded and CheckForUpdates. Start metadata loading |
111 // changestamp is older than the server changestamp. | 111 // of |directory_fetch_info|, and calls |callback| when it's done. If there is |
112 // See the comment at Load() for |directory_fetch_info| parameter. | 112 // already a loading job in-flight for |directory_fetch_info|, just append |
113 // |callback| must not be null. | 113 // the |callback| to the callback queue of the already running job. |
| 114 void Load(const DirectoryFetchInfo& directory_fetch_info, |
| 115 const FileOperationCallback& callback); |
| 116 |
| 117 // Part of Load(). DoInitialLoad() is called if it is the first time to Load. |
| 118 // Otherwise DoUpdateLoad() is used. The difference of two cases are: |
| 119 // - When we could load from cache, DoInitialLoad runs callback immediately |
| 120 // and further operations (check changestamp and load from server if needed) |
| 121 // in background. |
| 122 // - Even when |directory_fetch_info| is set, DoInitialLoad runs change list |
| 123 // loading after directory loading is finished. |
| 124 void DoInitialLoad(const DirectoryFetchInfo& directory_fetch_info, |
| 125 int64 local_changestamp); |
| 126 void DoUpdateLoad(const DirectoryFetchInfo& directory_fetch_info, |
| 127 int64 local_changestamp); |
| 128 |
| 129 // Part of Load(). |
| 130 // Initiates the change list loading from the server when |local_changestamp| |
| 131 // is older than the server changestamp. If |directory_fetch_info| is set, |
| 132 // do directory loading before change list loading. |
114 void LoadFromServerIfNeeded(const DirectoryFetchInfo& directory_fetch_info, | 133 void LoadFromServerIfNeeded(const DirectoryFetchInfo& directory_fetch_info, |
115 const FileOperationCallback& callback); | 134 int64 local_changestamp); |
116 | 135 |
117 // Checks the local changestamp. |callback| must not be null. | 136 // Part of Load(). |
118 void CheckLocalChangestamp(const GetChangestampCallback& callback); | 137 // Checks the directory's changestamp and |last_known_remote_changestamp_|, |
| 138 // and load the feed from server if it is old. Runs |callback| when it's done. |
| 139 void CheckChangestampAndLoadDirectoryIfNeeed( |
| 140 const DirectoryFetchInfo& directory_fetch_info, |
| 141 int64 local_changestamp, |
| 142 const FileOperationCallback& callback); |
119 | 143 |
120 // Part of Load(). Called after checking the local changestamp completes. | 144 // Part of LoadChangeListFromServer(). |
121 void LoadAfterCheckLocalChangestamp( | |
122 const DirectoryFetchInfo& directory_fetch_info, | |
123 const FileOperationCallback& callback, | |
124 int64 local_changestamp); | |
125 | |
126 // Callback to fetch all the resource list response from the server. | 145 // Callback to fetch all the resource list response from the server. |
127 // After all the resource list are fetched, |callback| | 146 // After all the resource list are fetched, |callback| |
128 // will be invoked with the collected change lists. | 147 // will be invoked with the collected change lists. |
129 // |callback| must not be null. | 148 // |callback| must not be null. |
130 void OnGetResourceList( | 149 void OnGetResourceList( |
131 ScopedVector<ChangeList> change_lists, | 150 ScopedVector<ChangeList> change_lists, |
132 const LoadFeedListCallback& callback, | 151 const LoadFeedListCallback& callback, |
133 base::TimeTicks start_time, | 152 base::TimeTicks start_time, |
134 google_apis::GDataErrorCode status, | 153 google_apis::GDataErrorCode status, |
135 scoped_ptr<google_apis::ResourceList> data); | 154 scoped_ptr<google_apis::ResourceList> data); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 DriveFileError error); | 196 DriveFileError error); |
178 | 197 |
179 // Part of DoLoadDirectoryFromServer(). Called after | 198 // Part of DoLoadDirectoryFromServer(). Called after |
180 // DriveResourceMetadata::RefreshDirectory() is complete. | 199 // DriveResourceMetadata::RefreshDirectory() is complete. |
181 void DoLoadDirectoryFromServerAfterRefresh( | 200 void DoLoadDirectoryFromServerAfterRefresh( |
182 const DirectoryFetchInfo& directory_fetch_info, | 201 const DirectoryFetchInfo& directory_fetch_info, |
183 const FileOperationCallback& callback, | 202 const FileOperationCallback& callback, |
184 DriveFileError error, | 203 DriveFileError error, |
185 const base::FilePath& directory_path); | 204 const base::FilePath& directory_path); |
186 | 205 |
187 // Part of LoadFromServerIfNeeded(). Called when | 206 // Part of LoadFromServerIfNeeded(). Called when GetAboutResource is complete. |
188 // DriveScheduler::GetAboutResource() is complete. This method calls | |
189 // CompareChangestampsAndLoadIfNeeded() to make a decision about whether or | |
190 // not to fetch the change list. | |
191 void LoadFromServerIfNeededAfterGetAbout( | 207 void LoadFromServerIfNeededAfterGetAbout( |
192 const DirectoryFetchInfo& directory_fetch_info, | 208 const DirectoryFetchInfo& directory_fetch_info, |
193 const FileOperationCallback& callback, | 209 int64 local_changestamp, |
194 google_apis::GDataErrorCode status, | 210 google_apis::GDataErrorCode status, |
195 scoped_ptr<google_apis::AboutResource> about_resource); | 211 scoped_ptr<google_apis::AboutResource> about_resource); |
196 | 212 |
197 // Compares the largetst_change_id in |about_resource| and |local_changestamp| | 213 // Part of LoadFromServerIfNeeded(). |
198 // and triggers LoadFromServer if necessary. | |
199 void CompareChangestampsAndLoadIfNeeded( | |
200 const DirectoryFetchInfo& directory_fetch_info, | |
201 const FileOperationCallback& callback, | |
202 scoped_ptr<google_apis::AboutResource> about_resource, | |
203 int64 local_changestamp); | |
204 | |
205 // Starts loading the change list since |start_changestamp|, or the full | 214 // Starts loading the change list since |start_changestamp|, or the full |
206 // resource list if |start_changestamp| is zero. For full update, the | 215 // resource list if |start_changestamp| is zero. For full update, the |
207 // largest_change_id and root_folder_id from |about_resource| will be used. | 216 // largest_change_id and root_folder_id from |about_resource| will be used. |
208 // |callback| must not be null. | |
209 void LoadChangeListFromServer( | 217 void LoadChangeListFromServer( |
210 scoped_ptr<google_apis::AboutResource> about_resource, | 218 scoped_ptr<google_apis::AboutResource> about_resource, |
211 int64 start_changestamp, | 219 int64 start_changestamp); |
212 const FileOperationCallback& callback); | |
213 | 220 |
| 221 // Part of LoadFromServerIfNeeded(). |
214 // Starts loading the change list from the server. Called after the | 222 // Starts loading the change list from the server. Called after the |
215 // directory contents are "fast-fetch"ed. | 223 // directory contents are "fast-fetch"ed. |
216 void StartLoadChangeListFromServer( | 224 void LoadChangeListFromServerAfterLoadDirectory( |
217 const DirectoryFetchInfo& directory_fetch_info, | 225 const DirectoryFetchInfo& directory_fetch_info, |
218 scoped_ptr<google_apis::AboutResource> about_resource, | 226 scoped_ptr<google_apis::AboutResource> about_resource, |
219 int64 start_changestamp, | 227 int64 start_changestamp, |
220 const FileOperationCallback& callback, | |
221 DriveFileError error); | 228 DriveFileError error); |
222 | 229 |
223 // Callback for handling response from |DriveAPIService::GetAppList|. | 230 // Callback for handling response from |DriveAPIService::GetAppList|. |
224 // If the application list is successfully parsed, passes the list to | 231 // If the application list is successfully parsed, passes the list to |
225 // Drive webapps registry. | 232 // Drive webapps registry. |
226 void OnGetAppList(google_apis::GDataErrorCode status, | 233 void OnGetAppList(google_apis::GDataErrorCode status, |
227 scoped_ptr<google_apis::AppList> app_list); | 234 scoped_ptr<google_apis::AppList> app_list); |
228 | 235 |
229 // Part of SearchFromServer. Called when ResourceList is fetched from the | 236 // Part of SearchFromServer. Called when ResourceList is fetched from the |
230 // server. | 237 // server. |
231 // |callback| must not be null. | 238 // |callback| must not be null. |
232 void SearchFromServerAfterGetResourceList( | 239 void SearchFromServerAfterGetResourceList( |
233 const LoadFeedListCallback& callback, | 240 const LoadFeedListCallback& callback, |
234 google_apis::GDataErrorCode status, | 241 google_apis::GDataErrorCode status, |
235 scoped_ptr<google_apis::ResourceList> resource_list); | 242 scoped_ptr<google_apis::ResourceList> resource_list); |
236 | 243 |
237 // Callback for handling feed content fetching while searching for file info. | 244 // Part of LoadChangeListFromServer(). |
238 // This callback is invoked after async feed fetch operation that was | 245 // Applies the change list loaded from the server to local metadata storage. |
239 // invoked by StartDirectoryRefresh() completes. This callback will update | |
240 // the content of the refreshed directory object and continue initially | |
241 // started FindEntryByPath() request. | |
242 void UpdateMetadataFromFeedAfterLoadFromServer( | 246 void UpdateMetadataFromFeedAfterLoadFromServer( |
243 scoped_ptr<google_apis::AboutResource> about_resource, | 247 scoped_ptr<google_apis::AboutResource> about_resource, |
244 bool is_delta_feed, | 248 bool is_delta_feed, |
245 const FileOperationCallback& callback, | |
246 ScopedVector<ChangeList> change_lists, | 249 ScopedVector<ChangeList> change_lists, |
247 DriveFileError error); | 250 DriveFileError error); |
248 | 251 |
249 // Callback for ChangeListProcessor::ApplyFeeds. | 252 // Callback for ChangeListProcessor::ApplyFeeds. |
250 void NotifyDirectoryChangedAfterApplyFeed( | 253 void NotifyDirectoryChangedAfterApplyFeed( |
251 bool should_notify, | 254 bool should_notify, |
252 const base::Closure& update_finished_callback); | 255 const base::Closure& update_finished_callback); |
253 | 256 |
254 // Callback for UpdateFromFeed. | 257 // Part of LoadChangeListFromServer(). |
255 void OnUpdateFromFeed(bool is_initial_load, | 258 // Called when UpdateMetadataFromFeedAfterLoadFromServer is finished. |
256 const FileOperationCallback& load_finished_callback); | 259 void OnUpdateFromFeed(); |
257 | 260 |
258 // This function should be called when the change list load is complete. | 261 // This function should be called when the change list load is complete. |
259 // Runs |callback| with |error|, and flushes the pending callbacks. | 262 // Flushes the callbacks for change list loading and all directory loading. |
260 void OnChangeListLoadComplete(const FileOperationCallback& callback, | 263 void OnChangeListLoadComplete(DriveFileError error); |
261 DriveFileError error); | |
262 | 264 |
263 // This function should be called when the change list load is complete. | 265 // This function should be called when the directory load is complete. |
264 // Runs |callback| with |error|, and flushes the pending callbacks. | 266 // Flushes the callbacks waiting for the directory to be loaded. |
265 void OnDirectoryLoadComplete(const DirectoryFetchInfo& directory_fetch_info, | 267 void OnDirectoryLoadComplete(const DirectoryFetchInfo& directory_fetch_info, |
266 const FileOperationCallback& callback, | |
267 DriveFileError error); | 268 DriveFileError error); |
268 | 269 |
269 // Schedules |callback| to run when it's ready (i.e. the change list | |
270 // loading is complete or the directory specified by |directory_fetch_info| | |
271 // is loaded). |directory_fetch_info| can be empty if the callback is not | |
272 // interested in a particular directory. | |
273 // |callback| must not be null. | |
274 void ScheduleRun(const DirectoryFetchInfo& directory_fetch_info, | |
275 const FileOperationCallback& callback); | |
276 | |
277 // Flushes the feed loading callbacks added via ScheduleRun(), by scheduling | |
278 // to run all of them with the given error code. | |
279 void FlushPendingLoadCallback(DriveFileError error); | |
280 | |
281 // Processes tasks that match the resource ID. | |
282 void ProcessPendingLoadCallbackForDirectory(const std::string& resource_id, | |
283 DriveFileError error); | |
284 | |
285 DriveResourceMetadata* resource_metadata_; // Not owned. | 270 DriveResourceMetadata* resource_metadata_; // Not owned. |
286 DriveScheduler* scheduler_; // Not owned. | 271 DriveScheduler* scheduler_; // Not owned. |
287 DriveWebAppsRegistry* webapps_registry_; // Not owned. | 272 DriveWebAppsRegistry* webapps_registry_; // Not owned. |
288 ObserverList<ChangeListLoaderObserver> observers_; | 273 ObserverList<ChangeListLoaderObserver> observers_; |
289 scoped_ptr<ChangeListProcessor> change_list_processor_; | 274 scoped_ptr<ChangeListProcessor> change_list_processor_; |
290 typedef std::map<std::string, std::vector<FileOperationCallback> > | 275 typedef std::map<std::string, std::vector<FileOperationCallback> > |
291 LoadCallbackMap; | 276 LoadCallbackMap; |
292 LoadCallbackMap pending_load_callback_; | 277 LoadCallbackMap pending_load_callback_; |
293 | 278 |
294 // Indicates whether there is a feed refreshing server request is in flight. | 279 // Indicates whether there is a feed refreshing server request is in flight. |
295 bool refreshing_; | |
296 int64 last_known_remote_changestamp_; | 280 int64 last_known_remote_changestamp_; |
297 | 281 |
298 // True if the file system feed is loaded from the cache or from the server. | 282 // True if the file system feed is loaded from the cache or from the server. |
299 bool loaded_; | 283 bool loaded_; |
300 | 284 |
301 // Note: This should remain the last member so it'll be destroyed and | 285 // Note: This should remain the last member so it'll be destroyed and |
302 // invalidate its weak pointers before any other members are destroyed. | 286 // invalidate its weak pointers before any other members are destroyed. |
303 base::WeakPtrFactory<ChangeListLoader> weak_ptr_factory_; | 287 base::WeakPtrFactory<ChangeListLoader> weak_ptr_factory_; |
304 DISALLOW_COPY_AND_ASSIGN(ChangeListLoader); | 288 DISALLOW_COPY_AND_ASSIGN(ChangeListLoader); |
305 }; | 289 }; |
306 | 290 |
307 } // namespace drive | 291 } // namespace drive |
308 | 292 |
309 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ | 293 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ |
OLD | NEW |