Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / ipc / chromium / src / base / message_pump_qt.h
blob476c9757acceb6074ff073bd14e6df9a9ff099f5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
7 #ifndef BASE_MESSAGE_PUMP_QT_H_
8 #define BASE_MESSAGE_PUMP_QT_H_
10 #include <qobject.h>
12 #include "base/message_pump.h"
13 #include "base/time.h"
15 class QTimer;
17 namespace base {
19 class MessagePumpForUI;
21 class MessagePumpQt : public QObject {
22 Q_OBJECT
24 public:
25 MessagePumpQt(MessagePumpForUI& pump);
26 ~MessagePumpQt();
28 virtual bool event(QEvent* e);
29 void scheduleDelayedIfNeeded(const TimeTicks& delayed_work_time);
31 public Q_SLOTS:
32 void dispatchDelayed();
34 private:
35 base::MessagePumpForUI& pump;
36 QTimer* mTimer;
39 // This class implements a MessagePump needed for TYPE_UI MessageLoops on
40 // XP_LINUX platforms using QApplication event loop
41 class MessagePumpForUI : public MessagePump {
42 public:
43 MessagePumpForUI();
44 ~MessagePumpForUI();
46 virtual void Run(Delegate* delegate);
47 virtual void Quit();
48 virtual void ScheduleWork();
49 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time);
51 // Internal methods used for processing the pump callbacks. They are
52 // public for simplicity but should not be used directly.
53 // HandleDispatch is called after the poll has completed.
54 void HandleDispatch();
56 private:
57 // We may make recursive calls to Run, so we save state that needs to be
58 // separate between them in this structure type.
59 struct RunState {
60 Delegate* delegate;
62 // Used to flag that the current Run() invocation should return ASAP.
63 bool should_quit;
65 // Used to count how many Run() invocations are on the stack.
66 int run_depth;
69 RunState* state_;
71 // This is the time when we need to do delayed work.
72 TimeTicks delayed_work_time_;
74 // MessagePump implementation for Qt based on the GLib implement.
75 // On Qt we use a QObject base class and the
76 // default qApp in order to process events through QEventLoop.
77 MessagePumpQt qt_pump;
79 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
82 } // namespace base
84 #endif // BASE_MESSAGE_PUMP_QT_H_