1 // Copyright (c) 2011 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_
12 #include "base/callback.h"
13 #include "base/pending_task.h"
14 #include "base/synchronization/lock.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "base/time/time.h"
20 namespace tracked_objects
{
24 // TaskMarshallerThroughMessageQueue is similar to base::MessageLoopForUI
25 // in cases where we do not control the thread lifetime and message retrieval
26 // and dispatching. It uses a HWND to ::PostMessage to it as a signal that
27 // the task queue is not empty.
28 class TaskMarshallerThroughMessageQueue
: public base::NonThreadSafe
{
30 TaskMarshallerThroughMessageQueue();
31 virtual ~TaskMarshallerThroughMessageQueue();
33 void SetWindow(HWND wnd
, UINT msg
) {
38 virtual void PostTask(const tracked_objects::Location
& from_here
,
39 const base::Closure
& task
);
40 virtual void PostDelayedTask(const tracked_objects::Location
& source
,
41 const base::Closure
& task
,
42 base::TimeDelta
& delay
);
44 // Called by the owner of the HWND.
45 BOOL
ProcessWindowMessage(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
46 LRESULT
& lResult
, DWORD dwMsgMapID
= 0);
49 inline base::Closure
PopTask();
50 inline void ExecuteQueuedTasks();
51 void ExecuteDelayedTasks();
53 // Shortest delays ordered at the top of the queue.
54 base::DelayedTaskQueue delayed_tasks_
;
56 // A list of tasks that need to be processed by this instance.
57 std::queue
<base::Closure
> pending_tasks_
;
59 // Lock accesses to |pending_tasks_|.
62 // ::PostMessage parameters.
67 #endif // CHROME_FRAME_TASK_MARSHALLER_H_