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 #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/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 const bool is_initial_load = (!loaded_ && !IsRefreshing()); | 345 const bool is_initial_load = (!loaded_ && !IsRefreshing()); |
346 | 346 |
347 // Register the callback function to be called when it is loaded. | 347 // Register the callback function to be called when it is loaded. |
348 pending_load_callback_.push_back(callback); | 348 pending_load_callback_.push_back(callback); |
349 | 349 |
350 // If loading task is already running, do nothing. | 350 // If loading task is already running, do nothing. |
351 if (pending_load_callback_.size() > 1) | 351 if (pending_load_callback_.size() > 1) |
352 return; | 352 return; |
353 | 353 |
354 // Check the current status of local metadata, and start loading if needed. | 354 // Check the current status of local metadata, and start loading if needed. |
| 355 int64* local_changestamp = new int64(0); |
355 base::PostTaskAndReplyWithResult( | 356 base::PostTaskAndReplyWithResult( |
356 blocking_task_runner_, | 357 blocking_task_runner_, |
357 FROM_HERE, | 358 FROM_HERE, |
358 base::Bind(&ResourceMetadata::GetLargestChangestamp, | 359 base::Bind(&ResourceMetadata::GetLargestChangestamp, |
359 base::Unretained(resource_metadata_)), | 360 base::Unretained(resource_metadata_), |
| 361 local_changestamp), |
360 base::Bind(&ChangeListLoader::LoadAfterGetLargestChangestamp, | 362 base::Bind(&ChangeListLoader::LoadAfterGetLargestChangestamp, |
361 weak_ptr_factory_.GetWeakPtr(), | 363 weak_ptr_factory_.GetWeakPtr(), |
362 is_initial_load)); | 364 is_initial_load, |
| 365 base::Owned(local_changestamp))); |
363 } | 366 } |
364 | 367 |
365 void ChangeListLoader::LoadAfterGetLargestChangestamp(bool is_initial_load, | 368 void ChangeListLoader::LoadAfterGetLargestChangestamp( |
366 int64 local_changestamp) { | 369 bool is_initial_load, |
| 370 const int64* local_changestamp, |
| 371 FileError error) { |
367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
368 | 373 |
369 if (is_initial_load && local_changestamp > 0) { | 374 if (error != FILE_ERROR_OK) { |
| 375 OnChangeListLoadComplete(error); |
| 376 return; |
| 377 } |
| 378 |
| 379 if (is_initial_load && *local_changestamp > 0) { |
370 // The local data is usable. Flush callbacks to tell loading was successful. | 380 // The local data is usable. Flush callbacks to tell loading was successful. |
371 OnChangeListLoadComplete(FILE_ERROR_OK); | 381 OnChangeListLoadComplete(FILE_ERROR_OK); |
372 | 382 |
373 // Continues to load from server in background. | 383 // Continues to load from server in background. |
374 // Put dummy callbacks to indicate that fetching is still continuing. | 384 // Put dummy callbacks to indicate that fetching is still continuing. |
375 pending_load_callback_.push_back( | 385 pending_load_callback_.push_back( |
376 base::Bind(&util::EmptyFileOperationCallback)); | 386 base::Bind(&util::EmptyFileOperationCallback)); |
377 } | 387 } |
378 | 388 |
379 about_resource_loader_->UpdateAboutResource( | 389 about_resource_loader_->UpdateAboutResource( |
380 base::Bind(&ChangeListLoader::LoadAfterGetAboutResource, | 390 base::Bind(&ChangeListLoader::LoadAfterGetAboutResource, |
381 weak_ptr_factory_.GetWeakPtr(), | 391 weak_ptr_factory_.GetWeakPtr(), |
382 local_changestamp)); | 392 *local_changestamp)); |
383 } | 393 } |
384 | 394 |
385 void ChangeListLoader::LoadAfterGetAboutResource( | 395 void ChangeListLoader::LoadAfterGetAboutResource( |
386 int64 local_changestamp, | 396 int64 local_changestamp, |
387 google_apis::GDataErrorCode status, | 397 google_apis::GDataErrorCode status, |
388 scoped_ptr<google_apis::AboutResource> about_resource) { | 398 scoped_ptr<google_apis::AboutResource> about_resource) { |
389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
390 | 400 |
391 FileError error = GDataToFileError(status); | 401 FileError error = GDataToFileError(status); |
392 if (error != FILE_ERROR_OK) { | 402 if (error != FILE_ERROR_OK) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 538 |
529 OnChangeListLoadComplete(error); | 539 OnChangeListLoadComplete(error); |
530 | 540 |
531 FOR_EACH_OBSERVER(ChangeListLoaderObserver, | 541 FOR_EACH_OBSERVER(ChangeListLoaderObserver, |
532 observers_, | 542 observers_, |
533 OnLoadFromServerComplete()); | 543 OnLoadFromServerComplete()); |
534 } | 544 } |
535 | 545 |
536 } // namespace internal | 546 } // namespace internal |
537 } // namespace drive | 547 } // namespace drive |
OLD | NEW |