| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 void GDataCacheMetadataMap::RemoveCacheEntry(const std::string& resource_id) { | 194 void GDataCacheMetadataMap::RemoveCacheEntry(const std::string& resource_id) { |
| 195 AssertOnSequencedWorkerPool(); | 195 AssertOnSequencedWorkerPool(); |
| 196 | 196 |
| 197 CacheMap::iterator iter = cache_map_.find(resource_id); | 197 CacheMap::iterator iter = cache_map_.find(resource_id); |
| 198 if (iter != cache_map_.end()) { | 198 if (iter != cache_map_.end()) { |
| 199 // Delete the CacheEntry and remove it from the map. | 199 // Delete the CacheEntry and remove it from the map. |
| 200 cache_map_.erase(iter); | 200 cache_map_.erase(iter); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 scoped_ptr<GDataCacheEntry> GDataCacheMetadataMap::GetCacheEntry( | 204 bool GDataCacheMetadataMap::GetCacheEntry(const std::string& resource_id, |
| 205 const std::string& resource_id, | 205 const std::string& md5, |
| 206 const std::string& md5) { | 206 GDataCacheEntry* entry) { |
| 207 DCHECK(entry); |
| 207 AssertOnSequencedWorkerPool(); | 208 AssertOnSequencedWorkerPool(); |
| 208 | 209 |
| 209 CacheMap::iterator iter = cache_map_.find(resource_id); | 210 CacheMap::iterator iter = cache_map_.find(resource_id); |
| 210 if (iter == cache_map_.end()) { | 211 if (iter == cache_map_.end()) { |
| 211 DVLOG(1) << "Can't find " << resource_id << " in cache map"; | 212 DVLOG(1) << "Can't find " << resource_id << " in cache map"; |
| 212 return scoped_ptr<GDataCacheEntry>(); | 213 return false; |
| 213 } | 214 } |
| 214 | 215 |
| 215 scoped_ptr<GDataCacheEntry> cache_entry( | 216 const GDataCacheEntry& cache_entry = iter->second; |
| 216 new GDataCacheEntry(iter->second)); | |
| 217 | 217 |
| 218 if (!CheckIfMd5Matches(md5, *cache_entry)) { | 218 if (!CheckIfMd5Matches(md5, cache_entry)) { |
| 219 DVLOG(1) << "Non-matching md5: want=" << md5 | 219 DVLOG(1) << "Non-matching md5: want=" << md5 |
| 220 << ", found=[res_id=" << resource_id | 220 << ", found=[res_id=" << resource_id |
| 221 << ", " << cache_entry->ToString() | 221 << ", " << cache_entry.ToString() |
| 222 << "]"; | 222 << "]"; |
| 223 return scoped_ptr<GDataCacheEntry>(); | 223 return false; |
| 224 } | 224 } |
| 225 | 225 |
| 226 DVLOG(1) << "Found entry for res_id=" << resource_id | 226 DVLOG(1) << "Found entry for res_id=" << resource_id |
| 227 << ", " << cache_entry->ToString(); | 227 << ", " << cache_entry.ToString(); |
| 228 | 228 |
| 229 return cache_entry.Pass(); | 229 *entry = cache_entry; |
| 230 return true; |
| 230 } | 231 } |
| 231 | 232 |
| 232 void GDataCacheMetadataMap::RemoveTemporaryFiles() { | 233 void GDataCacheMetadataMap::RemoveTemporaryFiles() { |
| 233 AssertOnSequencedWorkerPool(); | 234 AssertOnSequencedWorkerPool(); |
| 234 | 235 |
| 235 CacheMap::iterator iter = cache_map_.begin(); | 236 CacheMap::iterator iter = cache_map_.begin(); |
| 236 while (iter != cache_map_.end()) { | 237 while (iter != cache_map_.end()) { |
| 237 if (!iter->second.IsPersistent()) { | 238 if (!iter->second.IsPersistent()) { |
| 238 // Post-increment the iterator to avoid iterator invalidation. | 239 // Post-increment the iterator to avoid iterator invalidation. |
| 239 cache_map_.erase(iter++); | 240 cache_map_.erase(iter++); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // If the MD5 matching is not requested, don't check MD5. | 385 // If the MD5 matching is not requested, don't check MD5. |
| 385 return true; | 386 return true; |
| 386 } else if (md5 == cache_entry.md5()) { | 387 } else if (md5 == cache_entry.md5()) { |
| 387 // Otherwise, compare the MD5. | 388 // Otherwise, compare the MD5. |
| 388 return true; | 389 return true; |
| 389 } | 390 } |
| 390 return false; | 391 return false; |
| 391 } | 392 } |
| 392 | 393 |
| 393 } // namespace gdata | 394 } // namespace gdata |
| OLD | NEW |