Chromium Code Reviews| Index: base/message_pump_glib.cc |
| diff --git a/base/message_pump_glib.cc b/base/message_pump_glib.cc |
| index 721fedb6a63ab219043395b27353386daaa5c4bb..f12bb8abb622356180221b8b64033ad671462b5a 100644 |
| --- a/base/message_pump_glib.cc |
| +++ b/base/message_pump_glib.cc |
| @@ -10,12 +10,41 @@ |
| #include <gtk/gtk.h> |
| #include <glib.h> |
| +#include <string> |
| +#include <vector> |
| + |
| #include "base/eintr_wrapper.h" |
| #include "base/logging.h" |
| +#include "base/command_line.h" |
| #include "base/threading/platform_thread.h" |
| namespace { |
| +// TODO(jamiewalch): This is pretty much a direct copy of |
| +// gfx::GtkInitFromCommandLine. The fact that it calls gdk_init instead of |
| +// gtk_init is probably unimportant as the latter calls the former, but |
| +// we can't have base depending on ui so we can't use the function directly. |
| +void GdkInitFromCommandLine(const CommandLine& command_line) { |
| + const std::vector<std::string>& args = command_line.argv(); |
| + int argc = args.size(); |
| + scoped_array<char *> argv(new char *[argc + 1]); |
| + for (size_t i = 0; i < args.size(); ++i) { |
| + // gdk_init makes no const-ness guarantees so best to be safe here. If it |
| + // doesn't delete the arguments it consumes, then there is a small memory |
| + // leak, but the alternative is far more severe. |
| + argv[i] = strdup(args[i].c_str()); |
| + } |
| + argv[argc] = NULL; |
| + char **argv_pointer = argv.get(); |
| + |
| + gdk_init(&argc, &argv_pointer); |
| + // gfx::GtkInitFromCommandLine uses args.size() instead of argc for the loop |
| + // limit, which I believe is wrong, though probably benign. |
| + for (int i = 0; i < argc; ++i) { |
| + free(argv[i]); |
| + } |
| +} |
| + |
| // We send a byte across a pipe to wakeup the event loop. |
| const char kWorkScheduled = '\0'; |
| @@ -144,6 +173,9 @@ MessagePumpForUI::MessagePumpForUI() |
| : state_(NULL), |
| context_(g_main_context_default()), |
| wakeup_gpollfd_(new GPollFD) { |
| + // 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
|
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + GdkInitFromCommandLine(*command_line); |
| // Create our wakeup pipe, which is used to flag when work was scheduled. |
| int fds[2]; |
| CHECK_EQ(pipe(fds), 0); |