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

Unified Diff: webkit/tools/test_shell/test_shell_webblobregistry_impl.cc

Issue 6878059: test_shell_webblobregistry_impl.cc posts CString to other threads without (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Copyright date fixed Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/tools/test_shell/test_shell_webblobregistry_impl.cc
diff --git a/webkit/tools/test_shell/test_shell_webblobregistry_impl.cc b/webkit/tools/test_shell/test_shell_webblobregistry_impl.cc
index 9c451cc3ff767b083a88b7d7e212461bf2e0b51b..899b966336ea5bec6ad7bde363a68194439e4e2c 100644
--- a/webkit/tools/test_shell/test_shell_webblobregistry_impl.cc
+++ b/webkit/tools/test_shell/test_shell_webblobregistry_impl.cc
@@ -1,12 +1,14 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/tools/test_shell/test_shell_webblobregistry_impl.h"
#include "base/message_loop.h"
+#include "base/task.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "webkit/blob/blob_data.h"
@@ -21,6 +23,17 @@ namespace {
MessageLoop* g_io_thread;
webkit_blob::BlobStorageController* g_blob_storage_controller;
+// WebURL contains a WebCString object that is ref-counted,
+// but not thread-safe ref-counted.
+// "Normal" copying of WebURL results in a copy that is not thread-safe.
+// This method creates a deep copy of WebURL.
+WebURL GetWebURLThreadsafeCopy(const WebURL& source) {
+ const WebKit::WebCString spec(source.spec());
John Knottenbelt 2011/07/22 11:35:50 If I am reading the code correctly, spec will stil
+ const url_parse::Parsed& parsed(source.parsed());
+ const bool is_valid = source.isValid();
+ return WebURL(spec, parsed, is_valid);
+}
+
} // namespace
/* static */
@@ -42,34 +55,55 @@ TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() {
void TestShellWebBlobRegistryImpl::registerBlobURL(
const WebURL& url, WebBlobData& data) {
DCHECK(g_io_thread);
- // Note: BlobData is not refcounted thread safe.
- scoped_refptr<webkit_blob::BlobData> blob_data(
+ CancelableTask* task;
+ {
+ scoped_refptr<webkit_blob::BlobData> blob_data(
new webkit_blob::BlobData(data));
- g_io_thread->PostTask(
- FROM_HERE,
+ WebURL url_copy = GetWebURLThreadsafeCopy(url);
+ task =
NewRunnableMethod(
- this, &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl, url,
- blob_data));
+ this, &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl, url_copy,
+ blob_data);
+ // After this block exits, url_copy is disposed, and
+ // the underlying WebCString will have a refcount=1 and will
+ // only be accessible from the task object.
+ }
+ g_io_thread->PostTask(FROM_HERE, task);
}
void TestShellWebBlobRegistryImpl::registerBlobURL(
const WebURL& url, const WebURL& src_url) {
DCHECK(g_io_thread);
- g_io_thread->PostTask(
- FROM_HERE,
+ CancelableTask* task;
+ {
+ WebURL url_copy = GetWebURLThreadsafeCopy(url);
+ WebURL src_url_copy = GetWebURLThreadsafeCopy(src_url);
+ task =
NewRunnableMethod(this,
&TestShellWebBlobRegistryImpl::DoRegisterBlobUrlFrom,
- url,
- src_url));
+ url_copy,
+ src_url_copy);
+ // After this block exits, url_copy and src_url_copy are disposed, and
+ // the underlying WebCStrings will have a refcount=1 and will
+ // only be accessible from the task object.
+ }
+ g_io_thread->PostTask(FROM_HERE, task);
}
void TestShellWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
DCHECK(g_io_thread);
- g_io_thread->PostTask(
- FROM_HERE,
+ CancelableTask* task;
+ {
+ WebURL url_copy = GetWebURLThreadsafeCopy(url);
+ task =
NewRunnableMethod(this,
&TestShellWebBlobRegistryImpl::DoUnregisterBlobUrl,
- url));
+ url_copy);
+ // After this block exits, url_copy is disposed, and
+ // the underlying WebCString will have a refcount=1 and will
+ // only be accessible from the task object.
+ }
+ g_io_thread->PostTask(FROM_HERE, task);
}
void TestShellWebBlobRegistryImpl::DoRegisterBlobUrl(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698