| 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/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 Loading... |
| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(!params->load_finished_callback.is_null()); | 476 DCHECK(!params->load_finished_callback.is_null()); |
| 474 DCHECK(refreshing_); | 477 DCHECK(refreshing_); |
| 475 | 478 |
| 476 if (error == DRIVE_FILE_OK) { | 479 if (error == DRIVE_FILE_OK) { |
| 477 UpdateFromFeed(params->feed_list, | 480 UpdateFromFeed(params->feed_list, |
| 478 params->start_changestamp, | 481 params->start_changestamp, |
| 479 params->root_feed_changestamp); | 482 params->root_feed_changestamp, |
| 483 params->root_resource_id); |
| 480 } | 484 } |
| 481 refreshing_ = false; | 485 refreshing_ = false; |
| 482 | 486 |
| 483 if (error != DRIVE_FILE_OK) { | 487 if (error != DRIVE_FILE_OK) { |
| 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. |
| 489 SaveFileSystem(); | 493 SaveFileSystem(); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 FROM_HERE, | 845 FROM_HERE, |
| 842 blocking_task_runner_, | 846 blocking_task_runner_, |
| 843 base::Bind(&SaveProtoOnBlockingPool, path, | 847 base::Bind(&SaveProtoOnBlockingPool, path, |
| 844 base::Passed(serialized_proto.Pass()))); | 848 base::Passed(serialized_proto.Pass()))); |
| 845 } | 849 } |
| 846 } | 850 } |
| 847 | 851 |
| 848 void DriveFeedLoader::UpdateFromFeed( | 852 void DriveFeedLoader::UpdateFromFeed( |
| 849 const ScopedVector<google_apis::DocumentFeed>& feed_list, | 853 const ScopedVector<google_apis::DocumentFeed>& feed_list, |
| 850 int64 start_changestamp, | 854 int64 start_changestamp, |
| 851 int64 root_feed_changestamp) { | 855 int64 root_feed_changestamp, |
| 856 const std::string& root_resource_id) { |
| 852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 853 DVLOG(1) << "Updating directory with a feed"; | 858 DVLOG(1) << "Updating directory with a feed"; |
| 854 | 859 |
| 855 std::set<FilePath> changed_dirs; | 860 std::set<FilePath> changed_dirs; |
| 856 | 861 |
| 862 if (start_changestamp == 0) { |
| 863 // This is a full fetch and on full fetch the root has to be initialized |
| 864 // before children are added by DriveFeedProcessor. |
| 865 if (google_apis::util::IsDriveV2ApiEnabled()) { |
| 866 DCHECK(!root_resource_id.empty()); |
| 867 resource_metadata_->InitializeRootEntry(root_resource_id); |
| 868 } else { |
| 869 // Use fixed root resource ID for WAPI. |
| 870 resource_metadata_->InitializeRootEntry(kWAPIRootDirectoryResourceId); |
| 871 } |
| 872 } |
| 873 |
| 857 DriveFeedProcessor feed_processor(resource_metadata_); | 874 DriveFeedProcessor feed_processor(resource_metadata_); |
| 858 feed_processor.ApplyFeeds( | 875 feed_processor.ApplyFeeds( |
| 859 feed_list, | 876 feed_list, |
| 860 start_changestamp, | 877 start_changestamp, |
| 861 root_feed_changestamp, | 878 root_feed_changestamp, |
| 862 &changed_dirs); | 879 &changed_dirs); |
| 863 | 880 |
| 864 // Don't send directory content change notification while performing | 881 // Don't send directory content change notification while performing |
| 865 // the initial content retrieval. | 882 // the initial content retrieval. |
| 866 const bool should_notify_directory_changed = (start_changestamp != 0); | 883 const bool should_notify_directory_changed = (start_changestamp != 0); |
| 867 if (should_notify_directory_changed) { | 884 if (should_notify_directory_changed) { |
| 868 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); | 885 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); |
| 869 dir_iter != changed_dirs.end(); ++dir_iter) { | 886 dir_iter != changed_dirs.end(); ++dir_iter) { |
| 870 FOR_EACH_OBSERVER(DriveFeedLoaderObserver, observers_, | 887 FOR_EACH_OBSERVER(DriveFeedLoaderObserver, observers_, |
| 871 OnDirectoryChanged(*dir_iter)); | 888 OnDirectoryChanged(*dir_iter)); |
| 872 } | 889 } |
| 873 } | 890 } |
| 874 } | 891 } |
| 875 | 892 |
| 876 } // namespace drive | 893 } // namespace drive |
| OLD | NEW |