Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_cache_metadata.cc

Issue 10581038: chromeos: Stop returning scoped_ptr from GDataCache::GetCacheEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and review fix Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 void GDataCacheMetadataMap::RemoveFromCache(const std::string& resource_id) { 207 void GDataCacheMetadataMap::RemoveFromCache(const std::string& resource_id) {
208 AssertOnSequencedWorkerPool(); 208 AssertOnSequencedWorkerPool();
209 209
210 CacheMap::iterator iter = cache_map_.find(resource_id); 210 CacheMap::iterator iter = cache_map_.find(resource_id);
211 if (iter != cache_map_.end()) { 211 if (iter != cache_map_.end()) {
212 // Delete the CacheEntry and remove it from the map. 212 // Delete the CacheEntry and remove it from the map.
213 cache_map_.erase(iter); 213 cache_map_.erase(iter);
214 } 214 }
215 } 215 }
216 216
217 scoped_ptr<GDataCache::CacheEntry> GDataCacheMetadataMap::GetCacheEntry( 217 bool GDataCacheMetadataMap::GetCacheEntry(const std::string& resource_id,
218 const std::string& resource_id, 218 const std::string& md5,
219 const std::string& md5) { 219 GDataCache::CacheEntry* entry) {
220 DCHECK(entry);
220 AssertOnSequencedWorkerPool(); 221 AssertOnSequencedWorkerPool();
221 222
222 CacheMap::iterator iter = cache_map_.find(resource_id); 223 CacheMap::iterator iter = cache_map_.find(resource_id);
223 if (iter == cache_map_.end()) { 224 if (iter == cache_map_.end()) {
224 DVLOG(1) << "Can't find " << resource_id << " in cache map"; 225 DVLOG(1) << "Can't find " << resource_id << " in cache map";
225 return scoped_ptr<GDataCache::CacheEntry>(); 226 return false;
226 } 227 }
227 228
228 scoped_ptr<GDataCache::CacheEntry> cache_entry( 229 const GDataCache::CacheEntry& cache_entry = iter->second;
229 new GDataCache::CacheEntry(iter->second));
230 230
231 if (!CheckIfMd5Matches(md5, *cache_entry)) { 231 if (!CheckIfMd5Matches(md5, cache_entry)) {
232 DVLOG(1) << "Non-matching md5: want=" << md5 232 DVLOG(1) << "Non-matching md5: want=" << md5
233 << ", found=[res_id=" << resource_id 233 << ", found=[res_id=" << resource_id
234 << ", " << cache_entry->ToString() 234 << ", " << cache_entry.ToString()
235 << "]"; 235 << "]";
236 return scoped_ptr<GDataCache::CacheEntry>(); 236 return false;
237 } 237 }
238 238
239 DVLOG(1) << "Found entry for res_id=" << resource_id 239 DVLOG(1) << "Found entry for res_id=" << resource_id
240 << ", " << cache_entry->ToString(); 240 << ", " << cache_entry.ToString();
241 241
242 return cache_entry.Pass(); 242 *entry = cache_entry;
243 return true;
243 } 244 }
244 245
245 void GDataCacheMetadataMap::RemoveTemporaryFiles() { 246 void GDataCacheMetadataMap::RemoveTemporaryFiles() {
246 AssertOnSequencedWorkerPool(); 247 AssertOnSequencedWorkerPool();
247 248
248 CacheMap::iterator iter = cache_map_.begin(); 249 CacheMap::iterator iter = cache_map_.begin();
249 while (iter != cache_map_.end()) { 250 while (iter != cache_map_.end()) {
250 if (!iter->second.IsPersistent()) { 251 if (!iter->second.IsPersistent()) {
251 // Post-increment the iterator to avoid iterator invalidation. 252 // Post-increment the iterator to avoid iterator invalidation.
252 cache_map_.erase(iter++); 253 cache_map_.erase(iter++);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // If the MD5 matching is not requested, don't check MD5. 400 // If the MD5 matching is not requested, don't check MD5.
400 return true; 401 return true;
401 } else if (md5 == cache_entry.md5) { 402 } else if (md5 == cache_entry.md5) {
402 // Otherwise, compare the MD5. 403 // Otherwise, compare the MD5.
403 return true; 404 return true;
404 } 405 }
405 return false; 406 return false;
406 } 407 }
407 408
408 } // namespace gdata 409 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698