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

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

Issue 11227020: Set root resource ID upon full feed update. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 1 month 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
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/drive_feed_loader.h" 5 #include "chrome/browser/chromeos/drive/drive_feed_loader.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 scoped_ptr<google_apis::AboutResource> about_resource; 370 scoped_ptr<google_apis::AboutResource> about_resource;
371 if (feed_data.get()) 371 if (feed_data.get())
372 about_resource = google_apis::AboutResource::CreateFrom(*feed_data); 372 about_resource = google_apis::AboutResource::CreateFrom(*feed_data);
373 373
374 if (!about_resource.get()) { 374 if (!about_resource.get()) {
375 LoadFromServer(params.Pass()); 375 LoadFromServer(params.Pass());
376 return; 376 return;
377 } 377 }
378 378
379 int64 largest_changestamp = about_resource->largest_change_id(); 379 int64 largest_changestamp = about_resource->largest_change_id();
380 resource_metadata_->InitializeRootEntry(about_resource->root_folder_id()); 380
381 // Copy the root resource ID for use in UpdateFromFeed().
382 params->root_resource_id = about_resource->root_folder_id();
383 DCHECK(!params->root_resource_id.empty());
381 384
382 if (local_changestamp >= largest_changestamp) { 385 if (local_changestamp >= largest_changestamp) {
383 if (local_changestamp > largest_changestamp) { 386 if (local_changestamp > largest_changestamp) {
384 LOG(WARNING) << "Cached client feed is fresher than server, client = " 387 LOG(WARNING) << "Cached client feed is fresher than server, client = "
385 << local_changestamp 388 << local_changestamp
386 << ", server = " 389 << ", server = "
387 << largest_changestamp; 390 << largest_changestamp;
388 } 391 }
389 392
390 // No changes detected, tell the client that the loading was successful. 393 // No changes detected, tell the client that the loading was successful.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 471 }
469 472
470 void DriveFeedLoader::OnFeedFromServerLoaded(scoped_ptr<LoadFeedParams> params, 473 void DriveFeedLoader::OnFeedFromServerLoaded(scoped_ptr<LoadFeedParams> params,
471 DriveFileError error) { 474 DriveFileError error) {
472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
473 DCHECK(refreshing_); 476 DCHECK(refreshing_);
474 477
475 if (error == DRIVE_FILE_OK) { 478 if (error == DRIVE_FILE_OK) {
476 UpdateFromFeed(params->feed_list, 479 UpdateFromFeed(params->feed_list,
477 params->start_changestamp, 480 params->start_changestamp,
478 params->root_feed_changestamp); 481 params->root_feed_changestamp,
482 params->root_resource_id);
479 } 483 }
480 refreshing_ = false; 484 refreshing_ = false;
481 485
482 if (error != DRIVE_FILE_OK) { 486 if (error != DRIVE_FILE_OK) {
483 if (!params->load_finished_callback.is_null()) 487 if (!params->load_finished_callback.is_null())
484 params->load_finished_callback.Run(error); 488 params->load_finished_callback.Run(error);
485 return; 489 return;
486 } 490 }
487 491
488 // Save file system metadata to disk. 492 // Save file system metadata to disk.
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 FROM_HERE, 868 FROM_HERE,
865 blocking_task_runner_, 869 blocking_task_runner_,
866 base::Bind(&SaveProtoOnBlockingPool, path, 870 base::Bind(&SaveProtoOnBlockingPool, path,
867 base::Passed(serialized_proto.Pass()))); 871 base::Passed(serialized_proto.Pass())));
868 } 872 }
869 } 873 }
870 874
871 void DriveFeedLoader::UpdateFromFeed( 875 void DriveFeedLoader::UpdateFromFeed(
872 const ScopedVector<google_apis::DocumentFeed>& feed_list, 876 const ScopedVector<google_apis::DocumentFeed>& feed_list,
873 int64 start_changestamp, 877 int64 start_changestamp,
874 int64 root_feed_changestamp) { 878 int64 root_feed_changestamp,
879 const std::string& root_resource_id) {
875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
876 DVLOG(1) << "Updating directory with a feed"; 881 DVLOG(1) << "Updating directory with a feed";
877 882
878 std::set<FilePath> changed_dirs; 883 std::set<FilePath> changed_dirs;
879 884
885 if (start_changestamp == 0) {
886 // This is a full fetch and on full fetch the root has to be initialized
887 // before children are added by DriveFeedProcessor.
888 if (google_apis::util::IsDriveV2ApiEnabled()) {
889 DCHECK(!root_resource_id.empty());
890 resource_metadata_->InitializeRootEntry(root_resource_id);
891 } else {
892 // Use fixed root resource ID for WAPI.
893 resource_metadata_->InitializeRootEntry(kWAPIRootDirectoryResourceId);
894 }
895 }
896
880 DriveFeedProcessor feed_processor(resource_metadata_); 897 DriveFeedProcessor feed_processor(resource_metadata_);
881 feed_processor.ApplyFeeds( 898 feed_processor.ApplyFeeds(
882 feed_list, 899 feed_list,
883 start_changestamp, 900 start_changestamp,
884 root_feed_changestamp, 901 root_feed_changestamp,
885 &changed_dirs); 902 &changed_dirs);
886 903
887 // Don't send directory content change notification while performing 904 // Don't send directory content change notification while performing
888 // the initial content retrieval. 905 // the initial content retrieval.
889 const bool should_notify_directory_changed = (start_changestamp != 0); 906 const bool should_notify_directory_changed = (start_changestamp != 0);
890 if (should_notify_directory_changed) { 907 if (should_notify_directory_changed) {
891 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); 908 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin();
892 dir_iter != changed_dirs.end(); ++dir_iter) { 909 dir_iter != changed_dirs.end(); ++dir_iter) {
893 FOR_EACH_OBSERVER(DriveFeedLoaderObserver, observers_, 910 FOR_EACH_OBSERVER(DriveFeedLoaderObserver, observers_,
894 OnDirectoryChanged(*dir_iter)); 911 OnDirectoryChanged(*dir_iter));
895 } 912 }
896 } 913 }
897 } 914 }
898 915
899 } // namespace drive 916 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698