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

Side by Side 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: Address Sylvain comments. 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.
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.
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 #import <Foundation/Foundation.h>
sdefresne 2015/10/30 14:19:37 Is this required?
justincohen 2015/10/30 15:25:15 Done.
8
9 #include "components/favicon_base/fallback_icon_style.h"
10 #include "components/favicon_base/favicon_types.h"
11 #include "url/gurl.h"
12
13 namespace {
14
15 const NSInteger kMaxCacheSize = 12;
16
17 // Cache of LargeIconResult.
18
19 } // namespace
20
21 struct LargeIconCacheEntry {
22 LargeIconCacheEntry() {}
23 ~LargeIconCacheEntry() {}
24
25 scoped_ptr<favicon_base::LargeIconResult> result;
26 };
27
28 LargeIconCache::LargeIconCache() : cache_(kMaxCacheSize) {}
29
30 LargeIconCache::~LargeIconCache() {}
31
32 void LargeIconCache::SetCachedResult(
33 const GURL& url,
34 const favicon_base::LargeIconResult& result) {
35 LargeIconCacheEntry* entry = new LargeIconCacheEntry;
36 entry->result = CloneLargeIconResult(result);
37 cache_.Put(url, entry);
38 }
39
40 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult(
41 const GURL& url) {
42 base::OwningMRUCache<GURL, LargeIconCacheEntry*>::iterator iter =
43 cache_.Get(url);
44 if (iter != cache_.end()) {
45 DCHECK(iter->second->result);
46 return CloneLargeIconResult(*iter->second->result.get());
47 }
48
49 return scoped_ptr<favicon_base::LargeIconResult>();
50 }
51
52 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::CloneLargeIconResult(
53 const favicon_base::LargeIconResult& large_icon_result) {
54 scoped_ptr<favicon_base::LargeIconResult> clone;
55 if (large_icon_result.bitmap.is_valid()) {
56 clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap));
57 } else {
58 clone.reset(
59 new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle(
60 *large_icon_result.fallback_icon_style.get())));
61 }
62 return clone.Pass();
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698