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

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

Issue 13449004: drive: Update directory changestamp after "fast fetch" for the content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix Created 7 years, 8 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 | no next file » | 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/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 const FileOperationCallback& callback, 347 const FileOperationCallback& callback,
348 google_apis::GDataErrorCode status, 348 google_apis::GDataErrorCode status,
349 scoped_ptr<google_apis::AboutResource> about_resource) { 349 scoped_ptr<google_apis::AboutResource> about_resource) {
350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
351 DCHECK(!callback.is_null()); 351 DCHECK(!callback.is_null());
352 352
353 int64 remote_changestamp = 0; 353 int64 remote_changestamp = 0;
354 if (util::GDataToDriveFileError(status) == DRIVE_FILE_OK) { 354 if (util::GDataToDriveFileError(status) == DRIVE_FILE_OK) {
355 DCHECK(about_resource); 355 DCHECK(about_resource);
356 remote_changestamp = about_resource->largest_change_id(); 356 remote_changestamp = about_resource->largest_change_id();
357 last_known_remote_changestamp_ = remote_changestamp;
357 } 358 }
358 359
359 const DirectoryFetchInfo directory_fetch_info(directory_resource_id, 360 const DirectoryFetchInfo directory_fetch_info(directory_resource_id,
360 remote_changestamp); 361 remote_changestamp);
361 DoLoadDirectoryFromServer(directory_fetch_info, callback); 362 DoLoadDirectoryFromServer(directory_fetch_info, callback);
362 } 363 }
363 364
364 void ChangeListLoader::DoLoadDirectoryFromServer( 365 void ChangeListLoader::DoLoadDirectoryFromServer(
365 const DirectoryFetchInfo& directory_fetch_info, 366 const DirectoryFetchInfo& directory_fetch_info,
366 const FileOperationCallback& callback) { 367 const FileOperationCallback& callback) {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 // If the directory of interest is already scheduled to be fetched, add the 728 // If the directory of interest is already scheduled to be fetched, add the
728 // callback to the pending list and return. 729 // callback to the pending list and return.
729 LoadCallbackMap::iterator it = pending_load_callback_.find(resource_id); 730 LoadCallbackMap::iterator it = pending_load_callback_.find(resource_id);
730 if (it != pending_load_callback_.end()) { 731 if (it != pending_load_callback_.end()) {
731 it->second.push_back(callback); 732 it->second.push_back(callback);
732 return; 733 return;
733 } 734 }
734 735
735 // If the directory's changestamp is up-to-date, just schedule to run the 736 // If the directory's changestamp is up-to-date, just schedule to run the
736 // callback, as there is no need to fetch the directory. 737 // callback, as there is no need to fetch the directory.
737 if (directory_fetch_info.changestamp() >= last_known_remote_changestamp_) { 738 // Note that |last_known_remote_changestamp_| is 0 when it is not received
739 // yet. In that case we conservatively assume that we need to fetch.
740 if (last_known_remote_changestamp_ > 0 &&
741 directory_fetch_info.changestamp() >= last_known_remote_changestamp_) {
738 base::MessageLoopProxy::current()->PostTask( 742 base::MessageLoopProxy::current()->PostTask(
739 FROM_HERE, 743 FROM_HERE,
740 base::Bind(callback, DRIVE_FILE_OK)); 744 base::Bind(callback, DRIVE_FILE_OK));
741 return; 745 return;
742 } 746 }
743 747
744 // The directory should be fetched. Add a dummy task to so ScheduleRun() 748 // The directory should be fetched. Add a dummy task to so ScheduleRun()
745 // can check that the directory is being fetched. 749 // can check that the directory is being fetched.
746 pending_load_callback_[resource_id].push_back( 750 pending_load_callback_[resource_id].push_back(
747 base::Bind(&util::EmptyFileOperationCallback)); 751 base::Bind(&util::EmptyFileOperationCallback));
752
753 // Start fetching the directory content, and mark it with the changestamp
754 // |last_known_remote_changestamp_|. To be precise, instead we need to call
755 // GetAboutResource() to get the latest changestamp. However,
756 // - It is costly to do GetAboutResource HTTP request every time.
757 // - The chance using an old value is small; it only happens when LoadIfNeeded
758 // is called during one GetAboutResource roundtrip time of a feed fetching.
759 // - Even if the value is old, it just marks the directory as older. It may
760 // trigger one future unnecessary re-fetch, but it'll never lose data, etc.
761 DirectoryFetchInfo new_directory_fetch_info(
762 directory_fetch_info.resource_id(),
763 std::max(directory_fetch_info.changestamp(),
764 last_known_remote_changestamp_));
748 DoLoadDirectoryFromServer( 765 DoLoadDirectoryFromServer(
749 directory_fetch_info, 766 new_directory_fetch_info,
750 base::Bind(&ChangeListLoader::OnDirectoryLoadComplete, 767 base::Bind(&ChangeListLoader::OnDirectoryLoadComplete,
751 weak_ptr_factory_.GetWeakPtr(), 768 weak_ptr_factory_.GetWeakPtr(),
752 directory_fetch_info, 769 directory_fetch_info,
753 callback)); 770 callback));
754 } 771 }
755 772
756 void ChangeListLoader::NotifyDirectoryChangedAfterApplyFeed( 773 void ChangeListLoader::NotifyDirectoryChangedAfterApplyFeed(
757 bool should_notify_changed_directories, 774 bool should_notify_changed_directories,
758 const base::Closure& update_finished_callback) { 775 const base::Closure& update_finished_callback) {
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 for (size_t i = 0; i < callbacks.size(); ++i) { 867 for (size_t i = 0; i < callbacks.size(); ++i) {
851 base::MessageLoopProxy::current()->PostTask( 868 base::MessageLoopProxy::current()->PostTask(
852 FROM_HERE, 869 FROM_HERE,
853 base::Bind(callbacks[i], error)); 870 base::Bind(callbacks[i], error));
854 } 871 }
855 pending_load_callback_.erase(it); 872 pending_load_callback_.erase(it);
856 } 873 }
857 } 874 }
858 875
859 } // namespace drive 876 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698