diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 04:09:46 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 04:09:46 +0000 |
commit | ebc70e245c387f1f94137b4db0124c43e2ec98b0 (patch) | |
tree | 2b58e8d700c665a3ce82a59003e708844ad82bc2 | |
parent | 42b7dff0c290c85284ca922ae06a057faf0f03a3 (diff) | |
download | chromium_src-ebc70e245c387f1f94137b4db0124c43e2ec98b0.zip chromium_src-ebc70e245c387f1f94137b4db0124c43e2ec98b0.tar.gz chromium_src-ebc70e245c387f1f94137b4db0124c43e2ec98b0.tar.bz2 |
drive: Remove MD5 argument from FileCache::Pin/Unpin
BUG=246486
TEST=unit_tests
R=kinaba@chromium.org
Review URL: https://codereview.chromium.org/17223005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206895 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/drive/file_cache.cc | 22 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/file_cache.h | 7 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/file_cache_unittest.cc | 49 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/file_system.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/file_system/update_operation_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/sync_client.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/sync_client_unittest.cc | 11 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/test_util.cc | 1 |
8 files changed, 35 insertions, 61 deletions
diff --git a/chrome/browser/chromeos/drive/file_cache.cc b/chrome/browser/chromeos/drive/file_cache.cc index 2d7fb23..42f0f4d 100644 --- a/chrome/browser/chromeos/drive/file_cache.cc +++ b/chrome/browser/chromeos/drive/file_cache.cc @@ -419,7 +419,6 @@ FileError FileCache::Store(const std::string& resource_id, } void FileCache::PinOnUIThread(const std::string& resource_id, - const std::string& md5, const FileOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); @@ -427,24 +426,21 @@ void FileCache::PinOnUIThread(const std::string& resource_id, base::PostTaskAndReplyWithResult( blocking_task_runner_.get(), FROM_HERE, - base::Bind(&FileCache::Pin, base::Unretained(this), resource_id, md5), + base::Bind(&FileCache::Pin, base::Unretained(this), resource_id), callback); } -FileError FileCache::Pin(const std::string& resource_id, - const std::string& md5) { +FileError FileCache::Pin(const std::string& resource_id) { AssertOnSequencedWorkerPool(); FileCacheEntry cache_entry; - if (!GetCacheEntry(resource_id, md5, &cache_entry)) - cache_entry.set_md5(md5); + metadata_->GetCacheEntry(resource_id, &cache_entry); cache_entry.set_is_pinned(true); metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); return FILE_ERROR_OK; } void FileCache::UnpinOnUIThread(const std::string& resource_id, - const std::string& md5, const FileOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); @@ -452,26 +448,20 @@ void FileCache::UnpinOnUIThread(const std::string& resource_id, base::PostTaskAndReplyWithResult( blocking_task_runner_.get(), FROM_HERE, - base::Bind(&FileCache::Unpin, base::Unretained(this), resource_id, md5), + base::Bind(&FileCache::Unpin, base::Unretained(this), resource_id), callback); } -FileError FileCache::Unpin(const std::string& resource_id, - const std::string& md5) { +FileError FileCache::Unpin(const std::string& resource_id) { AssertOnSequencedWorkerPool(); // Unpinning a file means its entry must exist in cache. FileCacheEntry cache_entry; - if (!GetCacheEntry(resource_id, md5, &cache_entry)) { - LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" - << resource_id - << ", md5=" << md5; + if (!metadata_->GetCacheEntry(resource_id, &cache_entry)) return FILE_ERROR_NOT_FOUND; - } // Now that file operations have completed, update metadata. if (cache_entry.is_present()) { - cache_entry.set_md5(md5); cache_entry.set_is_pinned(false); metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); } else { diff --git a/chrome/browser/chromeos/drive/file_cache.h b/chrome/browser/chromeos/drive/file_cache.h index c9dcbf3..6399977 100644 --- a/chrome/browser/chromeos/drive/file_cache.h +++ b/chrome/browser/chromeos/drive/file_cache.h @@ -190,23 +190,20 @@ class FileCache { // |callback| must not be null. // Must be called on the UI thread. void PinOnUIThread(const std::string& resource_id, - const std::string& md5, const FileOperationCallback& callback); // Pins the specified entry. - FileError Pin(const std::string& resource_id, - const std::string& md5); + FileError Pin(const std::string& resource_id); // Runs Unpin() on |blocking_task_runner_|, and calls |callback| with the // result asynchronously. // |callback| must not be null. // Must be called on the UI thread. void UnpinOnUIThread(const std::string& resource_id, - const std::string& md5, const FileOperationCallback& callback); // Unpins the specified entry. - FileError Unpin(const std::string& resource_id, const std::string& md5); + FileError Unpin(const std::string& resource_id); // Sets the state of the cache entry corresponding to |resource_id| as // mounted. diff --git a/chrome/browser/chromeos/drive/file_cache_unittest.cc b/chrome/browser/chromeos/drive/file_cache_unittest.cc index d26b7d6..0bc2d17 100644 --- a/chrome/browser/chromeos/drive/file_cache_unittest.cc +++ b/chrome/browser/chromeos/drive/file_cache_unittest.cc @@ -165,7 +165,6 @@ class FileCacheTestOnUIThread : public testing::Test { } void TestPin(const std::string& resource_id, - const std::string& md5, FileError expected_error, int expected_cache_state) { expected_error_ = expected_error; @@ -173,14 +172,13 @@ class FileCacheTestOnUIThread : public testing::Test { FileError error = FILE_ERROR_OK; cache_->PinOnUIThread( - resource_id, md5, + resource_id, google_apis::test_util::CreateCopyResultCallback(&error)); google_apis::test_util::RunBlockingPoolTask(); - VerifyCacheFileState(error, resource_id, md5); + VerifyCacheFileState(error, resource_id, std::string()); } void TestUnpin(const std::string& resource_id, - const std::string& md5, FileError expected_error, int expected_cache_state) { expected_error_ = expected_error; @@ -188,10 +186,10 @@ class FileCacheTestOnUIThread : public testing::Test { FileError error = FILE_ERROR_OK; cache_->UnpinOnUIThread( - resource_id, md5, + resource_id, google_apis::test_util::CreateCopyResultCallback(&error)); google_apis::test_util::RunBlockingPoolTask(); - VerifyCacheFileState(error, resource_id, md5); + VerifyCacheFileState(error, resource_id, std::string()); } void TestMarkDirty(const std::string& resource_id, @@ -320,7 +318,7 @@ class FileCacheTestOnUIThread : public testing::Test { // Verify actual cache file. base::FilePath dest_path = cache_->GetCacheFilePath( resource_id, - md5, + cache_entry.md5(), test_util::ToCacheEntry(expected_cache_state_).is_dirty() ? FileCache::CACHED_FILE_LOCALLY_MODIFIED : FileCache::CACHED_FILE_FROM_SERVER); @@ -507,34 +505,31 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpin) { FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); // Pin the existing file in cache. - TestPin(resource_id, md5, FILE_ERROR_OK, + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_PINNED); // Unpin the existing file in cache. - TestUnpin(resource_id, md5, FILE_ERROR_OK, - test_util::TEST_CACHE_STATE_PRESENT); + TestUnpin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); // Pin back the same existing file in cache. - TestPin(resource_id, md5, FILE_ERROR_OK, + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_PINNED); // Pin a non-existent file in cache. resource_id = "document:1a2b"; - TestPin(resource_id, md5, FILE_ERROR_OK, - test_util::TEST_CACHE_STATE_PINNED); + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PINNED); // Unpin the previously pinned non-existent file in cache. - TestUnpin(resource_id, md5, FILE_ERROR_OK, - test_util::TEST_CACHE_STATE_NONE); + TestUnpin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_NONE); // Unpin a file that doesn't exist in cache and is not pinned, i.e. cache // has zero knowledge of the file. resource_id = "not-in-cache:1a2b"; - TestUnpin(resource_id, md5, FILE_ERROR_NOT_FOUND, + TestUnpin(resource_id, FILE_ERROR_NOT_FOUND, test_util::TEST_CACHE_STATE_NONE); } @@ -543,8 +538,7 @@ TEST_F(FileCacheTestOnUIThread, StoreToCachePinned) { std::string md5("abcdef0123456789"); // Pin a non-existent file. - TestPin(resource_id, md5, FILE_ERROR_OK, - test_util::TEST_CACHE_STATE_PINNED); + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PINNED); // Store an existing file to a previously pinned file. TestStoreToCache(resource_id, md5, dummy_file_path_, @@ -565,8 +559,7 @@ TEST_F(FileCacheTestOnUIThread, GetFromCachePinned) { std::string md5("abcdef0123456789"); // Pin a non-existent file. - TestPin(resource_id, md5, FILE_ERROR_OK, - test_util::TEST_CACHE_STATE_PINNED); + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PINNED); // Get the non-existent pinned file from cache. TestGetFileFromCacheByResourceIdAndMd5( @@ -591,7 +584,7 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromCachePinned) { // Store a file to cache, and pin it. TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); - TestPin(resource_id, md5, FILE_ERROR_OK, + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_PINNED); @@ -604,7 +597,7 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromCachePinned) { TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); - TestPin(resource_id, md5, FILE_ERROR_OK, + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_PINNED); @@ -636,7 +629,7 @@ TEST_F(FileCacheTestOnUIThread, DirtyCachePinned) { // First store a file to cache and pin it. TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); - TestPin(resource_id, md5, FILE_ERROR_OK, + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_PINNED); @@ -674,7 +667,7 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) { EXPECT_TRUE(file_util::PathExists(dirty_path)); // Pin the dirty file. - TestPin(resource_id, md5, FILE_ERROR_OK, + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_DIRTY | test_util::TEST_CACHE_STATE_PINNED); @@ -683,7 +676,7 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) { EXPECT_TRUE(file_util::PathExists(dirty_path)); // Unpin the dirty file. - TestUnpin(resource_id, md5, FILE_ERROR_OK, + TestUnpin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_DIRTY); @@ -757,7 +750,7 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) { // Store a file to cache, pin it, mark it dirty and commit it. TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); - TestPin(resource_id, md5, FILE_ERROR_OK, + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_PINNED); TestMarkDirty(resource_id, md5, FILE_ERROR_OK, @@ -892,7 +885,7 @@ TEST_F(FileCacheTestOnUIThread, UpdatePinnedCache) { test_util::TEST_CACHE_STATE_PRESENT); // Pin the file. - TestPin(resource_id, md5, FILE_ERROR_OK, + TestPin(resource_id, FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT | test_util::TEST_CACHE_STATE_PINNED); @@ -1005,7 +998,7 @@ TEST_F(FileCacheTest, FreeDiskSpaceIfNeededFor) { ASSERT_EQ(FILE_ERROR_OK, cache_->Store(resource_id_pinned, md5_pinned, src_file, FileCache::FILE_OPERATION_COPY)); - ASSERT_EQ(FILE_ERROR_OK, cache_->Pin(resource_id_pinned, md5_pinned)); + ASSERT_EQ(FILE_ERROR_OK, cache_->Pin(resource_id_pinned)); base::FilePath pinned_path; ASSERT_EQ(FILE_ERROR_OK, cache_->GetFile(resource_id_pinned, md5_pinned, &pinned_path)); diff --git a/chrome/browser/chromeos/drive/file_system.cc b/chrome/browser/chromeos/drive/file_system.cc index f0ec525..7b057a3 100644 --- a/chrome/browser/chromeos/drive/file_system.cc +++ b/chrome/browser/chromeos/drive/file_system.cc @@ -367,7 +367,6 @@ void FileSystem::PinAfterGetResourceEntryByPath( DCHECK(entry); cache_->PinOnUIThread(entry->resource_id(), - entry->file_specific_info().md5(), base::Bind(&FileSystem::FinishPin, weak_ptr_factory_.GetWeakPtr(), callback, @@ -415,7 +414,6 @@ void FileSystem::UnpinAfterGetResourceEntryByPath( DCHECK(entry); cache_->UnpinOnUIThread(entry->resource_id(), - entry->file_specific_info().md5(), base::Bind(&FileSystem::FinishUnpin, weak_ptr_factory_.GetWeakPtr(), callback, diff --git a/chrome/browser/chromeos/drive/file_system/update_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/update_operation_unittest.cc index a2ad16d..bb8b428 100644 --- a/chrome/browser/chromeos/drive/file_system/update_operation_unittest.cc +++ b/chrome/browser/chromeos/drive/file_system/update_operation_unittest.cc @@ -45,7 +45,7 @@ TEST_F(UpdateOperationTest, UpdateFileByResourceId_PersistentFile) { // Pin the file so it'll be store in "persistent" directory. FileError error = FILE_ERROR_FAILED; cache()->PinOnUIThread( - kResourceId, kMd5, + kResourceId, google_apis::test_util::CreateCopyResultCallback(&error)); google_apis::test_util::RunBlockingPoolTask(); EXPECT_EQ(FILE_ERROR_OK, error); diff --git a/chrome/browser/chromeos/drive/sync_client.cc b/chrome/browser/chromeos/drive/sync_client.cc index aa29172..afcc759 100644 --- a/chrome/browser/chromeos/drive/sync_client.cc +++ b/chrome/browser/chromeos/drive/sync_client.cc @@ -263,7 +263,6 @@ void SyncClient::OnRemove(const std::string& resource_id, // Before fetching, we should pin this file again, so that the fetched file // is downloaded properly to the persistent directory and marked pinned. cache_->PinOnUIThread(resource_id, - std::string(), base::Bind(&SyncClient::OnPinned, weak_ptr_factory_.GetWeakPtr(), resource_id)); @@ -299,7 +298,6 @@ void SyncClient::OnFetchFileComplete(const std::string& resource_id, // If user cancels download, unpin the file so that we do not sync the // file again. cache_->UnpinOnUIThread(resource_id, - std::string(), base::Bind(&util::EmptyFileOperationCallback)); break; case FILE_ERROR_NO_CONNECTION: diff --git a/chrome/browser/chromeos/drive/sync_client_unittest.cc b/chrome/browser/chromeos/drive/sync_client_unittest.cc index 876b689..e3b5ef3 100644 --- a/chrome/browser/chromeos/drive/sync_client_unittest.cc +++ b/chrome/browser/chromeos/drive/sync_client_unittest.cc @@ -141,13 +141,13 @@ class SyncClientTest : public testing::Test { // Prepare 3 pinned-but-not-present files. ASSERT_NO_FATAL_FAILURE(AddFileEntry("foo")); - EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["foo"], std::string())); + EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["foo"])); ASSERT_NO_FATAL_FAILURE(AddFileEntry("bar")); - EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["bar"], std::string())); + EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["bar"])); ASSERT_NO_FATAL_FAILURE(AddFileEntry("baz")); - EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["baz"], std::string())); + EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["baz"])); // Prepare a pinned-and-fetched file. const std::string md5_fetched = "md5"; @@ -155,8 +155,7 @@ class SyncClientTest : public testing::Test { EXPECT_EQ(FILE_ERROR_OK, cache_->Store(resource_ids_["fetched"], md5_fetched, temp_file, FileCache::FILE_OPERATION_COPY)); - EXPECT_EQ(FILE_ERROR_OK, - cache_->Pin(resource_ids_["fetched"], md5_fetched)); + EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["fetched"])); // Prepare a pinned-and-fetched-and-dirty file. const std::string md5_dirty = ""; // Don't care. @@ -164,7 +163,7 @@ class SyncClientTest : public testing::Test { EXPECT_EQ(FILE_ERROR_OK, cache_->Store(resource_ids_["dirty"], md5_dirty, temp_file, FileCache::FILE_OPERATION_COPY)); - EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["dirty"], md5_dirty)); + EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["dirty"])); EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(resource_ids_["dirty"], md5_dirty)); diff --git a/chrome/browser/chromeos/drive/test_util.cc b/chrome/browser/chromeos/drive/test_util.cc index 1f7c685..895baba 100644 --- a/chrome/browser/chromeos/drive/test_util.cc +++ b/chrome/browser/chromeos/drive/test_util.cc @@ -117,7 +117,6 @@ bool PrepareTestCacheResources( FileError error = FILE_ERROR_OK; cache->PinOnUIThread( resources[i].resource_id, - resources[i].md5, google_apis::test_util::CreateCopyResultCallback(&error)); google_apis::test_util::RunBlockingPoolTask(); if (error != FILE_ERROR_OK) |