Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / enhanced_bookmarks / test_image_store.cc
blob19d505ff650a80fd065418a0dc881c38df960949
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(const GURL& page_url,
21 const GURL& image_url,
22 const gfx::Image& image) {
23 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
25 Erase(page_url);
26 store_.insert(std::make_pair(
27 page_url,
28 std::make_pair(image,
29 image_url)));
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())
53 return gfx::Size();
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());
69 store_.clear();
72 int64 TestImageStore::GetStoreSizeInBytes() {
73 // Not 100% accurate, but it's for testing so the actual value is not
74 // important.
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();
84 return size;
87 TestImageStore::~TestImageStore() {
88 DCHECK(sequence_checker_.CalledOnValidSequencedThread());