blob: 28c8de086240fc0e72810bd027f2296e2a2435a9 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright 2014 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 "components/enhanced_bookmarks/test_image_store.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"
TestImageStore::TestImageStore() {
}
bool TestImageStore::HasKey(const GURL& page_url) {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
return store_.find(page_url) != store_.end();
}
void TestImageStore::Insert(
const GURL& page_url,
scoped_refptr<enhanced_bookmarks::ImageRecord> image_record) {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
Erase(page_url);
store_.insert(std::make_pair(page_url, image_record));
}
void TestImageStore::Erase(const GURL& page_url) {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
store_.erase(page_url);
}
scoped_refptr<enhanced_bookmarks::ImageRecord> TestImageStore::Get(
const GURL& page_url) {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
if (store_.find(page_url) == store_.end()) {
return scoped_refptr<enhanced_bookmarks::ImageRecord>(
new enhanced_bookmarks::ImageRecord());
}
return store_[page_url];
}
gfx::Size TestImageStore::GetSize(const GURL& page_url) {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
ImageMap::const_iterator pair_enumerator = store_.find(page_url);
if (pair_enumerator == store_.end())
return gfx::Size();
return store_[page_url]->image->Size();
}
void TestImageStore::GetAllPageUrls(std::set<GURL>* urls) {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
DCHECK(urls->empty());
for (ImageMap::const_iterator it = store_.begin(); it != store_.end(); ++it)
urls->insert(it->first);
}
void TestImageStore::ClearAll() {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
store_.clear();
}
int64 TestImageStore::GetStoreSizeInBytes() {
// Not 100% accurate, but it's for testing so the actual value is not
// important.
int64 size = sizeof(store_);
for (ImageMap::const_iterator it = store_.begin(); it != store_.end(); ++it) {
size += sizeof(it->first);
size += it->first.spec().length();
size += sizeof(it->second);
SkBitmap bitmap = it->second->image->AsBitmap();
size += bitmap.getSize();
size += it->second->url.spec().length();
size += sizeof(it->second->dominant_color);
}
return size;
}
TestImageStore::~TestImageStore() {
DCHECK(sequence_checker_.CalledOnValidSequencedThread());
}
|