chromeos: dbus: add Bluetooth properties support
[chromium-blink-merge.git] / chrome_frame / task_marshaller.h
blobe4b53c3fb1151f5ecc842dd5ed5115d4f3ef636d
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_
7 #pragma once
9 #include <windows.h>
10 #include <deque>
11 #include <queue>
13 #include "base/callback.h"
14 #include "base/pending_task.h"
15 #include "base/synchronization/lock.h"
16 #include "base/threading/non_thread_safe.h"
17 #include "base/time.h"
19 class Task;
21 namespace tracked_objects {
22 class Location;
25 // TaskMarshallerThroughMessageQueue is similar to base::MessageLoopForUI
26 // in cases where we do not control the thread lifetime and message retrieval
27 // and dispatching. It uses a HWND to ::PostMessage to it as a signal that
28 // the task queue is not empty.
29 class TaskMarshallerThroughMessageQueue : public base::NonThreadSafe {
30 public:
31 TaskMarshallerThroughMessageQueue();
32 virtual ~TaskMarshallerThroughMessageQueue();
34 void SetWindow(HWND wnd, UINT msg) {
35 wnd_ = wnd;
36 msg_ = msg;
39 virtual void PostTask(const tracked_objects::Location& from_here,
40 const base::Closure& task);
41 virtual void PostDelayedTask(const tracked_objects::Location& source,
42 const base::Closure& task,
43 base::TimeDelta& delay);
45 // Called by the owner of the HWND.
46 BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
47 LRESULT& lResult, DWORD dwMsgMapID = 0);
48 private:
49 void ClearTasks();
50 inline base::Closure PopTask();
51 inline void ExecuteQueuedTasks();
52 void ExecuteDelayedTasks();
54 // Shortest delays ordered at the top of the queue.
55 base::DelayedTaskQueue delayed_tasks_;
57 // A list of tasks that need to be processed by this instance.
58 std::queue<base::Closure> pending_tasks_;
60 // Lock accesses to |pending_tasks_|.
61 base::Lock lock_;
63 // ::PostMessage parameters.
64 HWND wnd_;
65 UINT msg_;
68 #endif // CHROME_FRAME_TASK_MARSHALLER_H_