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

Side by Side Diff: base/message_pump_glib.h

Issue 10833: Rewrite the glib UI pump. (Closed)
Patch Set: 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"
(...skipping 11 matching lines...) Expand all
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 private: 28 private:
29 // We may make recursive calls to Run, so we save state that needs to be 29 // We may make recursive calls to Run, so we save state that needs to be
30 // separate between them in this structure type. 30 // separate between them in this structure type.
31 struct RunState { 31 struct RunState {
32 // This is the delegate argument passed to Run.
33 Delegate* delegate; 32 Delegate* delegate;
34 // This tells us when to exit the event pump. 33
35 bool keep_running; 34 // Used to flag that the current Run() invocation should return ASAP.
36 // This tells our work source when to dispatch DoWork and DoDelayedWork. 35 bool should_quit;
37 bool should_do_work; 36
38 // This tells our idle source when to dispatch DoIdleWork. 37 // Used to count how many Run() invocations are on the stack.
39 bool should_do_idle_work; 38 int run_depth;
40 // Unlike the work source, which is shared by all calls to Run, each Run
41 // call gets its own idle source because we need to destroy it when we have
42 // no idle work, and we don't want to destroy someone else's source.
43 GSource* idle_source;
44 }; 39 };
45 40
46 struct WorkSource : GSource {
47 MessagePumpForUI* self;
48 };
49
50 // The source with these callbacks remain in the main loop forever. They
51 // will dispatch DoWork and DoDelayedWork, and calculate when and how long
52 // to block when GLib calls poll internally.
53 static GSourceFuncs WorkSourceFuncs;
54 static gboolean WorkSourcePrepare(GSource* source, gint* timeout_ms);
55 static gboolean WorkSourceCheck(GSource* source);
56 static gboolean WorkSourceDispatch(GSource* source, GSourceFunc unused_func,
57 gpointer unused_data);
58
59 // The source that uses these callbacks is added as an idle source, which
60 // means GLib will call it when there is no other work to do. We continue
61 // doing work as long as DoIdleWork or the other work functions return true.
62 // Once no work remains, we remove the idle source so GLib will block instead
63 // of firing it. Then we re-add it when we wake up.
64 static GSourceFuncs IdleSourceFuncs;
65 static gboolean IdleSourcePrepare(GSource* source, gint* timeout_ms);
66 static gboolean IdleSourceCheck(GSource* source);
67 static gboolean IdleSourceDispatch(GSource* source, GSourceFunc unused_func,
68 gpointer unused_data);
69
70 // This adds a GLib source to the main loop.
71 GSource* AddSource(GSourceFuncs* funcs, gint priority,
72 GPollFD* optional_poll_fd);
73
74 RunState* state_; 41 RunState* state_;
75 42
76 // This is a GLib structure that we can add event sources to. We use the 43 // This is a GLib structure that we can add event sources to. We use the
77 // default GLib context, which is the one to which all GTK events are 44 // default GLib context, which is the one to which all GTK events are
78 // dispatched. 45 // dispatched.
79 GMainContext* context_; 46 GMainContext* context_;
80 47
81 // This is the time when we need to do delayed work. 48 // This is the time when we need to do delayed work.
82 Time delayed_work_time_; 49 Time delayed_work_time_;
83 50
(...skipping 10 matching lines...) Expand all
94 GSource* work_source_; 61 GSource* work_source_;
95 // The GLib poll structure needs to be owned and freed by us. 62 // The GLib poll structure needs to be owned and freed by us.
96 scoped_ptr<GPollFD> work_source_poll_fd_; 63 scoped_ptr<GPollFD> work_source_poll_fd_;
97 64
98 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); 65 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
99 }; 66 };
100 67
101 } // namespace base 68 } // namespace base
102 69
103 #endif // BASE_MESSAGE_PUMP_GLIB_H_ 70 #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