Chromium Code Reviews| 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 "base/task.h" | |
| 8 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 12 #include "webkit/blob/blob_data.h" | 14 #include "webkit/blob/blob_data.h" |
| 13 #include "webkit/blob/blob_storage_controller.h" | 15 #include "webkit/blob/blob_storage_controller.h" |
| 14 | 16 |
| 15 using WebKit::WebBlobData; | 17 using WebKit::WebBlobData; |
| 16 using WebKit::WebString; | 18 using WebKit::WebString; |
| 17 using WebKit::WebURL; | 19 using WebKit::WebURL; |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 MessageLoop* g_io_thread; | 23 MessageLoop* g_io_thread; |
| 22 webkit_blob::BlobStorageController* g_blob_storage_controller; | 24 webkit_blob::BlobStorageController* g_blob_storage_controller; |
| 23 | 25 |
| 26 // Copy WebURL object to safely pass it to a different thread. | |
|
jianli
2011/04/19 23:58:00
Maybe better to add more comment like the followin
Dmitry Lomov
2011/04/20 00:27:01
Done.
| |
| 27 static WebURL GetWebURLCopy(const WebURL& source) { | |
|
jianli
2011/04/19 23:58:00
I think you can remove "static".
Dmitry Lomov
2011/04/20 00:27:01
Done.
| |
| 28 // Creates a copy of WebCString with refcount 1. | |
|
jianli
2011/04/19 23:58:00
I think this comment can be removed with the addit
Dmitry Lomov
2011/04/20 00:27:01
Done.
| |
| 29 const WebKit::WebCString spec(source.spec()); | |
| 30 const url_parse::Parsed& parsed(source.parsed()); | |
| 31 const bool is_valid = source.isValid(); | |
| 32 return WebURL(spec, parsed, is_valid); | |
| 33 } | |
| 34 | |
| 24 } // namespace | 35 } // namespace |
| 25 | 36 |
| 26 /* static */ | 37 /* static */ |
| 27 void TestShellWebBlobRegistryImpl::InitializeOnIOThread( | 38 void TestShellWebBlobRegistryImpl::InitializeOnIOThread( |
| 28 webkit_blob::BlobStorageController* blob_storage_controller) { | 39 webkit_blob::BlobStorageController* blob_storage_controller) { |
| 29 g_io_thread = MessageLoop::current(); | 40 g_io_thread = MessageLoop::current(); |
| 30 g_blob_storage_controller = blob_storage_controller; | 41 g_blob_storage_controller = blob_storage_controller; |
| 31 } | 42 } |
| 32 | 43 |
| 33 /* static */ | 44 /* static */ |
| 34 void TestShellWebBlobRegistryImpl::Cleanup() { | 45 void TestShellWebBlobRegistryImpl::Cleanup() { |
| 35 g_io_thread = NULL; | 46 g_io_thread = NULL; |
| 36 g_blob_storage_controller = NULL; | 47 g_blob_storage_controller = NULL; |
| 37 } | 48 } |
| 38 | 49 |
| 39 TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() { | 50 TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() { |
| 40 } | 51 } |
| 41 | 52 |
| 42 void TestShellWebBlobRegistryImpl::registerBlobURL( | 53 void TestShellWebBlobRegistryImpl::registerBlobURL( |
| 43 const WebURL& url, WebBlobData& data) { | 54 const WebURL& url, WebBlobData& data) { |
| 44 DCHECK(g_io_thread); | 55 DCHECK(g_io_thread); |
| 45 // Note: BlobData is not refcounted thread safe. | 56 CancelableTask* task; |
| 46 scoped_refptr<webkit_blob::BlobData> blob_data( | 57 { |
| 58 scoped_refptr<webkit_blob::BlobData> blob_data( | |
| 47 new webkit_blob::BlobData(data)); | 59 new webkit_blob::BlobData(data)); |
| 48 g_io_thread->PostTask( | 60 WebURL url_copy = ::GetWebURLCopy(url); |
| 49 FROM_HERE, | 61 task = |
| 50 NewRunnableMethod( | 62 NewRunnableMethod( |
| 51 this, &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl, url, | 63 this, &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl, url_copy, |
| 52 blob_data)); | 64 blob_data); |
| 65 } | |
| 66 g_io_thread->PostTask(FROM_HERE, task); | |
| 53 } | 67 } |
| 54 | 68 |
| 55 void TestShellWebBlobRegistryImpl::registerBlobURL( | 69 void TestShellWebBlobRegistryImpl::registerBlobURL( |
| 56 const WebURL& url, const WebURL& src_url) { | 70 const WebURL& url, const WebURL& src_url) { |
| 57 DCHECK(g_io_thread); | 71 DCHECK(g_io_thread); |
| 58 g_io_thread->PostTask( | 72 CancelableTask* task; |
| 59 FROM_HERE, | 73 { |
| 74 WebURL url_copy = ::GetWebURLCopy(url); | |
| 75 WebURL src_url_copy = ::GetWebURLCopy(src_url); | |
| 76 task = | |
| 60 NewRunnableMethod(this, | 77 NewRunnableMethod(this, |
| 61 &TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom, | 78 &TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom, |
| 62 url, | 79 url_copy, |
|
jianli
2011/04/19 23:58:00
You can put GetWebURLCopy(url) here directly. Doin
Dmitry Lomov
2011/04/20 00:27:01
Done.
| |
| 63 src_url)); | 80 src_url_copy); |
| 81 } | |
| 82 g_io_thread->PostTask(FROM_HERE, task); | |
| 64 } | 83 } |
| 65 | 84 |
| 66 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { | 85 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { |
| 67 DCHECK(g_io_thread); | 86 DCHECK(g_io_thread); |
| 68 g_io_thread->PostTask( | 87 CancelableTask* task; |
| 69 FROM_HERE, | 88 { |
| 89 WebURL url_copy = ::GetWebURLCopy(url); | |
| 90 task = | |
| 70 NewRunnableMethod(this, | 91 NewRunnableMethod(this, |
| 71 &TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl, | 92 &TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl, |
| 72 url)); | 93 url_copy); |
| 94 } | |
| 95 g_io_thread->PostTask(FROM_HERE, task); | |
| 73 } | 96 } |
| 74 | 97 |
| 75 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrl( | 98 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrl( |
| 76 const GURL& url, webkit_blob::BlobData* blob_data) { | 99 const GURL& url, webkit_blob::BlobData* blob_data) { |
| 77 DCHECK(g_blob_storage_controller); | 100 DCHECK(g_blob_storage_controller); |
| 78 g_blob_storage_controller->RegisterBlobUrl(url, blob_data); | 101 g_blob_storage_controller->RegisterBlobUrl(url, blob_data); |
| 79 } | 102 } |
| 80 | 103 |
| 81 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom( | 104 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom( |
| 82 const GURL& url, const GURL& src_url) { | 105 const GURL& url, const GURL& src_url) { |
| 83 DCHECK(g_blob_storage_controller); | 106 DCHECK(g_blob_storage_controller); |
| 84 g_blob_storage_controller->RegisterBlobUrlFrom(url, src_url); | 107 g_blob_storage_controller->RegisterBlobUrlFrom(url, src_url); |
| 85 } | 108 } |
| 86 | 109 |
| 87 void TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl(const GURL& url) { | 110 void TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl(const GURL& url) { |
| 88 DCHECK(g_blob_storage_controller); | 111 DCHECK(g_blob_storage_controller); |
| 89 g_blob_storage_controller->UnregisterBlobUrl(url); | 112 g_blob_storage_controller->UnregisterBlobUrl(url); |
| 90 } | 113 } |
| OLD | NEW |