Commit e9adce9e authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Make GDataCache::CacheEntry a struct

CacheEntry is now complex enough to be a class, rather than a struct.

BUG=136625
TEST=out/Release/unit_tests --gtest_filter=GData*

Review URL: https://chromiumcodereview.appspot.com/10698157

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146227 0039d316-1c4b-4281-b951-d872f2087c98
parent 2a281335
......@@ -347,7 +347,7 @@ std::string GDataCache::CacheEntry::ToString() const {
cache_states.push_back("persistent");
return base::StringPrintf("md5=%s, cache_state=%s",
md5.c_str(),
md5_.c_str(),
JoinString(cache_states, ',').c_str());
}
......@@ -830,7 +830,7 @@ void GDataCache::Store(const std::string& resource_id,
return;
}
new_cache_entry.cache_state = cache_entry->cache_state;
new_cache_entry.set_cache_state(cache_entry->cache_state());
// If file is pinned, determines destination path.
if (cache_entry->IsPinned()) {
......@@ -915,7 +915,7 @@ void GDataCache::Pin(const std::string& resource_id,
// then moved to 'persistent'.
sub_dir_type = CACHE_TYPE_TMP;
} else { // File exists in cache, determines destination path.
new_cache_entry.cache_state = cache_entry->cache_state;
new_cache_entry.set_cache_state(cache_entry->cache_state());
// Determine source and destination paths.
......@@ -1049,7 +1049,7 @@ void GDataCache::Unpin(const std::string& resource_id,
if (*error == base::PLATFORM_FILE_OK) {
// Now that file operations have completed, update cache map.
CacheEntry new_cache_entry(md5, cache_entry->cache_state);
CacheEntry new_cache_entry(md5, cache_entry->cache_state());
new_cache_entry.SetPinned(false);
new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
metadata_->UpdateCache(resource_id, new_cache_entry);
......@@ -1098,7 +1098,7 @@ void GDataCache::SetMountedState(const FilePath& file_path,
// Determine the source and destination paths for moving the cache blob.
FilePath source_path;
CacheSubDirectoryType dest_subdir;
CacheEntry new_cache_entry(md5, cache_entry->cache_state);
CacheEntry new_cache_entry(md5, cache_entry->cache_state());
if (to_mount) {
source_path = unmounted_path;
*cache_file_path = mounted_path;
......@@ -1219,7 +1219,7 @@ void GDataCache::MarkDirty(const std::string& resource_id,
if (*error == base::PLATFORM_FILE_OK) {
// Now that file operations have completed, update cache map.
CacheEntry new_cache_entry(md5, cache_entry->cache_state);
CacheEntry new_cache_entry(md5, cache_entry->cache_state());
new_cache_entry.SetDirty(true);
new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
metadata_->UpdateCache(resource_id, new_cache_entry);
......@@ -1367,7 +1367,7 @@ void GDataCache::ClearDirty(const std::string& resource_id,
if (*error == base::PLATFORM_FILE_OK) {
// Now that file operations have completed, update cache map.
CacheEntry new_cache_entry(md5, cache_entry->cache_state);
CacheEntry new_cache_entry(md5, cache_entry->cache_state());
new_cache_entry.SetDirty(false);
new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
metadata_->UpdateCache(resource_id, new_cache_entry);
......
......@@ -119,60 +119,71 @@ class GDataCache {
};
// Structure to store information of an existing cache file.
struct CacheEntry {
CacheEntry() : cache_state(CACHE_STATE_NONE) {}
class CacheEntry {
public:
CacheEntry() : cache_state_(CACHE_STATE_NONE) {}
CacheEntry(const std::string& md5,
int cache_state)
: md5(md5),
cache_state(cache_state) {
: md5_(md5),
cache_state_(cache_state) {
}
// The MD5 of the cache file. This can be "local" if the file is
// locally modified.
const std::string& md5() const { return md5_; }
// The cache state represented as a bitmask of GDataCacheState.
int cache_state() const { return cache_state_; }
void set_md5(const std::string& md5) { md5_ = md5; }
void set_cache_state(int cache_state) { cache_state_ = cache_state; }
// Returns true if the file is present locally.
bool IsPresent() const { return cache_state & CACHE_STATE_PRESENT; }
bool IsPresent() const { return cache_state_ & CACHE_STATE_PRESENT; }
// Returns true if the file is pinned (i.e. available offline).
bool IsPinned() const { return cache_state & CACHE_STATE_PINNED; }
bool IsPinned() const { return cache_state_ & CACHE_STATE_PINNED; }
// Returns true if the file is dirty (i.e. modified locally).
bool IsDirty() const { return cache_state & CACHE_STATE_DIRTY; }
bool IsDirty() const { return cache_state_ & CACHE_STATE_DIRTY; }
// Returns true if the file is a mounted archive file.
bool IsMounted() const { return cache_state & CACHE_STATE_MOUNTED; }
bool IsMounted() const { return cache_state_ & CACHE_STATE_MOUNTED; }
// Returns true if the file is in the persistent directory.
bool IsPersistent() const { return cache_state & CACHE_STATE_PERSISTENT; }
bool IsPersistent() const { return cache_state_ & CACHE_STATE_PERSISTENT; }
// Setters for the states describe above.
void SetPresent(bool value) {
if (value)
cache_state |= CACHE_STATE_PRESENT;
cache_state_ |= CACHE_STATE_PRESENT;
else
cache_state &= ~CACHE_STATE_PRESENT;
cache_state_ &= ~CACHE_STATE_PRESENT;
}
void SetPinned(bool value) {
if (value)
cache_state |= CACHE_STATE_PINNED;
cache_state_ |= CACHE_STATE_PINNED;
else
cache_state &= ~CACHE_STATE_PINNED;
cache_state_ &= ~CACHE_STATE_PINNED;
}
void SetDirty(bool value) {
if (value)
cache_state |= CACHE_STATE_DIRTY;
cache_state_ |= CACHE_STATE_DIRTY;
else
cache_state &= ~CACHE_STATE_DIRTY;
cache_state_ &= ~CACHE_STATE_DIRTY;
}
void SetMounted(bool value) {
if (value)
cache_state |= CACHE_STATE_MOUNTED;
cache_state_ |= CACHE_STATE_MOUNTED;
else
cache_state &= ~CACHE_STATE_MOUNTED;
cache_state_ &= ~CACHE_STATE_MOUNTED;
}
void SetPersistent(bool value) {
if (value)
cache_state |= CACHE_STATE_PERSISTENT;
cache_state_ |= CACHE_STATE_PERSISTENT;
else
cache_state &= ~CACHE_STATE_PERSISTENT;
cache_state_ &= ~CACHE_STATE_PERSISTENT;
}
// Returns the type of the sub directory where the cache file is stored.
......@@ -183,8 +194,9 @@ class GDataCache {
// For debugging purposes.
std::string ToString() const;
std::string md5;
int cache_state;
private:
std::string md5_;
int cache_state_;
};
// Callback for GetCacheEntryOnUIThread.
......
......@@ -182,21 +182,21 @@ void GDataCacheMetadataMap::UpdateCache(
CacheMap::iterator iter = cache_map_.find(resource_id);
if (iter == cache_map_.end()) { // New resource, create new entry.
// Makes no sense to create new entry if cache state is NONE.
DCHECK(cache_entry.cache_state != GDataCache::CACHE_STATE_NONE);
if (cache_entry.cache_state != GDataCache::CACHE_STATE_NONE) {
DCHECK(cache_entry.cache_state() != GDataCache::CACHE_STATE_NONE);
if (cache_entry.cache_state() != GDataCache::CACHE_STATE_NONE) {
cache_map_.insert(std::make_pair(resource_id, cache_entry));
DVLOG(1) << "Added res_id=" << resource_id
<< ", " << cache_entry.ToString();
}
} else { // Resource exists.
// If cache state is NONE, delete entry from cache map.
if (cache_entry.cache_state == GDataCache::CACHE_STATE_NONE) {
if (cache_entry.cache_state() == GDataCache::CACHE_STATE_NONE) {
DVLOG(1) << "Deleting res_id=" << resource_id
<< ", " << iter->second.ToString();
cache_map_.erase(iter);
} else { // Otherwise, update entry in cache map.
iter->second.md5 = cache_entry.md5;
iter->second.cache_state = cache_entry.cache_state;
iter->second.set_md5(cache_entry.md5());
iter->second.set_cache_state(cache_entry.cache_state());
DVLOG(1) << "Updated res_id=" << resource_id
<< ", " << iter->second.ToString();
}
......@@ -386,7 +386,7 @@ bool GDataCacheMetadataMap::CheckIfMd5Matches(
// If the entry is dirty, its MD5 may have been replaced by "local"
// during cache initialization, so we don't compare MD5.
return true;
} else if (cache_entry.IsPinned() && cache_entry.md5.empty()) {
} else if (cache_entry.IsPinned() && cache_entry.md5().empty()) {
// If the entry is pinned, it's ok for the entry to have an empty
// MD5. This can happen if the pinned file is not fetched. MD5 for pinned
// files are collected from files in "persistent" directory, but the
......@@ -395,7 +395,7 @@ bool GDataCacheMetadataMap::CheckIfMd5Matches(
} else if (md5.empty()) {
// If the MD5 matching is not requested, don't check MD5.
return true;
} else if (md5 == cache_entry.md5) {
} else if (md5 == cache_entry.md5()) {
// Otherwise, compare the MD5.
return true;
}
......
......@@ -150,15 +150,15 @@ TEST_F(GDataCacheMetadataMapTest, CacheTest) {
scoped_ptr<GDataCache::CacheEntry> cache_entry =
metadata_->GetCacheEntry(test_resource_id, test_file_md5);
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(test_file_md5, cache_entry->md5);
EXPECT_EQ(test_file_md5, cache_entry->md5());
EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType());
EXPECT_EQ(test_cache_state, cache_entry->cache_state);
EXPECT_EQ(test_cache_state, cache_entry->cache_state());
// Empty md5 should also work.
cache_entry =
metadata_->GetCacheEntry(test_resource_id, std::string()).Pass();
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(test_file_md5, cache_entry->md5);
EXPECT_EQ(test_file_md5, cache_entry->md5());
// resource_id doesn't exist.
cache_entry = metadata_->GetCacheEntry("not_found_resource_id",
......@@ -182,15 +182,15 @@ TEST_F(GDataCacheMetadataMapTest, CacheTest) {
cache_entry =
metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass();
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(test_file_md5, cache_entry->md5);
EXPECT_EQ(test_file_md5, cache_entry->md5());
EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType());
EXPECT_EQ(test_cache_state, cache_entry->cache_state);
EXPECT_EQ(test_cache_state, cache_entry->cache_state());
// Empty m5 should work.
cache_entry =
metadata_->GetCacheEntry(test_resource_id, std::string()).Pass();
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(test_file_md5, cache_entry->md5);
EXPECT_EQ(test_file_md5, cache_entry->md5());
// Test dirty cache.
test_file_md5 = "test_file_md5_3";
......@@ -204,21 +204,21 @@ TEST_F(GDataCacheMetadataMapTest, CacheTest) {
cache_entry =
metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass();
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(test_file_md5, cache_entry->md5);
EXPECT_EQ(test_file_md5, cache_entry->md5());
EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType());
EXPECT_EQ(test_cache_state, cache_entry->cache_state);
EXPECT_EQ(test_cache_state, cache_entry->cache_state());
// Empty md5 should work.
cache_entry =
metadata_->GetCacheEntry(test_resource_id, std::string()).Pass();
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(test_file_md5, cache_entry->md5);
EXPECT_EQ(test_file_md5, cache_entry->md5());
// Mismatched md5 should also work for dirty entries.
cache_entry =
metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass();
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(test_file_md5, cache_entry->md5);
EXPECT_EQ(test_file_md5, cache_entry->md5());
// Remove the entry.
metadata_->RemoveFromCache(test_resource_id);
......@@ -239,9 +239,9 @@ TEST_F(GDataCacheMetadataMapTest, CacheTest) {
cache_entry =
metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass();
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(test_file_md5, cache_entry->md5);
EXPECT_EQ(test_file_md5, cache_entry->md5());
EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType());
EXPECT_EQ(test_cache_state, cache_entry->cache_state);
EXPECT_EQ(test_cache_state, cache_entry->cache_state());
// Update with CACHE_STATE_NONE should evict the entry.
test_file_md5 = "test_file_md5_5";
......@@ -281,12 +281,12 @@ TEST_F(GDataCacheMetadataMapTest, Initialization) {
scoped_ptr<GDataCache::CacheEntry> cache_entry;
cache_entry = metadata_->GetCacheEntry("id_foo", "md5foo");
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ("md5foo", cache_entry->md5);
EXPECT_EQ("md5foo", cache_entry->md5());
EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT,
cache_entry->GetSubDirectoryType());
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED |
GDataCache::CACHE_STATE_PERSISTENT,
cache_entry->cache_state);
cache_entry->cache_state());
EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_foo.md5foo")));
EXPECT_TRUE(PathExists(pinned_directory_.AppendASCII("id_foo")));
// The invalid symlink in "outgoing" should be removed.
......@@ -295,12 +295,12 @@ TEST_F(GDataCacheMetadataMapTest, Initialization) {
// "id_bar" is present and dirty.
cache_entry = metadata_->GetCacheEntry("id_bar", "");
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ("local", cache_entry->md5);
EXPECT_EQ("local", cache_entry->md5());
EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT,
cache_entry->GetSubDirectoryType());
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY |
GDataCache::CACHE_STATE_PERSISTENT,
cache_entry->cache_state);
cache_entry->cache_state());
EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_bar.local")));
EXPECT_TRUE(PathExists(outgoing_directory_.AppendASCII("id_bar")));
......@@ -324,9 +324,9 @@ TEST_F(GDataCacheMetadataMapTest, Initialization) {
// "id_qux" is just present in tmp directory.
cache_entry = metadata_->GetCacheEntry("id_qux", "md5qux");
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ("md5qux", cache_entry->md5);
EXPECT_EQ("md5qux", cache_entry->md5());
EXPECT_EQ(GDataCache::CACHE_TYPE_TMP, cache_entry->GetSubDirectoryType());
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry->cache_state);
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry->cache_state());
EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux")));
// "id_quux" should be removed during cache initialization.
......@@ -344,8 +344,8 @@ TEST_F(GDataCacheMetadataMapTest, Initialization) {
// "id_corge" is pinned but not present.
cache_entry = metadata_->GetCacheEntry("id_corge", "");
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ("", cache_entry->md5);
EXPECT_EQ(GDataCache::CACHE_STATE_PINNED, cache_entry->cache_state);
EXPECT_EQ("", cache_entry->md5());
EXPECT_EQ(GDataCache::CACHE_STATE_PINNED, cache_entry->cache_state());
EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_corge")));
// "id_dangling" should be removed during cache initialization.
......
......@@ -340,7 +340,7 @@ class GDataCacheTest : public testing::Test {
scoped_ptr<GDataCache::CacheEntry> cache_entry =
GetCacheEntryFromOriginThread(resource.resource_id, md5);
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(resource.cache_state, cache_entry->cache_state);
EXPECT_EQ(resource.cache_state, cache_entry->cache_state());
EXPECT_EQ(resource.expected_sub_dir_type,
cache_entry->GetSubDirectoryType());
}
......@@ -570,7 +570,7 @@ class GDataCacheTest : public testing::Test {
EXPECT_EQ(expected_success_, success);
if (success) {
EXPECT_EQ(expected_cache_state_, cache_entry.cache_state);
EXPECT_EQ(expected_cache_state_, cache_entry.cache_state());
}
}
......@@ -697,7 +697,7 @@ class GDataCacheTest : public testing::Test {
if (ToCacheEntry(expected_cache_state_).IsPresent() ||
ToCacheEntry(expected_cache_state_).IsPinned()) {
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(expected_cache_state_, cache_entry->cache_state);
EXPECT_EQ(expected_cache_state_, cache_entry->cache_state());
EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType());
} else {
EXPECT_FALSE(cache_entry.get());
......@@ -878,7 +878,7 @@ TEST_F(GDataCacheTest, InitializeCache) {
TestInitializeCache();
}
TEST_F(GDataCacheTest, CacheEntry_Is) {
TEST_F(GDataCacheTest, CacheEntry_CacheStateChanges) {
GDataCache::CacheEntry cache_entry("dummy_md5", GDataCache::CACHE_STATE_NONE);
EXPECT_FALSE(cache_entry.IsPresent());
EXPECT_FALSE(cache_entry.IsPinned());
......@@ -886,96 +886,82 @@ TEST_F(GDataCacheTest, CacheEntry_Is) {
EXPECT_FALSE(cache_entry.IsMounted());
EXPECT_FALSE(cache_entry.IsPersistent());
cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT;
cache_entry.SetPresent(true);
EXPECT_TRUE(cache_entry.IsPresent());
EXPECT_FALSE(cache_entry.IsPinned());
EXPECT_FALSE(cache_entry.IsDirty());
EXPECT_FALSE(cache_entry.IsMounted());
EXPECT_FALSE(cache_entry.IsPersistent());
cache_entry.cache_state |= GDataCache::CACHE_STATE_PINNED;
cache_entry.SetPinned(true);
EXPECT_TRUE(cache_entry.IsPresent());
EXPECT_TRUE(cache_entry.IsPinned());
EXPECT_FALSE(cache_entry.IsDirty());
EXPECT_FALSE(cache_entry.IsMounted());
EXPECT_FALSE(cache_entry.IsPersistent());
cache_entry.cache_state |= GDataCache::CACHE_STATE_DIRTY;
cache_entry.SetDirty(true);
EXPECT_TRUE(cache_entry.IsPresent());
EXPECT_TRUE(cache_entry.IsPinned());
EXPECT_TRUE(cache_entry.IsDirty());
EXPECT_FALSE(cache_entry.IsMounted());
EXPECT_FALSE(cache_entry.IsPersistent());
cache_entry.cache_state |= GDataCache::CACHE_STATE_MOUNTED;
cache_entry.SetMounted(true);
EXPECT_TRUE(cache_entry.IsPresent());
EXPECT_TRUE(cache_entry.IsPinned());
EXPECT_TRUE(cache_entry.IsDirty());
EXPECT_TRUE(cache_entry.IsMounted());
EXPECT_FALSE(cache_entry.IsPersistent());
cache_entry.cache_state |= GDataCache::CACHE_STATE_PERSISTENT;
cache_entry.SetPersistent(true);
EXPECT_TRUE(cache_entry.IsPresent());
EXPECT_TRUE(cache_entry.IsPinned());
EXPECT_TRUE(cache_entry.IsDirty());
EXPECT_TRUE(cache_entry.IsMounted());
EXPECT_TRUE(cache_entry.IsPersistent());
}
TEST_F(GDataCacheTest, CacheEntry_Set) {
GDataCache::CacheEntry cache_entry("dummy_md5", GDataCache::CACHE_STATE_NONE);
cache_entry.SetPresent(true);
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry.cache_state);
cache_entry.SetPinned(true);
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
GDataCache::CACHE_STATE_PINNED,
cache_entry.cache_state);
cache_entry.SetDirty(true);
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
GDataCache::CACHE_STATE_PINNED |
GDataCache::CACHE_STATE_DIRTY,
cache_entry.cache_state);
cache_entry.SetMounted(true);
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
GDataCache::CACHE_STATE_PINNED |
GDataCache::CACHE_STATE_DIRTY |
GDataCache::CACHE_STATE_MOUNTED,
cache_entry.cache_state);
cache_entry.SetPersistent(true);
EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
GDataCache::CACHE_STATE_PINNED |
GDataCache::CACHE_STATE_DIRTY |
GDataCache::CACHE_STATE_MOUNTED |
GDataCache::CACHE_STATE_PERSISTENT,
cache_entry.cache_state);
cache_entry.SetPresent(false);
EXPECT_FALSE(cache_entry.IsPresent());
EXPECT_TRUE(cache_entry.IsPinned());
EXPECT_TRUE(cache_entry.IsDirty());
EXPECT_TRUE(cache_entry.IsMounted());
EXPECT_TRUE(cache_entry.IsPersistent());
cache_entry.SetPresent(false);
EXPECT_EQ(GDataCache::CACHE_STATE_PINNED |
GDataCache::CACHE_STATE_DIRTY |
GDataCache::CACHE_STATE_MOUNTED |
GDataCache::CACHE_STATE_PERSISTENT,
cache_entry.cache_state);
EXPECT_FALSE(cache_entry.IsPresent());
EXPECT_TRUE(cache_entry.IsPinned());
EXPECT_TRUE(cache_entry.IsDirty());
EXPECT_TRUE(cache_entry.IsMounted());
EXPECT_TRUE(cache_entry.IsPersistent());
cache_entry.SetPinned(false);
EXPECT_EQ(GDataCache::CACHE_STATE_DIRTY |
GDataCache::CACHE_STATE_MOUNTED |
GDataCache::CACHE_STATE_PERSISTENT,
cache_entry.cache_state);
EXPECT_FALSE(cache_entry.IsPresent());
EXPECT_FALSE(cache_entry.IsPinned());
EXPECT_TRUE(cache_entry.IsDirty());
EXPECT_TRUE(cache_entry.IsMounted());
EXPECT_TRUE(cache_entry.IsPersistent());
cache_entry.SetDirty(false);
EXPECT_EQ(GDataCache::CACHE_STATE_MOUNTED |
GDataCache::CACHE_STATE_PERSISTENT, cache_entry.cache_state);
EXPECT_FALSE(cache_entry.IsPresent());
EXPECT_FALSE(cache_entry.IsPinned());
EXPECT_FALSE(cache_entry.IsDirty());
EXPECT_TRUE(cache_entry.IsMounted());
EXPECT_TRUE(cache_entry.IsPersistent());
cache_entry.SetMounted(false);
EXPECT_EQ(GDataCache::CACHE_STATE_PERSISTENT, cache_entry.cache_state);
EXPECT_FALSE(cache_entry.IsPresent());
EXPECT_FALSE(cache_entry.IsPinned());
EXPECT_FALSE(cache_entry.IsDirty());
EXPECT_FALSE(cache_entry.IsMounted());
EXPECT_TRUE(cache_entry.IsPersistent());
cache_entry.SetPersistent(false);
EXPECT_EQ(GDataCache::CACHE_STATE_NONE, cache_entry.cache_state);
EXPECT_FALSE(cache_entry.IsPresent());
EXPECT_FALSE(cache_entry.IsPinned());
EXPECT_FALSE(cache_entry.IsDirty());
EXPECT_FALSE(cache_entry.IsMounted());
EXPECT_FALSE(cache_entry.IsPersistent());
}
TEST_F(GDataCacheTest, GetCacheFilePath) {
......
......@@ -707,7 +707,7 @@ class GDataFileSystemTest : public testing::Test {
if (ToCacheEntry(expected_cache_state_).IsPresent() ||
ToCacheEntry(expected_cache_state_).IsPinned()) {
ASSERT_TRUE(cache_entry.get());
EXPECT_EQ(expected_cache_state_, cache_entry->cache_state);
EXPECT_EQ(expected_cache_state_, cache_entry->cache_state());
EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType());
} else {
EXPECT_FALSE(cache_entry.get());
......
......@@ -356,7 +356,7 @@ void GDataSyncClient::OnGetCacheEntry(
// If MD5s don't match, it indicates the local cache file is stale, unless
// the file is dirty (the MD5 is "local"). We should never re-fetch the
// file when we have a locally modified version.
if (latest_md5 != cache_entry.md5 && !cache_entry.IsDirty()) {
if (latest_md5 != cache_entry.md5() && !cache_entry.IsDirty()) {
cache_->RemoveOnUIThread(
resource_id,
base::Bind(&GDataSyncClient::OnRemove,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment