OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 8 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
9 | 9 |
10 namespace gdata { | 10 namespace gdata { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 175 } |
176 | 176 |
177 void GDataCacheMetadataMap::UpdateCache( | 177 void GDataCacheMetadataMap::UpdateCache( |
178 const std::string& resource_id, | 178 const std::string& resource_id, |
179 const GDataCache::CacheEntry& cache_entry) { | 179 const GDataCache::CacheEntry& cache_entry) { |
180 AssertOnSequencedWorkerPool(); | 180 AssertOnSequencedWorkerPool(); |
181 | 181 |
182 CacheMap::iterator iter = cache_map_.find(resource_id); | 182 CacheMap::iterator iter = cache_map_.find(resource_id); |
183 if (iter == cache_map_.end()) { // New resource, create new entry. | 183 if (iter == cache_map_.end()) { // New resource, create new entry. |
184 // Makes no sense to create new entry if cache state is NONE. | 184 // Makes no sense to create new entry if cache state is NONE. |
185 DCHECK(cache_entry.cache_state != GDataCache::CACHE_STATE_NONE); | 185 DCHECK(cache_entry.cache_state() != GDataCache::CACHE_STATE_NONE); |
186 if (cache_entry.cache_state != GDataCache::CACHE_STATE_NONE) { | 186 if (cache_entry.cache_state() != GDataCache::CACHE_STATE_NONE) { |
187 cache_map_.insert(std::make_pair(resource_id, cache_entry)); | 187 cache_map_.insert(std::make_pair(resource_id, cache_entry)); |
188 DVLOG(1) << "Added res_id=" << resource_id | 188 DVLOG(1) << "Added res_id=" << resource_id |
189 << ", " << cache_entry.ToString(); | 189 << ", " << cache_entry.ToString(); |
190 } | 190 } |
191 } else { // Resource exists. | 191 } else { // Resource exists. |
192 // If cache state is NONE, delete entry from cache map. | 192 // If cache state is NONE, delete entry from cache map. |
193 if (cache_entry.cache_state == GDataCache::CACHE_STATE_NONE) { | 193 if (cache_entry.cache_state() == GDataCache::CACHE_STATE_NONE) { |
194 DVLOG(1) << "Deleting res_id=" << resource_id | 194 DVLOG(1) << "Deleting res_id=" << resource_id |
195 << ", " << iter->second.ToString(); | 195 << ", " << iter->second.ToString(); |
196 cache_map_.erase(iter); | 196 cache_map_.erase(iter); |
197 } else { // Otherwise, update entry in cache map. | 197 } else { // Otherwise, update entry in cache map. |
198 iter->second.md5 = cache_entry.md5; | 198 iter->second.set_md5(cache_entry.md5()); |
199 iter->second.cache_state = cache_entry.cache_state; | 199 iter->second.set_cache_state(cache_entry.cache_state()); |
200 DVLOG(1) << "Updated res_id=" << resource_id | 200 DVLOG(1) << "Updated res_id=" << resource_id |
201 << ", " << iter->second.ToString(); | 201 << ", " << iter->second.ToString(); |
202 } | 202 } |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 void GDataCacheMetadataMap::RemoveFromCache(const std::string& resource_id) { | 206 void GDataCacheMetadataMap::RemoveFromCache(const std::string& resource_id) { |
207 AssertOnSequencedWorkerPool(); | 207 AssertOnSequencedWorkerPool(); |
208 | 208 |
209 CacheMap::iterator iter = cache_map_.find(resource_id); | 209 CacheMap::iterator iter = cache_map_.find(resource_id); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 379 } |
380 | 380 |
381 // static | 381 // static |
382 bool GDataCacheMetadataMap::CheckIfMd5Matches( | 382 bool GDataCacheMetadataMap::CheckIfMd5Matches( |
383 const std::string& md5, | 383 const std::string& md5, |
384 const GDataCache::CacheEntry& cache_entry) { | 384 const GDataCache::CacheEntry& cache_entry) { |
385 if (cache_entry.IsDirty()) { | 385 if (cache_entry.IsDirty()) { |
386 // If the entry is dirty, its MD5 may have been replaced by "local" | 386 // If the entry is dirty, its MD5 may have been replaced by "local" |
387 // during cache initialization, so we don't compare MD5. | 387 // during cache initialization, so we don't compare MD5. |
388 return true; | 388 return true; |
389 } else if (cache_entry.IsPinned() && cache_entry.md5.empty()) { | 389 } else if (cache_entry.IsPinned() && cache_entry.md5().empty()) { |
390 // If the entry is pinned, it's ok for the entry to have an empty | 390 // If the entry is pinned, it's ok for the entry to have an empty |
391 // MD5. This can happen if the pinned file is not fetched. MD5 for pinned | 391 // MD5. This can happen if the pinned file is not fetched. MD5 for pinned |
392 // files are collected from files in "persistent" directory, but the | 392 // files are collected from files in "persistent" directory, but the |
393 // persistent files do not exisit if these are not fetched yet. | 393 // persistent files do not exisit if these are not fetched yet. |
394 return true; | 394 return true; |
395 } else if (md5.empty()) { | 395 } else if (md5.empty()) { |
396 // If the MD5 matching is not requested, don't check MD5. | 396 // If the MD5 matching is not requested, don't check MD5. |
397 return true; | 397 return true; |
398 } else if (md5 == cache_entry.md5) { | 398 } else if (md5 == cache_entry.md5()) { |
399 // Otherwise, compare the MD5. | 399 // Otherwise, compare the MD5. |
400 return true; | 400 return true; |
401 } | 401 } |
402 return false; | 402 return false; |
403 } | 403 } |
404 | 404 |
405 } // namespace gdata | 405 } // namespace gdata |
OLD | NEW |