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 | |
| 18 | |
| 19 LargeIconCache::LargeIconCache(ios::ChromeBrowserState* browser_state) | |
| 20 : browser_state_(browser_state), cache_(kMaxCacheSize) {} | |
| 21 | |
| 22 LargeIconCache::~LargeIconCache() {} | |
| 23 | |
| 24 void LargeIconCache::SetCachedResult( | |
| 25 GURL url, | |
| 26 const favicon_base::LargeIconResult& result) { | |
| 27 favicon_base::LargeIconResult* cache_value; | |
|
sdefresne
2015/10/29 16:45:25
scoped_ptr<favicon_base::LargeIconResult> cache_va
justincohen
2015/10/29 20:32:17
Removed completely
| |
| 28 if (result.bitmap.is_valid()) { | |
| 29 cache_value = new favicon_base::LargeIconResult(result.bitmap); | |
| 30 } else { | |
| 31 scoped_ptr<favicon_base::FallbackIconStyle> fallback_icon_style; | |
| 32 fallback_icon_style.reset(new favicon_base::FallbackIconStyle); | |
| 33 fallback_icon_style->background_color = | |
| 34 result.fallback_icon_style->background_color; | |
| 35 fallback_icon_style->text_color = result.fallback_icon_style->text_color; | |
| 36 cache_value = | |
| 37 new favicon_base::LargeIconResult(fallback_icon_style.release()); | |
| 38 } | |
| 39 | |
| 40 CacheEntry* entry = new CacheEntry; | |
| 41 entry->result.reset(cache_value); | |
| 42 cache_.Put(url, entry); | |
| 43 } | |
| 44 | |
| 45 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult( | |
| 46 GURL url) { | |
| 47 base::OwningMRUCache<GURL, CacheEntry*>::iterator iter = cache_.Get(url); | |
| 48 if (iter != cache_.end()) { | |
| 49 return iter->second->result.Pass(); | |
|
sdefresne
2015/10/29 16:45:25
You're sinking the reference here (since result is
justincohen
2015/10/29 20:32:17
Changed to not Pass what we hold on to.
| |
| 50 } | |
| 51 | |
| 52 // Otherwise, return an empty cache value. | |
| 53 scoped_ptr<favicon_base::LargeIconResult> cache_value; | |
| 54 return cache_value.Pass(); | |
|
sdefresne
2015/10/29 16:45:25
return scoped_ptr<favicon_base::LargeIconResult>()
justincohen
2015/10/29 20:32:17
Done.
| |
| 55 } | |
| 56 | |
| 57 LargeIconCache::CacheEntry::CacheEntry() {} | |
| 58 | |
| 59 LargeIconCache::CacheEntry::~CacheEntry() {} | |
| OLD | NEW |