Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ios/chrome/browser/favicon/large_icon_cache.h" | |
| 6 | |
| 7 #include "components/favicon_base/fallback_icon_style.h" | |
| 8 #include "components/favicon_base/favicon_types.h" | |
| 9 #include "url/gurl.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 const int kMaxCacheSize = 12; | |
| 14 | |
| 15 // Cache of LargeIconResult. | |
|
sdefresne
2015/10/30 17:20:14
nit: what is this comment doing here? Remove.
justincohen
2015/10/30 19:43:24
Done.
| |
| 16 | |
| 17 } // namespace | |
| 18 | |
| 19 struct LargeIconCacheEntry { | |
| 20 LargeIconCacheEntry() {} | |
| 21 ~LargeIconCacheEntry() {} | |
| 22 | |
| 23 scoped_ptr<favicon_base::LargeIconResult> result; | |
| 24 }; | |
| 25 | |
| 26 LargeIconCache::LargeIconCache() : cache_(kMaxCacheSize) {} | |
| 27 | |
| 28 LargeIconCache::~LargeIconCache() {} | |
| 29 | |
| 30 void LargeIconCache::SetCachedResult( | |
| 31 const GURL& url, | |
| 32 const favicon_base::LargeIconResult& result) { | |
| 33 LargeIconCacheEntry* entry = new LargeIconCacheEntry; | |
| 34 entry->result = CloneLargeIconResult(result); | |
| 35 cache_.Put(url, entry); | |
| 36 } | |
| 37 | |
| 38 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult( | |
| 39 const GURL& url) { | |
| 40 base::OwningMRUCache<GURL, LargeIconCacheEntry*>::iterator iter = | |
|
sdefresne
2015/10/30 17:20:14
nit: you could have used "auto iter = cache_.Get(u
justincohen
2015/10/30 19:43:24
Done.
| |
| 41 cache_.Get(url); | |
| 42 if (iter != cache_.end()) { | |
| 43 DCHECK(iter->second->result); | |
| 44 return CloneLargeIconResult(*iter->second->result.get()); | |
| 45 } | |
| 46 | |
| 47 return scoped_ptr<favicon_base::LargeIconResult>(); | |
| 48 } | |
| 49 | |
| 50 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::CloneLargeIconResult( | |
| 51 const favicon_base::LargeIconResult& large_icon_result) { | |
| 52 scoped_ptr<favicon_base::LargeIconResult> clone; | |
| 53 if (large_icon_result.bitmap.is_valid()) { | |
| 54 clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap)); | |
| 55 } else { | |
| 56 clone.reset( | |
| 57 new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle( | |
| 58 *large_icon_result.fallback_icon_style.get()))); | |
| 59 } | |
| 60 return clone.Pass(); | |
| 61 } | |
| OLD | NEW |