1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_FRAME_TASK_MARSHALLER_H_
6 #define CHROME_FRAME_TASK_MARSHALLER_H_
13 #include "base/synchronization/lock.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/time.h"
18 namespace tracked_objects
{
22 // TaskMarshallerThroughMessageQueue is similar to base::MessageLoopForUI
23 // in cases where we do not control the thread lifetime and message retrieval
24 // and dispatching. It uses a HWND to ::PostMessage to it as a signal that
25 // the task queue is not empty.
26 class TaskMarshallerThroughMessageQueue
: public base::NonThreadSafe
{
28 TaskMarshallerThroughMessageQueue();
29 ~TaskMarshallerThroughMessageQueue();
31 void SetWindow(HWND wnd
, UINT msg
) {
36 virtual void PostTask(const tracked_objects::Location
& from_here
,
38 virtual void PostDelayedTask(const tracked_objects::Location
& source
,
40 base::TimeDelta
& delay
);
41 // Called by the owner of the HWND.
42 BOOL
ProcessWindowMessage(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
43 LRESULT
& lResult
, DWORD dwMsgMapID
= 0);
46 inline Task
* PopTask();
47 inline void ExecuteQueuedTasks();
48 void ExecuteDelayedTasks();
49 void RunTask(Task
* task
);
52 DelayedTask(Task
* task
, base::Time at
) : run_at(at
), task(task
), seq(0) {}
56 // To support sorting based on time in priority_queue.
57 bool operator<(const DelayedTask
& other
) const;
60 std::priority_queue
<DelayedTask
> delayed_tasks_
;
61 std::queue
<Task
*> pending_tasks_
;
68 #endif // CHROME_FRAME_TASK_MARSHALLER_H_