diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-16 06:57:12 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-16 06:57:12 +0000 |
commit | 9971db1ebe9ff595e767fe80c45027e5cf43da73 (patch) | |
tree | a8064aa3c8e68c174c9e20a27b7164d2de3ee189 | |
parent | e0879c19fe65c1455d6eab36a4a01524465ffb08 (diff) | |
download | chromium_src-9971db1ebe9ff595e767fe80c45027e5cf43da73.zip chromium_src-9971db1ebe9ff595e767fe80c45027e5cf43da73.tar.gz chromium_src-9971db1ebe9ff595e767fe80c45027e5cf43da73.tar.bz2 |
drive: Remove FileCache::GetCacheEntry
BUG=275271
TEST=unit_tests
Review URL: https://codereview.chromium.org/285323002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270952 0039d316-1c4b-4281-b951-d872f2087c98
11 files changed, 110 insertions, 222 deletions
diff --git a/chrome/browser/chromeos/drive/file_cache.cc b/chrome/browser/chromeos/drive/file_cache.cc index 2cc936c..5fa5d82 100644 --- a/chrome/browser/chromeos/drive/file_cache.cc +++ b/chrome/browser/chromeos/drive/file_cache.cc @@ -71,13 +71,6 @@ bool FileCache::IsUnderFileCacheDirectory(const base::FilePath& path) const { return cache_file_directory_.IsParent(path); } -FileError FileCache::GetCacheEntry(const std::string& id, - FileCacheEntry* entry) { - DCHECK(entry); - AssertOnSequencedWorkerPool(); - return storage_->GetCacheEntry(id, entry); -} - bool FileCache::FreeDiskSpaceIfNeededFor(int64 num_bytes) { AssertOnSequencedWorkerPool(); diff --git a/chrome/browser/chromeos/drive/file_cache.h b/chrome/browser/chromeos/drive/file_cache.h index 2a18172..c85be5d 100644 --- a/chrome/browser/chromeos/drive/file_cache.h +++ b/chrome/browser/chromeos/drive/file_cache.h @@ -21,8 +21,6 @@ class SequencedTaskRunner; namespace drive { -class FileCacheEntry; - namespace internal { // Interface class used for getting the free disk space. Tests can inject an @@ -66,10 +64,6 @@ class FileCache { // Can be called on any thread. bool IsUnderFileCacheDirectory(const base::FilePath& path) const; - // Gets the cache entry for file corresponding to |id| and returns true if - // entry exists in cache map. - FileError GetCacheEntry(const std::string& id, FileCacheEntry* entry); - // Frees up disk space to store a file with |num_bytes| size content, while // keeping cryptohome::kMinFreeSpaceInBytes bytes on the disk, if needed. // Returns true if we successfully manage to have enough space, otherwise diff --git a/chrome/browser/chromeos/drive/file_cache_unittest.cc b/chrome/browser/chromeos/drive/file_cache_unittest.cc index 633552e..0f38245 100644 --- a/chrome/browser/chromeos/drive/file_cache_unittest.cc +++ b/chrome/browser/chromeos/drive/file_cache_unittest.cc @@ -60,6 +60,12 @@ class FileCacheTest : public testing::Test { return cache->RenameCacheFilesToNewFormat(); } + FileError GetCacheEntry(FileCache* cache, + const std::string& id, + FileCacheEntry* cache_entry) { + return cache->storage_->GetCacheEntry(id, cache_entry); + } + content::TestBrowserThreadBundle thread_bundle_; base::ScopedTempDir temp_dir_; base::FilePath cache_files_dir_; @@ -148,10 +154,10 @@ TEST_F(FileCacheTest, FreeDiskSpaceIfNeededFor) { // Only 'temporary' file gets removed. FileCacheEntry entry; - EXPECT_EQ(FILE_ERROR_NOT_FOUND, cache_->GetCacheEntry(id_tmp, &entry)); + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetCacheEntry(cache_.get(), id_tmp, &entry)); EXPECT_FALSE(base::PathExists(tmp_path)); - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id_pinned, &entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id_pinned, &entry)); EXPECT_TRUE(base::PathExists(pinned_path)); // Returns false when disk space cannot be freed. @@ -220,7 +226,7 @@ TEST_F(FileCacheTest, Store) { id, md5, src_file_path, FileCache::FILE_OPERATION_COPY)); FileCacheEntry cache_entry; - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &cache_entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &cache_entry)); EXPECT_TRUE(cache_entry.is_present()); EXPECT_EQ(md5, cache_entry.md5()); @@ -237,7 +243,7 @@ TEST_F(FileCacheTest, Store) { EXPECT_EQ(FILE_ERROR_OK, cache_->Store( id, std::string(), src_file_path, FileCache::FILE_OPERATION_COPY)); - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &cache_entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &cache_entry)); EXPECT_TRUE(cache_entry.is_present()); EXPECT_TRUE(cache_entry.md5().empty()); EXPECT_TRUE(cache_entry.is_dirty()); @@ -262,33 +268,34 @@ TEST_F(FileCacheTest, PinAndUnpin) { id, md5, src_file_path, FileCache::FILE_OPERATION_COPY)); FileCacheEntry cache_entry; - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &cache_entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &cache_entry)); EXPECT_FALSE(cache_entry.is_pinned()); // Pin the existing file. EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(id)); - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &cache_entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &cache_entry)); EXPECT_TRUE(cache_entry.is_pinned()); // Unpin the file. EXPECT_EQ(FILE_ERROR_OK, cache_->Unpin(id)); - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &cache_entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &cache_entry)); EXPECT_FALSE(cache_entry.is_pinned()); // Pin a non-present file. std::string id_non_present = "id_non_present"; EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(id_non_present)); - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id_non_present, &cache_entry)); + EXPECT_EQ(FILE_ERROR_OK, + GetCacheEntry(cache_.get(), id_non_present, &cache_entry)); EXPECT_TRUE(cache_entry.is_pinned()); // Unpin the previously pinned non-existent file. EXPECT_EQ(FILE_ERROR_OK, cache_->Unpin(id_non_present)); EXPECT_EQ(FILE_ERROR_NOT_FOUND, - cache_->GetCacheEntry(id_non_present, &cache_entry)); + GetCacheEntry(cache_.get(), id_non_present, &cache_entry)); // Unpin a file that doesn't exist in cache and is not pinned. EXPECT_EQ(FILE_ERROR_NOT_FOUND, cache_->Unpin("id_non_existent")); @@ -332,7 +339,7 @@ TEST_F(FileCacheTest, OpenForWrite) { // Entry is not dirty nor opened. EXPECT_FALSE(cache_->IsOpenedForWrite(id)); FileCacheEntry entry; - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &entry)); EXPECT_FALSE(entry.is_dirty()); // Open (1). @@ -341,7 +348,7 @@ TEST_F(FileCacheTest, OpenForWrite) { EXPECT_TRUE(cache_->IsOpenedForWrite(id)); // Entry is dirty. - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &entry)); EXPECT_TRUE(entry.is_dirty()); // Open (2). @@ -390,12 +397,12 @@ TEST_F(FileCacheTest, UpdateMd5) { // MD5 was cleared by OpenForWrite(). FileCacheEntry entry; - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &entry)); EXPECT_TRUE(entry.md5().empty()); // Update MD5. EXPECT_EQ(FILE_ERROR_OK, cache_->UpdateMd5(id)); - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &entry)); EXPECT_EQ(base::MD5String(contents_after), entry.md5()); } @@ -414,7 +421,7 @@ TEST_F(FileCacheTest, ClearDirty) { // Entry is dirty. FileCacheEntry entry; - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &entry)); EXPECT_TRUE(entry.is_dirty()); // Cannot clear the dirty bit of an opened entry. @@ -425,7 +432,7 @@ TEST_F(FileCacheTest, ClearDirty) { EXPECT_EQ(FILE_ERROR_OK, cache_->ClearDirty(id)); // Entry is not dirty. - EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &entry)); + EXPECT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &entry)); EXPECT_FALSE(entry.is_dirty()); } @@ -502,13 +509,14 @@ TEST_F(FileCacheTest, ClearAll) { // Verify that the cache entry is created. FileCacheEntry cache_entry; - ASSERT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(id, &cache_entry)); + ASSERT_EQ(FILE_ERROR_OK, GetCacheEntry(cache_.get(), id, &cache_entry)); // Clear cache. EXPECT_TRUE(cache_->ClearAll()); // Verify that the cache is removed. - EXPECT_EQ(FILE_ERROR_NOT_FOUND, cache_->GetCacheEntry(id, &cache_entry)); + EXPECT_EQ(FILE_ERROR_NOT_FOUND, + GetCacheEntry(cache_.get(), id, &cache_entry)); EXPECT_TRUE(base::IsDirectoryEmpty(cache_files_dir_)); } diff --git a/chrome/browser/chromeos/drive/file_system.cc b/chrome/browser/chromeos/drive/file_system.cc index 4fd1c20..598a375 100644 --- a/chrome/browser/chromeos/drive/file_system.cc +++ b/chrome/browser/chromeos/drive/file_system.cc @@ -62,16 +62,13 @@ FileError GetLocallyStoredResourceEntry( return FILE_ERROR_OK; // When cache is not found, use the original resource entry as is. - FileCacheEntry cache_entry; - error = cache->GetCacheEntry(local_id, &cache_entry); - if (error == FILE_ERROR_NOT_FOUND) + if (!entry->file_specific_info().has_cache_state()) return FILE_ERROR_OK; - if (error != FILE_ERROR_OK) - return error; // When cache is non-dirty and obsolete (old hash), use the original entry. - if (!cache_entry.is_dirty() && - entry->file_specific_info().md5() != cache_entry.md5()) + if (!entry->file_specific_info().cache_state().is_dirty() && + entry->file_specific_info().md5() != + entry->file_specific_info().cache_state().md5()) return FILE_ERROR_OK; // If there's a valid cache, obtain the file info from the cache file itself. diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation.cc b/chrome/browser/chromeos/drive/file_system/copy_operation.cc index 93ca0a1..d3f3af8 100644 --- a/chrome/browser/chromeos/drive/file_system/copy_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/copy_operation.cc @@ -117,11 +117,8 @@ FileError TryToCopyLocally(internal::ResourceMetadata* metadata, // If the cache file is not present and the entry exists on the server, // server side copy should be used. - FileCacheEntry cache_entry; - error = cache->GetCacheEntry(params->src_entry.local_id(), &cache_entry); - if (error != FILE_ERROR_OK && error != FILE_ERROR_NOT_FOUND) - return error; - if (!cache_entry.is_present() && !params->src_entry.resource_id().empty()) { + if (!params->src_entry.file_specific_info().cache_state().is_present() && + !params->src_entry.resource_id().empty()) { *should_copy_on_server = true; return FILE_ERROR_OK; } @@ -147,7 +144,7 @@ FileError TryToCopyLocally(internal::ResourceMetadata* metadata, updated_local_ids->push_back(local_id); *directory_changed = true; - if (!cache_entry.is_present()) { + if (!params->src_entry.file_specific_info().cache_state().is_present()) { DCHECK(params->src_entry.resource_id().empty()); // Locally created empty file may have no cache file. return FILE_ERROR_OK; diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc index ce6307b..7722301 100644 --- a/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc +++ b/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc @@ -59,21 +59,9 @@ TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_RegularFile) { // TransferFileFromLocalToRemote stores a copy of the local file in the cache, // marks it dirty and requests the observer to upload the file. EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); - EXPECT_EQ(1U, observer()->updated_local_ids().count( - GetLocalId(remote_dest_path))); - FileCacheEntry cache_entry; - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&internal::FileCache::GetCacheEntry, - base::Unretained(cache()), - GetLocalId(remote_dest_path), - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_OK, error); - EXPECT_TRUE(cache_entry.is_present()); - EXPECT_TRUE(cache_entry.is_dirty()); + EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); EXPECT_EQ(1U, observer()->get_changed_paths().size()); EXPECT_TRUE(observer()->get_changed_paths().count( @@ -105,17 +93,8 @@ TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_Overwrite) { // marks it dirty and requests the observer to upload the file. EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); - FileCacheEntry cache_entry; - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&internal::FileCache::GetCacheEntry, - base::Unretained(cache()), entry.local_id(), &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_OK, error); - EXPECT_TRUE(cache_entry.is_present()); - EXPECT_TRUE(cache_entry.is_dirty()); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); EXPECT_EQ(1U, observer()->get_changed_paths().size()); EXPECT_TRUE(observer()->get_changed_paths().count( @@ -349,18 +328,7 @@ TEST_F(CopyOperationTest, CopyDirtyFile) { EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); // Copied cache file should be dirty. - FileCacheEntry cache_entry; - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&internal::FileCache::GetCacheEntry, - base::Unretained(cache()), - dest_entry.local_id(), - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_OK, error); - EXPECT_TRUE(cache_entry.is_dirty()); + EXPECT_TRUE(dest_entry.file_specific_info().cache_state().is_dirty()); // File contents should match. base::FilePath cache_file_path; diff --git a/chrome/browser/chromeos/drive/file_system/open_file_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/open_file_operation_unittest.cc index a03bb4c..2c63a0e 100644 --- a/chrome/browser/chromeos/drive/file_system/open_file_operation_unittest.cc +++ b/chrome/browser/chromeos/drive/file_system/open_file_operation_unittest.cc @@ -163,19 +163,10 @@ TEST_F(OpenFileOperationTest, OpenOrCreateExistingFile) { close_callback.Run(); EXPECT_EQ(1U, observer()->updated_local_ids().count(src_entry.local_id())); - FileCacheEntry cache_entry; - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&internal::FileCache::GetCacheEntry, - base::Unretained(cache()), - src_entry.local_id(), - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_OK, error); - EXPECT_TRUE(cache_entry.is_present()); - EXPECT_TRUE(cache_entry.is_dirty()); + ResourceEntry result_entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &result_entry)); + EXPECT_TRUE(result_entry.file_specific_info().cache_state().is_present()); + EXPECT_TRUE(result_entry.file_specific_info().cache_state().is_dirty()); } TEST_F(OpenFileOperationTest, OpenOrCreateNonExistingFile) { diff --git a/chrome/browser/chromeos/drive/file_system_unittest.cc b/chrome/browser/chromeos/drive/file_system_unittest.cc index c202beb7..84b724d 100644 --- a/chrome/browser/chromeos/drive/file_system_unittest.cc +++ b/chrome/browser/chromeos/drive/file_system_unittest.cc @@ -797,11 +797,10 @@ TEST_F(FileSystemTest, PinAndUnpin) { test_util::RunBlockingPoolTask(); EXPECT_EQ(FILE_ERROR_OK, error); - FileCacheEntry cache_entry; - EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(entry->local_id(), &cache_entry)); - EXPECT_TRUE(cache_entry.is_pinned()); - EXPECT_TRUE(cache_entry.is_present()); + entry = GetResourceEntrySync(file_path); + ASSERT_TRUE(entry); + EXPECT_TRUE(entry->file_specific_info().cache_state().is_pinned()); + EXPECT_TRUE(entry->file_specific_info().cache_state().is_present()); // Unpin the file. error = FILE_ERROR_FAILED; @@ -810,9 +809,9 @@ TEST_F(FileSystemTest, PinAndUnpin) { test_util::RunBlockingPoolTask(); EXPECT_EQ(FILE_ERROR_OK, error); - EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(entry->local_id(), &cache_entry)); - EXPECT_FALSE(cache_entry.is_pinned()); + entry = GetResourceEntrySync(file_path); + ASSERT_TRUE(entry); + EXPECT_FALSE(entry->file_specific_info().cache_state().is_pinned()); // Pinned file gets synced and it results in entry state changes. ASSERT_EQ(1u, mock_directory_observer_->changed_directories().size()); @@ -845,9 +844,9 @@ TEST_F(FileSystemTest, PinAndUnpin_NotSynced) { EXPECT_EQ(FILE_ERROR_OK, error_unpin); // No cache file available because the sync was cancelled by Unpin(). - FileCacheEntry cache_entry; - EXPECT_EQ(FILE_ERROR_NOT_FOUND, - cache_->GetCacheEntry(entry->local_id(), &cache_entry)); + entry = GetResourceEntrySync(file_path); + ASSERT_TRUE(entry); + EXPECT_FALSE(entry->file_specific_info().cache_state().is_present()); } TEST_F(FileSystemTest, GetAvailableSpace) { diff --git a/chrome/browser/chromeos/drive/sync/entry_update_performer.cc b/chrome/browser/chromeos/drive/sync/entry_update_performer.cc index dbc018a..47954b2 100644 --- a/chrome/browser/chromeos/drive/sync/entry_update_performer.cc +++ b/chrome/browser/chromeos/drive/sync/entry_update_performer.cc @@ -54,12 +54,9 @@ FileError PrepareUpdate(ResourceMetadata* metadata, if (error != FILE_ERROR_OK) return error; - FileCacheEntry cache_entry; - error = cache->GetCacheEntry(local_id, &cache_entry); - if (error != FILE_ERROR_OK && error != FILE_ERROR_NOT_FOUND) - return error; if (!local_state->entry.file_info().is_directory() && - !cache_entry.is_present() && local_state->entry.resource_id().empty()) { + !local_state->entry.file_specific_info().cache_state().is_present() && + local_state->entry.resource_id().empty()) { // Locally created file with no cache file, store an empty file. base::FilePath empty_file; if (!base::CreateTemporaryFile(&empty_file)) @@ -68,24 +65,26 @@ FileError PrepareUpdate(ResourceMetadata* metadata, FileCache::FILE_OPERATION_MOVE); if (error != FILE_ERROR_OK) return error; - error = cache->GetCacheEntry(local_id, &cache_entry); + error = metadata->GetResourceEntryById(local_id, &local_state->entry); if (error != FILE_ERROR_OK) return error; } // Check if content update is needed or not. - if (cache_entry.is_dirty() && !cache->IsOpenedForWrite(local_id)) { + if (local_state->entry.file_specific_info().cache_state().is_dirty() && + !cache->IsOpenedForWrite(local_id)) { // Update cache entry's MD5 if needed. - if (cache_entry.md5().empty()) { + if (local_state->entry.file_specific_info().cache_state().md5().empty()) { error = cache->UpdateMd5(local_id); if (error != FILE_ERROR_OK) return error; - error = cache->GetCacheEntry(local_id, &cache_entry); + error = metadata->GetResourceEntryById(local_id, &local_state->entry); if (error != FILE_ERROR_OK) return error; } - if (cache_entry.md5() == local_state->entry.file_specific_info().md5()) { + if (local_state->entry.file_specific_info().cache_state().md5() == + local_state->entry.file_specific_info().md5()) { error = cache->ClearDirty(local_id); if (error != FILE_ERROR_OK) return error; @@ -166,12 +165,9 @@ FileError FinishUpdate(ResourceMetadata* metadata, return error; // Clear dirty bit unless the file has been edited during update. - FileCacheEntry cache_entry; - error = cache->GetCacheEntry(local_id, &cache_entry); - if (error != FILE_ERROR_OK && error != FILE_ERROR_NOT_FOUND) - return error; - if (cache_entry.is_dirty() && - cache_entry.md5() == entry.file_specific_info().md5()) { + if (entry.file_specific_info().cache_state().is_dirty() && + entry.file_specific_info().cache_state().md5() == + entry.file_specific_info().md5()) { error = cache->ClearDirty(local_id); if (error != FILE_ERROR_OK) return error; diff --git a/chrome/browser/chromeos/drive/sync/entry_update_performer_unittest.cc b/chrome/browser/chromeos/drive/sync/entry_update_performer_unittest.cc index 241294c..6481cb3 100644 --- a/chrome/browser/chromeos/drive/sync/entry_update_performer_unittest.cc +++ b/chrome/browser/chromeos/drive/sync/entry_update_performer_unittest.cc @@ -235,18 +235,9 @@ TEST_F(EntryUpdatePerformerTest, UpdateEntry_ContentUpdate) { server_entry->file_size()); // Make sure that the cache is no longer dirty. - FileCacheEntry cache_entry; - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&FileCache::GetCacheEntry, - base::Unretained(cache()), - local_id, - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - ASSERT_EQ(FILE_ERROR_OK, error); - EXPECT_FALSE(cache_entry.is_dirty()); + ResourceEntry entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); } TEST_F(EntryUpdatePerformerTest, UpdateEntry_ContentUpdateMd5Check) { @@ -288,18 +279,9 @@ TEST_F(EntryUpdatePerformerTest, UpdateEntry_ContentUpdateMd5Check) { server_entry->file_size()); // Make sure that the cache is no longer dirty. - FileCacheEntry cache_entry; - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&FileCache::GetCacheEntry, - base::Unretained(cache()), - local_id, - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - ASSERT_EQ(FILE_ERROR_OK, error); - EXPECT_FALSE(cache_entry.is_dirty()); + ResourceEntry entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); // Again mark the cache file dirty. scoped_ptr<base::ScopedClosureRunner> file_closer; @@ -332,17 +314,8 @@ TEST_F(EntryUpdatePerformerTest, UpdateEntry_ContentUpdateMd5Check) { fake_service()->about_resource().largest_change_id()); // Make sure that the cache is no longer dirty. - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&FileCache::GetCacheEntry, - base::Unretained(cache()), - local_id, - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - ASSERT_EQ(FILE_ERROR_OK, error); - EXPECT_FALSE(cache_entry.is_dirty()); + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); } TEST_F(EntryUpdatePerformerTest, UpdateEntry_OpenedForWrite) { @@ -379,18 +352,9 @@ TEST_F(EntryUpdatePerformerTest, UpdateEntry_OpenedForWrite) { EXPECT_EQ(FILE_ERROR_OK, error); // Make sure that the cache is still dirty. - FileCacheEntry cache_entry; - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&FileCache::GetCacheEntry, - base::Unretained(cache()), - local_id, - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_OK, error); - EXPECT_TRUE(cache_entry.is_dirty()); + ResourceEntry entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); // Close the file. file_closer.reset(); @@ -405,17 +369,8 @@ TEST_F(EntryUpdatePerformerTest, UpdateEntry_OpenedForWrite) { EXPECT_EQ(FILE_ERROR_OK, error); // Make sure that the cache is no longer dirty. - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&FileCache::GetCacheEntry, - base::Unretained(cache()), - local_id, - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_OK, error); - EXPECT_FALSE(cache_entry.is_dirty()); + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); } TEST_F(EntryUpdatePerformerTest, UpdateEntry_UploadNewFile) { @@ -459,18 +414,7 @@ TEST_F(EntryUpdatePerformerTest, UpdateEntry_UploadNewFile) { EXPECT_EQ(ResourceEntry::CLEAN, entry.metadata_edit_state()); // Make sure that the cache is no longer dirty. - FileCacheEntry cache_entry; - base::PostTaskAndReplyWithResult( - blocking_task_runner(), - FROM_HERE, - base::Bind(&FileCache::GetCacheEntry, - base::Unretained(cache()), - local_id, - &cache_entry), - google_apis::test_util::CreateCopyResultCallback(&error)); - test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_OK, error); - EXPECT_FALSE(cache_entry.is_dirty()); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); // Make sure that we really created a file. google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; diff --git a/chrome/browser/chromeos/drive/sync_client_unittest.cc b/chrome/browser/chromeos/drive/sync_client_unittest.cc index b39d989..a99b368 100644 --- a/chrome/browser/chromeos/drive/sync_client_unittest.cc +++ b/chrome/browser/chromeos/drive/sync_client_unittest.cc @@ -275,24 +275,24 @@ TEST_F(SyncClientTest, StartProcessingBacklog) { sync_client_->StartProcessingBacklog(); base::RunLoop().RunUntilIdle(); - FileCacheEntry cache_entry; + ResourceEntry entry; // Pinned files get downloaded. EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); - EXPECT_TRUE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("foo"), &entry)); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("bar"), &cache_entry)); - EXPECT_TRUE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("bar"), &entry)); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("baz"), &cache_entry)); - EXPECT_TRUE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("baz"), &entry)); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); // Dirty file gets uploaded. EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); - EXPECT_FALSE(cache_entry.is_dirty()); + metadata_->GetResourceEntryById(GetLocalId("dirty"), &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); // Removed entry is not found. google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; @@ -322,10 +322,10 @@ TEST_F(SyncClientTest, AddFetchTask) { sync_client_->AddFetchTask(GetLocalId("foo")); base::RunLoop().RunUntilIdle(); - FileCacheEntry cache_entry; + ResourceEntry entry; EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); - EXPECT_TRUE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("foo"), &entry)); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); } TEST_F(SyncClientTest, AddFetchTaskAndCancelled) { @@ -335,9 +335,10 @@ TEST_F(SyncClientTest, AddFetchTaskAndCancelled) { base::RunLoop().RunUntilIdle(); // The file should be unpinned if the user wants the download to be cancelled. - FileCacheEntry cache_entry; - EXPECT_EQ(FILE_ERROR_NOT_FOUND, - cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); + ResourceEntry entry; + EXPECT_EQ(FILE_ERROR_OK, + metadata_->GetResourceEntryById(GetLocalId("foo"), &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_pinned()); } TEST_F(SyncClientTest, RemoveFetchTask) { @@ -350,18 +351,18 @@ TEST_F(SyncClientTest, RemoveFetchTask) { base::RunLoop().RunUntilIdle(); // Only "bar" should be fetched. - FileCacheEntry cache_entry; + ResourceEntry entry; EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); - EXPECT_FALSE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("foo"), &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_present()); EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("bar"), &cache_entry)); - EXPECT_TRUE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("bar"), &entry)); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("baz"), &cache_entry)); - EXPECT_FALSE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("baz"), &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_present()); } @@ -406,13 +407,13 @@ TEST_F(SyncClientTest, RetryOnDisconnection) { base::RunLoop().RunUntilIdle(); // Not yet fetched nor uploaded. - FileCacheEntry cache_entry; + ResourceEntry entry; EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); - EXPECT_FALSE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("foo"), &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_present()); EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); - EXPECT_TRUE(cache_entry.is_dirty()); + metadata_->GetResourceEntryById(GetLocalId("dirty"), &entry)); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); // Switch to online. fake_network_change_notifier_->SetConnectionType( @@ -422,11 +423,11 @@ TEST_F(SyncClientTest, RetryOnDisconnection) { // Fetched and uploaded. EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); - EXPECT_TRUE(cache_entry.is_present()); + metadata_->GetResourceEntryById(GetLocalId("foo"), &entry)); + EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); EXPECT_EQ(FILE_ERROR_OK, - cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); - EXPECT_FALSE(cache_entry.is_dirty()); + metadata_->GetResourceEntryById(GetLocalId("dirty"), &entry)); + EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); } TEST_F(SyncClientTest, ScheduleRerun) { |