Changeset 66701 in webkit


Ignore:
Timestamp:
Sep 2, 2010 6:51:23 PM (14 years ago)
Author:
tkent@chromium.org
Message:

2010-09-02 Kent Tamura <tkent@chromium.org>

Reviewed by Dimitri Glazkov.

[DRT/Chromium] Remove dependency to base/task.h and base/timer.h
https://bugs.webkit.org/show_bug.cgi?id=45091

  • DEPS: Roll Chromium revision to 58277 in order to have webkit_support::PostDelayedTask().

2010-09-02 Kent Tamura <tkent@chromium.org>

Reviewed by Dimitri Glazkov.

[DRT/Chromium] Remove dependency to base/task.h and base/timer.h
https://bugs.webkit.org/show_bug.cgi?id=45091

Task.{cpp,h} introduces a simpler version of Chromium
base/task.h. It doesn't have TupleN and Method.

  • DumpRenderTree/DumpRenderTree.gypi: Add Task.cpp and Task.h
  • DumpRenderTree/chromium/DRTDevToolsAgent.cpp: (DRTDevToolsAgent::DRTDevToolsAgent): (DRTDevToolsAgent::reset): (DRTDevToolsAgent::asyncCall): (DRTDevToolsAgent::frontendLoaded):
  • DumpRenderTree/chromium/DRTDevToolsAgent.h: (DRTDevToolsAgent::taskList): Added to use MethodTask<T>.
  • DumpRenderTree/chromium/DRTDevToolsClient.cpp: (DRTDevToolsClient::DRTDevToolsClient): (DRTDevToolsClient::~DRTDevToolsClient): (DRTDevToolsClient::reset): (DRTDevToolsClient::asyncCall):
  • DumpRenderTree/chromium/DRTDevToolsClient.h: (DRTDevToolsClient::taskList): Added to use MethodTask<T>.
  • DumpRenderTree/chromium/EventSender.cpp: (EventSender::EventSender): (EventSender::reset): (EventSender::scheduleAsynchronousClick):
  • DumpRenderTree/chromium/EventSender.h: (EventSender::taskList): Added to use MethodTask<T>.
  • DumpRenderTree/chromium/LayoutTestController.cpp: (LayoutTestController::LayoutTestController): (LayoutTestController::WorkQueue::processWorkSoon): (LayoutTestController::waitUntilDone): (LayoutTestController::notifyDone): (LayoutTestController::reset):
  • DumpRenderTree/chromium/LayoutTestController.h: (LayoutTestController::taskList): Added to use MethodTask<T>. (LayoutTestController::WorkQueue::taskList): Added to use MethodTask<T>.
  • DumpRenderTree/chromium/NotificationPresenter.cpp: (deferredDisplayDispatch): (NotificationPresenter::show):
  • DumpRenderTree/chromium/Task.cpp: Added.
  • DumpRenderTree/chromium/Task.h: Added.
