Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: webkit/tools/test_shell/test_shell_webblobregistry_impl.cc

Issue 7974011: Break large blobs into multiple ipcs during creation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/message_loop.h" 8 #include "base/message_loop.h"
8 #include "base/task.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #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"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
14 #include "webkit/blob/blob_data.h" 12 #include "webkit/blob/blob_data.h"
15 #include "webkit/blob/blob_storage_controller.h" 13 #include "webkit/blob/blob_storage_controller.h"
16 14
17 using WebKit::WebBlobData; 15 using WebKit::WebBlobData;
18 using WebKit::WebString;
19 using WebKit::WebURL; 16 using WebKit::WebURL;
17 using webkit_blob::BlobData;
20 18
21 namespace { 19 namespace {
22 20
23 MessageLoop* g_io_thread; 21 MessageLoop* g_io_thread;
24 webkit_blob::BlobStorageController* g_blob_storage_controller; 22 webkit_blob::BlobStorageController* g_blob_storage_controller;
25 23
26 // WebURL contains a WebCString object that is ref-counted,
27 // but not thread-safe ref-counted.
28 // "Normal" copying of WebURL results in a copy that is not thread-safe.
29 // This method creates a deep copy of WebURL.
30 WebURL GetWebURLThreadsafeCopy(const WebURL& source) {
31 const WebKit::WebCString spec(source.spec().data(), source.spec().length());
32 const url_parse::Parsed& parsed(source.parsed());
33 const bool is_valid = source.isValid();
34 return WebURL(spec, parsed, is_valid);
35 }
36
37 } // namespace 24 } // namespace
38 25
39 /* static */ 26 /* static */
40 void TestShellWebBlobRegistryImpl::InitializeOnIOThread( 27 void TestShellWebBlobRegistryImpl::InitializeOnIOThread(
41 webkit_blob::BlobStorageController* blob_storage_controller) { 28 webkit_blob::BlobStorageController* blob_storage_controller) {
42 g_io_thread = MessageLoop::current(); 29 g_io_thread = MessageLoop::current();
43 g_blob_storage_controller = blob_storage_controller; 30 g_blob_storage_controller = blob_storage_controller;
44 } 31 }
45 32
46 /* static */ 33 /* static */
47 void TestShellWebBlobRegistryImpl::Cleanup() { 34 void TestShellWebBlobRegistryImpl::Cleanup() {
48 g_io_thread = NULL; 35 g_io_thread = NULL;
49 g_blob_storage_controller = NULL; 36 g_blob_storage_controller = NULL;
50 } 37 }
51 38
52 TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() { 39 TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() {
53 } 40 }
54 41
55 void TestShellWebBlobRegistryImpl::registerBlobURL( 42 void TestShellWebBlobRegistryImpl::registerBlobURL(
56 const WebURL& url, WebBlobData& data) { 43 const WebURL& url, WebBlobData& data) {
57 DCHECK(g_io_thread); 44 DCHECK(g_io_thread);
58 CancelableTask* task; 45 GURL thread_safe_url = url; // WebURL uses refcounted strings.
59 { 46 g_io_thread->PostTask(FROM_HERE, base::Bind(
60 scoped_refptr<webkit_blob::BlobData> blob_data( 47 &TestShellWebBlobRegistryImpl::AddFinishedBlob, this,
61 new webkit_blob::BlobData(data)); 48 thread_safe_url, make_scoped_refptr(new BlobData(data))));
62 WebURL url_copy = GetWebURLThreadsafeCopy(url);
63 task =
64 NewRunnableMethod(
65 this, &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl, url_copy,
66 blob_data);
67 // After this block exits, url_copy is disposed, and
68 // the underlying WebCString will have a refcount=1 and will
69 // only be accessible from the task object.
70 }
71 g_io_thread->PostTask(FROM_HERE, task);
72 } 49 }
73 50
74 void TestShellWebBlobRegistryImpl::registerBlobURL( 51 void TestShellWebBlobRegistryImpl::registerBlobURL(
75 const WebURL& url, const WebURL& src_url) { 52 const WebURL& url, const WebURL& src_url) {
76 DCHECK(g_io_thread); 53 DCHECK(g_io_thread);
77 CancelableTask* task; 54 GURL thread_safe_url = url;
78 { 55 GURL thread_safe_src_url = src_url;
79 WebURL url_copy = GetWebURLThreadsafeCopy(url); 56 g_io_thread->PostTask(FROM_HERE, base::Bind(
80 WebURL src_url_copy = GetWebURLThreadsafeCopy(src_url); 57 &TestShellWebBlobRegistryImpl::CloneBlob, this,
81 task = 58 thread_safe_url, thread_safe_src_url));
82 NewRunnableMethod(this,
83 &TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom,
84 url_copy,
85 src_url_copy);
86 // After this block exits, url_copy and src_url_copy are disposed, and
87 // the underlying WebCStrings will have a refcount=1 and will
88 // only be accessible from the task object.
89 }
90 g_io_thread->PostTask(FROM_HERE, task);
91 } 59 }
92 60
93 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { 61 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
94 DCHECK(g_io_thread); 62 DCHECK(g_io_thread);
95 CancelableTask* task; 63 GURL thread_safe_url = url;
96 { 64 g_io_thread->PostTask(FROM_HERE, base::Bind(
97 WebURL url_copy = GetWebURLThreadsafeCopy(url); 65 &TestShellWebBlobRegistryImpl::RemoveBlob, this,
98 task = 66 thread_safe_url));
99 NewRunnableMethod(this,
100 &TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl,
101 url_copy);
102 // After this block exits, url_copy is disposed, and
103 // the underlying WebCString will have a refcount=1 and will
104 // only be accessible from the task object.
105 }
106 g_io_thread->PostTask(FROM_HERE, task);
107 } 67 }
108 68
109 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrl( 69 void TestShellWebBlobRegistryImpl::AddFinishedBlob(
110 const GURL& url, webkit_blob::BlobData* blob_data) { 70 const GURL& url, BlobData* blob_data) {
111 DCHECK(g_blob_storage_controller); 71 DCHECK(g_blob_storage_controller);
112 g_blob_storage_controller->RegisterBlobUrl(url, blob_data); 72 g_blob_storage_controller->AddFinishedBlob(url, blob_data);
113 } 73 }
114 74
115 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom( 75 void TestShellWebBlobRegistryImpl::CloneBlob(
116 const GURL& url, const GURL& src_url) { 76 const GURL& url, const GURL& src_url) {
117 DCHECK(g_blob_storage_controller); 77 DCHECK(g_blob_storage_controller);
118 g_blob_storage_controller->RegisterBlobUrlFrom(url, src_url); 78 g_blob_storage_controller->CloneBlob(url, src_url);
119 } 79 }
120 80
121 void TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl(const GURL& url) { 81 void TestShellWebBlobRegistryImpl::RemoveBlob(const GURL& url) {
122 DCHECK(g_blob_storage_controller); 82 DCHECK(g_blob_storage_controller);
123 g_blob_storage_controller->UnregisterBlobUrl(url); 83 g_blob_storage_controller->RemoveBlob(url);
124 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698