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

Side by Side Diff: ios/chrome/browser/favicon/large_icon_cache.cc

Issue 1413903008: Add LargeIconCache and LargeIconServiceFactory for iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits for unit test Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
(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 #include "components/favicon_base/fallback_icon_style.h"
8 #include "components/favicon_base/favicon_types.h"
9 #include "url/gurl.h"
10
11 namespace {
12
13 const int kMaxCacheSize = 12;
noyau (Ping after 24h) 2015/10/30 23:22:31 Do you need to cache 12 of them on all platforms?
justincohen 2015/10/31 03:54:21 Right now smaller form factors still load 12 favic
14
15 } // namespace
16
17 struct LargeIconCacheEntry {
18 LargeIconCacheEntry() {}
19 ~LargeIconCacheEntry() {}
20
21 scoped_ptr<favicon_base::LargeIconResult> result;
22 };
23
24 LargeIconCache::LargeIconCache() : cache_(kMaxCacheSize) {}
25
26 LargeIconCache::~LargeIconCache() {}
27
28 void LargeIconCache::SetCachedResult(
29 const GURL& url,
30 const favicon_base::LargeIconResult& result) {
31 LargeIconCacheEntry* entry = new LargeIconCacheEntry;
32 entry->result = CloneLargeIconResult(result);
33 cache_.Put(url, entry);
34 }
35
36 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult(
37 const GURL& url) {
38 auto iter = cache_.Get(url);
39 if (iter != cache_.end()) {
40 DCHECK(iter->second->result);
41 return CloneLargeIconResult(*iter->second->result.get());
42 }
43
44 return scoped_ptr<favicon_base::LargeIconResult>();
45 }
46
47 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::CloneLargeIconResult(
48 const favicon_base::LargeIconResult& large_icon_result) {
49 scoped_ptr<favicon_base::LargeIconResult> clone;
50 if (large_icon_result.bitmap.is_valid()) {
51 clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap));
52 } else {
53 clone.reset(
54 new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle(
55 *large_icon_result.fallback_icon_style.get())));
56 }
57 return clone.Pass();
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698