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

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: 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..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() {}

Powered by Google App Engine
This is Rietveld 408576698