Chromium Code Reviews| 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 | 353 |
| 354 if (loaded_) { | 354 if (loaded_) { |
| 355 // We only start to check for updates iff the load is done. | 355 // We only start to check for updates iff the load is done. |
| 356 // I.e., we ignore checking updates if not loaded to avoid starting the | 356 // I.e., we ignore checking updates if not loaded to avoid starting the |
| 357 // load without user's explicit interaction (such as opening Drive). | 357 // load without user's explicit interaction (such as opening Drive). |
| 358 util::Log(logging::LOG_INFO, "Checking for updates"); | 358 util::Log(logging::LOG_INFO, "Checking for updates"); |
| 359 Load(DirectoryFetchInfo(), callback); | 359 Load(DirectoryFetchInfo(), callback); |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 | 362 |
| 363 void ChangeListLoader::LoadIfNeeded( | 363 void ChangeListLoader::LoadDirectoryIfNeeded( |
| 364 const DirectoryFetchInfo& directory_fetch_info, | 364 const base::FilePath& directory_path, |
| 365 const FileOperationCallback& callback) { | 365 const FileOperationCallback& callback) { |
| 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 367 DCHECK(!callback.is_null()); | 367 DCHECK(!callback.is_null()); |
| 368 | 368 |
| 369 // If the resource metadata has been already loaded, for normal change list | 369 ResourceEntry* entry = new ResourceEntry; |
| 370 // fetch (= empty directory_fetch_info), we have nothing to do. For "fast | 370 base::PostTaskAndReplyWithResult( |
| 371 // fetch", we need to schedule a fetching if a refresh is currently | 371 blocking_task_runner_.get(), |
| 372 // running, because we don't want to wait a possibly large delta change | 372 FROM_HERE, |
| 373 // list to arrive. | 373 base::Bind(&ResourceMetadata::GetResourceEntryByPath, |
| 374 if (loaded_ && (directory_fetch_info.empty() || !IsRefreshing())) { | 374 base::Unretained(resource_metadata_), |
| 375 base::MessageLoopProxy::current()->PostTask( | 375 directory_path, |
| 376 FROM_HERE, | 376 entry), |
| 377 base::Bind(callback, FILE_ERROR_OK)); | 377 base::Bind(&ChangeListLoader::LoadDirectoryIfNeededAfterGetEntry, |
| 378 return; | 378 weak_ptr_factory_.GetWeakPtr(), |
| 379 } | 379 directory_path, |
| 380 Load(directory_fetch_info, callback); | 380 callback, |
| 381 true, // should_try_loading_parent | |
| 382 base::Owned(entry))); | |
| 383 } | |
| 384 | |
| 385 void ChangeListLoader::LoadForTesting(const FileOperationCallback& callback) { | |
| 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 387 DCHECK(!callback.is_null()); | |
| 388 | |
| 389 Load(DirectoryFetchInfo(), callback); | |
| 381 } | 390 } |
| 382 | 391 |
| 383 void ChangeListLoader::GetAboutResource( | 392 void ChangeListLoader::GetAboutResource( |
| 384 const google_apis::AboutResourceCallback& callback) { | 393 const google_apis::AboutResourceCallback& callback) { |
| 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 386 DCHECK(!callback.is_null()); | 395 DCHECK(!callback.is_null()); |
| 387 | 396 |
| 388 if (cached_about_resource_) { | 397 if (cached_about_resource_) { |
| 389 base::MessageLoopProxy::current()->PostTask( | 398 base::MessageLoopProxy::current()->PostTask( |
| 390 FROM_HERE, | 399 FROM_HERE, |
| 391 base::Bind( | 400 base::Bind( |
| 392 callback, | 401 callback, |
| 393 google_apis::HTTP_NO_CONTENT, | 402 google_apis::HTTP_NO_CONTENT, |
| 394 base::Passed(scoped_ptr<google_apis::AboutResource>( | 403 base::Passed(scoped_ptr<google_apis::AboutResource>( |
| 395 new google_apis::AboutResource(*cached_about_resource_))))); | 404 new google_apis::AboutResource(*cached_about_resource_))))); |
| 396 } else { | 405 } else { |
| 397 UpdateAboutResource(callback); | 406 UpdateAboutResource(callback); |
| 398 } | 407 } |
| 399 } | 408 } |
| 400 | 409 |
| 410 void ChangeListLoader::LoadDirectoryIfNeededAfterGetEntry( | |
| 411 const base::FilePath& directory_path, | |
| 412 const FileOperationCallback& callback, | |
| 413 bool should_try_loading_parent, | |
| 414 const ResourceEntry* entry, | |
| 415 FileError error) { | |
| 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 417 DCHECK(!callback.is_null()); | |
| 418 | |
| 419 if (error == FILE_ERROR_NOT_FOUND && should_try_loading_parent) { | |
| 420 // This entry may be found after loading the parent. | |
| 421 LoadDirectoryIfNeeded( | |
| 422 directory_path.DirName(), | |
|
kinaba
2013/12/20 04:54:14
This recursive call implicitly assume that it even
hashimoto
2013/12/20 06:29:29
Moved a check from FileSystem::GetResourceEntry.
| |
| 423 base::Bind(&ChangeListLoader::LoadDirectoryIfNeededAfterLoadParent, | |
| 424 weak_ptr_factory_.GetWeakPtr(), | |
| 425 directory_path, | |
| 426 callback)); | |
| 427 return; | |
| 428 } | |
| 429 if (error != FILE_ERROR_OK) { | |
| 430 callback.Run(error); | |
| 431 return; | |
| 432 } | |
| 433 | |
| 434 if (!entry->file_info().is_directory()) { | |
| 435 callback.Run(FILE_ERROR_NOT_A_DIRECTORY); | |
| 436 return; | |
| 437 } | |
| 438 | |
| 439 // drive/other does not exist on the server. | |
| 440 if (entry->local_id() == util::kDriveOtherDirLocalId) { | |
| 441 callback.Run(FILE_ERROR_OK); | |
| 442 return; | |
| 443 } | |
| 444 | |
| 445 // If the resource metadata has been already loaded, we need to schedule a | |
| 446 // fetching if a refresh is currently running, because we don't want to wait a | |
| 447 // possibly large delta change list to arrive. | |
| 448 if (loaded_ && !IsRefreshing()) { | |
|
kinaba
2013/12/20 04:54:14
Can we move this check to the very beginning of Lo
hashimoto
2013/12/20 06:29:29
Sounds good, but this results in LoadDirectoryIfNe
| |
| 449 callback.Run(FILE_ERROR_OK); | |
| 450 return; | |
| 451 } | |
| 452 Load(DirectoryFetchInfo(entry->resource_id(), | |
| 453 entry->directory_specific_info().changestamp()), | |
| 454 callback); | |
| 455 } | |
| 456 | |
| 457 void ChangeListLoader::LoadDirectoryIfNeededAfterLoadParent( | |
| 458 const base::FilePath& directory_path, | |
| 459 const FileOperationCallback& callback, | |
| 460 FileError error) { | |
| 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 462 DCHECK(!callback.is_null()); | |
| 463 | |
| 464 if (error != FILE_ERROR_OK) { | |
| 465 callback.Run(error); | |
| 466 return; | |
| 467 } | |
| 468 | |
| 469 ResourceEntry* entry = new ResourceEntry; | |
| 470 base::PostTaskAndReplyWithResult( | |
| 471 blocking_task_runner_.get(), | |
| 472 FROM_HERE, | |
| 473 base::Bind(&ResourceMetadata::GetResourceEntryByPath, | |
| 474 base::Unretained(resource_metadata_), | |
| 475 directory_path, | |
| 476 entry), | |
| 477 base::Bind(&ChangeListLoader::LoadDirectoryIfNeededAfterGetEntry, | |
| 478 weak_ptr_factory_.GetWeakPtr(), | |
| 479 directory_path, | |
| 480 callback, | |
| 481 false, // should_try_loading_parent | |
| 482 base::Owned(entry))); | |
| 483 } | |
| 484 | |
| 401 void ChangeListLoader::Load(const DirectoryFetchInfo& directory_fetch_info, | 485 void ChangeListLoader::Load(const DirectoryFetchInfo& directory_fetch_info, |
| 402 const FileOperationCallback& callback) { | 486 const FileOperationCallback& callback) { |
| 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 404 DCHECK(!callback.is_null()); | 488 DCHECK(!callback.is_null()); |
| 405 | 489 |
| 406 // Check if this is the first time this ChangeListLoader do loading. | 490 // Check if this is the first time this ChangeListLoader do loading. |
| 407 // Note: IsRefreshing() depends on pending_load_callback_ so check in advance. | 491 // Note: IsRefreshing() depends on pending_load_callback_ so check in advance. |
| 408 const bool is_initial_load = (!loaded_ && !IsRefreshing()); | 492 const bool is_initial_load = (!loaded_ && !IsRefreshing()); |
| 409 | 493 |
| 410 // Register the callback function to be called when it is loaded. | 494 // Register the callback function to be called when it is loaded. |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 | 920 |
| 837 cached_about_resource_.reset( | 921 cached_about_resource_.reset( |
| 838 new google_apis::AboutResource(*about_resource)); | 922 new google_apis::AboutResource(*about_resource)); |
| 839 } | 923 } |
| 840 | 924 |
| 841 callback.Run(status, about_resource.Pass()); | 925 callback.Run(status, about_resource.Pass()); |
| 842 } | 926 } |
| 843 | 927 |
| 844 } // namespace internal | 928 } // namespace internal |
| 845 } // namespace drive | 929 } // namespace drive |
| OLD | NEW |