[email protected] | 38d0b2d4 | 2012-01-18 03:37:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/browser/browser_main_loop.h" |
| 6 | |
[email protected] | 820de97 | 2012-01-03 18:23:04 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 8 | #include "base/command_line.h" |
| 9 | #include "base/debug/trace_event.h" |
[email protected] | b3aabd34 | 2012-06-04 19:33:56 | [diff] [blame^] | 10 | #include "base/hi_res_timer_manager.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 11 | #include "base/logging.h" |
| 12 | #include "base/message_loop.h" |
| 13 | #include "base/metrics/field_trial.h" |
| 14 | #include "base/metrics/histogram.h" |
[email protected] | a6381cb5 | 2012-02-13 22:39:34 | [diff] [blame] | 15 | #include "base/string_number_conversions.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 16 | #include "base/threading/thread_restrictions.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 17 | #include "content/browser/browser_thread_impl.h" |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 18 | #include "content/browser/download/download_file_manager.h" |
| 19 | #include "content/browser/download/save_file_manager.h" |
[email protected] | 5b040e59 | 2012-02-10 02:56:10 | [diff] [blame] | 20 | #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
[email protected] | 99af54b | 2012-03-03 01:06:50 | [diff] [blame] | 21 | #include "content/browser/gpu/gpu_process_host.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 22 | #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 23 | #include "content/browser/in_process_webkit/webkit_thread.h" |
[email protected] | bff327f | 2012-03-11 22:17:19 | [diff] [blame] | 24 | #include "content/browser/net/browser_online_state_observer.h" |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 25 | #include "content/browser/plugin_service_impl.h" |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 26 | #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
[email protected] | 28df14d | 2012-05-16 14:51:22 | [diff] [blame] | 27 | #include "content/browser/speech/speech_recognition_manager_impl.h" |
[email protected] | 900e912 | 2012-03-13 15:43:08 | [diff] [blame] | 28 | #include "content/browser/trace_controller_impl.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 29 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 30 | #include "content/public/browser/browser_shutdown.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 31 | #include "content/public/browser/content_browser_client.h" |
[email protected] | b14b873b | 2012-05-03 03:56:09 | [diff] [blame] | 32 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | a6381cb5 | 2012-02-13 22:39:34 | [diff] [blame] | 33 | #include "content/public/browser/render_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 34 | #include "content/public/common/content_switches.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 35 | #include "content/public/common/main_function_params.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 36 | #include "content/public/common/result_codes.h" |
| 37 | #include "crypto/nss_util.h" |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 38 | #include "media/audio/audio_manager.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 39 | #include "net/base/network_change_notifier.h" |
| 40 | #include "net/base/ssl_config_service.h" |
| 41 | #include "net/socket/client_socket_factory.h" |
| 42 | #include "net/socket/tcp_client_socket.h" |
| 43 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 44 | #if defined(USE_AURA) |
| 45 | #include "content/browser/renderer_host/image_transport_factory.h" |
| 46 | #endif |
| 47 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 48 | #if defined(OS_WIN) |
| 49 | #include <windows.h> |
| 50 | #include <commctrl.h> |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 51 | #include <shellapi.h> |
| 52 | |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 53 | #include "content/browser/system_message_window_win.h" |
[email protected] | 6a7da76 | 2012-03-31 02:12:33 | [diff] [blame] | 54 | #include "content/common/sandbox_policy.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 55 | #include "ui/base/l10n/l10n_util_win.h" |
| 56 | #include "net/base/winsock_init.h" |
| 57 | #endif |
| 58 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 59 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 60 | #include <glib-object.h> |
| 61 | #endif |
| 62 | |
| 63 | #if defined(OS_CHROMEOS) |
| 64 | #include <dbus/dbus-glib.h> |
| 65 | #endif |
| 66 | |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 67 | #if defined(TOOLKIT_GTK) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 68 | #include "ui/gfx/gtk_util.h" |
| 69 | #endif |
| 70 | |
| 71 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 72 | #include <sys/stat.h> |
| 73 | #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
[email protected] | c2c68b1f | 2012-02-25 00:29:15 | [diff] [blame] | 74 | #include "content/browser/zygote_host_impl_linux.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 75 | #endif |
| 76 | |
[email protected] | 462d4a3 | 2012-01-19 00:11:04 | [diff] [blame] | 77 | #if defined(USE_X11) |
| 78 | #include <X11/Xlib.h> |
| 79 | #endif |
| 80 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 81 | // One of the linux specific headers defines this as a macro. |
| 82 | #ifdef DestroyAll |
| 83 | #undef DestroyAll |
| 84 | #endif |
| 85 | |
[email protected] | 900e912 | 2012-03-13 15:43:08 | [diff] [blame] | 86 | using content::TraceControllerImpl; |
| 87 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 88 | namespace { |
| 89 | |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 90 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 91 | void SetupSandbox(const CommandLine& parsed_command_line) { |
| 92 | // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this |
| 93 | // code en masse out of chrome_main for now. |
| 94 | const char* sandbox_binary = NULL; |
| 95 | struct stat st; |
| 96 | |
| 97 | // In Chromium branded builds, developers can set an environment variable to |
| 98 | // use the development sandbox. See |
| 99 | // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment |
| 100 | if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid()) |
| 101 | sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); |
| 102 | |
| 103 | #if defined(LINUX_SANDBOX_PATH) |
| 104 | if (!sandbox_binary) |
| 105 | sandbox_binary = LINUX_SANDBOX_PATH; |
| 106 | #endif |
| 107 | |
| 108 | std::string sandbox_cmd; |
| 109 | if (sandbox_binary && !parsed_command_line.HasSwitch(switches::kNoSandbox)) |
| 110 | sandbox_cmd = sandbox_binary; |
| 111 | |
| 112 | // Tickle the sandbox host and zygote host so they fork now. |
[email protected] | c2c68b1f | 2012-02-25 00:29:15 | [diff] [blame] | 113 | RenderSandboxHostLinux::GetInstance()->Init(sandbox_cmd); |
| 114 | ZygoteHostImpl::GetInstance()->Init(sandbox_cmd); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 115 | } |
| 116 | #endif |
| 117 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 118 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 119 | static void GLibLogHandler(const gchar* log_domain, |
| 120 | GLogLevelFlags log_level, |
| 121 | const gchar* message, |
| 122 | gpointer userdata) { |
| 123 | if (!log_domain) |
| 124 | log_domain = "<unknown>"; |
| 125 | if (!message) |
| 126 | message = "<no message>"; |
| 127 | |
| 128 | if (strstr(message, "Loading IM context type") || |
| 129 | strstr(message, "wrong ELF class: ELFCLASS64")) { |
| 130 | // http://crbug.com/9643 |
| 131 | // Until we have a real 64-bit build or all of these 32-bit package issues |
| 132 | // are sorted out, don't fatal on ELF 32/64-bit mismatch warnings and don't |
| 133 | // spam the user with more than one of them. |
| 134 | static bool alerted = false; |
| 135 | if (!alerted) { |
| 136 | LOG(ERROR) << "Bug 9643: " << log_domain << ": " << message; |
| 137 | alerted = true; |
| 138 | } |
[email protected] | 8a1ea19 | 2011-11-29 22:40:50 | [diff] [blame] | 139 | } else if (strstr(message, "Unable to retrieve the file info for")) { |
| 140 | LOG(ERROR) << "GTK File code error: " << message; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 141 | } else if (strstr(message, "Theme file for default has no") || |
| 142 | strstr(message, "Theme directory") || |
[email protected] | 2bdaecf | 2011-12-15 02:44:55 | [diff] [blame] | 143 | strstr(message, "theme pixmap") || |
| 144 | strstr(message, "locate theme engine")) { |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 145 | LOG(ERROR) << "GTK theme error: " << message; |
| 146 | } else if (strstr(message, "gtk_drag_dest_leave: assertion")) { |
| 147 | LOG(ERROR) << "Drag destination deleted: http://crbug.com/18557"; |
| 148 | } else if (strstr(message, "Out of memory") && |
| 149 | strstr(log_domain, "<unknown>")) { |
| 150 | LOG(ERROR) << "DBus call timeout or out of memory: " |
| 151 | << "http://crosbug.com/15496"; |
| 152 | } else if (strstr(message, "XDG_RUNTIME_DIR variable not set")) { |
| 153 | LOG(ERROR) << message << " (http://bugs.chromium.org/97293)"; |
| 154 | } else { |
| 155 | LOG(DFATAL) << log_domain << ": " << message; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | static void SetUpGLibLogHandler() { |
| 160 | // Register GLib-handled assertions to go through our logging system. |
| 161 | const char* kLogDomains[] = { NULL, "Gtk", "Gdk", "GLib", "GLib-GObject" }; |
| 162 | for (size_t i = 0; i < arraysize(kLogDomains); i++) { |
| 163 | g_log_set_handler(kLogDomains[i], |
| 164 | static_cast<GLogLevelFlags>(G_LOG_FLAG_RECURSION | |
| 165 | G_LOG_FLAG_FATAL | |
| 166 | G_LOG_LEVEL_ERROR | |
| 167 | G_LOG_LEVEL_CRITICAL | |
| 168 | G_LOG_LEVEL_WARNING), |
| 169 | GLibLogHandler, |
| 170 | NULL); |
| 171 | } |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | } // namespace |
| 176 | |
| 177 | namespace content { |
| 178 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 179 | // The currently-running BrowserMainLoop. There can be one or zero. |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 180 | BrowserMainLoop* g_current_browser_main_loop = NULL; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 181 | |
| 182 | // This is just to be able to keep ShutdownThreadsAndCleanUp out of |
| 183 | // the public interface of BrowserMainLoop. |
| 184 | class BrowserShutdownImpl { |
| 185 | public: |
| 186 | static void ImmediateShutdownAndExitProcess() { |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 187 | DCHECK(g_current_browser_main_loop); |
| 188 | g_current_browser_main_loop->ShutdownThreadsAndCleanUp(); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 189 | |
| 190 | #if defined(OS_WIN) |
| 191 | // At this point the message loop is still running yet we've shut everything |
| 192 | // down. If any messages are processed we'll likely crash. Exit now. |
| 193 | ExitProcess(content::RESULT_CODE_NORMAL_EXIT); |
| 194 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
| 195 | _exit(content::RESULT_CODE_NORMAL_EXIT); |
| 196 | #else |
| 197 | NOTIMPLEMENTED(); |
| 198 | #endif |
| 199 | } |
| 200 | }; |
| 201 | |
| 202 | void ImmediateShutdownAndExitProcess() { |
| 203 | BrowserShutdownImpl::ImmediateShutdownAndExitProcess(); |
| 204 | } |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 205 | |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 206 | // static |
[email protected] | 67dfea90 | 2012-04-03 01:49:09 | [diff] [blame] | 207 | media::AudioManager* BrowserMainLoop::GetAudioManager() { |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 208 | return g_current_browser_main_loop->audio_manager_.get(); |
| 209 | } |
| 210 | |
[email protected] | e974ad29 | 2012-03-07 07:34:51 | [diff] [blame] | 211 | // BrowserMainLoop construction / destruction ============================= |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 212 | |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 213 | BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 214 | : parameters_(parameters), |
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame] | 215 | parsed_command_line_(parameters.command_line), |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 216 | result_code_(content::RESULT_CODE_NORMAL_EXIT) { |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 217 | DCHECK(!g_current_browser_main_loop); |
| 218 | g_current_browser_main_loop = this; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | BrowserMainLoop::~BrowserMainLoop() { |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 222 | DCHECK_EQ(this, g_current_browser_main_loop); |
| 223 | g_current_browser_main_loop = NULL; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void BrowserMainLoop::Init() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 227 | parts_.reset( |
| 228 | GetContentClient()->browser()->CreateBrowserMainParts(parameters_)); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | // BrowserMainLoop stages ================================================== |
| 232 | |
| 233 | void BrowserMainLoop::EarlyInitialization() { |
[email protected] | 462d4a3 | 2012-01-19 00:11:04 | [diff] [blame] | 234 | #if defined(USE_X11) |
| 235 | if (parsed_command_line_.HasSwitch(switches::kSingleProcess) || |
| 236 | parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { |
| 237 | if (!XInitThreads()) { |
| 238 | LOG(ERROR) << "Failed to put Xlib into threaded mode."; |
| 239 | } |
| 240 | } |
| 241 | #endif |
| 242 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 243 | if (parts_.get()) |
| 244 | parts_->PreEarlyInitialization(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 245 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 246 | #if defined(OS_WIN) |
| 247 | net::EnsureWinsockInit(); |
| 248 | #endif |
| 249 | |
[email protected] | 1648b29 | 2011-11-03 23:57:39 | [diff] [blame] | 250 | #if !defined(USE_OPENSSL) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 251 | // Use NSS for SSL by default. |
| 252 | // The default client socket factory uses NSS for SSL by default on |
| 253 | // Windows and Mac. |
| 254 | bool init_nspr = false; |
| 255 | #if defined(OS_WIN) || defined(OS_MACOSX) |
| 256 | if (parsed_command_line_.HasSwitch(switches::kUseSystemSSL)) { |
| 257 | net::ClientSocketFactory::UseSystemSSL(); |
| 258 | } else { |
| 259 | init_nspr = true; |
| 260 | } |
[email protected] | c480510 | 2012-03-02 23:34:32 | [diff] [blame] | 261 | UMA_HISTOGRAM_BOOLEAN("Chrome.CommandLineUseSystemSSL", !init_nspr); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 262 | #elif defined(USE_NSS) |
| 263 | init_nspr = true; |
| 264 | #endif |
| 265 | if (init_nspr) { |
| 266 | // We want to be sure to init NSPR on the main thread. |
| 267 | crypto::EnsureNSPRInit(); |
| 268 | } |
[email protected] | 1648b29 | 2011-11-03 23:57:39 | [diff] [blame] | 269 | #endif // !defined(USE_OPENSSL) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 270 | |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 271 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 272 | SetupSandbox(parsed_command_line_); |
| 273 | #endif |
| 274 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 275 | if (parsed_command_line_.HasSwitch(switches::kEnableSSLCachedInfo)) |
| 276 | net::SSLConfigService::EnableCachedInfo(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 277 | |
| 278 | // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't |
| 279 | // seem dependent on SSL initialization(). |
| 280 | if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) |
| 281 | net::set_tcp_fastopen_enabled(true); |
| 282 | |
[email protected] | a6381cb5 | 2012-02-13 22:39:34 | [diff] [blame] | 283 | if (parsed_command_line_.HasSwitch(switches::kRendererProcessLimit)) { |
| 284 | std::string limit_string = parsed_command_line_.GetSwitchValueASCII( |
| 285 | switches::kRendererProcessLimit); |
| 286 | size_t process_limit; |
| 287 | if (base::StringToSizeT(limit_string, &process_limit)) { |
| 288 | content::RenderProcessHost::SetMaxRendererProcessCount(process_limit); |
| 289 | } |
| 290 | } |
| 291 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 292 | if (parts_.get()) |
| 293 | parts_->PostEarlyInitialization(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void BrowserMainLoop::MainMessageLoopStart() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 297 | if (parts_.get()) |
| 298 | parts_->PreMainMessageLoopStart(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 299 | |
| 300 | #if defined(OS_WIN) |
| 301 | // If we're running tests (ui_task is non-null), then the ResourceBundle |
| 302 | // has already been initialized. |
[email protected] | 716476c | 2011-12-29 00:07:03 | [diff] [blame] | 303 | if (!parameters_.ui_task) { |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 304 | // Override the configured locale with the user's preferred UI language. |
| 305 | l10n_util::OverrideLocaleWithUILanguageList(); |
| 306 | } |
| 307 | #endif |
| 308 | |
[email protected] | de88c5e | 2012-04-10 23:35:23 | [diff] [blame] | 309 | // Create a MessageLoop if one does not already exist for the current thread. |
| 310 | if (!MessageLoop::current()) |
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 311 | main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 312 | |
| 313 | InitializeMainThread(); |
| 314 | |
[email protected] | 50f3842 | 2011-11-09 19:21:33 | [diff] [blame] | 315 | // Start tracing to a file if needed. |
[email protected] | 900e912 | 2012-03-13 15:43:08 | [diff] [blame] | 316 | if (base::debug::TraceLog::GetInstance()->IsEnabled()) { |
| 317 | TraceControllerImpl::GetInstance()->InitStartupTracing( |
| 318 | parsed_command_line_); |
| 319 | } |
[email protected] | 50f3842 | 2011-11-09 19:21:33 | [diff] [blame] | 320 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 321 | system_monitor_.reset(new base::SystemMonitor); |
| 322 | hi_res_timer_manager_.reset(new HighResolutionTimerManager); |
| 323 | |
| 324 | network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
[email protected] | 67dfea90 | 2012-04-03 01:49:09 | [diff] [blame] | 325 | audio_manager_.reset(media::AudioManager::Create()); |
[email protected] | bff327f | 2012-03-11 22:17:19 | [diff] [blame] | 326 | online_state_observer_.reset(new BrowserOnlineStateObserver); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 327 | |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 328 | #if defined(OS_WIN) |
| 329 | system_message_window_.reset(new SystemMessageWindowWin); |
| 330 | #endif |
| 331 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 332 | // Prior to any processing happening on the io thread, we create the |
| 333 | // plugin service as it is predominantly used from the io thread, |
| 334 | // but must be created on the main thread. The service ctor is |
| 335 | // inexpensive and does not invoke the io_thread() accessor. |
| 336 | PluginService::GetInstance()->Init(); |
| 337 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 338 | if (parts_.get()) |
| 339 | parts_->PostMainMessageLoopStart(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 340 | } |
| 341 | |
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 342 | void BrowserMainLoop::CreateThreads() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 343 | if (parts_.get()) |
[email protected] | 69479b92 | 2012-02-02 09:56:20 | [diff] [blame] | 344 | result_code_ = parts_->PreCreateThreads(); |
| 345 | |
| 346 | if (result_code_ > 0) |
| 347 | return; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 348 | |
| 349 | base::Thread::Options default_options; |
| 350 | base::Thread::Options io_message_loop_options; |
| 351 | io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO; |
| 352 | base::Thread::Options ui_message_loop_options; |
| 353 | ui_message_loop_options.message_loop_type = MessageLoop::TYPE_UI; |
| 354 | |
| 355 | // Start threads in the order they occur in the BrowserThread::ID |
| 356 | // enumeration, except for BrowserThread::UI which is the main |
| 357 | // thread. |
| 358 | // |
| 359 | // Must be size_t so we can increment it. |
| 360 | for (size_t thread_id = BrowserThread::UI + 1; |
| 361 | thread_id < BrowserThread::ID_COUNT; |
| 362 | ++thread_id) { |
| 363 | scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; |
| 364 | base::Thread::Options* options = &default_options; |
| 365 | |
| 366 | switch (thread_id) { |
| 367 | case BrowserThread::DB: |
| 368 | thread_to_start = &db_thread_; |
| 369 | break; |
[email protected] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 370 | case BrowserThread::WEBKIT_DEPRECATED: |
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 371 | // Special case as WebKitThread is a separate |
| 372 | // type. |thread_to_start| is not used in this case. |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 373 | break; |
[email protected] | 31dbf9d | 2011-12-07 01:25:30 | [diff] [blame] | 374 | case BrowserThread::FILE_USER_BLOCKING: |
| 375 | thread_to_start = &file_user_blocking_thread_; |
| 376 | break; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 377 | case BrowserThread::FILE: |
| 378 | thread_to_start = &file_thread_; |
| 379 | #if defined(OS_WIN) |
| 380 | // On Windows, the FILE thread needs to be have a UI message loop |
| 381 | // which pumps messages in such a way that Google Update can |
| 382 | // communicate back to us. |
| 383 | options = &ui_message_loop_options; |
| 384 | #else |
| 385 | options = &io_message_loop_options; |
| 386 | #endif |
| 387 | break; |
| 388 | case BrowserThread::PROCESS_LAUNCHER: |
| 389 | thread_to_start = &process_launcher_thread_; |
| 390 | break; |
| 391 | case BrowserThread::CACHE: |
| 392 | thread_to_start = &cache_thread_; |
| 393 | options = &io_message_loop_options; |
| 394 | break; |
| 395 | case BrowserThread::IO: |
| 396 | thread_to_start = &io_thread_; |
| 397 | options = &io_message_loop_options; |
| 398 | break; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 399 | case BrowserThread::UI: |
| 400 | case BrowserThread::ID_COUNT: |
| 401 | default: |
| 402 | NOTREACHED(); |
| 403 | break; |
| 404 | } |
| 405 | |
| 406 | BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
| 407 | |
[email protected] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 408 | if (thread_id == BrowserThread::WEBKIT_DEPRECATED) { |
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 409 | webkit_thread_.reset(new WebKitThread); |
| 410 | webkit_thread_->Initialize(); |
| 411 | } else if (thread_to_start) { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 412 | (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
| 413 | (*thread_to_start)->StartWithOptions(*options); |
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 414 | } else { |
| 415 | NOTREACHED(); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 416 | } |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 417 | } |
| 418 | |
[email protected] | 5b040e59 | 2012-02-10 02:56:10 | [diff] [blame] | 419 | BrowserGpuChannelHostFactory::Initialize(); |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 420 | #if defined(USE_AURA) |
| 421 | ImageTransportFactory::Initialize(); |
| 422 | #endif |
[email protected] | 5b040e59 | 2012-02-10 02:56:10 | [diff] [blame] | 423 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 424 | BrowserThreadsStarted(); |
| 425 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 426 | if (parts_.get()) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 427 | parts_->PreMainMessageLoopRun(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 428 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 429 | // If the UI thread blocks, the whole UI is unresponsive. |
| 430 | // Do not allow disk IO from the UI thread. |
| 431 | base::ThreadRestrictions::SetIOAllowed(false); |
[email protected] | 3a7b66d | 2012-04-26 16:34:16 | [diff] [blame] | 432 | base::ThreadRestrictions::DisallowWaiting(); |
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | void BrowserMainLoop::RunMainMessageLoopParts() { |
| 436 | TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 437 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 438 | bool ran_main_loop = false; |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 439 | if (parts_.get()) |
| 440 | ran_main_loop = parts_->MainMessageLoopRun(&result_code_); |
| 441 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 442 | if (!ran_main_loop) |
| 443 | MainMessageLoopRun(); |
| 444 | |
| 445 | TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | void BrowserMainLoop::ShutdownThreadsAndCleanUp() { |
| 449 | // Teardown may start in PostMainMessageLoopRun, and during teardown we |
| 450 | // need to be able to perform IO. |
| 451 | base::ThreadRestrictions::SetIOAllowed(true); |
| 452 | BrowserThread::PostTask( |
[email protected] | 8f5a7e49 | 2012-01-01 02:14:47 | [diff] [blame] | 453 | BrowserThread::IO, FROM_HERE, |
[email protected] | 71cb8aa | 2011-12-29 19:14:00 | [diff] [blame] | 454 | base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), |
| 455 | true)); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 456 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 457 | if (parts_.get()) |
| 458 | parts_->PostMainMessageLoopRun(); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 459 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 460 | // Destroying the GpuProcessHostUIShims on the UI thread posts a task to |
| 461 | // delete related objects on the GPU thread. This must be done before |
| 462 | // stopping the GPU thread. The GPU thread will close IPC channels to renderer |
| 463 | // processes so this has to happen before stopping the IO thread. |
| 464 | GpuProcessHostUIShim::DestroyAll(); |
| 465 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 466 | // Cancel pending requests and prevent new requests. |
| 467 | if (resource_dispatcher_host_.get()) |
| 468 | resource_dispatcher_host_.get()->Shutdown(); |
| 469 | |
[email protected] | 28df14d | 2012-05-16 14:51:22 | [diff] [blame] | 470 | speech_recognition_manager_.reset(); |
| 471 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 472 | #if defined(USE_AURA) |
| 473 | ImageTransportFactory::Terminate(); |
| 474 | #endif |
[email protected] | 5b040e59 | 2012-02-10 02:56:10 | [diff] [blame] | 475 | BrowserGpuChannelHostFactory::Terminate(); |
| 476 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 477 | // Must be size_t so we can subtract from it. |
| 478 | for (size_t thread_id = BrowserThread::ID_COUNT - 1; |
| 479 | thread_id >= (BrowserThread::UI + 1); |
| 480 | --thread_id) { |
| 481 | // Find the thread object we want to stop. Looping over all valid |
| 482 | // BrowserThread IDs and DCHECKing on a missing case in the switch |
| 483 | // statement helps avoid a mismatch between this code and the |
| 484 | // BrowserThread::ID enumeration. |
| 485 | // |
| 486 | // The destruction order is the reverse order of occurrence in the |
| 487 | // BrowserThread::ID list. The rationale for the order is as |
| 488 | // follows (need to be filled in a bit): |
| 489 | // |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 490 | // |
| 491 | // - The IO thread is the only user of the CACHE thread. |
| 492 | // |
| 493 | // - The PROCESS_LAUNCHER thread must be stopped after IO in case |
| 494 | // the IO thread posted a task to terminate a process on the |
| 495 | // process launcher thread. |
| 496 | // |
| 497 | // - (Not sure why FILE needs to stop before WEBKIT.) |
| 498 | // |
| 499 | // - The WEBKIT thread (which currently is the responsibility of |
| 500 | // the embedder to stop, by destroying ResourceDispatcherHost |
| 501 | // before the DB thread is stopped) |
| 502 | // |
| 503 | // - (Not sure why DB stops last.) |
| 504 | scoped_ptr<BrowserProcessSubThread>* thread_to_stop = NULL; |
| 505 | switch (thread_id) { |
| 506 | case BrowserThread::DB: |
| 507 | thread_to_stop = &db_thread_; |
| 508 | break; |
[email protected] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 509 | case BrowserThread::WEBKIT_DEPRECATED: |
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 510 | // Special case as WebKitThread is a separate |
| 511 | // type. |thread_to_stop| is not used in this case. |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 512 | |
| 513 | // Need to destroy ResourceDispatcherHost before PluginService |
| 514 | // and since it caches a pointer to it. |
| 515 | resource_dispatcher_host_.reset(); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 516 | break; |
[email protected] | 31dbf9d | 2011-12-07 01:25:30 | [diff] [blame] | 517 | case BrowserThread::FILE_USER_BLOCKING: |
| 518 | thread_to_stop = &file_user_blocking_thread_; |
| 519 | break; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 520 | case BrowserThread::FILE: |
| 521 | thread_to_stop = &file_thread_; |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 522 | |
| 523 | // Clean up state that lives on or uses the file_thread_ before |
| 524 | // it goes away. |
| 525 | if (resource_dispatcher_host_.get()) { |
| 526 | resource_dispatcher_host_.get()->download_file_manager()->Shutdown(); |
| 527 | resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); |
| 528 | } |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 529 | break; |
| 530 | case BrowserThread::PROCESS_LAUNCHER: |
| 531 | thread_to_stop = &process_launcher_thread_; |
| 532 | break; |
| 533 | case BrowserThread::CACHE: |
| 534 | thread_to_stop = &cache_thread_; |
| 535 | break; |
| 536 | case BrowserThread::IO: |
| 537 | thread_to_stop = &io_thread_; |
| 538 | break; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 539 | case BrowserThread::UI: |
| 540 | case BrowserThread::ID_COUNT: |
| 541 | default: |
| 542 | NOTREACHED(); |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
| 547 | |
[email protected] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 548 | if (id == BrowserThread::WEBKIT_DEPRECATED) { |
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 549 | webkit_thread_.reset(); |
| 550 | } else if (thread_to_stop) { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 551 | thread_to_stop->reset(); |
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 552 | } else { |
| 553 | NOTREACHED(); |
| 554 | } |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 555 | } |
| 556 | |
[email protected] | 3189013e | 2012-01-19 04:11:57 | [diff] [blame] | 557 | // Close the blocking I/O pool after the other threads. Other threads such |
| 558 | // as the I/O thread may need to schedule work like closing files or flushing |
| 559 | // data during shutdown, so the blocking pool needs to be available. There |
| 560 | // may also be slow operations pending that will blcok shutdown, so closing |
| 561 | // it here (which will block until required operations are complete) gives |
| 562 | // more head start for those operations to finish. |
| 563 | BrowserThreadImpl::ShutdownThreadPool(); |
| 564 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 565 | if (parts_.get()) |
| 566 | parts_->PostDestroyThreads(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | void BrowserMainLoop::InitializeMainThread() { |
| 570 | const char* kThreadName = "CrBrowserMain"; |
| 571 | base::PlatformThread::SetName(kThreadName); |
[email protected] | de88c5e | 2012-04-10 23:35:23 | [diff] [blame] | 572 | if (main_message_loop_.get()) |
| 573 | main_message_loop_->set_thread_name(kThreadName); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 574 | |
| 575 | // Register the main thread by instantiating it, but don't call any methods. |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 576 | main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
| 577 | MessageLoop::current())); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 578 | } |
| 579 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 580 | |
| 581 | void BrowserMainLoop::BrowserThreadsStarted() { |
| 582 | // RDH needs the IO thread to be created. |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 583 | resource_dispatcher_host_.reset(new ResourceDispatcherHostImpl()); |
[email protected] | b14b873b | 2012-05-03 03:56:09 | [diff] [blame] | 584 | |
[email protected] | 28df14d | 2012-05-16 14:51:22 | [diff] [blame] | 585 | #if defined(ENABLE_INPUT_SPEECH) |
| 586 | speech_recognition_manager_.reset(new speech::SpeechRecognitionManagerImpl()); |
| 587 | #endif |
| 588 | |
[email protected] | b13afb7 | 2012-05-30 07:38:17 | [diff] [blame] | 589 | // When running the GPU thread in-process, avoid optimistically starting it |
| 590 | // since creating the GPU thread races against creation of the one-and-only |
| 591 | // ChildProcess instance which is created by the renderer thread. |
| 592 | if (!parsed_command_line_.HasSwitch(switches::kDisableGpuProcessPrelaunch) && |
| 593 | !parsed_command_line_.HasSwitch(switches::kSingleProcess) && |
| 594 | !parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { |
| 595 | TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process"); |
| 596 | BrowserThread::PostTask( |
| 597 | BrowserThread::IO, FROM_HERE, base::Bind( |
| 598 | base::IgnoreResult(&GpuProcessHost::Get), |
| 599 | GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| 600 | content::CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); |
| 601 | } |
| 602 | |
[email protected] | b14b873b | 2012-05-03 03:56:09 | [diff] [blame] | 603 | // Start the GpuDataManager before we set up the MessageLoops because |
| 604 | // otherwise we'll trigger the assertion about doing IO on the UI thread. |
| 605 | content::GpuDataManager::GetInstance(); |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 606 | } |
| 607 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 608 | void BrowserMainLoop::InitializeToolkit() { |
| 609 | // TODO(evan): this function is rather subtle, due to the variety |
| 610 | // of intersecting ifdefs we have. To keep it easy to follow, there |
| 611 | // are no #else branches on any #ifs. |
| 612 | // TODO(stevenjb): Move platform specific code into platform specific Parts |
| 613 | // (Need to add InitializeToolkit stage to BrowserParts). |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 614 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 615 | // Glib type system initialization. Needed at least for gconf, |
| 616 | // used in net/proxy/proxy_config_service_linux.cc. Most likely |
| 617 | // this is superfluous as gtk_init() ought to do this. It's |
| 618 | // definitely harmless, so retained as a reminder of this |
| 619 | // requirement for gconf. |
| 620 | g_type_init(); |
| 621 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 622 | #if !defined(USE_AURA) |
[email protected] | 38d0b2d4 | 2012-01-18 03:37:34 | [diff] [blame] | 623 | gfx::GtkInitFromCommandLine(parsed_command_line_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 624 | #endif |
| 625 | |
| 626 | SetUpGLibLogHandler(); |
| 627 | #endif |
| 628 | |
| 629 | #if defined(TOOLKIT_GTK) |
| 630 | // It is important for this to happen before the first run dialog, as it |
| 631 | // styles the dialog as well. |
| 632 | gfx::InitRCStyles(); |
| 633 | #endif |
| 634 | |
| 635 | #if defined(OS_WIN) |
| 636 | // Init common control sex. |
| 637 | INITCOMMONCONTROLSEX config; |
| 638 | config.dwSize = sizeof(config); |
| 639 | config.dwICC = ICC_WIN95_CLASSES; |
| 640 | if (!InitCommonControlsEx(&config)) |
| 641 | LOG_GETLASTERROR(FATAL); |
| 642 | #endif |
| 643 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 644 | if (parts_.get()) |
| 645 | parts_->ToolkitInitialized(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | void BrowserMainLoop::MainMessageLoopRun() { |
[email protected] | 716476c | 2011-12-29 00:07:03 | [diff] [blame] | 649 | if (parameters_.ui_task) |
[email protected] | 71cb8aa | 2011-12-29 19:14:00 | [diff] [blame] | 650 | MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 651 | |
| 652 | #if defined(OS_MACOSX) |
| 653 | MessageLoopForUI::current()->Run(); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 654 | #elif defined(OS_ANDROID) |
| 655 | // Android's main message loop is the Java message loop. |
| 656 | NOTREACHED(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 657 | #else |
| 658 | MessageLoopForUI::current()->RunWithDispatcher(NULL); |
| 659 | #endif |
| 660 | } |
| 661 | |
| 662 | } // namespace content |