blob: 44f8b1600aae569b1fd6f60ffe1e63467ec45187 [file] [log] [blame]
[email protected]262060ff2011-11-17 23:26:531// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]5a8db802010-10-06 17:34:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_FRAME_TASK_MARSHALLER_H_
6#define CHROME_FRAME_TASK_MARSHALLER_H_
[email protected]5a8db802010-10-06 17:34:437
8#include <windows.h>
9#include <deque>
10#include <queue>
[email protected]20305ec2011-01-21 04:55:5211
[email protected]262060ff2011-11-17 23:26:5312#include "base/callback.h"
13#include "base/pending_task.h"
[email protected]20305ec2011-01-21 04:55:5214#include "base/synchronization/lock.h"
[email protected]c9177502011-01-01 04:48:4915#include "base/threading/non_thread_safe.h"
[email protected]5a8db802010-10-06 17:34:4316#include "base/time.h"
[email protected]c9177502011-01-01 04:48:4917
[email protected]5a8db802010-10-06 17:34:4318class Task;
[email protected]bb04c4e2011-11-18 20:44:2219
[email protected]5a8db802010-10-06 17:34:4320namespace tracked_objects {
[email protected]bb04c4e2011-11-18 20:44:2221class Location;
[email protected]5a8db802010-10-06 17:34:4322}
23
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.
[email protected]c9177502011-01-01 04:48:4928class TaskMarshallerThroughMessageQueue : public base::NonThreadSafe {
[email protected]5a8db802010-10-06 17:34:4329 public:
30 TaskMarshallerThroughMessageQueue();
[email protected]262060ff2011-11-17 23:26:5331 virtual ~TaskMarshallerThroughMessageQueue();
[email protected]5a8db802010-10-06 17:34:4332
33 void SetWindow(HWND wnd, UINT msg) {
34 wnd_ = wnd;
35 msg_ = msg;
36 }
37
38 virtual void PostTask(const tracked_objects::Location& from_here,
[email protected]262060ff2011-11-17 23:26:5339 const base::Closure& task);
[email protected]5a8db802010-10-06 17:34:4340 virtual void PostDelayedTask(const tracked_objects::Location& source,
[email protected]262060ff2011-11-17 23:26:5341 const base::Closure& task,
[email protected]5a8db802010-10-06 17:34:4342 base::TimeDelta& delay);
[email protected]262060ff2011-11-17 23:26:5343
[email protected]11b6e602010-10-13 16:02:2644 // Called by the owner of the HWND.
45 BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
46 LRESULT& lResult, DWORD dwMsgMapID = 0);
[email protected]5a8db802010-10-06 17:34:4347 private:
[email protected]262060ff2011-11-17 23:26:5348 void ClearTasks();
49 inline base::Closure PopTask();
[email protected]5a8db802010-10-06 17:34:4350 inline void ExecuteQueuedTasks();
51 void ExecuteDelayedTasks();
[email protected]5a8db802010-10-06 17:34:4352
[email protected]262060ff2011-11-17 23:26:5353 // Shortest delays ordered at the top of the queue.
54 base::DelayedTaskQueue delayed_tasks_;
[email protected]5a8db802010-10-06 17:34:4355
[email protected]262060ff2011-11-17 23:26:5356 // A list of tasks that need to be processed by this instance.
57 std::queue<base::Closure> pending_tasks_;
58
59 // Lock accesses to |pending_tasks_|.
[email protected]20305ec2011-01-21 04:55:5260 base::Lock lock_;
[email protected]262060ff2011-11-17 23:26:5361
62 // ::PostMessage parameters.
[email protected]5a8db802010-10-06 17:34:4363 HWND wnd_;
64 UINT msg_;
[email protected]5a8db802010-10-06 17:34:4365};
66
67#endif // CHROME_FRAME_TASK_MARSHALLER_H_