diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-19 12:11:22 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-19 12:11:22 +0000 |
commit | 0d28b24bbddcf76e4b254e1cf4c6eacadbcda096 (patch) | |
tree | cfbd4c57bf397d85de73489b25dd4d4736d585b1 | |
parent | 275dafa8c0b0491b08b236dfcc88f73d28505f05 (diff) | |
download | chromium_src-0d28b24bbddcf76e4b254e1cf4c6eacadbcda096.zip chromium_src-0d28b24bbddcf76e4b254e1cf4c6eacadbcda096.tar.gz chromium_src-0d28b24bbddcf76e4b254e1cf4c6eacadbcda096.tar.bz2 |
Add ChangeListLoaderObserver::OnInitialFeedLoaded().
This is a preparation for moving Load"IfNeeded" logic from
DriveFileSystem to ChangeListLoader.
BUG=178348
Review URL: https://codereview.chromium.org/12620011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188998 0039d316-1c4b-4281-b951-d872f2087c98
13 files changed, 44 insertions, 48 deletions
diff --git a/chrome/browser/chromeos/drive/change_list_loader.cc b/chrome/browser/chromeos/drive/change_list_loader.cc index 3cbf6df..9fdea6f 100644 --- a/chrome/browser/chromeos/drive/change_list_loader.cc +++ b/chrome/browser/chromeos/drive/change_list_loader.cc @@ -464,6 +464,7 @@ void ChangeListLoader::UpdateMetadataFromFeedAfterLoadFromServer( feed_changestamp, base::Bind(&ChangeListLoader::OnUpdateFromFeed, weak_ptr_factory_.GetWeakPtr(), + !loaded(), // is_initial_load callback)); } @@ -628,6 +629,9 @@ void ChangeListLoader::LoadAfterLoadFromCache( // The loading from the cache file succeeded. Change the refreshing state // and tell the callback that the loading was successful. OnChangeListLoadComplete(callback, DRIVE_FILE_OK); + FOR_EACH_OBSERVER(ChangeListLoaderObserver, + observers_, + OnInitialFeedLoaded()); // Load from server if needed (i.e. the cache is old). Note that we // should still propagate |directory_fetch_info| though the directory is @@ -757,11 +761,17 @@ void ChangeListLoader::NotifyDirectoryChangedAfterApplyFeed( } void ChangeListLoader::OnUpdateFromFeed( + bool is_inital_load, const FileOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); OnChangeListLoadComplete(callback, DRIVE_FILE_OK); + if (is_inital_load) { + FOR_EACH_OBSERVER(ChangeListLoaderObserver, + observers_, + OnInitialFeedLoaded()); + } // Save file system metadata to disk. SaveFileSystem(); diff --git a/chrome/browser/chromeos/drive/change_list_loader.h b/chrome/browser/chromeos/drive/change_list_loader.h index 98e418b..fb2e2d2 100644 --- a/chrome/browser/chromeos/drive/change_list_loader.h +++ b/chrome/browser/chromeos/drive/change_list_loader.h @@ -254,7 +254,8 @@ class ChangeListLoader { const base::Closure& update_finished_callback); // Callback for UpdateFromFeed. - void OnUpdateFromFeed(const FileOperationCallback& load_finished_callback); + void OnUpdateFromFeed(bool is_initial_load, + const FileOperationCallback& load_finished_callback); // This function should be called when the change list load is complete. // Runs |callback| with |error|, and flushes the pending callbacks. diff --git a/chrome/browser/chromeos/drive/change_list_loader_observer.h b/chrome/browser/chromeos/drive/change_list_loader_observer.h index ad96ff8..b00fbd7 100644 --- a/chrome/browser/chromeos/drive/change_list_loader_observer.h +++ b/chrome/browser/chromeos/drive/change_list_loader_observer.h @@ -30,6 +30,11 @@ class ChangeListLoaderObserver { virtual void OnFeedFromServerLoaded() { } + // Triggered when the feed is loaded for the first time, either from the + // cache or the server. + virtual void OnInitialFeedLoaded() { + } + protected: virtual ~ChangeListLoaderObserver() {} }; diff --git a/chrome/browser/chromeos/drive/drive_file_system.cc b/chrome/browser/chromeos/drive/drive_file_system.cc index b343486..7cc0dd0 100644 --- a/chrome/browser/chromeos/drive/drive_file_system.cc +++ b/chrome/browser/chromeos/drive/drive_file_system.cc @@ -241,10 +241,8 @@ void DriveFileSystem::Reload() { change_list_loader_->LoadFromServerIfNeeded( DirectoryFetchInfo(), - base::Bind(&DriveFileSystem::NotifyInitialLoadFinishedAndRun, - weak_ptr_factory_.GetWeakPtr(), - base::Bind(&DriveFileSystem::OnUpdateChecked, - weak_ptr_factory_.GetWeakPtr()))); + base::Bind(&DriveFileSystem::OnUpdateChecked, + weak_ptr_factory_.GetWeakPtr())); } void DriveFileSystem::Initialize() { @@ -425,11 +423,7 @@ void DriveFileSystem::LoadIfNeeded( return; } - change_list_loader_->Load( - directory_fetch_info, - base::Bind(&DriveFileSystem::NotifyInitialLoadFinishedAndRun, - weak_ptr_factory_.GetWeakPtr(), - callback)); + change_list_loader_->Load(directory_fetch_info, callback); } void DriveFileSystem::TransferFileFromRemoteToLocal( @@ -1216,6 +1210,14 @@ void DriveFileSystem::OnFeedFromServerLoaded() { OnFeedFromServerLoaded()); } +void DriveFileSystem::OnInitialFeedLoaded() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + FOR_EACH_OBSERVER(DriveFileSystemObserver, + observers_, + OnInitialLoadFinished()); +} + void DriveFileSystem::LoadFromCacheForTesting( const FileOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -1331,20 +1333,6 @@ void DriveFileSystem::NotifyFileSystemToBeUnmounted() { OnFileSystemBeingUnmounted()); } -void DriveFileSystem::NotifyInitialLoadFinishedAndRun( - const FileOperationCallback& callback, - DriveFileError error) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(!callback.is_null()); - - // Notify the observers that root directory has been loaded. - FOR_EACH_OBSERVER(DriveFileSystemObserver, - observers_, - OnInitialLoadFinished(error)); - - callback.Run(error); -} - void DriveFileSystem::AddUploadedFile( scoped_ptr<google_apis::ResourceEntry> entry, const base::FilePath& file_content_path, diff --git a/chrome/browser/chromeos/drive/drive_file_system.h b/chrome/browser/chromeos/drive/drive_file_system.h index baa9d0f..c3c0d2d 100644 --- a/chrome/browser/chromeos/drive/drive_file_system.h +++ b/chrome/browser/chromeos/drive/drive_file_system.h @@ -151,6 +151,7 @@ class DriveFileSystem : public DriveFileSystemInterface, const base::FilePath& directory_path) OVERRIDE; virtual void OnResourceListFetched(int num_accumulated_entries) OVERRIDE; virtual void OnFeedFromServerLoaded() OVERRIDE; + virtual void OnInitialFeedLoaded() OVERRIDE; // Used in tests to load the file system from the cache. void LoadFromCacheForTesting(const FileOperationCallback& callback); @@ -309,11 +310,6 @@ class DriveFileSystem : public DriveFileSystemInterface, // from CheckForUpdates(). void OnUpdateChecked(DriveFileError error); - // Notifies that the initial feed load is finished and runs |callback|. - // |callback| must not be null. - void NotifyInitialLoadFinishedAndRun(const FileOperationCallback& callback, - DriveFileError error); - // Helper function for internally handling responses from // GetFileFromCacheByResourceIdAndMd5() calls during processing of // GetFileByPath() request. diff --git a/chrome/browser/chromeos/drive/drive_file_system_observer.h b/chrome/browser/chromeos/drive/drive_file_system_observer.h index 0d3a678..a0ab283 100644 --- a/chrome/browser/chromeos/drive/drive_file_system_observer.h +++ b/chrome/browser/chromeos/drive/drive_file_system_observer.h @@ -25,7 +25,7 @@ class DriveFileSystemObserver { } // Triggered when the file system is initially loaded. - virtual void OnInitialLoadFinished(DriveFileError error) { + virtual void OnInitialLoadFinished() { } // Triggered when a document feed is fetched. |num_accumulated_entries| diff --git a/chrome/browser/chromeos/drive/drive_prefetcher.cc b/chrome/browser/chromeos/drive/drive_prefetcher.cc index 94e20ca..9704ee4 100644 --- a/chrome/browser/chromeos/drive/drive_prefetcher.cc +++ b/chrome/browser/chromeos/drive/drive_prefetcher.cc @@ -78,11 +78,10 @@ DrivePrefetcher::~DrivePrefetcher() { file_system_->RemoveObserver(this); } -void DrivePrefetcher::OnInitialLoadFinished(DriveFileError error) { +void DrivePrefetcher::OnInitialLoadFinished() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (error == DRIVE_FILE_OK) - StartPrefetcherCycle(); + StartPrefetcherCycle(); } void DrivePrefetcher::OnDirectoryChanged(const base::FilePath& directory_path) { diff --git a/chrome/browser/chromeos/drive/drive_prefetcher.h b/chrome/browser/chromeos/drive/drive_prefetcher.h index f35310f..5632b03 100644 --- a/chrome/browser/chromeos/drive/drive_prefetcher.h +++ b/chrome/browser/chromeos/drive/drive_prefetcher.h @@ -43,7 +43,7 @@ class DrivePrefetcher : public DriveFileSystemObserver { virtual ~DrivePrefetcher(); // DriveFileSystemObserver overrides. - virtual void OnInitialLoadFinished(DriveFileError error) OVERRIDE; + virtual void OnInitialLoadFinished() OVERRIDE; virtual void OnDirectoryChanged( const base::FilePath& directory_path) OVERRIDE; diff --git a/chrome/browser/chromeos/drive/drive_prefetcher_unittest.cc b/chrome/browser/chromeos/drive/drive_prefetcher_unittest.cc index ee2bc48..354b0b0 100644 --- a/chrome/browser/chromeos/drive/drive_prefetcher_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_prefetcher_unittest.cc @@ -174,7 +174,7 @@ class DrivePrefetcherTest : public testing::Test { EXPECT_CALL(*mock_file_system_, GetFileByResourceId(_, _, _, _)).Times(0); EXPECT_CALL(*mock_file_system_, GetFileByResourceId(_, _, _, _)) .WillRepeatedly(MockGetFile(&fetched_list)); - prefetcher_->OnInitialLoadFinished(DRIVE_FILE_OK); + prefetcher_->OnInitialLoadFinished(); RunMessageLoop(); EXPECT_EQ(expected, fetched_list); } diff --git a/chrome/browser/chromeos/drive/drive_sync_client.cc b/chrome/browser/chromeos/drive/drive_sync_client.cc index 1d5cd63..2b87df4 100644 --- a/chrome/browser/chromeos/drive/drive_sync_client.cc +++ b/chrome/browser/chromeos/drive/drive_sync_client.cc @@ -117,11 +117,10 @@ std::vector<std::string> DriveSyncClient::GetResourceIdsForTesting( return std::vector<std::string>(); } -void DriveSyncClient::OnInitialLoadFinished(DriveFileError error) { +void DriveSyncClient::OnInitialLoadFinished() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (error == DRIVE_FILE_OK) - StartProcessingBacklog(); + StartProcessingBacklog(); } void DriveSyncClient::OnFeedFromServerLoaded() { diff --git a/chrome/browser/chromeos/drive/drive_sync_client.h b/chrome/browser/chromeos/drive/drive_sync_client.h index 610ac43..435e072 100644 --- a/chrome/browser/chromeos/drive/drive_sync_client.h +++ b/chrome/browser/chromeos/drive/drive_sync_client.h @@ -62,7 +62,7 @@ class DriveSyncClient void Initialize(); // DriveFileSystemInterface::Observer overrides. - virtual void OnInitialLoadFinished(DriveFileError error) OVERRIDE; + virtual void OnInitialLoadFinished() OVERRIDE; virtual void OnFeedFromServerLoaded() OVERRIDE; // DriveCache::Observer overrides. diff --git a/chrome/browser/chromeos/drive/stale_cache_files_remover.cc b/chrome/browser/chromeos/drive/stale_cache_files_remover.cc index a6fb378..1029644 100644 --- a/chrome/browser/chromeos/drive/stale_cache_files_remover.cc +++ b/chrome/browser/chromeos/drive/stale_cache_files_remover.cc @@ -40,16 +40,14 @@ StaleCacheFilesRemover::~StaleCacheFilesRemover() { file_system_->RemoveObserver(this); } -void StaleCacheFilesRemover::OnInitialLoadFinished(DriveFileError error) { +void StaleCacheFilesRemover::OnInitialLoadFinished() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (error == DRIVE_FILE_OK) { - cache_->Iterate( - base::Bind( - &StaleCacheFilesRemover::GetEntryInfoAndRemoveCacheIfNecessary, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&base::DoNothing)); - } + cache_->Iterate( + base::Bind( + &StaleCacheFilesRemover::GetEntryInfoAndRemoveCacheIfNecessary, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&base::DoNothing)); } void StaleCacheFilesRemover::GetEntryInfoAndRemoveCacheIfNecessary( diff --git a/chrome/browser/chromeos/drive/stale_cache_files_remover.h b/chrome/browser/chromeos/drive/stale_cache_files_remover.h index d3f4350..9c6a31e 100644 --- a/chrome/browser/chromeos/drive/stale_cache_files_remover.h +++ b/chrome/browser/chromeos/drive/stale_cache_files_remover.h @@ -32,7 +32,7 @@ class StaleCacheFilesRemover : public DriveFileSystemObserver { // Removes stale cache files. // Gets the list of all the resource id and calls OnGetResourceIdsOfAllFiles() // with the list. - virtual void OnInitialLoadFinished(DriveFileError error) OVERRIDE; + virtual void OnInitialLoadFinished() OVERRIDE; // Gets the file entry and calls RemoveCacheIfNecessary() with the file entry. // This is called from StaleCacheFilesRemover::OnInitialLoadFinished. |