diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-18 19:35:49 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-18 19:35:49 +0000 |
commit | d7664c2ba4f3cf3e785d15acfb0b4eeb5f404c96 (patch) | |
tree | ff42975e938282f8926e1ea0798970a36041ca32 /chrome/browser/chromeos | |
parent | 961f03c7e62df2cae02b1d99309d7961043e0f46 (diff) | |
download | chromium_src-d7664c2ba4f3cf3e785d15acfb0b4eeb5f404c96.zip chromium_src-d7664c2ba4f3cf3e785d15acfb0b4eeb5f404c96.tar.gz chromium_src-d7664c2ba4f3cf3e785d15acfb0b4eeb5f404c96.tar.bz2 |
gdata: Add GDataCache::OnCacheCommitted event.
The event will be used to upload dirty files.
BUG=127080
TEST=add expectations to gdata_file_system_unittest.cc
Review URL: https://chromiumcodereview.appspot.com/10556047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142784 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
6 files changed, 43 insertions, 4 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_cache.cc b/chrome/browser/chromeos/gdata/gdata_cache.cc index 32539f3..9c07325 100644 --- a/chrome/browser/chromeos/gdata/gdata_cache.cc +++ b/chrome/browser/chromeos/gdata/gdata_cache.cc @@ -593,11 +593,12 @@ void GDataCache::CommitDirtyOnUIThread(const std::string& resource_id, md5, GDataCache::FILE_OPERATION_MOVE, error), - base::Bind(&RunCacheOperationCallback, - callback, + base::Bind(&GDataCache::OnCommitDirty, + ui_weak_ptr_, base::Owned(error), resource_id, - md5)); + md5, + callback)); } void GDataCache::ClearDirtyOnUIThread(const std::string& resource_id, @@ -1397,6 +1398,20 @@ void GDataCache::OnUnpinned(base::PlatformFileError* error, base::Owned(has_enough_space))); } +void GDataCache::OnCommitDirty(base::PlatformFileError* error, + const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(error); + + if (!callback.is_null()) + callback.Run(*error, resource_id, md5); + + if (*error == base::PLATFORM_FILE_OK) + FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); +} + // static FilePath GDataCache::GetCacheRootPath(Profile* profile) { FilePath cache_base_path; diff --git a/chrome/browser/chromeos/gdata/gdata_cache.h b/chrome/browser/chromeos/gdata/gdata_cache.h index 2032855..90d59cd 100644 --- a/chrome/browser/chromeos/gdata/gdata_cache.h +++ b/chrome/browser/chromeos/gdata/gdata_cache.h @@ -103,6 +103,9 @@ class GDataCache { virtual void OnCacheUnpinned(const std::string& resource_id, const std::string& md5) {} + // Triggered when a dirty file has been committed (saved) successfully. + virtual void OnCacheCommitted(const std::string& resource_id) {} + protected: virtual ~Observer() {} }; @@ -396,6 +399,12 @@ class GDataCache { const std::string& md5, const CacheOperationCallback& callback); + // Runs callback and notifies the observers when file is committed. + void OnCommitDirty(base::PlatformFileError* error, + const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback); + // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1). const FilePath cache_root_path_; // Paths for all subdirectories of GCache, one for each diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc index 0b6974f..db214ba 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc +++ b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc @@ -2666,6 +2666,7 @@ TEST_F(GDataFileSystemTest, RemoveFromCachePinned) { TEST_F(GDataFileSystemTest, DirtyCacheSimple) { std::string resource_id("pdf:1a2b"); std::string md5("abcdef0123456789"); + EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); // First store a file to cache. TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), @@ -2699,6 +2700,7 @@ TEST_F(GDataFileSystemTest, DirtyCachePinned) { std::string resource_id("pdf:1a2b"); std::string md5("abcdef0123456789"); EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); + EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); // First store a file to cache and pin it. TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), @@ -2781,6 +2783,7 @@ TEST_F(GDataFileSystemTest, PinAndUnpinDirtyCache) { TEST_F(GDataFileSystemTest, DirtyCacheRepetitive) { std::string resource_id("pdf:1a2b"); std::string md5("abcdef0123456789"); + EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(3); // First store a file to cache. TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), @@ -2912,6 +2915,7 @@ TEST_F(GDataFileSystemTest, RemoveFromDirtyCache) { std::string resource_id("pdf:1a2b"); std::string md5("abcdef0123456789"); EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); + EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); // Store a file to cache, pin it, mark it dirty and commit it. TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), @@ -3852,6 +3856,9 @@ TEST_F(GDataFileSystemTest, OpenAndCloseFile) { const std::string file_resource_id = entry->resource_id(); const std::string file_md5 = file->file_md5(); + // A dirty file is created on close. + EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(file_resource_id)).Times(1); + // Pretend we have enough space. EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); diff --git a/chrome/browser/chromeos/gdata/gdata_sync_client.cc b/chrome/browser/chromeos/gdata/gdata_sync_client.cc index f21b784..2536f6c 100644 --- a/chrome/browser/chromeos/gdata/gdata_sync_client.cc +++ b/chrome/browser/chromeos/gdata/gdata_sync_client.cc @@ -220,6 +220,13 @@ void GDataSyncClient::OnCacheUnpinned(const std::string& resource_id, queue_.erase(iter); } +void GDataSyncClient::OnCacheCommitted(const std::string& resource_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + // TODO(satorux): Initiate uploading of the committed file. + // crbug.com/127080 +} + void GDataSyncClient::OnInitialScanComplete( const base::Closure& closure, std::vector<std::string>* resource_ids) { diff --git a/chrome/browser/chromeos/gdata/gdata_sync_client.h b/chrome/browser/chromeos/gdata/gdata_sync_client.h index 7858f84..33ff5c8 100644 --- a/chrome/browser/chromeos/gdata/gdata_sync_client.h +++ b/chrome/browser/chromeos/gdata/gdata_sync_client.h @@ -76,6 +76,7 @@ class GDataSyncClient const std::string& md5) OVERRIDE; virtual void OnCacheUnpinned(const std::string& resource_id, const std::string& md5) OVERRIDE; + virtual void OnCacheCommitted(const std::string& resource_id) OVERRIDE; // Starts scanning the pinned directory in the cache to collect // pinned-but-not-fetched files. |closure| is run on the calling thread diff --git a/chrome/browser/chromeos/gdata/mock_gdata_sync_client.h b/chrome/browser/chromeos/gdata/mock_gdata_sync_client.h index 2ea030c..ac67674 100644 --- a/chrome/browser/chromeos/gdata/mock_gdata_sync_client.h +++ b/chrome/browser/chromeos/gdata/mock_gdata_sync_client.h @@ -32,7 +32,7 @@ class MockGDataSyncClient : public GDataSyncClientInterface, const std::string& md5)); MOCK_METHOD2(OnCacheUnpinned, void(const std::string& resource_id, const std::string& md5)); - // GDataSyncClient is not interested in OnDirectoryChanged. + MOCK_METHOD1(OnCacheCommitted, void(const std::string& resource_id)); }; } // namespace gdata |