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

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
« no previous file with comments | « webkit/tools/test_shell/test_shell_webblobregistry_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/task.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 scoped_refptr<BlobData> blob_data(new BlobData(data));
60 scoped_refptr<webkit_blob::BlobData> blob_data( 47 g_io_thread->PostTask(FROM_HERE, NewRunnableMethod(
michaeln 2011/09/29 19:36:20 also switched to using base::Bind in this file
61 new webkit_blob::BlobData(data)); 48 this, &TestShellWebBlobRegistryImpl::AddFinishedBlob,
62 WebURL url_copy = GetWebURLThreadsafeCopy(url); 49 thread_safe_url, blob_data));
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 } 50 }
73 51
74 void TestShellWebBlobRegistryImpl::registerBlobURL( 52 void TestShellWebBlobRegistryImpl::registerBlobURL(
75 const WebURL& url, const WebURL& src_url) { 53 const WebURL& url, const WebURL& src_url) {
76 DCHECK(g_io_thread); 54 DCHECK(g_io_thread);
77 CancelableTask* task; 55 GURL thread_safe_url = url;
78 { 56 GURL thread_safe_src_url = src_url;
79 WebURL url_copy = GetWebURLThreadsafeCopy(url); 57 g_io_thread->PostTask(FROM_HERE, NewRunnableMethod(
80 WebURL src_url_copy = GetWebURLThreadsafeCopy(src_url); 58 this, &TestShellWebBlobRegistryImpl::CloneBlob,
81 task = 59 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 } 60 }
92 61
93 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { 62 void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
94 DCHECK(g_io_thread); 63 DCHECK(g_io_thread);
95 CancelableTask* task; 64 GURL thread_safe_url = url;
96 { 65 g_io_thread->PostTask(FROM_HERE, NewRunnableMethod(
97 WebURL url_copy = GetWebURLThreadsafeCopy(url); 66 this, &TestShellWebBlobRegistryImpl::RemoveBlob,
98 task = 67 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 } 68 }
108 69
109 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrl( 70 void TestShellWebBlobRegistryImpl::AddFinishedBlob(
110 const GURL& url, webkit_blob::BlobData* blob_data) { 71 const GURL& url, BlobData* blob_data) {
111 DCHECK(g_blob_storage_controller); 72 DCHECK(g_blob_storage_controller);
112 g_blob_storage_controller->RegisterBlobUrl(url, blob_data); 73 g_blob_storage_controller->AddFinishedBlob(url, blob_data);
113 } 74 }
114 75
115 void TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom( 76 void TestShellWebBlobRegistryImpl::CloneBlob(
116 const GURL& url, const GURL& src_url) { 77 const GURL& url, const GURL& src_url) {
117 DCHECK(g_blob_storage_controller); 78 DCHECK(g_blob_storage_controller);
118 g_blob_storage_controller->RegisterBlobUrlFrom(url, src_url); 79 g_blob_storage_controller->CloneBlob(url, src_url);
119 } 80 }
120 81
121 void TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl(const GURL& url) { 82 void TestShellWebBlobRegistryImpl::RemoveBlob(const GURL& url) {
122 DCHECK(g_blob_storage_controller); 83 DCHECK(g_blob_storage_controller);
123 g_blob_storage_controller->UnregisterBlobUrl(url); 84 g_blob_storage_controller->RemoveBlob(url);
124 } 85 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_shell_webblobregistry_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698