Location:
trunk
Files:
13 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r66647 r66701  
     12010-09-02  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        [DRT/Chromium] Remove dependency to base/task.h and base/timer.h
     6        https://bugs.webkit.org/show_bug.cgi?id=45091
     7
     8        * DEPS: Roll Chromium revision to 58277 in order to have
     9        webkit_support::PostDelayedTask().
     10
    1112010-09-02  Ilya Sherman  <isherman@google.com>
    212
  • trunk/WebKit/chromium/DEPS

    r66351 r66701  
    3333vars = {
    3434  'chromium_svn': 'http://src.chromium.org/svn/trunk/src',
    35   'chromium_rev': '57823',
     35  'chromium_rev': '58277',
    3636}
    3737
  • trunk/WebKitTools/ChangeLog

    r66685 r66701  
     12010-09-02  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        [DRT/Chromium] Remove dependency to base/task.h and base/timer.h
     6        https://bugs.webkit.org/show_bug.cgi?id=45091
     7
     8        Task.{cpp,h} introduces a simpler version of Chromium
     9        base/task.h. It doesn't have TupleN and Method.
     10
     11        * DumpRenderTree/DumpRenderTree.gypi:
     12         Add Task.cpp and Task.h
     13        * DumpRenderTree/chromium/DRTDevToolsAgent.cpp:
     14        (DRTDevToolsAgent::DRTDevToolsAgent):
     15        (DRTDevToolsAgent::reset):
     16        (DRTDevToolsAgent::asyncCall):
     17        (DRTDevToolsAgent::frontendLoaded):
     18        * DumpRenderTree/chromium/DRTDevToolsAgent.h:
     19        (DRTDevToolsAgent::taskList): Added to use MethodTask<T>.
     20        * DumpRenderTree/chromium/DRTDevToolsClient.cpp:
     21        (DRTDevToolsClient::DRTDevToolsClient):
     22        (DRTDevToolsClient::~DRTDevToolsClient):
     23        (DRTDevToolsClient::reset):
     24        (DRTDevToolsClient::asyncCall):
     25        * DumpRenderTree/chromium/DRTDevToolsClient.h:
     26        (DRTDevToolsClient::taskList): Added to use MethodTask<T>.
     27        * DumpRenderTree/chromium/EventSender.cpp:
     28        (EventSender::EventSender):
     29        (EventSender::reset):
     30        (EventSender::scheduleAsynchronousClick):
     31        * DumpRenderTree/chromium/EventSender.h:
     32        (EventSender::taskList): Added to use MethodTask<T>.
     33        * DumpRenderTree/chromium/LayoutTestController.cpp:
     34        (LayoutTestController::LayoutTestController):
     35        (LayoutTestController::WorkQueue::processWorkSoon):
     36        (LayoutTestController::waitUntilDone):
     37        (LayoutTestController::notifyDone):
     38        (LayoutTestController::reset):
     39        * DumpRenderTree/chromium/LayoutTestController.h:
     40        (LayoutTestController::taskList): Added to use MethodTask<T>.
     41        (LayoutTestController::WorkQueue::taskList): Added to use MethodTask<T>.
     42        * DumpRenderTree/chromium/NotificationPresenter.cpp:
     43        (deferredDisplayDispatch):
     44        (NotificationPresenter::show):
     45        * DumpRenderTree/chromium/Task.cpp: Added.
     46        * DumpRenderTree/chromium/Task.h: Added.
     47
    1482010-09-02  Steve Block  <steveblock@google.com>
    249
  • trunk/WebKitTools/DumpRenderTree/DumpRenderTree.gypi

    r62545 r66701  
    2727            'chromium/PlainTextController.cpp',
    2828            'chromium/PlainTextController.h',
     29            'chromium/Task.h',
     30            'chromium/Task.cpp',
    2931            'chromium/TestEventPrinter.h',
    3032            'chromium/TestEventPrinter.cpp',
  • trunk/WebKitTools/DumpRenderTree/chromium/DRTDevToolsAgent.cpp

    r66194 r66701  
    4444
    4545DRTDevToolsAgent::DRTDevToolsAgent()
    46     : m_callMethodFactory(this)
    47     , m_drtDevToolsClient(0)
     46    : m_drtDevToolsClient(0)
    4847    , m_webView(0)
    4948{
     
    5756void DRTDevToolsAgent::reset()
    5857{
    59     m_callMethodFactory.RevokeAll();
     58    m_taskList.revokeAll();
    6059}
    6160
     
    9089}
    9190
    92 void DRTDevToolsAgent::asyncCall(const DRTDevToolsCallArgs &args)
     91void DRTDevToolsAgent::asyncCall(const DRTDevToolsCallArgs& args)
    9392{
    94     webkit_support::PostTaskFromHere(
    95         m_callMethodFactory.NewRunnableMethod(&DRTDevToolsAgent::call, args));
     93    postTask(new AsyncCallTask(this, args));
    9694}
    9795
     
    138136}
    139137
    140 void DRTDevToolsAgent::frontendLoaded() {
    141     webkit_support::PostTaskFromHere(
    142         m_callMethodFactory.NewRunnableMethod(&DRTDevToolsAgent::delayedFrontendLoaded));
     138void DRTDevToolsAgent::frontendLoaded()
     139{
     140    postTask(new DelayedFrontendLoadedTask(this));
    143141}
    144142
  • trunk/WebKitTools/DumpRenderTree/chromium/DRTDevToolsAgent.h

    r66194 r66701  
    3232#define DRTDevToolsAgent_h
    3333
    34 #include "base/task.h" // FIXME: remove this
     34#include "DRTDevToolsCallArgs.h"
     35#include "Task.h"
    3536#include "public/WebDevToolsAgentClient.h"
    3637#include <wtf/HashMap.h>
     
    4748} // namespace WebKit
    4849
    49 class DRTDevToolsCallArgs;
    5050class DRTDevToolsClient;
    5151
     
    7575    bool evaluateInWebInspector(long callID, const std::string& script);
    7676    bool setTimelineProfilingEnabled(bool enable);
     77    TaskList* taskList() { return &m_taskList; }
    7778
    7879private:
     
    8283    WebKit::WebDevToolsAgent* webDevToolsAgent();
    8384
    84     ScopedRunnableMethodFactory<DRTDevToolsAgent> m_callMethodFactory;
     85    class AsyncCallTask: public MethodTask<DRTDevToolsAgent> {
     86    public:
     87        AsyncCallTask(DRTDevToolsAgent* object, const DRTDevToolsCallArgs& args)
     88            : MethodTask<DRTDevToolsAgent>(object), m_args(args) {}
     89        virtual void runIfValid() { m_object->call(m_args); }
     90    private:
     91        DRTDevToolsCallArgs m_args;
     92    };
     93
     94    struct DelayedFrontendLoadedTask: public MethodTask<DRTDevToolsAgent> {
     95        DelayedFrontendLoadedTask(DRTDevToolsAgent* object) : MethodTask<DRTDevToolsAgent>(object) {}
     96        virtual void runIfValid() { m_object->delayedFrontendLoaded(); }
     97    };
     98
     99    TaskList m_taskList;
    85100    DRTDevToolsClient* m_drtDevToolsClient;
    86101    int m_routingID;
  • trunk/WebKitTools/DumpRenderTree/chromium/DRTDevToolsClient.cpp

    r64843 r66701  
    4646
    4747DRTDevToolsClient::DRTDevToolsClient(DRTDevToolsAgent* agent, WebView* webView)
    48     : m_callMethodFactory(this)
    49     , m_drtDevToolsAgent(agent)
     48    : m_drtDevToolsAgent(agent)
    5049    , m_webView(webView)
    5150{
     
    6059    // There is a chance that the page will be destroyed at detach step of
    6160    // m_drtDevToolsAgent and we should clean pending requests a bit earlier.
    62     m_callMethodFactory.RevokeAll();
     61    m_taskList.revokeAll();
    6362    if (m_drtDevToolsAgent)
    6463        m_drtDevToolsAgent->detach();
     
    6766void DRTDevToolsClient::reset()
    6867{
    69     m_callMethodFactory.RevokeAll();
     68    m_taskList.revokeAll();
    7069}
    7170
     
    108107void DRTDevToolsClient::asyncCall(const DRTDevToolsCallArgs& args)
    109108{
    110     webkit_support::PostTaskFromHere(
    111         m_callMethodFactory.NewRunnableMethod(&DRTDevToolsClient::call, args));
     109    postTask(new AsyncCallTask(this, args));
    112110}
    113111
  • trunk/WebKitTools/DumpRenderTree/chromium/DRTDevToolsClient.h

    r64843 r66701  
    3232#define DRTDevToolsClient_h
    3333
    34 #include "base/task.h" // FIXME: remove this
     34#include "DRTDevToolsCallArgs.h"
     35#include "Task.h"
    3536#include "public/WebDevToolsFrontendClient.h"
    3637#include <wtf/Noncopyable.h>
     
    4647} // namespace WebKit
    4748
    48 class DRTDevToolsCallArgs;
    4949class DRTDevToolsAgent;
    5050
     
    6969
    7070    void allMessagesProcessed();
     71    TaskList* taskList() { return &m_taskList; }
    7172
    7273 private:
    7374    void call(const DRTDevToolsCallArgs&);
     75    class AsyncCallTask: public MethodTask<DRTDevToolsClient> {
     76    public:
     77        AsyncCallTask(DRTDevToolsClient* object, const DRTDevToolsCallArgs& args)
     78            : MethodTask<DRTDevToolsClient>(object), m_args(args) {}
     79        virtual void runIfValid() { m_object->call(m_args); }
     80    private:
     81        DRTDevToolsCallArgs m_args;
     82    };
    7483
    75     ScopedRunnableMethodFactory<DRTDevToolsClient> m_callMethodFactory;
     84    TaskList m_taskList;
    7685    WebKit::WebView* m_webView;
    7786    DRTDevToolsAgent* m_drtDevToolsAgent;
  • trunk/WebKitTools/DumpRenderTree/chromium/EventSender.cpp

    r66666 r66701  
    245245
    246246EventSender::EventSender(TestShell* shell)
    247     : m_methodFactory(this)
    248     , m_shell(shell)
     247    : m_shell(shell)
    249248{
    250249    // Initialize the map that associates methods of this class with the names
     
    323322    touchModifiers = 0;
    324323    touchPoints.clear();
    325     m_methodFactory.RevokeAll();
     324    m_taskList.revokeAll();
    326325}
    327326
     
    751750}
    752751
     752class MouseDownTask: public MethodTask<EventSender> {
     753public:
     754    MouseDownTask(EventSender* obj, const CppArgumentList& arg)
     755        : MethodTask<EventSender>(obj), m_arguments(arg) {}
     756    virtual void runIfValid() { m_object->mouseDown(m_arguments, 0); }
     757private:
     758    CppArgumentList m_arguments;
     759};
     760
     761class MouseUpTask: public MethodTask<EventSender> {
     762public:
     763    MouseUpTask(EventSender* obj, const CppArgumentList& arg)
     764        : MethodTask<EventSender>(obj), m_arguments(arg) {}
     765    virtual void runIfValid() { m_object->mouseUp(m_arguments, 0); }
     766private:
     767    CppArgumentList m_arguments;
     768};
     769
    753770void EventSender::scheduleAsynchronousClick(const CppArgumentList& arguments, CppVariant* result)
    754771{
    755772    result->setNull();
    756 
    757     webkit_support::PostTaskFromHere(m_methodFactory.NewRunnableMethod(
    758             &EventSender::mouseDown, arguments, static_cast<CppVariant*>(0)));
    759     webkit_support::PostTaskFromHere(m_methodFactory.NewRunnableMethod(
    760             &EventSender::mouseUp, arguments, static_cast<CppVariant*>(0)));
     773    postTask(new MouseDownTask(this, arguments));
     774    postTask(new MouseUpTask(this, arguments));
    761775}
    762776
  • trunk/WebKitTools/DumpRenderTree/chromium/EventSender.h

    r66666 r66701  
    3939
    4040#include "CppBoundClass.h"
    41 #include "base/task.h"
     41#include "Task.h"
    4242#include "public/WebDragOperation.h"
    4343#include "public/WebInputEvent.h"
     
    109109#endif
    110110
     111    TaskList* taskList() { return &m_taskList; }
     112
    111113private:
    112114    // Returns the test shell's webview.
     
    142144    void handleMouseWheel(const CppArgumentList&, CppVariant*, bool continuous);
    143145
    144     ScopedRunnableMethodFactory<EventSender> m_methodFactory;
     146    TaskList m_taskList;
    145147
    146148    // Non-owning pointer.  The EventSender is owned by the TestShell.
  • trunk/WebKitTools/DumpRenderTree/chromium/LayoutTestController.cpp

    r66546 r66701  
    6868
    6969LayoutTestController::LayoutTestController(TestShell* shell)
    70     : m_timeoutFactory(this)
    71     , m_shell(shell)
     70    : m_shell(shell)
    7271    , m_workQueue(this)
    7372{
     
    208207    if (!m_queue.isEmpty()) {
    209208        // We delay processing queued work to avoid recursion problems.
    210         m_timer.Start(base::TimeDelta(), this, &WorkQueue::processWork);
    211     } else if (!m_controller->m_waitUntilDone) {
     209        postTask(new WorkQueueTask(this));
     210    } else if (!m_controller->m_waitUntilDone)
    212211        m_controller->m_shell->testFinished();
    213     }
    214212}
    215213
     
    321319void LayoutTestController::waitUntilDone(const CppArgumentList&, CppVariant* result)
    322320{
    323     if (!webkit_support::BeingDebugged()) {
    324         webkit_support::PostDelayedTaskFromHere(
    325             m_timeoutFactory.NewRunnableMethod(&LayoutTestController::notifyDoneTimedOut),
    326             m_shell->layoutTestTimeout());
    327     }
     321    if (!webkit_support::BeingDebugged())
     322        postDelayedTask(new NotifyDoneTimedOutTask(this), m_shell->layoutTestTimeout());
    328323    m_waitUntilDone = true;
    329324    result->setNull();
     
    333328{
    334329    // Test didn't timeout. Kill the timeout timer.
    335     m_timeoutFactory.RevokeAll();
     330    m_taskList.revokeAll();
    336331
    337332    completeNotifyDone(false);
    338333    result->setNull();
    339 }
    340 
    341 void LayoutTestController::notifyDoneTimedOut()
    342 {
    343     completeNotifyDone(true);
    344334}
    345335
     
    522512        m_closeRemainingWindows = true;
    523513    m_workQueue.reset();
    524     m_timeoutFactory.RevokeAll();
     514    m_taskList.revokeAll();
    525515}
    526516
  • trunk/WebKitTools/DumpRenderTree/chromium/LayoutTestController.h

    r66546 r66701  
    4343
    4444#include "CppBoundClass.h"
    45 #include "base/timer.h" // FIXME: Remove this.
     45#include "Task.h"
    4646#include "public/WebString.h"
    4747#include "public/WebURL.h"
     
    117117    void waitUntilDone(const CppArgumentList&, CppVariant*);
    118118    void notifyDone(const CppArgumentList&, CppVariant*);
    119     void notifyDoneTimedOut();
    120119
    121120    // Methods for adding actions to the work queue.  Used in conjunction with
     
    361360    };
    362361
     362    TaskList* taskList() { return &m_taskList; }
     363
    363364private:
    364365    friend class WorkItem;
     
    380381        void setFrozen(bool frozen) { m_frozen = frozen; }
    381382        bool isEmpty() { return m_queue.isEmpty(); }
     383        TaskList* taskList() { return &m_taskList; }
    382384
    383385    private:
    384386        void processWork();
    385 
    386         base::OneShotTimer<WorkQueue> m_timer;
     387        class WorkQueueTask: public MethodTask<WorkQueue> {
     388        public:
     389            WorkQueueTask(WorkQueue* object): MethodTask<WorkQueue>(object) {}
     390            virtual void runIfValid() { m_object->processWork(); }
     391        };
     392
     393        TaskList m_taskList;
    387394        Deque<WorkItem*> m_queue;
    388395        bool m_frozen;
     
    397404    void logErrorToConsole(const std::string&);
    398405    void completeNotifyDone(bool isTimeout);
     406    class NotifyDoneTimedOutTask: public MethodTask<LayoutTestController> {
     407    public:
     408        NotifyDoneTimedOutTask(LayoutTestController* object): MethodTask<LayoutTestController>(object) {}
     409        virtual void runIfValid() { m_object->completeNotifyDone(true); }
     410    };
     411
    399412
    400413    bool pauseAnimationAtTimeOnElementWithId(const WebKit::WebString& animationName, double time, const WebKit::WebString& elementId);
     
    406419
    407420    // Used for test timeouts.
    408     ScopedRunnableMethodFactory<LayoutTestController> m_timeoutFactory;
     421    TaskList m_taskList;
    409422
    410423    // Non-owning pointer.  The LayoutTestController is owned by the host.
  • trunk/WebKitTools/DumpRenderTree/chromium/NotificationPresenter.cpp

    r66470 r66701  
    3232#include "NotificationPresenter.h"
    3333
    34 #include "base/task.h" // FIXME: Remove this
    3534#include "googleurl/src/gurl.h"
     35#include "public/WebKit.h"
     36#include "public/WebKitClient.h"
    3637#include "public/WebNotification.h"
    3738#include "public/WebNotificationPermissionCallback.h"
     
    3940#include "public/WebString.h"
    4041#include "public/WebURL.h"
    41 #include "webkit/support/webkit_support.h"
    4242#include <wtf/text/CString.h>
    4343#include <wtf/text/WTFString.h>
     
    5252}
    5353
    54 static void deferredDisplayDispatch(WebNotification notification)
     54static void deferredDisplayDispatch(void* context)
    5555{
    56     notification.dispatchDisplayEvent();
     56    WebNotification* notification = static_cast<WebNotification*>(context);
     57    notification->dispatchDisplayEvent();
     58    delete notification;
    5759}
    5860
     
    106108    m_activeNotifications.set(id, notification);
    107109
    108     WebNotification eventTarget(notification);
    109     webkit_support::PostTaskFromHere(NewRunnableFunction(&deferredDisplayDispatch, eventTarget));
     110    webKitClient()->callOnMainThread(deferredDisplayDispatch, new WebNotification(notification));
    110111    return true;
    111112}
  • trunk/WebKitTools/DumpRenderTree/chromium/Task.cpp

    r66700 r66701  
    2929 */
    3030
    31 #ifndef DRTDevToolsClient_h
    32 #define DRTDevToolsClient_h
     31#include "config.h"
     32#include "Task.h"
    3333
    34 #include "base/task.h" // FIXME: remove this
    35 #include "public/WebDevToolsFrontendClient.h"
    36 #include <wtf/Noncopyable.h>
    37 #include <wtf/OwnPtr.h>
     34#include "public/WebKit.h"
     35#include "public/WebKitClient.h"
     36#include "webkit/support/webkit_support.h"
    3837
    39 namespace WebKit {
     38WebTask::WebTask(TaskList* list): m_taskList(list) { m_taskList->registerTask(this); }
     39WebTask::~WebTask() { m_taskList->unregisterTask(this); }
    4040
    41 class WebDevToolsFrontend;
    42 struct WebDevToolsMessageData;
    43 class WebString;
    44 class WebView;
     41void TaskList::unregisterTask(WebTask* task)
     42{
     43    size_t index = m_tasks.find(task);
     44    if (index != notFound)
     45        m_tasks.remove(index);
     46}
    4547
    46 } // namespace WebKit
     48void TaskList::revokeAll()
     49{
     50    for (unsigned i = 0; i < m_tasks.size(); ++i)
     51        m_tasks[i]->cancel();
     52    m_tasks.clear();
     53}
    4754
    48 class DRTDevToolsCallArgs;
    49 class DRTDevToolsAgent;
     55static void invokeTask(void* context)
     56{
     57    WebTask* task = static_cast<WebTask*>(context);
     58    task->run();
     59    delete task;
     60}
    5061
    51 class DRTDevToolsClient : public WebKit::WebDevToolsFrontendClient
    52                         , public Noncopyable {
    53 public:
    54     DRTDevToolsClient(DRTDevToolsAgent*, WebKit::WebView*);
    55     virtual ~DRTDevToolsClient();
    56     void reset();
     62void postTask(WebTask* task)
     63{
     64    WebKit::webKitClient()->callOnMainThread(invokeTask, static_cast<void*>(task));
     65}
    5766
    58     // WebDevToolsFrontendClient implementation
    59     virtual void sendFrontendLoaded();
    60     virtual void sendMessageToBackend(const WebKit::WebString&);
    61     virtual void sendDebuggerCommandToAgent(const WebKit::WebString& command);
     67void postDelayedTask(WebTask* task, int64_t ms)
     68{
     69    webkit_support::PostDelayedTask(invokeTask, static_cast<void*>(task), ms);
     70}
    6271
    63     virtual void activateWindow();
    64     virtual void closeWindow();
    65     virtual void dockWindow();
    66     virtual void undockWindow();
    6772
    68     void asyncCall(const DRTDevToolsCallArgs&);
    69 
    70     void allMessagesProcessed();
    71 
    72  private:
    73     void call(const DRTDevToolsCallArgs&);
    74 
    75     ScopedRunnableMethodFactory<DRTDevToolsClient> m_callMethodFactory;
    76     WebKit::WebView* m_webView;
    77     DRTDevToolsAgent* m_drtDevToolsAgent;
    78     WTF::OwnPtr<WebKit::WebDevToolsFrontend> m_webDevToolsFrontend;
    79 };
    80 
    81 #endif // DRTDevToolsClient_h
  • trunk/WebKitTools/DumpRenderTree/chromium/Task.h

    r66700 r66701  
    2929 */
    3030
    31 #ifndef DRTDevToolsClient_h
    32 #define DRTDevToolsClient_h
     31#ifndef Task_h
     32#define Task_h
    3333
    34 #include "base/task.h" // FIXME: remove this
    35 #include "public/WebDevToolsFrontendClient.h"
    36 #include <wtf/Noncopyable.h>
    37 #include <wtf/OwnPtr.h>
     34#include <wtf/Vector.h>
    3835
    39 namespace WebKit {
     36class TaskList;
    4037
    41 class WebDevToolsFrontend;
    42 struct WebDevToolsMessageData;
    43 class WebString;
    44 class WebView;
    45 
    46 } // namespace WebKit
    47 
    48 class DRTDevToolsCallArgs;
    49 class DRTDevToolsAgent;
    50 
    51 class DRTDevToolsClient : public WebKit::WebDevToolsFrontendClient
    52                         , public Noncopyable {
     38// WebTask represents a task which can run by postTask() or postDelayedTask().
     39// it is named "WebTask", not "Task", to avoid conflist with base/task.h.
     40class WebTask {
    5341public:
    54     DRTDevToolsClient(DRTDevToolsAgent*, WebKit::WebView*);
    55     virtual ~DRTDevToolsClient();
    56     void reset();
    57 
    58     // WebDevToolsFrontendClient implementation
    59     virtual void sendFrontendLoaded();
    60     virtual void sendMessageToBackend(const WebKit::WebString&);
    61     virtual void sendDebuggerCommandToAgent(const WebKit::WebString& command);
    62 
    63     virtual void activateWindow();
    64     virtual void closeWindow();
    65     virtual void dockWindow();
    66     virtual void undockWindow();
    67 
    68     void asyncCall(const DRTDevToolsCallArgs&);
    69 
    70     void allMessagesProcessed();
    71 
    72  private:
    73     void call(const DRTDevToolsCallArgs&);
    74 
    75     ScopedRunnableMethodFactory<DRTDevToolsClient> m_callMethodFactory;
    76     WebKit::WebView* m_webView;
    77     DRTDevToolsAgent* m_drtDevToolsAgent;
    78     WTF::OwnPtr<WebKit::WebDevToolsFrontend> m_webDevToolsFrontend;
     42    WebTask(TaskList*);
     43    // The main code of this task.
     44    // An implementation of run() should return immediately if cancel() was called.
     45    virtual void run() = 0;
     46    virtual void cancel() = 0;
     47    virtual ~WebTask();
     48private:
     49    TaskList* m_taskList;
    7950};
    8051
    81 #endif // DRTDevToolsClient_h
     52class TaskList {
     53public:
     54    TaskList() {}
     55    ~TaskList() { revokeAll(); }
     56    void registerTask(WebTask* task) { m_tasks.append(task); }
     57    void unregisterTask(WebTask* task);
     58    void revokeAll();
     59private:
     60    Vector<WebTask*> m_tasks;
     61};
     62
     63// A task containing an object pointer of class T. Is is supposed that
     64// runifValid() calls a member function of the object pointer.
     65// Class T must have "TaskList* taskList()".
     66template<class T> class MethodTask: public WebTask {
     67public:
     68    MethodTask(T* object): WebTask(object->taskList()), m_object(object) {}
     69    virtual void run()
     70    {
     71        if (m_object)
     72            runIfValid();
     73    }
     74    virtual void cancel() { m_object = 0; }
     75    virtual void runIfValid() = 0;
     76protected:
     77    T* m_object;
     78};
     79
     80void postTask(WebTask* task);
     81void postDelayedTask(WebTask* task, int64_t ms);
     82
     83#endif // Task_h
Note: See TracChangeset for help on using the changeset viewer.