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

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: Add comments (+rebase). 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 | « chrome/browser/chromeos/drive/change_list_loader.h ('k') | 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
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. Note that to exit from the feed loading, we always have to flush
211 callback.Run(DRIVE_FILE_ERROR_FAILED); 211 // the pending callback tasks via OnChangeListLoadComplete.
212 OnChangeListLoadComplete(callback, DRIVE_FILE_ERROR_FAILED);
212 return; 213 return;
213 } 214 }
214 215
215 if (directory_fetch_info.empty()) { 216 if (directory_fetch_info.empty()) {
216 // If the caller is not interested in a particular directory, just start 217 // If the caller is not interested in a particular directory, just start
217 // loading the change list. 218 // loading the change list.
218 LoadChangeListFromServer(about_resource.Pass(), 219 LoadChangeListFromServer(about_resource.Pass(),
219 start_changestamp, 220 start_changestamp,
220 callback); 221 callback);
221 } else if (directory_fetch_info.changestamp() < remote_changestamp) { 222 } else if (directory_fetch_info.changestamp() < remote_changestamp) {
222 // If the caller is interested in a particular directory, and the 223 // If the caller is interested in a particular directory, and the
223 // directory changestamp is older than server's, start loading the 224 // directory changestamp is older than server's, start loading the
224 // directory first. 225 // directory first.
225 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString() 226 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString()
226 << "; remote_changestamp: " << remote_changestamp; 227 << "; remote_changestamp: " << remote_changestamp;
227 const DirectoryFetchInfo new_directory_fetch_info( 228 const DirectoryFetchInfo new_directory_fetch_info(
228 directory_fetch_info.resource_id(), remote_changestamp); 229 directory_fetch_info.resource_id(), remote_changestamp);
229 DoLoadDirectoryFromServer( 230 DoLoadDirectoryFromServer(
230 new_directory_fetch_info, 231 new_directory_fetch_info,
231 base::Bind(&ChangeListLoader::StartLoadChangeListFromServer, 232 base::Bind(&ChangeListLoader::StartLoadChangeListFromServer,
232 weak_ptr_factory_.GetWeakPtr(), 233 weak_ptr_factory_.GetWeakPtr(),
233 directory_fetch_info, 234 directory_fetch_info,
234 base::Passed(&about_resource), 235 base::Passed(&about_resource),
235 start_changestamp, 236 start_changestamp,
236 callback)); 237 callback));
237 } else { 238 } else {
238 // The directory is up-to-date, hence there is no need to load. 239 // The directory is up-to-date, but not the case for other parts.
239 OnChangeListLoadComplete(callback, DRIVE_FILE_OK); 240 // Proceed to change list loading. StartLoadChangeListFromServer will
241 // run |callback| for notifying the directory is ready before feed load.
242 StartLoadChangeListFromServer(directory_fetch_info,
243 about_resource.Pass(),
244 start_changestamp,
245 callback,
246 DRIVE_FILE_OK);
240 } 247 }
241 } 248 }
242 249
243 void ChangeListLoader::LoadChangeListFromServer( 250 void ChangeListLoader::LoadChangeListFromServer(
244 scoped_ptr<google_apis::AboutResource> about_resource, 251 scoped_ptr<google_apis::AboutResource> about_resource,
245 int64 start_changestamp, 252 int64 start_changestamp,
246 const FileOperationCallback& callback) { 253 const FileOperationCallback& callback) {
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
248 DCHECK(!callback.is_null()); 255 DCHECK(!callback.is_null());
249 DCHECK(refreshing_); 256 DCHECK(refreshing_);
(...skipping 13 matching lines...) Expand all
263 const DirectoryFetchInfo& directory_fetch_info, 270 const DirectoryFetchInfo& directory_fetch_info,
264 scoped_ptr<google_apis::AboutResource> about_resource, 271 scoped_ptr<google_apis::AboutResource> about_resource,
265 int64 start_changestamp, 272 int64 start_changestamp,
266 const FileOperationCallback& callback, 273 const FileOperationCallback& callback,
267 DriveFileError error) { 274 DriveFileError error) {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
269 DCHECK(!callback.is_null()); 276 DCHECK(!callback.is_null());
270 DCHECK(refreshing_); 277 DCHECK(refreshing_);
271 278
272 if (error == DRIVE_FILE_OK) { 279 if (error == DRIVE_FILE_OK) {
273 callback.Run(DRIVE_FILE_OK); 280 OnDirectoryLoadComplete(directory_fetch_info, callback, DRIVE_FILE_OK);
274 DVLOG(1) << "Fast-fetch was successful: " << directory_fetch_info.ToString() 281 DVLOG(1) << "Fast-fetch was successful: " << directory_fetch_info.ToString()
275 << "; Start loading the change list"; 282 << "; Start loading the change list";
276 // Stop passing |callback| as it's just consumed. 283 // Stop passing |callback| as it's just consumed.
277 LoadChangeListFromServer( 284 LoadChangeListFromServer(
278 about_resource.Pass(), 285 about_resource.Pass(),
279 start_changestamp, 286 start_changestamp,
280 base::Bind(&util::EmptyFileOperationCallback)); 287 base::Bind(&util::EmptyFileOperationCallback));
281 } else { 288 } else {
282 // The directory fast-fetch failed, but the change list loading may 289 // The directory fast-fetch failed, but the change list loading may
283 // succeed. Keep passing |callback| so it's run after the change list 290 // succeed. Keep passing |callback| so it's run after the change list
284 // loading is complete. 291 // loading is complete.
285 LoadChangeListFromServer( 292 LoadChangeListFromServer(
286 about_resource.Pass(), start_changestamp, callback); 293 about_resource.Pass(), start_changestamp, callback);
287 } 294 }
288 } 295 }
289 296
290 void ChangeListLoader::OnGetAppList(google_apis::GDataErrorCode status, 297 void ChangeListLoader::OnGetAppList(google_apis::GDataErrorCode status,
291 scoped_ptr<google_apis::AppList> app_list) { 298 scoped_ptr<google_apis::AppList> app_list) {
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
293 300
294 DriveFileError error = util::GDataToDriveFileError(status); 301 DriveFileError error = util::GDataToDriveFileError(status);
295 if (error != DRIVE_FILE_OK) 302 if (error != DRIVE_FILE_OK)
296 return; 303 return;
297 304
298 if (app_list.get()) { 305 if (app_list.get()) {
299 webapps_registry_->UpdateFromAppList(*app_list); 306 webapps_registry_->UpdateFromAppList(*app_list);
300 } 307 }
301 } 308 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 414
408 void ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh( 415 void ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh(
409 const DirectoryFetchInfo& directory_fetch_info, 416 const DirectoryFetchInfo& directory_fetch_info,
410 const FileOperationCallback& callback, 417 const FileOperationCallback& callback,
411 DriveFileError error, 418 DriveFileError error,
412 const base::FilePath& directory_path) { 419 const base::FilePath& directory_path) {
413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
414 DCHECK(!callback.is_null()); 421 DCHECK(!callback.is_null());
415 422
416 DVLOG(1) << "Directory loaded: " << directory_fetch_info.ToString(); 423 DVLOG(1) << "Directory loaded: " << directory_fetch_info.ToString();
417 OnDirectoryLoadComplete(directory_fetch_info, callback, error); 424 callback.Run(error);
418 // Also notify the observers. 425 // Also notify the observers.
419 if (error == DRIVE_FILE_OK) { 426 if (error == DRIVE_FILE_OK) {
420 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_, 427 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_,
421 OnDirectoryChanged(directory_path)); 428 OnDirectoryChanged(directory_path));
422 } 429 }
423 } 430 }
424 431
425 void ChangeListLoader::SearchFromServer( 432 void ChangeListLoader::SearchFromServer(
426 const std::string& search_query, 433 const std::string& search_query,
427 bool shared_with_me, 434 bool shared_with_me,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 740
734 // If the directory's changestamp is up-to-date, just schedule to run the 741 // 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. 742 // callback, as there is no need to fetch the directory.
736 if (directory_fetch_info.changestamp() >= last_known_remote_changestamp_) { 743 if (directory_fetch_info.changestamp() >= last_known_remote_changestamp_) {
737 base::MessageLoopProxy::current()->PostTask( 744 base::MessageLoopProxy::current()->PostTask(
738 FROM_HERE, 745 FROM_HERE,
739 base::Bind(callback, DRIVE_FILE_OK)); 746 base::Bind(callback, DRIVE_FILE_OK));
740 return; 747 return;
741 } 748 }
742 749
743 // The directory should be fetched. Add the callback to the pending list. The 750 // The directory should be fetched. Add a dummy task to so ScheduleRun()
744 // callback will be run after the directory is loaded. 751 // can check that the directory is being fetched.
745 pending_load_callback_[resource_id].push_back(callback); 752 pending_load_callback_[resource_id].push_back(
746 DoLoadDirectoryFromServer(directory_fetch_info, 753 base::Bind(&util::EmptyFileOperationCallback));
747 base::Bind(&util::EmptyFileOperationCallback)); 754 DoLoadDirectoryFromServer(
755 directory_fetch_info,
756 base::Bind(&ChangeListLoader::OnDirectoryLoadComplete,
757 weak_ptr_factory_.GetWeakPtr(),
758 directory_fetch_info,
759 callback));
748 } 760 }
749 761
750 void ChangeListLoader::NotifyDirectoryChangedAfterApplyFeed( 762 void ChangeListLoader::NotifyDirectoryChangedAfterApplyFeed(
751 bool should_notify_changed_directories, 763 bool should_notify_changed_directories,
752 const base::Closure& update_finished_callback) { 764 const base::Closure& update_finished_callback) {
753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
754 DCHECK(change_list_processor_.get()); 766 DCHECK(change_list_processor_.get());
755 DCHECK(!update_finished_callback.is_null()); 767 DCHECK(!update_finished_callback.is_null());
756 768
757 loaded_ = true; 769 loaded_ = true;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 for (size_t i = 0; i < callbacks.size(); ++i) { 856 for (size_t i = 0; i < callbacks.size(); ++i) {
845 base::MessageLoopProxy::current()->PostTask( 857 base::MessageLoopProxy::current()->PostTask(
846 FROM_HERE, 858 FROM_HERE,
847 base::Bind(callbacks[i], error)); 859 base::Bind(callbacks[i], error));
848 } 860 }
849 pending_load_callback_.erase(it); 861 pending_load_callback_.erase(it);
850 } 862 }
851 } 863 }
852 864
853 } // namespace drive 865 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/change_list_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698