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 GURL
& image_url
,
22 const gfx::Image
& image
) {
23 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
26 store_
.insert(std::make_pair(
32 void TestImageStore::Erase(const GURL
& page_url
) {
33 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
35 store_
.erase(page_url
);
38 std::pair
<gfx::Image
, GURL
> TestImageStore::Get(const GURL
& page_url
) {
39 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
41 ImageMap::const_iterator pair_enumerator
= store_
.find(page_url
);
42 if (pair_enumerator
== store_
.end())
43 return std::make_pair(gfx::Image(), GURL());
45 return std::make_pair(store_
[page_url
].first
, store_
[page_url
].second
);
48 gfx::Size
TestImageStore::GetSize(const GURL
& page_url
) {
49 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
51 ImageMap::const_iterator pair_enumerator
= store_
.find(page_url
);
52 if (pair_enumerator
== store_
.end())
55 return store_
[page_url
].first
.Size();
58 void TestImageStore::GetAllPageUrls(std::set
<GURL
>* urls
) {
59 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
60 DCHECK(urls
->empty());
62 for (ImageMap::const_iterator it
= store_
.begin(); it
!= store_
.end(); ++it
)
63 urls
->insert(it
->first
);
66 void TestImageStore::ClearAll() {
67 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
72 int64
TestImageStore::GetStoreSizeInBytes() {
73 // Not 100% accurate, but it's for testing so the actual value is not
75 int64 size
= sizeof(store_
);
76 for (ImageMap::const_iterator it
= store_
.begin(); it
!= store_
.end(); ++it
) {
77 size
+= sizeof(it
->first
);
78 size
+= it
->first
.spec().length();
79 size
+= sizeof(it
->second
);
80 SkBitmap bitmap
= it
->second
.first
.AsBitmap();
81 size
+= bitmap
.getSize();
82 size
+= it
->second
.second
.spec().length();
87 TestImageStore::~TestImageStore() {
88 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());