Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_file_system.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| index bd79a7fada83c8cb2e48f257cbe1f9bfb8cc4cde..2e728553c791c7917603ba4e844754bf8da31535 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| @@ -77,6 +77,13 @@ const FilePath::CharType kFilesystemProtoFile[] = |
| FILE_PATH_LITERAL("file_system.pb"); |
| const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null"); |
| +// GData update check interval (in seconds). |
| +#ifndef NDEBUG |
| +const int kGDataUpdateCheckIntervalInSec = 5; |
| +#else |
| +const int kGDataUpdateCheckIntervalInSec = 60; |
| +#endif |
| + |
| // Schedule for dumping root file system proto buffers to disk depending its |
| // total protobuffer size in MB. |
| typedef struct { |
| @@ -928,6 +935,7 @@ GDataFileSystem::GDataFileSystem(Profile* profile, |
| true /* manual reset */, true /* initially signaled */)), |
| cache_initialization_started_(false), |
| num_pending_tasks_(0), |
| + update_timer_(true /* retain_user_task */, true /* is_repeating */), |
| hide_hosted_docs_(false), |
| ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( |
| new base::WeakPtrFactory<GDataFileSystem>(this))), |
| @@ -961,6 +969,18 @@ void GDataFileSystem::Initialize() { |
| InitializePreferenceObserver(); |
| } |
| +void GDataFileSystem::CheckForUpdates() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + ContentOrigin initial_origin = root_->origin(); |
| + if (initial_origin == FROM_SERVER) { |
| + root_->set_origin(REFRESHING); |
| + ReloadFeedFromServerIfNeeded(initial_origin, |
| + root_->largest_changestamp(), |
| + root_->GetFilePath(), |
| + gdata::FindEntryCallback()); |
| + } |
| +} |
| + |
| bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { |
| if (cache_initialization_started_) |
| return false; |
| @@ -1016,6 +1036,20 @@ void GDataFileSystem::RemoveObserver(Observer* observer) { |
| observers_.RemoveObserver(observer); |
| } |
| +void GDataFileSystem::StartUpdates() { |
| + DCHECK(!update_timer_.IsRunning()); |
| + update_timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromSeconds( |
| + kGDataUpdateCheckIntervalInSec), |
| + base::Bind(&GDataFileSystem::CheckForUpdates, |
| + ui_weak_ptr_)); |
| +} |
| + |
| +void GDataFileSystem::StopUpdates() { |
| + DCHECK(update_timer_.IsRunning()); |
|
hshi
2012/05/03 21:45:01
Ditto.
|
| + update_timer_.Stop(); |
| +} |
| + |
| void GDataFileSystem::Authenticate(const AuthStatusCallback& callback) { |
| // TokenFetcher, used in DocumentsService, must be run on UI thread. |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -1066,16 +1100,6 @@ void GDataFileSystem::FindEntryByPathAsyncOnUIThread( |
| search_file_path, |
| callback); |
| return; |
| - } else if (root_->NeedsRefresh()) { |
| - // If content is stale or from disk from cache, fetch content from |
| - // the server. |
| - ContentOrigin initial_origin = root_->origin(); |
| - root_->set_origin(REFRESHING); |
| - ReloadFeedFromServerIfNeeded(initial_origin, |
| - root_->largest_changestamp(), |
| - search_file_path, |
| - callback); |
| - return; |
| } |
| // Post a task to the same thread, rather than calling it here, as |