Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / enhanced_bookmarks / test_image_store.cc
blob28c8de086240fc0e72810bd027f2296e2a2435a9
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"
9 #include "url/gurl.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(
21 const GURL& page_url,
22 scoped_refptr<enhanced_bookmarks::ImageRecord> image_record) {
23 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
25 Erase(page_url);
26 store_.insert(std::make_pair(page_url, image_record));
29 void TestImageStore::Erase(const GURL& page_url) {
30 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
32 store_.erase(page_url);
35 scoped_refptr<enhanced_bookmarks::ImageRecord> TestImageStore::Get(
36 const GURL& page_url) {
37 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
39 if (store_.find(page_url) == store_.end()) {
40 return scoped_refptr<enhanced_bookmarks::ImageRecord>(
41 new enhanced_bookmarks::ImageRecord());
44 return store_[page_url];
47 gfx::Size TestImageStore::GetSize(const GURL& page_url) {
48 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
50 ImageMap::const_iterator pair_enumerator = store_.find(page_url);
51 if (pair_enumerator == store_.end())
52 return gfx::Size();
54 return store_[page_url]->image->Size();
57 void TestImageStore::GetAllPageUrls(std::set<GURL>* urls) {
58 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
59 DCHECK(urls->empty());
61 for (ImageMap::const_iterator it = store_.begin(); it != store_.end(); ++it)
62 urls->insert(it->first);
65 void TestImageStore::ClearAll() {
66 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
68 store_.clear();
71 int64 TestImageStore::GetStoreSizeInBytes() {
72 // Not 100% accurate, but it's for testing so the actual value is not
73 // important.
74 int64 size = sizeof(store_);
75 for (ImageMap::const_iterator it = store_.begin(); it != store_.end(); ++it) {
76 size += sizeof(it->first);
77 size += it->first.spec().length();
78 size += sizeof(it->second);
79 SkBitmap bitmap = it->second->image->AsBitmap();
80 size += bitmap.getSize();
81 size += it->second->url.spec().length();
82 size += sizeof(it->second->dominant_color);
84 return size;
87 TestImageStore::~TestImageStore() {
88 DCHECK(sequence_checker_.CalledOnValidSequencedThread());