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

Side by Side Diff: base/message_pump_glib.cc

Issue 6489031: Run event executor on the ui thread to remove the need to explicitly XFlush() the XTest calls. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: git cl try Created 9 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/service/remoting/chromoting_host_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "base/message_pump_glib.h" 5 #include "base/message_pump_glib.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <math.h> 8 #include <math.h>
9 9
10 #include <gtk/gtk.h> 10 #include <gtk/gtk.h>
11 #include <glib.h> 11 #include <glib.h>
12 12
13 #include <string>
14 #include <vector>
15
13 #include "base/eintr_wrapper.h" 16 #include "base/eintr_wrapper.h"
14 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/command_line.h"
15 #include "base/threading/platform_thread.h" 19 #include "base/threading/platform_thread.h"
16 20
17 namespace { 21 namespace {
18 22
23 // TODO(jamiewalch): This is pretty much a direct copy of
24 // gfx::GtkInitFromCommandLine. The fact that it calls gdk_init instead of
25 // gtk_init is probably unimportant as the latter calls the former, but
26 // we can't have base depending on ui so we can't use the function directly.
27 void GdkInitFromCommandLine(const CommandLine& command_line) {
28 const std::vector<std::string>& args = command_line.argv();
29 int argc = args.size();
30 scoped_array<char *> argv(new char *[argc + 1]);
31 for (size_t i = 0; i < args.size(); ++i) {
32 // gdk_init makes no const-ness guarantees so best to be safe here. If it
33 // doesn't delete the arguments it consumes, then there is a small memory
34 // leak, but the alternative is far more severe.
35 argv[i] = strdup(args[i].c_str());
36 }
37 argv[argc] = NULL;
38 char **argv_pointer = argv.get();
39
40 gdk_init(&argc, &argv_pointer);
41 // gfx::GtkInitFromCommandLine uses args.size() instead of argc for the loop
42 // limit, which I believe is wrong, though probably benign.
43 for (int i = 0; i < argc; ++i) {
44 free(argv[i]);
45 }
46 }
47
19 // We send a byte across a pipe to wakeup the event loop. 48 // We send a byte across a pipe to wakeup the event loop.
20 const char kWorkScheduled = '\0'; 49 const char kWorkScheduled = '\0';
21 50
22 // Return a timeout suitable for the glib loop, -1 to block forever, 51 // Return a timeout suitable for the glib loop, -1 to block forever,
23 // 0 to return right away, or a timeout in milliseconds from now. 52 // 0 to return right away, or a timeout in milliseconds from now.
24 int GetTimeIntervalMilliseconds(const base::TimeTicks& from) { 53 int GetTimeIntervalMilliseconds(const base::TimeTicks& from) {
25 if (from.is_null()) 54 if (from.is_null())
26 return -1; 55 return -1;
27 56
28 // Be careful here. TimeDelta has a precision of microseconds, but we want a 57 // Be careful here. TimeDelta has a precision of microseconds, but we want a
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // This keeps the state of whether the pump got signaled that there was new 166 // This keeps the state of whether the pump got signaled that there was new
138 // work to be done. Since we eat the message on the wake up pipe as soon as 167 // work to be done. Since we eat the message on the wake up pipe as soon as
139 // we get it, we keep that state here to stay consistent. 168 // we get it, we keep that state here to stay consistent.
140 bool has_work; 169 bool has_work;
141 }; 170 };
142 171
143 MessagePumpForUI::MessagePumpForUI() 172 MessagePumpForUI::MessagePumpForUI()
144 : state_(NULL), 173 : state_(NULL),
145 context_(g_main_context_default()), 174 context_(g_main_context_default()),
146 wakeup_gpollfd_(new GPollFD) { 175 wakeup_gpollfd_(new GPollFD) {
176 // Initialize gdk.
Dean McNamee 2011/02/15 17:06:26 This is the classic style of comment: // Add one
Jamie 2011/02/15 17:17:03 Yes, I put the comment in before I factored out th
177 CommandLine* command_line = CommandLine::ForCurrentProcess();
178 GdkInitFromCommandLine(*command_line);
147 // Create our wakeup pipe, which is used to flag when work was scheduled. 179 // Create our wakeup pipe, which is used to flag when work was scheduled.
148 int fds[2]; 180 int fds[2];
149 CHECK_EQ(pipe(fds), 0); 181 CHECK_EQ(pipe(fds), 0);
150 wakeup_pipe_read_ = fds[0]; 182 wakeup_pipe_read_ = fds[0];
151 wakeup_pipe_write_ = fds[1]; 183 wakeup_pipe_write_ = fds[1];
152 wakeup_gpollfd_->fd = wakeup_pipe_read_; 184 wakeup_gpollfd_->fd = wakeup_pipe_read_;
153 wakeup_gpollfd_->events = G_IO_IN; 185 wakeup_gpollfd_->events = G_IO_IN;
154 186
155 work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource)); 187 work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource));
156 static_cast<WorkSource*>(work_source_)->pump = this; 188 static_cast<WorkSource*>(work_source_)->pump = this;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 FOR_EACH_OBSERVER(Observer, observers_, DidProcessEvent(event)); 387 FOR_EACH_OBSERVER(Observer, observers_, DidProcessEvent(event));
356 } 388 }
357 389
358 // static 390 // static
359 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) { 391 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) {
360 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data); 392 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data);
361 message_pump->DispatchEvents(event); 393 message_pump->DispatchEvents(event);
362 } 394 }
363 395
364 } // namespace base 396 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/service/remoting/chromoting_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698