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

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

Issue 107293013: drive: Stop comparing resource ID against kDriveGrandRootLocalId (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | chrome/browser/chromeos/drive/change_list_processor.h » ('j') | 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/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 callback.Run(FILE_ERROR_NOT_A_DIRECTORY); 444 callback.Run(FILE_ERROR_NOT_A_DIRECTORY);
445 return; 445 return;
446 } 446 }
447 447
448 // drive/other does not exist on the server. 448 // drive/other does not exist on the server.
449 if (entry->local_id() == util::kDriveOtherDirLocalId) { 449 if (entry->local_id() == util::kDriveOtherDirLocalId) {
450 callback.Run(FILE_ERROR_OK); 450 callback.Run(FILE_ERROR_OK);
451 return; 451 return;
452 } 452 }
453 453
454 Load(DirectoryFetchInfo(entry->resource_id(), 454 Load(DirectoryFetchInfo(entry->local_id(),
455 entry->resource_id(),
455 entry->directory_specific_info().changestamp()), 456 entry->directory_specific_info().changestamp()),
456 callback); 457 callback);
457 } 458 }
458 459
459 void ChangeListLoader::LoadDirectoryIfNeededAfterLoadParent( 460 void ChangeListLoader::LoadDirectoryIfNeededAfterLoadParent(
460 const base::FilePath& directory_path, 461 const base::FilePath& directory_path,
461 const FileOperationCallback& callback, 462 const FileOperationCallback& callback,
462 FileError error) { 463 FileError error) {
463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
464 DCHECK(!callback.is_null()); 465 DCHECK(!callback.is_null());
(...skipping 22 matching lines...) Expand all
487 void ChangeListLoader::Load(const DirectoryFetchInfo& directory_fetch_info, 488 void ChangeListLoader::Load(const DirectoryFetchInfo& directory_fetch_info,
488 const FileOperationCallback& callback) { 489 const FileOperationCallback& callback) {
489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
490 DCHECK(!callback.is_null()); 491 DCHECK(!callback.is_null());
491 492
492 // Check if this is the first time this ChangeListLoader do loading. 493 // Check if this is the first time this ChangeListLoader do loading.
493 // Note: IsRefreshing() depends on pending_load_callback_ so check in advance. 494 // Note: IsRefreshing() depends on pending_load_callback_ so check in advance.
494 const bool is_initial_load = (!loaded_ && !IsRefreshing()); 495 const bool is_initial_load = (!loaded_ && !IsRefreshing());
495 496
496 // Register the callback function to be called when it is loaded. 497 // Register the callback function to be called when it is loaded.
497 const std::string& resource_id = directory_fetch_info.resource_id(); 498 const std::string& local_id = directory_fetch_info.local_id();
498 pending_load_callback_[resource_id].push_back(callback); 499 pending_load_callback_[local_id].push_back(callback);
499 500
500 // If loading task for |resource_id| is already running, do nothing. 501 // If loading task for |resource_id| is already running, do nothing.
501 if (pending_load_callback_[resource_id].size() > 1) 502 if (pending_load_callback_[local_id].size() > 1)
502 return; 503 return;
503 504
504 // For initial loading, even for directory fetching, we do load the full 505 // For initial loading, even for directory fetching, we do load the full
505 // resource list from the server to sync up. So we register a dummy 506 // resource list from the server to sync up. So we register a dummy
506 // callback to indicate that update for full hierarchy is running. 507 // callback to indicate that update for full hierarchy is running.
507 if (is_initial_load && !resource_id.empty()) { 508 if (is_initial_load && !directory_fetch_info.empty()) {
508 pending_load_callback_[""].push_back( 509 pending_load_callback_[""].push_back(
509 base::Bind(&util::EmptyFileOperationCallback)); 510 base::Bind(&util::EmptyFileOperationCallback));
510 } 511 }
511 512
512 // Check the current status of local metadata, and start loading if needed. 513 // Check the current status of local metadata, and start loading if needed.
513 base::PostTaskAndReplyWithResult( 514 base::PostTaskAndReplyWithResult(
514 blocking_task_runner_, 515 blocking_task_runner_,
515 FROM_HERE, 516 FROM_HERE,
516 base::Bind(&ResourceMetadata::GetLargestChangestamp, 517 base::Bind(&ResourceMetadata::GetLargestChangestamp,
517 base::Unretained(resource_metadata_)), 518 base::Unretained(resource_metadata_)),
518 base::Bind(&ChangeListLoader::LoadAfterGetLargestChangestamp, 519 base::Bind(&ChangeListLoader::LoadAfterGetLargestChangestamp,
519 weak_ptr_factory_.GetWeakPtr(), 520 weak_ptr_factory_.GetWeakPtr(),
520 directory_fetch_info, 521 directory_fetch_info,
521 is_initial_load)); 522 is_initial_load));
522 } 523 }
523 524
524 void ChangeListLoader::LoadAfterGetLargestChangestamp( 525 void ChangeListLoader::LoadAfterGetLargestChangestamp(
525 const DirectoryFetchInfo& directory_fetch_info, 526 const DirectoryFetchInfo& directory_fetch_info,
526 bool is_initial_load, 527 bool is_initial_load,
527 int64 local_changestamp) { 528 int64 local_changestamp) {
528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
529 530
530 if (is_initial_load && local_changestamp > 0) { 531 if (is_initial_load && local_changestamp > 0) {
531 // The local data is usable. Flush callbacks to tell loading was successful. 532 // The local data is usable. Flush callbacks to tell loading was successful.
532 OnChangeListLoadComplete(FILE_ERROR_OK); 533 OnChangeListLoadComplete(FILE_ERROR_OK);
533 534
534 // Continues to load from server in background. 535 // Continues to load from server in background.
535 // Put dummy callbacks to indicate that fetching is still continuing. 536 // Put dummy callbacks to indicate that fetching is still continuing.
536 pending_load_callback_[directory_fetch_info.resource_id()].push_back( 537 pending_load_callback_[directory_fetch_info.local_id()].push_back(
537 base::Bind(&util::EmptyFileOperationCallback)); 538 base::Bind(&util::EmptyFileOperationCallback));
538 if (!directory_fetch_info.empty()) { 539 if (!directory_fetch_info.empty()) {
539 pending_load_callback_[""].push_back( 540 pending_load_callback_[""].push_back(
540 base::Bind(&util::EmptyFileOperationCallback)); 541 base::Bind(&util::EmptyFileOperationCallback));
541 } 542 }
542 } 543 }
543 544
544 if (directory_fetch_info.empty()) { 545 if (directory_fetch_info.empty()) {
545 UpdateAboutResource(base::Bind(&ChangeListLoader::LoadAfterGetAboutResource, 546 UpdateAboutResource(base::Bind(&ChangeListLoader::LoadAfterGetAboutResource,
546 weak_ptr_factory_.GetWeakPtr(), 547 weak_ptr_factory_.GetWeakPtr(),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 // callback, as there is no need to fetch the directory. 616 // callback, as there is no need to fetch the directory.
616 if (directory_changestamp >= remote_changestamp) { 617 if (directory_changestamp >= remote_changestamp) {
617 LoadAfterLoadDirectory(directory_fetch_info, is_initial_load, 618 LoadAfterLoadDirectory(directory_fetch_info, is_initial_load,
618 start_changestamp, FILE_ERROR_OK); 619 start_changestamp, FILE_ERROR_OK);
619 return; 620 return;
620 } 621 }
621 622
622 // Start fetching the directory content, and mark it with the changestamp 623 // Start fetching the directory content, and mark it with the changestamp
623 // |remote_changestamp|. 624 // |remote_changestamp|.
624 DirectoryFetchInfo new_directory_fetch_info( 625 DirectoryFetchInfo new_directory_fetch_info(
625 directory_fetch_info.resource_id(), remote_changestamp); 626 directory_fetch_info.local_id(), directory_fetch_info.resource_id(),
627 remote_changestamp);
626 LoadDirectoryFromServer( 628 LoadDirectoryFromServer(
627 new_directory_fetch_info, 629 new_directory_fetch_info,
628 base::Bind(&ChangeListLoader::LoadAfterLoadDirectory, 630 base::Bind(&ChangeListLoader::LoadAfterLoadDirectory,
629 weak_ptr_factory_.GetWeakPtr(), 631 weak_ptr_factory_.GetWeakPtr(),
630 directory_fetch_info, 632 directory_fetch_info,
631 is_initial_load, 633 is_initial_load,
632 start_changestamp)); 634 start_changestamp));
633 } 635 }
634 } 636 }
635 637
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 680
679 void ChangeListLoader::OnDirectoryLoadComplete( 681 void ChangeListLoader::OnDirectoryLoadComplete(
680 const DirectoryFetchInfo& directory_fetch_info, 682 const DirectoryFetchInfo& directory_fetch_info,
681 FileError error) { 683 FileError error) {
682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
683 685
684 util::Log(logging::LOG_INFO, 686 util::Log(logging::LOG_INFO,
685 "Fast-fetch complete: %s => %s", 687 "Fast-fetch complete: %s => %s",
686 directory_fetch_info.ToString().c_str(), 688 directory_fetch_info.ToString().c_str(),
687 FileErrorToString(error).c_str()); 689 FileErrorToString(error).c_str());
688 const std::string& resource_id = directory_fetch_info.resource_id(); 690 const std::string& local_id = directory_fetch_info.local_id();
689 LoadCallbackMap::iterator it = pending_load_callback_.find(resource_id); 691 LoadCallbackMap::iterator it = pending_load_callback_.find(local_id);
690 if (it != pending_load_callback_.end()) { 692 if (it != pending_load_callback_.end()) {
691 DVLOG(1) << "Running callback for " << resource_id; 693 DVLOG(1) << "Running callback for " << local_id;
692 const std::vector<FileOperationCallback>& callbacks = it->second; 694 const std::vector<FileOperationCallback>& callbacks = it->second;
693 for (size_t i = 0; i < callbacks.size(); ++i) { 695 for (size_t i = 0; i < callbacks.size(); ++i) {
694 base::MessageLoopProxy::current()->PostTask( 696 base::MessageLoopProxy::current()->PostTask(
695 FROM_HERE, 697 FROM_HERE,
696 base::Bind(callbacks[i], error)); 698 base::Bind(callbacks[i], error));
697 } 699 }
698 pending_load_callback_.erase(it); 700 pending_load_callback_.erase(it);
699 } 701 }
700 } 702 }
701 703
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 797
796 void ChangeListLoader::LoadDirectoryFromServer( 798 void ChangeListLoader::LoadDirectoryFromServer(
797 const DirectoryFetchInfo& directory_fetch_info, 799 const DirectoryFetchInfo& directory_fetch_info,
798 const FileOperationCallback& callback) { 800 const FileOperationCallback& callback) {
799 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
800 DCHECK(!callback.is_null()); 802 DCHECK(!callback.is_null());
801 DCHECK(!directory_fetch_info.empty()); 803 DCHECK(!directory_fetch_info.empty());
802 DCHECK(cached_about_resource_); 804 DCHECK(cached_about_resource_);
803 DVLOG(1) << "Start loading directory: " << directory_fetch_info.ToString(); 805 DVLOG(1) << "Start loading directory: " << directory_fetch_info.ToString();
804 806
805 if (directory_fetch_info.resource_id() == util::kDriveGrandRootLocalId) { 807 if (directory_fetch_info.local_id() == util::kDriveGrandRootLocalId) {
806 // Load for a grand root directory means slightly different from other 808 // Load for a grand root directory means slightly different from other
807 // directories. It should have two directories; <other> and mydrive root. 809 // directories. It should have two directories; <other> and mydrive root.
808 // <other> directory should always exist, but mydrive root should be 810 // <other> directory should always exist, but mydrive root should be
809 // created by root resource id retrieved from the server. 811 // created by root resource id retrieved from the server.
810 base::FilePath* changed_directory_path = new base::FilePath; 812 base::FilePath* changed_directory_path = new base::FilePath;
811 base::PostTaskAndReplyWithResult( 813 base::PostTaskAndReplyWithResult(
812 blocking_task_runner_, 814 blocking_task_runner_,
813 FROM_HERE, 815 FROM_HERE,
814 base::Bind(&AddMyDriveIfNeeded, 816 base::Bind(&AddMyDriveIfNeeded,
815 resource_metadata_, 817 resource_metadata_,
(...skipping 30 matching lines...) Expand all
846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
847 DCHECK(!callback.is_null()); 849 DCHECK(!callback.is_null());
848 DCHECK(!directory_fetch_info.empty()); 850 DCHECK(!directory_fetch_info.empty());
849 851
850 // Delete the fetcher. 852 // Delete the fetcher.
851 fast_fetch_feed_fetcher_set_.erase(fetcher); 853 fast_fetch_feed_fetcher_set_.erase(fetcher);
852 delete fetcher; 854 delete fetcher;
853 855
854 if (error != FILE_ERROR_OK) { 856 if (error != FILE_ERROR_OK) {
855 LOG(ERROR) << "Failed to load directory: " 857 LOG(ERROR) << "Failed to load directory: "
856 << directory_fetch_info.resource_id() 858 << directory_fetch_info.local_id()
857 << ": " << FileErrorToString(error); 859 << ": " << FileErrorToString(error);
858 callback.Run(error); 860 callback.Run(error);
859 return; 861 return;
860 } 862 }
861 863
862 base::FilePath* directory_path = new base::FilePath; 864 base::FilePath* directory_path = new base::FilePath;
863 base::PostTaskAndReplyWithResult( 865 base::PostTaskAndReplyWithResult(
864 blocking_task_runner_, 866 blocking_task_runner_,
865 FROM_HERE, 867 FROM_HERE,
866 base::Bind(&ChangeListProcessor::RefreshDirectory, 868 base::Bind(&ChangeListProcessor::RefreshDirectory,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 924
923 cached_about_resource_.reset( 925 cached_about_resource_.reset(
924 new google_apis::AboutResource(*about_resource)); 926 new google_apis::AboutResource(*about_resource));
925 } 927 }
926 928
927 callback.Run(status, about_resource.Pass()); 929 callback.Run(status, about_resource.Pass());
928 } 930 }
929 931
930 } // namespace internal 932 } // namespace internal
931 } // namespace drive 933 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/change_list_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698