Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / html_viewer / mock_web_blob_registry_impl.cc
blob02cff578282b53a145f1167bece7ada8d05b85ea
1 // Copyright 2015 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/html_viewer/mock_web_blob_registry_impl.h"
7 #include "third_party/WebKit/public/platform/WebBlobData.h"
8 #include "third_party/WebKit/public/platform/WebString.h"
9 #include "third_party/WebKit/public/platform/WebURL.h"
10 #include "third_party/WebKit/public/platform/WebVector.h"
12 using blink::WebBlobData;
13 using blink::WebString;
14 using blink::WebURL;
15 using blink::WebVector;
17 namespace html_viewer {
19 MockWebBlobRegistryImpl::MockWebBlobRegistryImpl() {
22 MockWebBlobRegistryImpl::~MockWebBlobRegistryImpl() {
25 void MockWebBlobRegistryImpl::registerBlobData(const WebString& uuid,
26 const WebBlobData& data) {
27 const std::string uuid_str(uuid.utf8());
28 blob_ref_count_map_[uuid_str] = 1;
29 scoped_ptr<ScopedVector<blink::WebBlobData::Item>> items(
30 new ScopedVector<blink::WebBlobData::Item>);
31 items->reserve(data.itemCount());
32 for (size_t i = 0; i < data.itemCount(); ++i) {
33 scoped_ptr<blink::WebBlobData::Item> item(new blink::WebBlobData::Item);
34 data.itemAt(i, *item);
35 items->push_back(item.release());
37 blob_data_items_map_.set(uuid_str, items.Pass());
40 void MockWebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) {
41 blob_ref_count_map_[uuid.utf8()]++;
44 void MockWebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) {
45 const std::string uuid_str(uuid.utf8());
46 auto it = blob_ref_count_map_.find(uuid_str);
47 if (it != blob_ref_count_map_.end() && !--it->second) {
48 blob_data_items_map_.erase(uuid_str);
49 blob_ref_count_map_.erase(it);
53 void MockWebBlobRegistryImpl::registerPublicBlobURL(const WebURL& url,
54 const WebString& uuid) {
55 public_url_to_uuid_[url.spec()] = uuid;
56 addBlobDataRef(uuid);
59 void MockWebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) {
60 auto it = public_url_to_uuid_.find(url.spec());
61 if (it != public_url_to_uuid_.end()) {
62 removeBlobDataRef(it->second);
63 public_url_to_uuid_.erase(it);
67 void MockWebBlobRegistryImpl::registerStreamURL(const WebURL& url,
68 const WebString& content_type) {
69 NOTIMPLEMENTED();
72 void MockWebBlobRegistryImpl::registerStreamURL(const WebURL& url,
73 const blink::WebURL& src_url) {
74 NOTIMPLEMENTED();
77 void MockWebBlobRegistryImpl::addDataToStream(const WebURL& url,
78 const char* data,
79 size_t length) {
80 NOTIMPLEMENTED();
83 void MockWebBlobRegistryImpl::flushStream(const WebURL& url) {
84 NOTIMPLEMENTED();
87 void MockWebBlobRegistryImpl::finalizeStream(const WebURL& url) {
88 NOTIMPLEMENTED();
91 void MockWebBlobRegistryImpl::abortStream(const WebURL& url) {
92 NOTIMPLEMENTED();
95 void MockWebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) {
96 NOTIMPLEMENTED();
99 bool MockWebBlobRegistryImpl::GetUUIDForURL(const blink::WebURL& url,
100 blink::WebString* uuid) const {
101 auto it = public_url_to_uuid_.find(url.spec());
102 if (it != public_url_to_uuid_.end()) {
103 *uuid = it->second;
104 return true;
107 return false;
110 bool MockWebBlobRegistryImpl::GetBlobItems(
111 const WebString& uuid,
112 WebVector<WebBlobData::Item*>* items) const {
113 ScopedVector<WebBlobData::Item>* item_vector =
114 blob_data_items_map_.get(uuid.utf8());
115 if (!item_vector)
116 return false;
117 *items = item_vector->get();
118 return true;
121 } // namespace html_viewer