Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: chrome/browser/chromeos/drive/change_list_loader.cc

Issue 13079006: Fix ChangeListLoader's callback invocation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/chromeos/drive/change_list_loader.h" 5 #include "chrome/browser/chromeos/drive/change_list_loader.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 // No changes detected, tell the client that the loading was successful. 202 // No changes detected, tell the client that the loading was successful.
203 OnChangeListLoadComplete(callback, DRIVE_FILE_OK); 203 OnChangeListLoadComplete(callback, DRIVE_FILE_OK);
204 return; 204 return;
205 } 205 }
206 206
207 int64 start_changestamp = local_changestamp > 0 ? local_changestamp + 1 : 0; 207 int64 start_changestamp = local_changestamp > 0 ? local_changestamp + 1 : 0;
208 if (start_changestamp == 0 && !about_resource.get()) { 208 if (start_changestamp == 0 && !about_resource.get()) {
209 // Full update needs AboutResource. If this is a full update, we should just 209 // Full update needs AboutResource. If this is a full update, we should just
210 // give up. 210 // give up.
211 callback.Run(DRIVE_FILE_ERROR_FAILED); 211 OnChangeListLoadComplete(callback, DRIVE_FILE_ERROR_FAILED);
kinaba 2013/03/26 01:48:31 To exit from the feed loading, we always have to f
satorux1 2013/03/26 03:48:59 Add this as a comment?
kinaba 2013/03/26 04:13:22 Done.
212 return; 212 return;
213 } 213 }
214 214
215 if (directory_fetch_info.empty()) { 215 if (directory_fetch_info.empty()) {
216 // If the caller is not interested in a particular directory, just start 216 // If the caller is not interested in a particular directory, just start
217 // loading the change list. 217 // loading the change list.
218 LoadChangeListFromServer(about_resource.Pass(), 218 LoadChangeListFromServer(about_resource.Pass(),
219 start_changestamp, 219 start_changestamp,
220 callback); 220 callback);
221 } else if (directory_fetch_info.changestamp() < remote_changestamp) { 221 } else if (directory_fetch_info.changestamp() < remote_changestamp) {
222 // If the caller is interested in a particular directory, and the 222 // If the caller is interested in a particular directory, and the
223 // directory changestamp is older than server's, start loading the 223 // directory changestamp is older than server's, start loading the
224 // directory first. 224 // directory first.
225 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString() 225 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString()
226 << "; remote_changestamp: " << remote_changestamp; 226 << "; remote_changestamp: " << remote_changestamp;
227 const DirectoryFetchInfo new_directory_fetch_info( 227 const DirectoryFetchInfo new_directory_fetch_info(
228 directory_fetch_info.resource_id(), remote_changestamp); 228 directory_fetch_info.resource_id(), remote_changestamp);
229 DoLoadDirectoryFromServer( 229 DoLoadDirectoryFromServer(
230 new_directory_fetch_info, 230 new_directory_fetch_info,
231 base::Bind(&ChangeListLoader::StartLoadChangeListFromServer, 231 base::Bind(&ChangeListLoader::StartLoadChangeListFromServer,
232 weak_ptr_factory_.GetWeakPtr(), 232 weak_ptr_factory_.GetWeakPtr(),
233 directory_fetch_info, 233 directory_fetch_info,
234 base::Passed(&about_resource), 234 base::Passed(&about_resource),
235 start_changestamp, 235 start_changestamp,
236 callback)); 236 callback));
237 } else { 237 } else {
238 // The directory is up-to-date, hence there is no need to load. 238 // The directory is up-to-date. Proceed to change list loading.
kinaba 2013/03/26 01:48:31 The directory is up-to-date, but not the case for
satorux1 2013/03/26 03:48:59 add this as a comment?
kinaba 2013/03/26 04:13:22 Done.
239 OnChangeListLoadComplete(callback, DRIVE_FILE_OK); 239 StartLoadChangeListFromServer(directory_fetch_info,
240 about_resource.Pass(),
241 start_changestamp,
242 callback,
243 DRIVE_FILE_OK);
240 } 244 }
241 } 245 }
242 246
243 void ChangeListLoader::LoadChangeListFromServer( 247 void ChangeListLoader::LoadChangeListFromServer(
244 scoped_ptr<google_apis::AboutResource> about_resource, 248 scoped_ptr<google_apis::AboutResource> about_resource,
245 int64 start_changestamp, 249 int64 start_changestamp,
246 const FileOperationCallback& callback) { 250 const FileOperationCallback& callback) {
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
248 DCHECK(!callback.is_null()); 252 DCHECK(!callback.is_null());
249 DCHECK(refreshing_); 253 DCHECK(refreshing_);
(...skipping 13 matching lines...) Expand all
263 const DirectoryFetchInfo& directory_fetch_info, 267 const DirectoryFetchInfo& directory_fetch_info,
264 scoped_ptr<google_apis::AboutResource> about_resource, 268 scoped_ptr<google_apis::AboutResource> about_resource,
265 int64 start_changestamp, 269 int64 start_changestamp,
266 const FileOperationCallback& callback, 270 const FileOperationCallback& callback,
267 DriveFileError error) { 271 DriveFileError error) {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
269 DCHECK(!callback.is_null()); 273 DCHECK(!callback.is_null());
270 DCHECK(refreshing_); 274 DCHECK(refreshing_);
271 275
272 if (error == DRIVE_FILE_OK) { 276 if (error == DRIVE_FILE_OK) {
273 callback.Run(DRIVE_FILE_OK); 277 OnDirectoryLoadComplete(directory_fetch_info, callback, DRIVE_FILE_OK);
kinaba 2013/03/26 01:48:31 see below.
274 DVLOG(1) << "Fast-fetch was successful: " << directory_fetch_info.ToString() 278 DVLOG(1) << "Fast-fetch was successful: " << directory_fetch_info.ToString()
275 << "; Start loading the change list"; 279 << "; Start loading the change list";
276 // Stop passing |callback| as it's just consumed. 280 // Stop passing |callback| as it's just consumed.
277 LoadChangeListFromServer( 281 LoadChangeListFromServer(
278 about_resource.Pass(), 282 about_resource.Pass(),
279 start_changestamp, 283 start_changestamp,
280 base::Bind(&util::EmptyFileOperationCallback)); 284 base::Bind(&util::EmptyFileOperationCallback));
281 } else { 285 } else {
282 // The directory fast-fetch failed, but the change list loading may 286 // The directory fast-fetch failed, but the change list loading may
283 // succeed. Keep passing |callback| so it's run after the change list 287 // succeed. Keep passing |callback| so it's run after the change list
284 // loading is complete. 288 // loading is complete.
285 LoadChangeListFromServer( 289 LoadChangeListFromServer(
286 about_resource.Pass(), start_changestamp, callback); 290 about_resource.Pass(), start_changestamp, callback);
287 } 291 }
288 } 292 }
289 293
290 void ChangeListLoader::OnGetAppList(google_apis::GDataErrorCode status, 294 void ChangeListLoader::OnGetAppList(google_apis::GDataErrorCode status,
291 scoped_ptr<google_apis::AppList> app_list) { 295 scoped_ptr<google_apis::AppList> app_list) {
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
293 297
294 DriveFileError error = util::GDataToDriveFileError(status); 298 DriveFileError error = util::GDataToDriveFileError(status);
295 if (error != DRIVE_FILE_OK) 299 if (error != DRIVE_FILE_OK)
296 return; 300 return;
297 301
298 if (app_list.get()) { 302 if (app_list.get()) {
299 webapps_registry_->UpdateFromAppList(*app_list); 303 webapps_registry_->UpdateFromAppList(*app_list);
300 } 304 }
301 } 305 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 411
408 void ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh( 412 void ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh(
409 const DirectoryFetchInfo& directory_fetch_info, 413 const DirectoryFetchInfo& directory_fetch_info,
410 const FileOperationCallback& callback, 414 const FileOperationCallback& callback,
411 DriveFileError error, 415 DriveFileError error,
412 const base::FilePath& directory_path) { 416 const base::FilePath& directory_path) {
413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
414 DCHECK(!callback.is_null()); 418 DCHECK(!callback.is_null());
415 419
416 DVLOG(1) << "Directory loaded: " << directory_fetch_info.ToString(); 420 DVLOG(1) << "Directory loaded: " << directory_fetch_info.ToString();
417 OnDirectoryLoadComplete(directory_fetch_info, callback, error); 421 callback.Run(error);
kinaba 2013/03/26 01:48:31 Let me set the policy that "DoLoadDirectoryFromSer
satorux1 2013/03/26 03:48:59 Add this as a function comment in .h file?
kinaba 2013/03/26 04:13:22 Done.
418 // Also notify the observers. 422 // Also notify the observers.
419 if (error == DRIVE_FILE_OK) { 423 if (error == DRIVE_FILE_OK) {
420 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_, 424 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_,
421 OnDirectoryChanged(directory_path)); 425 OnDirectoryChanged(directory_path));
422 } 426 }
423 } 427 }
424 428
425 void ChangeListLoader::SearchFromServer( 429 void ChangeListLoader::SearchFromServer(
426 const std::string& search_query, 430 const std::string& search_query,
427 bool shared_with_me, 431 bool shared_with_me,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 737
734 // If the directory's changestamp is up-to-date, just schedule to run the 738 // If the directory's changestamp is up-to-date, just schedule to run the
735 // callback, as there is no need to fetch the directory. 739 // callback, as there is no need to fetch the directory.
736 if (directory_fetch_info.changestamp() >= last_known_remote_changestamp_) { 740 if (directory_fetch_info.changestamp() >= last_known_remote_changestamp_) {
737 base::MessageLoopProxy::current()->PostTask( 741 base::MessageLoopProxy::current()->PostTask(
738 FROM_HERE, 742 FROM_HERE,
739 base::Bind(callback, DRIVE_FILE_OK)); 743 base::Bind(callback, DRIVE_FILE_OK));
740 return; 744 return;
741 } 745 }
742 746
743 // The directory should be fetched. Add the callback to the pending list. The 747 // The directory should be fetched. Add a dummy task to so ScheduleRun()
744 // callback will be run after the directory is loaded. 748 // can check that the directory is being fetched.
745 pending_load_callback_[resource_id].push_back(callback); 749 pending_load_callback_[resource_id].push_back(
746 DoLoadDirectoryFromServer(directory_fetch_info, 750 base::Bind(&util::EmptyFileOperationCallback));
747 base::Bind(&util::EmptyFileOperationCallback)); 751 DoLoadDirectoryFromServer(
752 directory_fetch_info,
753 base::Bind(&ChangeListLoader::OnDirectoryLoadComplete,
kinaba 2013/03/26 01:48:31 see above. flushing tasks is the duty of callers o
754 weak_ptr_factory_.GetWeakPtr(),
755 directory_fetch_info,
756 callback));
748 } 757 }
749 758
750 void ChangeListLoader::NotifyDirectoryChangedAfterApplyFeed( 759 void ChangeListLoader::NotifyDirectoryChangedAfterApplyFeed(
751 bool should_notify_changed_directories, 760 bool should_notify_changed_directories,
752 const base::Closure& update_finished_callback) { 761 const base::Closure& update_finished_callback) {
753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 762 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
754 DCHECK(change_list_processor_.get()); 763 DCHECK(change_list_processor_.get());
755 DCHECK(!update_finished_callback.is_null()); 764 DCHECK(!update_finished_callback.is_null());
756 765
757 loaded_ = true; 766 loaded_ = true;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 for (size_t i = 0; i < callbacks.size(); ++i) { 853 for (size_t i = 0; i < callbacks.size(); ++i) {
845 base::MessageLoopProxy::current()->PostTask( 854 base::MessageLoopProxy::current()->PostTask(
846 FROM_HERE, 855 FROM_HERE,
847 base::Bind(callbacks[i], error)); 856 base::Bind(callbacks[i], error));
848 } 857 }
849 pending_load_callback_.erase(it); 858 pending_load_callback_.erase(it);
850 } 859 }
851 } 860 }
852 861
853 } // namespace drive 862 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698