1 // Copyright 2014 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.
5 #include "components/enhanced_bookmarks/test_image_store.h"
7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/gfx/geometry/size.h"
11 TestImageStore::TestImageStore() {
14 bool TestImageStore::HasKey(const GURL
& page_url
) {
15 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
17 return store_
.find(page_url
) != store_
.end();
20 void TestImageStore::Insert(const GURL
& page_url
,
21 const enhanced_bookmarks::ImageRecord
& image
) {
22 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
25 store_
.insert(std::make_pair(page_url
, image
));
28 void TestImageStore::Erase(const GURL
& page_url
) {
29 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
31 store_
.erase(page_url
);
34 enhanced_bookmarks::ImageRecord
TestImageStore::Get(const GURL
& page_url
) {
35 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
37 if (store_
.find(page_url
) == store_
.end())
38 return enhanced_bookmarks::ImageRecord();
40 return store_
[page_url
];
43 gfx::Size
TestImageStore::GetSize(const GURL
& page_url
) {
44 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
46 ImageMap::const_iterator pair_enumerator
= store_
.find(page_url
);
47 if (pair_enumerator
== store_
.end())
50 return store_
[page_url
].image
.Size();
53 void TestImageStore::GetAllPageUrls(std::set
<GURL
>* urls
) {
54 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
55 DCHECK(urls
->empty());
57 for (ImageMap::const_iterator it
= store_
.begin(); it
!= store_
.end(); ++it
)
58 urls
->insert(it
->first
);
61 void TestImageStore::ClearAll() {
62 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
67 int64
TestImageStore::GetStoreSizeInBytes() {
68 // Not 100% accurate, but it's for testing so the actual value is not
70 int64 size
= sizeof(store_
);
71 for (ImageMap::const_iterator it
= store_
.begin(); it
!= store_
.end(); ++it
) {
72 size
+= sizeof(it
->first
);
73 size
+= it
->first
.spec().length();
74 size
+= sizeof(it
->second
);
75 SkBitmap bitmap
= it
->second
.image
.AsBitmap();
76 size
+= bitmap
.getSize();
77 size
+= it
->second
.url
.spec().length();
78 size
+= sizeof(it
->second
.dominant_color
);
83 TestImageStore::~TestImageStore() {
84 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());