blob: b05b79b9946889b7ec3193ca48db48b7a767dcea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// 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"
#include "components/favicon_base/fallback_icon_style.h"
#include "components/favicon_base/favicon_types.h"
#include "url/gurl.h"
namespace {
const int kMaxCacheSize = 12;
} // 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) {
scoped_ptr<LargeIconCacheEntry> entry(new LargeIconCacheEntry);
entry->result = CloneLargeIconResult(result);
cache_.Put(url, std::move(entry));
}
scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult(
const GURL& url) {
auto 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;
}
|