Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Unified Diff: ios/chrome/browser/favicon/large_icon_cache.mm

Issue 1413903008: Add LargeIconCache and LargeIconServiceFactory for iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using wrong thread pool Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4d3b698b3989ea64bc612c792cc7afb87da4d6d8
--- /dev/null
+++ b/ios/chrome/browser/favicon/large_icon_cache.mm
@@ -0,0 +1,57 @@
+// 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
sdefresne 2015/10/30 09:27:19 style: } // namespace
justincohen 2015/10/30 11:59:21 Done.
+
+LargeIconCache::LargeIconCache() : cache_(kMaxCacheSize) {}
+
+LargeIconCache::~LargeIconCache() {}
+
+void LargeIconCache::SetCachedResult(
+ GURL url,
sdefresne 2015/10/30 09:27:19 GURL -> const GURL&
justincohen 2015/10/30 11:59:21 Done.
+ const favicon_base::LargeIconResult& result) {
+ CacheEntry* entry = new CacheEntry;
+ entry->result = CloneLargeIconResult(result);
+ cache_.Put(url, entry);
+}
+
+scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult(
+ const GURL& url) {
+ base::OwningMRUCache<GURL, CacheEntry*>::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();
+}
+
+LargeIconCache::CacheEntry::CacheEntry() {}
+
+LargeIconCache::CacheEntry::~CacheEntry() {}

Powered by Google App Engine
This is Rietveld 408576698