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..d829f86d59ade5a46923696656cc3a1e6f6a9182 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,8 @@ GDataFileSystem::GDataFileSystem(Profile* profile, |
true /* manual reset */, true /* initially signaled */)), |
cache_initialization_started_(false), |
num_pending_tasks_(0), |
+ num_update_requests_(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 +970,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 +1037,28 @@ void GDataFileSystem::RemoveObserver(Observer* observer) { |
observers_.RemoveObserver(observer); |
} |
+void GDataFileSystem::RequestStartUpdates() { |
+ // Perform an immediate check for updates. |
+ CheckForUpdates(); |
+ ++num_update_requests_; |
zel
2012/05/03 19:54:30
You should move num_update_requests_ logic to File
hshi
2012/05/03 21:17:49
Done.
|
+ if (num_update_requests_ == 1) { |
+ // If this is the first StartUpdate request, start timer to periodically |
+ // check for updates at the specified intervals. |
+ update_timer_.Start(FROM_HERE, |
+ base::TimeDelta::FromSeconds( |
+ kGDataUpdateCheckIntervalInSec), |
+ base::Bind(&GDataFileSystem::CheckForUpdates, |
+ ui_weak_ptr_)); |
+ } |
+} |
+ |
+void GDataFileSystem::RequestStopUpdates() { |
+ DCHECK_LE(0, num_update_requests_); |
+ --num_update_requests_; |
+ if (num_update_requests_ == 0) |
+ 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 +1109,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 |