From 07f63c6bba7e33160fc54af7f2cf4cf207e0831b Mon Sep 17 00:00:00 2001 From: "morrita@chromium.org" Date: Tue, 1 Mar 2011 06:41:13 +0000 Subject: 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 --- webkit/support/webkit_support.cc | 26 ++++++++++++++++++++++++++ webkit/support/webkit_support.h | 13 +++++++++++++ 2 files changed, 39 insertions(+) (limited to 'webkit/support') 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 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. -- cgit v1.1