Chromium Code Reviews| Index: ios/chrome/browser/favicon/large_icon_cache.mm |
| diff --git a/ios/chrome/browser/favicon/large_icon_cache.mm b/ios/chrome/browser/favicon/large_icon_cache.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..21d8743cfbe2ca1c391cf96d2142cd0c61efa681 |
| --- /dev/null |
| +++ b/ios/chrome/browser/favicon/large_icon_cache.mm |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ios/chrome/browser/favicon/large_icon_cache.h" |
| + |
| +#import <Foundation/Foundation.h> |
| + |
| +#include "components/favicon_base/fallback_icon_style.h" |
| +#include "components/favicon_base/favicon_types.h" |
| +#include "url/gurl.h" |
| + |
| +namespace { |
| + |
| +const NSInteger kMaxCacheSize = 12; |
| + |
| +} // anonymous namespace |
| + |
| +LargeIconCache::LargeIconCache(ios::ChromeBrowserState* browser_state) |
| + : browser_state_(browser_state), cache_(kMaxCacheSize) {} |
| + |
| +LargeIconCache::~LargeIconCache() {} |
| + |
| +void LargeIconCache::SetCachedResult( |
| + GURL url, |
| + const favicon_base::LargeIconResult& result) { |
| + 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
|
| + if (result.bitmap.is_valid()) { |
| + cache_value = new favicon_base::LargeIconResult(result.bitmap); |
| + } else { |
| + scoped_ptr<favicon_base::FallbackIconStyle> fallback_icon_style; |
| + fallback_icon_style.reset(new favicon_base::FallbackIconStyle); |
| + fallback_icon_style->background_color = |
| + result.fallback_icon_style->background_color; |
| + fallback_icon_style->text_color = result.fallback_icon_style->text_color; |
| + cache_value = |
| + new favicon_base::LargeIconResult(fallback_icon_style.release()); |
| + } |
| + |
| + CacheEntry* entry = new CacheEntry; |
| + entry->result.reset(cache_value); |
| + cache_.Put(url, entry); |
| +} |
| + |
| +scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult( |
| + GURL url) { |
| + base::OwningMRUCache<GURL, CacheEntry*>::iterator iter = cache_.Get(url); |
| + if (iter != cache_.end()) { |
| + 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.
|
| + } |
| + |
| + // Otherwise, return an empty cache value. |
| + scoped_ptr<favicon_base::LargeIconResult> cache_value; |
| + 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.
|
| +} |
| + |
| +LargeIconCache::CacheEntry::CacheEntry() {} |
| + |
| +LargeIconCache::CacheEntry::~CacheEntry() {} |