summaryrefslogtreecommitdiffstats
path: root/chrome_frame/task_marshaller.h
diff options
context:
space:
mode:
authorstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-06 17:34:43 +0000
committerstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-06 17:34:43 +0000
commit5a8db8040f8f1e4e320f882b1ffea89b6f32d5ea (patch)
treeb29c31cc55b6fec96d9b34e543d9425fce26153d /chrome_frame/task_marshaller.h
parent85fb807c92bcf07512d12bff47dd5a9e22c03161 (diff)
downloadchromium_src-5a8db8040f8f1e4e320f882b1ffea89b6f32d5ea.zip
chromium_src-5a8db8040f8f1e4e320f882b1ffea89b6f32d5ea.tar.gz
chromium_src-5a8db8040f8f1e4e320f882b1ffea89b6f32d5ea.tar.bz2
Reland http://codereview.chromium.org/3528004/
Initial skeleton for refactored ChromeFrameAutomationClient and AutomationProxy for the needs of ChromeFrame. TBR=amit Review URL: http://codereview.chromium.org/3567019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61665 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/task_marshaller.h')
-rw-r--r--chrome_frame/task_marshaller.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/chrome_frame/task_marshaller.h b/chrome_frame/task_marshaller.h
new file mode 100644
index 0000000..b3f87b8
--- /dev/null
+++ b/chrome_frame/task_marshaller.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_FRAME_TASK_MARSHALLER_H_
+#define CHROME_FRAME_TASK_MARSHALLER_H_
+#pragma once
+
+#include <windows.h>
+#include <deque>
+#include <queue>
+#include "base/lock.h"
+#include "base/non_thread_safe.h"
+#include "base/time.h"
+class Task;
+namespace tracked_objects {
+ class Location;
+}
+
+// TaskMarshallerThroughMessageQueue is similar to base::MessageLoopForUI
+// in cases where we do not control the thread lifetime and message retrieval
+// and dispatching. It uses a HWND to ::PostMessage to it as a signal that
+// the task queue is not empty.
+class TaskMarshallerThroughMessageQueue : public NonThreadSafe {
+ public:
+ TaskMarshallerThroughMessageQueue();
+ ~TaskMarshallerThroughMessageQueue();
+
+ void SetWindow(HWND wnd, UINT msg) {
+ wnd_ = wnd;
+ msg_ = msg;
+ }
+
+ virtual void PostTask(const tracked_objects::Location& from_here,
+ Task* task);
+ virtual void PostDelayedTask(const tracked_objects::Location& source,
+ Task* task,
+ base::TimeDelta& delay);
+ private:
+ void DeleteAll();
+ inline Task* PopTask();
+ inline void ExecuteQueuedTasks();
+ void ExecuteDelayedTasks();
+ void RunTask(Task* task);
+
+ struct DelayedTask {
+ DelayedTask(Task* task, base::Time at) : run_at(at), task(task), seq(0) {}
+ base::Time run_at;
+ Task* task;
+ int seq;
+ // To support sorting based on time in priority_queue.
+ bool operator<(const DelayedTask& other) const;
+ };
+
+ std::priority_queue<DelayedTask> delayed_tasks_;
+ std::queue<Task*> pending_tasks_;
+ Lock lock_;
+ HWND wnd_;
+ UINT msg_;
+ int invoke_task_;
+};
+
+#endif // CHROME_FRAME_TASK_MARSHALLER_H_