OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
12 #include "webkit/blob/blob_data.h" | 13 #include "webkit/blob/blob_data.h" |
13 #include "webkit/blob/blob_storage_controller.h" | 14 #include "webkit/blob/blob_storage_controller.h" |
14 | 15 |
15 using WebKit::WebBlobData; | 16 using WebKit::WebBlobData; |
16 using WebKit::WebString; | 17 using WebKit::WebString; |
17 using WebKit::WebURL; | 18 using WebKit::WebURL; |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 MessageLoop* g_io_thread; | 22 MessageLoop* g_io_thread; |
22 webkit_blob::BlobStorageController* g_blob_storage_controller; | 23 webkit_blob::BlobStorageController* g_blob_storage_controller; |
23 | 24 |
24 } // namespace | 25 } // namespace |
25 | 26 |
26 /* static */ | 27 /* static */ |
27 void TestShellWebBlobRegistryImpl::InitializeOnIOThread( | 28 void TestShellWebBlobRegistryImpl::InitializeOnIOThread( |
28 webkit_blob::BlobStorageController* blob_storage_controller) { | 29 webkit_blob::BlobStorageController* blob_storage_controller) { |
29 g_io_thread = MessageLoop::current(); | 30 g_io_thread = MessageLoop::current(); |
30 g_blob_storage_controller = blob_storage_controller; | 31 g_blob_storage_controller = blob_storage_controller; |
31 } | 32 } |
32 | 33 |
33 /* static */ | 34 /* static */ |
34 void TestShellWebBlobRegistryImpl::Cleanup() { | 35 void TestShellWebBlobRegistryImpl::Cleanup() { |
35 g_io_thread = NULL; | 36 g_io_thread = NULL; |
36 g_blob_storage_controller = NULL; | 37 g_blob_storage_controller = NULL; |
37 } | 38 } |
38 | 39 |
40 // Copy WebURL object to safely pass it to a different thread | |
41 static void CopyWebURL(const WebURL& source, WebURL* target) { | |
tony
2011/04/19 22:27:35
I would probably just return a WebURL. There's an
jianli
2011/04/19 22:53:02
I agree with Tony that returning a WebURL will mak
| |
42 // Creates a copy of WebCString with refcount 1 | |
jianli
2011/04/19 22:53:02
Please end with period.
| |
43 const WebKit::WebCString spec(source.spec()); | |
44 const url_parse::Parsed& parsed(source.parsed()); | |
45 const bool is_valid = source.isValid(); | |
46 target->assign(spec, parsed, is_valid); | |
47 } | |
48 | |
39 TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() { | 49 TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() { |
40 } | 50 } |
41 | 51 |
42 void TestShellWebBlobRegistryImpl::registerBlobURL( | 52 void TestShellWebBlobRegistryImpl::registerBlobURL( |
43 const WebURL& url, WebBlobData& data) { | 53 const WebURL& url, WebBlobData& data) { |
44 DCHECK(g_io_thread); | 54 DCHECK(g_io_thread); |
45 // Note: BlobData is not refcounted thread safe. | 55 // Note: BlobData is not refcounted thread safe. |
46 scoped_refptr<webkit_blob::BlobData> blob_data( | 56 scoped_refptr<webkit_blob::BlobData> blob_data( |
47 new webkit_blob::BlobData(data)); | 57 new webkit_blob::BlobData(data)); |
58 WebURL url_copy; | |
59 CopyWebURL(url, &url_copy); | |
48 g_io_thread->PostTask( | 60 g_io_thread->PostTask( |
49 FROM_HERE, | 61 FROM_HERE, |
50 NewRunnableMethod( | 62 NewRunnableMethod( |
51 this, &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl, url, | 63 this, &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl, url_copy, |
52 blob_data)); | 64 blob_data)); |
53 } | 65 } |
54 | 66 |
55 void TestShellWebBlobRegistryImpl::registerBlobURL( | 67 void TestShellWebBlobRegistryImpl::registerBlobURL( |
56 const WebURL& url, const WebURL& src_url) { | 68 const WebURL& url, const WebURL& src_url) { |
57 DCHECK(g_io_thread); | 69 DCHECK(g_io_thread); |
70 WebURL url_copy; | |
71 CopyWebURL(url, &url_copy); | |
72 WebURL src_url_copy; | |
73 CopyWebURL(src_url, &src_url_copy); | |
58 g_io_thread->PostTask( | 74 g_io_thread->PostTask( |
59 FROM_HERE, | 75 FROM_HERE, |
60 NewRunnableMethod(this, | 76 NewRunnableMethod(this, |
61 &TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom, | 77 &TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom, |
62 url, | 78 url_copy, |
63 src_url)); | 79 src_url_copy)); |
64 } | 80 } |
65 | 81 |
66 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { | 82 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { |
67 DCHECK(g_io_thread); | 83 DCHECK(g_io_thread); |
84 WebURL url_copy; | |
85 CopyWebURL(url, &url_copy); | |
68 g_io_thread->PostTask( | 86 g_io_thread->PostTask( |
69 FROM_HERE, | 87 FROM_HERE, |
70 NewRunnableMethod(this, | 88 NewRunnableMethod(this, |
71 &TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl, | 89 &TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl, |
72 url)); | 90 url)); |
tony
2011/04/19 22:27:35
Did you mean to use url_copy here?
| |
73 } | 91 } |
74 | 92 |
75 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrl( | 93 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrl( |
76 const GURL& url, webkit_blob::BlobData* blob_data) { | 94 const GURL& url, webkit_blob::BlobData* blob_data) { |
77 DCHECK(g_blob_storage_controller); | 95 DCHECK(g_blob_storage_controller); |
78 g_blob_storage_controller->RegisterBlobUrl(url, blob_data); | 96 g_blob_storage_controller->RegisterBlobUrl(url, blob_data); |
79 } | 97 } |
80 | 98 |
81 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom( | 99 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom( |
82 const GURL& url, const GURL& src_url) { | 100 const GURL& url, const GURL& src_url) { |
83 DCHECK(g_blob_storage_controller); | 101 DCHECK(g_blob_storage_controller); |
84 g_blob_storage_controller->RegisterBlobUrlFrom(url, src_url); | 102 g_blob_storage_controller->RegisterBlobUrlFrom(url, src_url); |
85 } | 103 } |
86 | 104 |
87 void TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl(const GURL& url) { | 105 void TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl(const GURL& url) { |
88 DCHECK(g_blob_storage_controller); | 106 DCHECK(g_blob_storage_controller); |
89 g_blob_storage_controller->UnregisterBlobUrl(url); | 107 g_blob_storage_controller->UnregisterBlobUrl(url); |
90 } | 108 } |
OLD | NEW |