summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authornduca@chromium.org <nduca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-16 15:24:03 +0000
committernduca@chromium.org <nduca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-16 15:24:03 +0000
commit238b63f5d24e2fe475fc57c1d98693033f1498b5 (patch)
tree26ad2c0fc0662304a60b2a5a28f71376986b645c /webkit
parent3e981b2931608892407246bd2823a36097df16f4 (diff)
downloadchromium_src-238b63f5d24e2fe475fc57c1d98693033f1498b5.zip
chromium_src-238b63f5d24e2fe475fc57c1d98693033f1498b5.tar.gz
chromium_src-238b63f5d24e2fe475fc57c1d98693033f1498b5.tar.bz2
This is an implementation of WebThread to allow WebKit to create threads that are backed by base::MessageThreads and thus base's MessageLoops. Doing this allows Chromium services to be more easily used on webkit threads.
Review URL: http://codereview.chromium.org/7600016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96946 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/glue/webkitclient_impl.cc5
-rw-r--r--webkit/glue/webkitclient_impl.h2
-rw-r--r--webkit/glue/webthread_impl.cc44
-rw-r--r--webkit/glue/webthread_impl.h27
5 files changed, 80 insertions, 0 deletions
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 28f1ded..0d93dd4 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -433,6 +433,8 @@
'webthemeengine_impl_linux.cc',
'webthemeengine_impl_mac.cc',
'webthemeengine_impl_win.cc',
+ 'webthread_impl.h',
+ 'webthread_impl.cc',
'weburlloader_impl.cc',
'weburlloader_impl.h',
'webvideoframe_impl.cc',
diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc
index d3f61d3..2192c37 100644
--- a/webkit/glue/webkitclient_impl.cc
+++ b/webkit/glue/webkitclient_impl.cc
@@ -41,6 +41,7 @@
#include "webkit/plugins/webplugininfo.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/websocketstreamhandle_impl.h"
+#include "webkit/glue/webthread_impl.h"
#include "webkit/glue/weburlloader_impl.h"
#if defined(OS_LINUX)
@@ -545,6 +546,10 @@ void WebKitClientImpl::callOnMainThread(void (*func)(void*), void* context) {
main_loop_->PostTask(FROM_HERE, NewRunnableFunction(func, context));
}
+WebKit::WebThread* WebKitClientImpl::createThread(const char* name) {
+ return new WebThreadImpl(name);
+}
+
base::PlatformFile WebKitClientImpl::databaseOpenFile(
const WebKit::WebString& vfs_file_name, int desired_flags) {
return base::kInvalidPlatformFileValue;
diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h
index eb8f484..7f5bdc0 100644
--- a/webkit/glue/webkitclient_impl.h
+++ b/webkit/glue/webkitclient_impl.h
@@ -6,6 +6,7 @@
#define WEBKIT_CLIENT_IMPL_H_
#include "base/platform_file.h"
+#include "base/scoped_ptr.h"
#include "base/timer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h"
#if defined(OS_WIN)
@@ -80,6 +81,7 @@ class WebKitClientImpl : public WebKit::WebKitClient {
#endif
virtual void stopSharedTimer();
virtual void callOnMainThread(void (*func)(void*), void* context);
+ virtual WebKit::WebThread* createThread(const char* name);
void SuspendSharedTimer();
void ResumeSharedTimer();
diff --git a/webkit/glue/webthread_impl.cc b/webkit/glue/webthread_impl.cc
new file mode 100644
index 0000000..3fe3a1d
--- /dev/null
+++ b/webkit/glue/webthread_impl.cc
@@ -0,0 +1,44 @@
+// 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.
+
+// An implementation of WebThread in terms of base::MessageLoop and
+// base::Thread
+
+#include "webkit/glue/webthread_impl.h"
+
+#include "base/task.h"
+#include "base/message_loop.h"
+
+namespace webkit_glue {
+
+class TaskAdapter : public Task {
+public:
+ TaskAdapter(WebKit::WebThread::Task* task) : task_(task) { }
+ virtual void Run() {
+ task_->run();
+ }
+private:
+ scoped_ptr<WebKit::WebThread::Task> task_;
+};
+
+WebThreadImpl::WebThreadImpl(const char* name)
+ : thread_(new base::Thread(name)) {
+ thread_->Start();
+}
+
+void WebThreadImpl::postTask(Task* task) {
+ thread_->message_loop()->PostTask(FROM_HERE,
+ new TaskAdapter(task));
+}
+void WebThreadImpl::postDelayedTask(
+ Task* task, int64 delay_ms) {
+ thread_->message_loop()->PostDelayedTask(
+ FROM_HERE, new TaskAdapter(task), delay_ms);
+}
+
+WebThreadImpl::~WebThreadImpl() {
+ thread_->Stop();
+}
+
+}
diff --git a/webkit/glue/webthread_impl.h b/webkit/glue/webthread_impl.h
new file mode 100644
index 0000000..478c069
--- /dev/null
+++ b/webkit/glue/webthread_impl.h
@@ -0,0 +1,27 @@
+// 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.
+#ifndef WEBKIT_GLUE_WEBTHREAD_IMPL_H_
+#define WEBKIT_GLUE_WEBTHREAD_IMPL_H_
+
+#include "base/threading/thread.h"
+#include "base/memory/scoped_ptr.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebThread.h"
+
+namespace webkit_glue {
+
+class WebThreadImpl : public WebKit::WebThread {
+ public:
+ WebThreadImpl(const char* name);
+ virtual ~WebThreadImpl();
+
+ virtual void postTask(Task* task);
+ virtual void postDelayedTask(Task* task, int64 delay_ms);
+
+ protected:
+ scoped_ptr<base::Thread> thread_;
+};
+
+} // namespace webkit_glue
+
+#endif