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
;
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
;
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
) {
72 void MockWebBlobRegistryImpl::registerStreamURL(const WebURL
& url
,
73 const blink::WebURL
& src_url
) {
77 void MockWebBlobRegistryImpl::addDataToStream(const WebURL
& url
,
83 void MockWebBlobRegistryImpl::flushStream(const WebURL
& url
) {
87 void MockWebBlobRegistryImpl::finalizeStream(const WebURL
& url
) {
91 void MockWebBlobRegistryImpl::abortStream(const WebURL
& url
) {
95 void MockWebBlobRegistryImpl::unregisterStreamURL(const WebURL
& url
) {
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()) {
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());
117 *items
= item_vector
->get();
121 } // namespace html_viewer