summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-26 03:03:18 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-26 03:03:18 +0000
commit8f608b2c8e3e11325f14b6306bc616aedc0fbac3 (patch)
treec90650f6d386800098ecce84905dc40a20784ae3 /chrome/browser
parentb1cf1c4e3489c52a478343eae080ed850f292a87 (diff)
downloadchromium_src-8f608b2c8e3e11325f14b6306bc616aedc0fbac3.zip
chromium_src-8f608b2c8e3e11325f14b6306bc616aedc0fbac3.tar.gz
chromium_src-8f608b2c8e3e11325f14b6306bc616aedc0fbac3.tar.bz2
Merge 33144 - RESUBMIT of http://codereview.chromium.org/404025/show
Start the WebKit thread when we initialize the resource dispatcher host. NOTE: It's very possible this will have a startup performance impact. I'm going to watch the bots after committing. TODO: Clean up shutdown logic that exists simply because we don't know whether or not we'll ever start the WebKit thread. Originally landed in r33063, reverted in r33101 due to coincidence with Modules Linux startup test failures. TBR=jorlow, darin TEST=The WebKit thread gets spun up early in the initialization process. BUG=24144,28364 Review URL: http://codereview.chromium.org/441025 TBR=chase@chromium.org Review URL: http://codereview.chromium.org/443014 git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@33170 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc52
-rw-r--r--chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h4
-rw-r--r--chrome/browser/in_process_webkit/webkit_thread.cc31
-rw-r--r--chrome/browser/in_process_webkit/webkit_thread.h19
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.cc1
5 files changed, 42 insertions, 65 deletions
diff --git a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc
index 75b9bfc..d295ce1 100644
--- a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc
+++ b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc
@@ -150,9 +150,9 @@ void DOMStorageDispatcherHost::Send(IPC::Message* message) {
void DOMStorageDispatcherHost::OnNamespaceId(DOMStorageType storage_type,
IPC::Message* reply_msg) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnNamespaceId,
- storage_type, reply_msg));
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnNamespaceId, storage_type,
+ reply_msg));
return;
}
@@ -170,9 +170,9 @@ void DOMStorageDispatcherHost::OnNamespaceId(DOMStorageType storage_type,
void DOMStorageDispatcherHost::OnCloneNamespaceId(int64 namespace_id,
IPC::Message* reply_msg) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnCloneNamespaceId,
- namespace_id, reply_msg));
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnCloneNamespaceId, namespace_id,
+ reply_msg));
return;
}
@@ -195,9 +195,9 @@ void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id,
const string16& origin,
IPC::Message* reply_msg) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnStorageAreaId,
- namespace_id, origin, reply_msg));
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnStorageAreaId, namespace_id, origin,
+ reply_msg));
return;
}
@@ -219,8 +219,8 @@ void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id,
void DOMStorageDispatcherHost::OnLength(int64 storage_area_id,
IPC::Message* reply_msg) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg));
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg));
return;
}
@@ -240,8 +240,9 @@ void DOMStorageDispatcherHost::OnLength(int64 storage_area_id,
void DOMStorageDispatcherHost::OnKey(int64 storage_area_id, unsigned index,
IPC::Message* reply_msg) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnKey, storage_area_id, index, reply_msg));
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnKey, storage_area_id, index,
+ reply_msg));
return;
}
@@ -262,9 +263,9 @@ void DOMStorageDispatcherHost::OnGetItem(int64 storage_area_id,
const string16& key,
IPC::Message* reply_msg) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnGetItem,
- storage_area_id, key, reply_msg));
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnGetItem, storage_area_id, key,
+ reply_msg));
return;
}
@@ -285,8 +286,8 @@ void DOMStorageDispatcherHost::OnSetItem(
int64 storage_area_id, const string16& key, const string16& value,
const GURL& url, IPC::Message* reply_msg) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnSetItem, storage_area_id, key, value,
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnSetItem, storage_area_id, key, value,
url, reply_msg));
return;
}
@@ -309,8 +310,9 @@ void DOMStorageDispatcherHost::OnSetItem(
void DOMStorageDispatcherHost::OnRemoveItem(
int64 storage_area_id, const string16& key, const GURL& url) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key, url));
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key,
+ url));
return;
}
@@ -328,8 +330,8 @@ void DOMStorageDispatcherHost::OnRemoveItem(
void DOMStorageDispatcherHost::OnClear(int64 storage_area_id, const GURL& url) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
- &DOMStorageDispatcherHost::OnClear, storage_area_id, url));
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &DOMStorageDispatcherHost::OnClear, storage_area_id, url));
return;
}
@@ -356,9 +358,3 @@ void DOMStorageDispatcherHost::OnStorageEvent(
++cur;
}
}
-
-void DOMStorageDispatcherHost::PostTaskToWebKitThread(
- const tracked_objects::Location& from_here, Task* task) {
- webkit_thread_->EnsureInitialized();
- ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, task);
-}
diff --git a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h
index b99ac94..6ca2d62 100644
--- a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h
+++ b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h
@@ -76,10 +76,6 @@ class DOMStorageDispatcherHost
return webkit_context_->dom_storage_context();
}
- // Posts a task to the WebKit thread, initializing it if necessary.
- void PostTaskToWebKitThread(
- const tracked_objects::Location& from_here, Task* task);
-
// Use whenever there's a chance OnStorageEvent will be called.
class ScopedStorageEventContext {
public:
diff --git a/chrome/browser/in_process_webkit/webkit_thread.cc b/chrome/browser/in_process_webkit/webkit_thread.cc
index 6311140..c3ad81f 100644
--- a/chrome/browser/in_process_webkit/webkit_thread.cc
+++ b/chrome/browser/in_process_webkit/webkit_thread.cc
@@ -9,9 +9,7 @@
#include "chrome/common/chrome_switches.h"
#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
-// This happens on the UI thread before the IO thread has been shut down.
WebKitThread::WebKitThread() {
- // The thread is started lazily by InitializeThread() on the IO thread.
}
// This happens on the UI thread after the IO thread has been shut down.
@@ -23,11 +21,19 @@ WebKitThread::~WebKitThread() {
DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
}
-void WebKitThread::EnsureInitialized() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- if (webkit_thread_.get())
+void WebKitThread::Initialize() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ DCHECK(!webkit_thread_.get());
+
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) {
+ // TODO(jorlow): This thread should be used (and started) in single process
+ // mode rather than following different code paths.
return;
- InitializeThread();
+ }
+
+ webkit_thread_.reset(new InternalWebKitThread);
+ bool started = webkit_thread_->Start();
+ DCHECK(started);
}
WebKitThread::InternalWebKitThread::InternalWebKitThread()
@@ -43,21 +49,10 @@ void WebKitThread::InternalWebKitThread::Init() {
webkit_client_.reset(new BrowserWebKitClientImpl);
WebKit::initialize(webkit_client_.get());
// If possible, post initialization tasks to this thread (rather than doing
- // them now) so we don't block the IO thread any longer than we have to.
+ // them now) so we don't block the UI thread any longer than we have to.
}
void WebKitThread::InternalWebKitThread::CleanUp() {
DCHECK(webkit_client_.get());
WebKit::shutdown();
}
-
-MessageLoop* WebKitThread::InitializeThread() {
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
- return NULL;
-
- DCHECK(!webkit_thread_.get());
- webkit_thread_.reset(new InternalWebKitThread);
- bool started = webkit_thread_->Start();
- DCHECK(started);
- return webkit_thread_->message_loop();
-}
diff --git a/chrome/browser/in_process_webkit/webkit_thread.h b/chrome/browser/in_process_webkit/webkit_thread.h
index 97b1856..9838730 100644
--- a/chrome/browser/in_process_webkit/webkit_thread.h
+++ b/chrome/browser/in_process_webkit/webkit_thread.h
@@ -14,20 +14,14 @@
class BrowserWebKitClientImpl;
-// This is an object that represents WebKit's "main" thread within the browser
-// process. It should be instantiated and destroyed on the UI thread
-// before/after the IO thread is created/destroyed. All other usage should be
-// on the IO thread. If the browser is being run in --single-process mode, a
-// thread will never be spun up.
+// This creates a WebKit main thread on instantiation (if not in
+// --single-process mode) on construction and kills it on deletion.
class WebKitThread {
public:
// Called from the UI thread.
WebKitThread();
~WebKitThread();
-
- // Creates the WebKit thread if it hasn't been already created. Only call
- // from the IO thread. Only do fast-path work here.
- void EnsureInitialized();
+ void Initialize();
private:
// Must be private so that we can carefully control its lifetime.
@@ -45,12 +39,7 @@ class WebKitThread {
scoped_ptr<BrowserWebKitClientImpl> webkit_client_;
};
- // Returns the WebKit thread's message loop or NULL if we're in
- // --single-process mode. Do slow-path initialization work here.
- MessageLoop* InitializeThread();
-
- // Pointer to the actual WebKitThread. NULL if not yet started. Only modify
- // from the IO thread while the WebKit thread is not running.
+ // Pointer to the actual WebKitThread.
scoped_ptr<InternalWebKitThread> webkit_thread_;
DISALLOW_COPY_AND_ASSIGN(WebKitThread);
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc
index 3432eb1..77345b1 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc
@@ -293,6 +293,7 @@ ResourceDispatcherHost::~ResourceDispatcherHost() {
void ResourceDispatcherHost::Initialize() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ webkit_thread_->Initialize();
safe_browsing_->Initialize();
ChromeThread::PostTask(
ChromeThread::IO, FROM_HERE,