summaryrefslogtreecommitdiffstats
path: root/webkit/support
diff options
context:
space:
mode:
authormorrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-01 06:41:13 +0000
committermorrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-01 06:41:13 +0000
commit07f63c6bba7e33160fc54af7f2cf4cf207e0831b (patch)
treecea4aac3782d324a787a7f08fbc3113e841189dc /webkit/support
parent1f06a56edde410253186f4b6b5cdfe516f0bb4ff (diff)
downloadchromium_src-07f63c6bba7e33160fc54af7f2cf4cf207e0831b.zip
chromium_src-07f63c6bba7e33160fc54af7f2cf4cf207e0831b.tar.gz
chromium_src-07f63c6bba7e33160fc54af7f2cf4cf207e0831b.tar.bz2
Add webkit_support::TaskAdaptor to make tasks have the desttructor.
BUG=73675 TEST=none Review URL: http://codereview.chromium.org/6602006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76362 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/support')
-rw-r--r--webkit/support/webkit_support.cc26
-rw-r--r--webkit/support/webkit_support.h13
2 files changed, 39 insertions, 0 deletions
diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc
index 9e850f4..2d994af 100644
--- a/webkit/support/webkit_support.cc
+++ b/webkit/support/webkit_support.cc
@@ -17,6 +17,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/process_util.h"
+#include "base/ref_counted.h"
#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
@@ -190,6 +191,26 @@ class WebKitClientMessageLoopImpl
MessageLoop* message_loop_;
};
+// An wrapper object for giving TaskAdaptor ref-countability,
+// which NewRunnableMethod() requires.
+class TaskAdaptorHolder : public CancelableTask {
+ public:
+ explicit TaskAdaptorHolder(webkit_support::TaskAdaptor* adaptor)
+ : adaptor_(adaptor) {
+ }
+
+ virtual void Run() {
+ adaptor_->Run();
+ }
+
+ virtual void Cancel() {
+ adaptor_.reset();
+ }
+
+ private:
+ scoped_ptr<webkit_support::TaskAdaptor> adaptor_;
+};
+
} // namespace
namespace webkit_support {
@@ -371,6 +392,11 @@ void PostDelayedTask(void (*func)(void*), void* context, int64 delay_ms) {
FROM_HERE, NewRunnableFunction(func, context), delay_ms);
}
+void PostDelayedTask(TaskAdaptor* task, int64 delay_ms) {
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, new TaskAdaptorHolder(task), delay_ms);
+}
+
// Wrappers for FilePath and file_util
WebString GetAbsoluteWebStringFromUTF8Path(const std::string& utf8_path) {
diff --git a/webkit/support/webkit_support.h b/webkit/support/webkit_support.h
index d145955..a3711da 100644
--- a/webkit/support/webkit_support.h
+++ b/webkit/support/webkit_support.h
@@ -102,6 +102,17 @@ void ServeAsynchronousMockedRequests();
bool BeingDebugged();
// -------- Message loop and task
+
+// A wrapper for Chromium's Task class.
+// The lifecycle is managed by webkit_support thus
+// You shouldn't delete the object.
+// Note that canceled object is just removed.
+class TaskAdaptor {
+ public:
+ virtual ~TaskAdaptor() {}
+ virtual void Run() = 0;
+};
+
void RunMessageLoop();
void QuitMessageLoop();
void RunAllPendingMessages();
@@ -112,6 +123,8 @@ WebKit::WebDevToolsAgentClient::WebKitClientMessageLoop*
CreateDevToolsMessageLoop();
void PostDelayedTask(void (*func)(void*), void* context, int64 delay_ms);
+void PostDelayedTask(TaskAdaptor* task, int64 delay_ms);
+
// -------- File path and PathService
// Converts the specified path string to an absolute path in WebString.
// |utf8_path| is in UTF-8 encoding, not native multibyte string.