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 #import <Foundation/Foundation.h> | |
| 8 | |
| 9 #include "components/favicon_base/fallback_icon_style.h" | |
| 10 #include "components/favicon_base/favicon_types.h" | |
| 11 #include "url/gurl.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const NSInteger kMaxCacheSize = 12; | |
| 16 | |
| 17 } // anonymous namespace | |
|
sdefresne
2015/10/30 09:27:19
style: } // namespace
justincohen
2015/10/30 11:59:21
Done.
| |
| 18 | |
| 19 LargeIconCache::LargeIconCache() : cache_(kMaxCacheSize) {} | |
| 20 | |
| 21 LargeIconCache::~LargeIconCache() {} | |
| 22 | |
| 23 void LargeIconCache::SetCachedResult( | |
| 24 GURL url, | |
|
sdefresne
2015/10/30 09:27:19
GURL -> const GURL&
justincohen
2015/10/30 11:59:21
Done.
| |
| 25 const favicon_base::LargeIconResult& result) { | |
| 26 CacheEntry* entry = new CacheEntry; | |
| 27 entry->result = CloneLargeIconResult(result); | |
| 28 cache_.Put(url, entry); | |
| 29 } | |
| 30 | |
| 31 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult( | |
| 32 const GURL& url) { | |
| 33 base::OwningMRUCache<GURL, CacheEntry*>::iterator iter = cache_.Get(url); | |
| 34 if (iter != cache_.end()) { | |
| 35 DCHECK(iter->second->result); | |
| 36 return CloneLargeIconResult(*iter->second->result.get()); | |
| 37 } | |
| 38 | |
| 39 return scoped_ptr<favicon_base::LargeIconResult>(); | |
| 40 } | |
| 41 | |
| 42 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::CloneLargeIconResult( | |
| 43 const favicon_base::LargeIconResult& large_icon_result) { | |
| 44 scoped_ptr<favicon_base::LargeIconResult> clone; | |
| 45 if (large_icon_result.bitmap.is_valid()) { | |
| 46 clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap)); | |
| 47 } else { | |
| 48 clone.reset( | |
| 49 new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle( | |
| 50 *large_icon_result.fallback_icon_style.get()))); | |
| 51 } | |
| 52 return clone.Pass(); | |
| 53 } | |
| 54 | |
| 55 LargeIconCache::CacheEntry::CacheEntry() {} | |
| 56 | |
| 57 LargeIconCache::CacheEntry::~CacheEntry() {} | |
| OLD | NEW |