Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1054)

Side by Side Diff: base/message_pump_glib.h

Issue 10854: Restructor the the pump for nested loops. (Closed)
Patch Set: x Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/message_pump_glib.cc » ('j') | base/message_pump_glib.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MESSAGE_PUMP_GLIB_H_ 5 #ifndef BASE_MESSAGE_PUMP_GLIB_H_
6 #define BASE_MESSAGE_PUMP_GLIB_H_ 6 #define BASE_MESSAGE_PUMP_GLIB_H_
7 7
8 #include <glib.h> 8 #include <glib.h>
9 9
10 #include "base/message_pump.h" 10 #include "base/message_pump.h"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 // This class implements a MessagePump needed for TYPE_UI MessageLoops on 16 // This class implements a MessagePump needed for TYPE_UI MessageLoops on
17 // OS_LINUX platforms using GLib. 17 // OS_LINUX platforms using GLib.
18 class MessagePumpForUI : public MessagePump { 18 class MessagePumpForUI : public MessagePump {
19 public: 19 public:
20 MessagePumpForUI(); 20 MessagePumpForUI();
21 ~MessagePumpForUI(); 21 ~MessagePumpForUI();
22 22
23 virtual void Run(Delegate* delegate); 23 virtual void Run(Delegate* delegate);
24 virtual void Quit(); 24 virtual void Quit();
25 virtual void ScheduleWork(); 25 virtual void ScheduleWork();
26 virtual void ScheduleDelayedWork(const Time& delayed_work_time); 26 virtual void ScheduleDelayedWork(const Time& delayed_work_time);
27 27
28 // Internal methods used for processing the pump callbacks. They are
29 // public for simplicity but should not be used directly. HandlePrepare
30 // is called during the prepare step of glib, and returns a timeout that
31 // will be passed to the poll. HandleDispatch is called after the poll
32 // has completed.
33 int HandlePrepare();
34 void HandleDispatch();
35
28 private: 36 private:
29 // We may make recursive calls to Run, so we save state that needs to be 37 // We may make recursive calls to Run, so we save state that needs to be
30 // separate between them in this structure type. 38 // separate between them in this structure type.
31 struct RunState { 39 struct RunState {
32 Delegate* delegate; 40 Delegate* delegate;
33 41
34 // Used to flag that the current Run() invocation should return ASAP. 42 // Used to flag that the current Run() invocation should return ASAP.
35 bool should_quit; 43 bool should_quit;
36 44
37 // Used to count how many Run() invocations are on the stack. 45 // Used to count how many Run() invocations are on the stack.
38 int run_depth; 46 int run_depth;
47
48 // Used internally for controlling whether we want a message pump
49 // iteration to be blocking or not.
50 bool more_work_is_plausible;
39 }; 51 };
40 52
41 RunState* state_; 53 RunState* state_;
42 54
43 // This is a GLib structure that we can add event sources to. We use the 55 // This is a GLib structure that we can add event sources to. We use the
44 // default GLib context, which is the one to which all GTK events are 56 // default GLib context, which is the one to which all GTK events are
45 // dispatched. 57 // dispatched.
46 GMainContext* context_; 58 GMainContext* context_;
47 59
48 // This is the time when we need to do delayed work. 60 // This is the time when we need to do delayed work.
49 Time delayed_work_time_; 61 Time delayed_work_time_;
50 62
51 // The work source. It is shared by all calls to Run and destroyed when 63 // The work source. It is shared by all calls to Run and destroyed when
52 // the message pump is destroyed. 64 // the message pump is destroyed.
53 GSource* work_source_; 65 GSource* work_source_;
54 66
55 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); 67 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
56 }; 68 };
57 69
58 } // namespace base 70 } // namespace base
59 71
60 #endif // BASE_MESSAGE_PUMP_GLIB_H_ 72 #endif // BASE_MESSAGE_PUMP_GLIB_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_pump_glib.cc » ('j') | base/message_pump_glib.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698