OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/tools/test_shell/test_shell_webblobregistry_impl.h" | 5 #include "webkit/tools/test_shell/test_shell_webblobregistry_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebBlobData.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebBlobData.h" |
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
12 #include "webkit/base/file_path_string_conversions.h" | 12 #include "webkit/base/file_path_string_conversions.h" |
13 #include "webkit/blob/blob_data.h" | 13 #include "webkit/blob/blob_data.h" |
14 #include "webkit/blob/blob_storage_controller.h" | 14 #include "webkit/blob/blob_storage_context.h" |
15 | 15 |
16 using WebKit::WebBlobData; | 16 using WebKit::WebBlobData; |
| 17 using WebKit::WebString; |
17 using WebKit::WebURL; | 18 using WebKit::WebURL; |
18 using webkit_blob::BlobData; | 19 using webkit_blob::BlobData; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 MessageLoop* g_io_thread; | 23 MessageLoop* g_io_thread; |
23 webkit_blob::BlobStorageController* g_blob_storage_controller; | 24 webkit_blob::BlobStorageContext* g_blob_storage_context; |
24 | 25 |
25 // Creates a new BlobData from WebBlobData. | 26 // Creates a new BlobData from WebBlobData. |
26 BlobData* NewBlobData(const WebBlobData& data) { | 27 BlobData* NewBlobData(const std::string& uuid, const WebBlobData& data) { |
27 BlobData* blob = new BlobData; | 28 BlobData* blob = new BlobData(uuid); |
28 size_t i = 0; | 29 size_t i = 0; |
29 WebBlobData::Item item; | 30 WebBlobData::Item item; |
30 while (data.itemAt(i++, item)) { | 31 while (data.itemAt(i++, item)) { |
31 switch (item.type) { | 32 switch (item.type) { |
32 case WebBlobData::Item::TypeData: | 33 case WebBlobData::Item::TypeData: |
33 if (!item.data.isEmpty()) { | 34 if (!item.data.isEmpty()) { |
34 // WebBlobData does not allow partial data. | 35 // WebBlobData does not allow partial data. |
35 DCHECK(!item.offset && item.length == -1); | 36 DCHECK(!item.offset && item.length == -1); |
36 blob->AppendData(item.data); | 37 blob->AppendData(item.data); |
37 } | 38 } |
38 break; | 39 break; |
39 case WebBlobData::Item::TypeFile: | 40 case WebBlobData::Item::TypeFile: |
40 if (item.length) { | 41 if (item.length) { |
41 blob->AppendFile( | 42 blob->AppendFile( |
42 webkit_base::WebStringToFilePath(item.filePath), | 43 webkit_base::WebStringToFilePath(item.filePath), |
43 static_cast<uint64>(item.offset), | 44 static_cast<uint64>(item.offset), |
44 static_cast<uint64>(item.length), | 45 static_cast<uint64>(item.length), |
45 base::Time::FromDoubleT(item.expectedModificationTime)); | 46 base::Time::FromDoubleT(item.expectedModificationTime)); |
46 } | 47 } |
47 break; | 48 break; |
48 case WebBlobData::Item::TypeBlob: | 49 case WebBlobData::Item::TypeBlob: |
49 if (item.length) { | 50 if (item.length) { |
50 blob->AppendBlob( | 51 blob->AppendBlob( |
51 item.blobURL, | 52 item.blobUUID.utf8(), |
52 static_cast<uint64>(item.offset), | 53 static_cast<uint64>(item.offset), |
53 static_cast<uint64>(item.length)); | 54 static_cast<uint64>(item.length)); |
54 } | 55 } |
55 break; | 56 break; |
56 default: | 57 default: |
57 NOTREACHED(); | 58 NOTREACHED(); |
58 } | 59 } |
59 } | 60 } |
60 blob->set_content_type(data.contentType().utf8().data()); | 61 blob->set_content_type(data.contentType().utf8().data()); |
61 blob->set_content_disposition(data.contentDisposition().utf8().data()); | 62 blob->set_content_disposition(data.contentDisposition().utf8().data()); |
62 return blob; | 63 return blob; |
63 } | 64 } |
64 | 65 |
65 } // namespace | 66 } // namespace |
66 | 67 |
67 /* static */ | 68 /* static */ |
68 void TestShellWebBlobRegistryImpl::InitializeOnIOThread( | 69 void TestShellWebBlobRegistryImpl::InitializeOnIOThread( |
69 webkit_blob::BlobStorageController* blob_storage_controller) { | 70 webkit_blob::BlobStorageContext* blob_storage_context) { |
70 g_io_thread = MessageLoop::current(); | 71 g_io_thread = MessageLoop::current(); |
71 g_blob_storage_controller = blob_storage_controller; | 72 g_blob_storage_context = blob_storage_context; |
72 } | 73 } |
73 | 74 |
74 /* static */ | 75 /* static */ |
75 void TestShellWebBlobRegistryImpl::Cleanup() { | 76 void TestShellWebBlobRegistryImpl::Cleanup() { |
76 g_io_thread = NULL; | 77 g_io_thread = NULL; |
77 g_blob_storage_controller = NULL; | 78 g_blob_storage_context = NULL; |
78 } | 79 } |
79 | 80 |
80 void TestShellWebBlobRegistryImpl::registerBlobURL( | 81 void TestShellWebBlobRegistryImpl::registerBlobData( |
81 const WebURL& url, WebBlobData& data) { | 82 const WebString& uuid, const WebBlobData& data) { |
82 DCHECK(g_io_thread); | 83 DCHECK(g_io_thread); |
83 GURL thread_safe_url = url; // WebURL uses refcounted strings. | |
84 g_io_thread->PostTask(FROM_HERE, base::Bind( | 84 g_io_thread->PostTask(FROM_HERE, base::Bind( |
85 &TestShellWebBlobRegistryImpl::AddFinishedBlob, this, | 85 &TestShellWebBlobRegistryImpl::AddFinishedBlob, this, |
86 thread_safe_url, make_scoped_refptr(NewBlobData(data)))); | 86 make_scoped_refptr(NewBlobData(uuid.utf8(), data)))); |
87 } | 87 } |
88 | 88 |
89 void TestShellWebBlobRegistryImpl::registerBlobURL( | 89 void TestShellWebBlobRegistryImpl::addBlobDataRef(const WebKit::WebString& uuid)
{ |
90 const WebURL& url, const WebURL& src_url) { | 90 DCHECK(g_io_thread); |
| 91 std::string thread_safe_uuid = uuid.utf8(); |
| 92 g_io_thread->PostTask(FROM_HERE, base::Bind( |
| 93 &TestShellWebBlobRegistryImpl::AddBlobDataRef, this, thread_safe_uuid)); |
| 94 } |
| 95 |
| 96 void TestShellWebBlobRegistryImpl::removeBlobDataRef(const WebKit::WebString& uu
id) { |
| 97 DCHECK(g_io_thread); |
| 98 std::string thread_safe_uuid = uuid.utf8(); |
| 99 g_io_thread->PostTask(FROM_HERE, base::Bind( |
| 100 &TestShellWebBlobRegistryImpl::RemoveBlobDataRef, this, thread_safe_uuid))
; |
| 101 } |
| 102 |
| 103 void TestShellWebBlobRegistryImpl::registerPublicBlobURL( |
| 104 const WebURL& url, const WebKit::WebString& uuid) { |
91 DCHECK(g_io_thread); | 105 DCHECK(g_io_thread); |
92 GURL thread_safe_url = url; | 106 GURL thread_safe_url = url; |
93 GURL thread_safe_src_url = src_url; | 107 std::string thread_safe_uuid = uuid.utf8(); |
94 g_io_thread->PostTask(FROM_HERE, base::Bind( | 108 g_io_thread->PostTask(FROM_HERE, base::Bind( |
95 &TestShellWebBlobRegistryImpl::CloneBlob, this, | 109 &TestShellWebBlobRegistryImpl::RegisterPublicBlobURL, this, |
96 thread_safe_url, thread_safe_src_url)); | 110 thread_safe_url, thread_safe_uuid)); |
97 } | 111 } |
98 | 112 |
99 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { | 113 void TestShellWebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { |
100 DCHECK(g_io_thread); | 114 DCHECK(g_io_thread); |
101 GURL thread_safe_url = url; | 115 GURL thread_safe_url = url; |
102 g_io_thread->PostTask(FROM_HERE, base::Bind( | 116 g_io_thread->PostTask(FROM_HERE, base::Bind( |
103 &TestShellWebBlobRegistryImpl::RemoveBlob, this, | 117 &TestShellWebBlobRegistryImpl::RevokePublicBlobURL, this, |
104 thread_safe_url)); | 118 thread_safe_url)); |
105 } | 119 } |
106 | 120 |
107 TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() {} | 121 TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() {} |
108 | 122 |
109 void TestShellWebBlobRegistryImpl::AddFinishedBlob( | 123 void TestShellWebBlobRegistryImpl::AddFinishedBlob( |
110 const GURL& url, BlobData* blob_data) { | 124 BlobData* blob_data) { |
111 DCHECK(g_blob_storage_controller); | 125 DCHECK(g_blob_storage_context); |
112 g_blob_storage_controller->AddFinishedBlob(url, blob_data); | 126 g_blob_storage_context->AddFinishedBlob(blob_data); |
113 } | 127 } |
114 | 128 |
115 void TestShellWebBlobRegistryImpl::CloneBlob( | 129 void TestShellWebBlobRegistryImpl::AddBlobDataRef( |
116 const GURL& url, const GURL& src_url) { | 130 const std::string& uuid) { |
117 DCHECK(g_blob_storage_controller); | 131 DCHECK(g_blob_storage_context); |
118 g_blob_storage_controller->CloneBlob(url, src_url); | 132 g_blob_storage_context->IncrementBlobRefCount(uuid); |
119 } | 133 } |
120 | 134 |
121 void TestShellWebBlobRegistryImpl::RemoveBlob(const GURL& url) { | 135 void TestShellWebBlobRegistryImpl::RemoveBlobDataRef( |
122 DCHECK(g_blob_storage_controller); | 136 const std::string& uuid) { |
123 g_blob_storage_controller->RemoveBlob(url); | 137 DCHECK(g_blob_storage_context); |
| 138 g_blob_storage_context->DecrementBlobRefCount(uuid); |
124 } | 139 } |
| 140 |
| 141 void TestShellWebBlobRegistryImpl::RegisterPublicBlobURL( |
| 142 const GURL& url, const std::string& uuid) { |
| 143 DCHECK(g_blob_storage_context); |
| 144 g_blob_storage_context->RegisterPublicBlobURL(url, uuid); |
| 145 } |
| 146 |
| 147 void TestShellWebBlobRegistryImpl::RevokePublicBlobURL(const GURL& url) { |
| 148 DCHECK(g_blob_storage_context); |
| 149 g_blob_storage_context->RevokePublicBlobURL(url); |
| 150 } |
| 151 |
OLD | NEW |