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..db7f37c3ef1ed8c3d956dae2cc605cf71a09fa37 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), |
| + num_file_watches_(0), |
| 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,26 @@ void GDataFileSystem::RemoveObserver(Observer* observer) { |
| observers_.RemoveObserver(observer); |
| } |
| +void GDataFileSystem::AddFileWatch(const FilePath&) { |
| + // Perform an immediate check for updates. |
| + CheckForUpdates(); |
| + // Start timer to periodically check for updates at the given intervals. |
| + if (!(num_file_watches_++)) { |
|
satorux1
2012/05/03 16:49:29
This looks tricky. maybe:
++num_file_watches_;
if
hshi
2012/05/03 17:46:35
Done.
|
| + file_watch_timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromSeconds( |
| + kGDataUpdateCheckIntervalInSec), |
| + this, &GDataFileSystem::CheckForUpdates); |
|
zel
2012/05/03 03:41:07
this should be ui_weak_ptr_ instead of 'this'
satorux1
2012/05/03 16:49:29
Looking at base/timer.h, there is another Start()
hshi
2012/05/03 17:46:35
Zel & Satoru, the documentation in base/timer.h ac
satorux1
2012/05/03 18:09:29
This is worrisome. Is this safe? I don't know how
|
| + } |
| +} |
| + |
| +void GDataFileSystem::RemoveFileWatch(const FilePath&) { |
| + if (num_file_watches_ <= 0) { |
| + NOTREACHED(); |
| + } else if (!(--num_file_watches_)) { |
|
satorux1
2012/05/03 16:49:29
This also looks tricky. maybe
else {
--num_fil
hshi
2012/05/03 17:46:35
Done.
|
| + file_watch_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 +1106,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 |