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..bff3777b2f735fe6b4d962e9567cf960d1e5e867 |
| --- /dev/null |
| +++ b/ios/chrome/browser/favicon/large_icon_cache.mm |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
sdefresne
2015/10/30 14:19:37
It looks like this file is pure C++, can you renam
justincohen
2015/10/30 15:25:16
Done.
|
| +// 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> |
|
sdefresne
2015/10/30 14:19:37
Is this required?
justincohen
2015/10/30 15:25:15
Done.
|
| + |
| +#include "components/favicon_base/fallback_icon_style.h" |
| +#include "components/favicon_base/favicon_types.h" |
| +#include "url/gurl.h" |
| + |
| +namespace { |
| + |
| +const NSInteger kMaxCacheSize = 12; |
| + |
| +// Cache of LargeIconResult. |
| + |
| +} // namespace |
| + |
| +struct LargeIconCacheEntry { |
| + LargeIconCacheEntry() {} |
| + ~LargeIconCacheEntry() {} |
| + |
| + scoped_ptr<favicon_base::LargeIconResult> result; |
| +}; |
| + |
| +LargeIconCache::LargeIconCache() : cache_(kMaxCacheSize) {} |
| + |
| +LargeIconCache::~LargeIconCache() {} |
| + |
| +void LargeIconCache::SetCachedResult( |
| + const GURL& url, |
| + const favicon_base::LargeIconResult& result) { |
| + LargeIconCacheEntry* entry = new LargeIconCacheEntry; |
| + entry->result = CloneLargeIconResult(result); |
| + cache_.Put(url, entry); |
| +} |
| + |
| +scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult( |
| + const GURL& url) { |
| + base::OwningMRUCache<GURL, LargeIconCacheEntry*>::iterator iter = |
| + cache_.Get(url); |
| + if (iter != cache_.end()) { |
| + DCHECK(iter->second->result); |
| + return CloneLargeIconResult(*iter->second->result.get()); |
| + } |
| + |
| + return scoped_ptr<favicon_base::LargeIconResult>(); |
| +} |
| + |
| +scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::CloneLargeIconResult( |
| + const favicon_base::LargeIconResult& large_icon_result) { |
| + scoped_ptr<favicon_base::LargeIconResult> clone; |
| + if (large_icon_result.bitmap.is_valid()) { |
| + clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap)); |
| + } else { |
| + clone.reset( |
| + new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle( |
| + *large_icon_result.fallback_icon_style.get()))); |
| + } |
| + return clone.Pass(); |
| +} |