| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/browser_main.h" | 5 #include "content/browser/browser_main.h" |
| 6 | 6 |
| 7 #include "base/allocator/allocator_shim.h" | 7 #include "base/allocator/allocator_shim.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 GLibLogHandler, | 160 GLibLogHandler, |
| 161 NULL); | 161 NULL); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 #endif | 164 #endif |
| 165 | 165 |
| 166 } // namespace | 166 } // namespace |
| 167 | 167 |
| 168 namespace content { | 168 namespace content { |
| 169 | 169 |
| 170 // BrowserParts |
| 171 |
| 172 void BrowserParts::PreEarlyInitialization() { |
| 173 } |
| 174 |
| 175 void BrowserParts::PostEarlyInitialization() { |
| 176 } |
| 177 |
| 178 void BrowserParts::PreMainMessageLoopStart() { |
| 179 } |
| 180 |
| 181 void BrowserParts::PostMainMessageLoopStart() { |
| 182 } |
| 183 |
| 184 void BrowserParts::PreMainMessageLoopRun() { |
| 185 } |
| 186 |
| 187 void BrowserParts::PostMainMessageLoopRun() { |
| 188 } |
| 189 |
| 190 // BrowserMainParts |
| 191 |
| 170 BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) | 192 BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) |
| 171 : parameters_(parameters), | 193 : parameters_(parameters), |
| 172 parsed_command_line_(parameters.command_line_), | 194 parsed_command_line_(parameters.command_line_), |
| 173 result_code_(content::RESULT_CODE_NORMAL_EXIT) { | 195 result_code_(content::RESULT_CODE_NORMAL_EXIT) { |
| 174 #if defined(OS_WIN) | 196 #if defined(OS_WIN) |
| 175 OleInitialize(NULL); | 197 OleInitialize(NULL); |
| 176 #endif | 198 #endif |
| 177 } | 199 } |
| 178 | 200 |
| 179 BrowserMainParts::~BrowserMainParts() { | 201 BrowserMainParts::~BrowserMainParts() { |
| 202 // Destroy added parts in reverse order. |
| 203 for (PartsList::reverse_iterator riter = added_parts_.rbegin(); |
| 204 riter != added_parts_.rend(); ++riter) { |
| 205 delete *riter; |
| 206 } |
| 207 added_parts_.clear(); |
| 208 |
| 180 #if defined(OS_WIN) | 209 #if defined(OS_WIN) |
| 181 OleUninitialize(); | 210 OleUninitialize(); |
| 182 #endif | 211 #endif |
| 183 } | 212 } |
| 184 | 213 |
| 214 void BrowserMainParts::AddParts(BrowserParts* parts) { |
| 215 added_parts_.push_back(parts); |
| 216 } |
| 217 |
| 185 void BrowserMainParts::EarlyInitialization() { | 218 void BrowserMainParts::EarlyInitialization() { |
| 186 PreEarlyInitialization(); | 219 PreEarlyInitialization(); |
| 220 for (PartsList::iterator iter = added_parts_.begin(); |
| 221 iter != added_parts_.end(); ++iter) { |
| 222 (*iter)->PreEarlyInitialization(); |
| 223 } |
| 224 |
| 225 // Start watching for jank during shutdown. It gets disarmed when |
| 187 | 226 |
| 188 #if defined(OS_WIN) | 227 #if defined(OS_WIN) |
| 189 net::EnsureWinsockInit(); | 228 net::EnsureWinsockInit(); |
| 190 #endif | 229 #endif |
| 191 | 230 |
| 192 // Use NSS for SSL by default. | 231 // Use NSS for SSL by default. |
| 193 // The default client socket factory uses NSS for SSL by default on | 232 // The default client socket factory uses NSS for SSL by default on |
| 194 // Windows and Mac. | 233 // Windows and Mac. |
| 195 #if defined(OS_WIN) || defined(OS_MACOSX) | 234 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 196 if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { | 235 if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 219 switches::kEnableDNSCertProvenanceChecking)) { | 258 switches::kEnableDNSCertProvenanceChecking)) { |
| 220 net::SSLConfigService::EnableDNSCertProvenanceChecking(); | 259 net::SSLConfigService::EnableDNSCertProvenanceChecking(); |
| 221 } | 260 } |
| 222 | 261 |
| 223 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't | 262 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't |
| 224 // seem dependent on SSL initialization(). | 263 // seem dependent on SSL initialization(). |
| 225 if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) | 264 if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) |
| 226 net::set_tcp_fastopen_enabled(true); | 265 net::set_tcp_fastopen_enabled(true); |
| 227 | 266 |
| 228 PostEarlyInitialization(); | 267 PostEarlyInitialization(); |
| 268 for (PartsList::iterator iter = added_parts_.begin(); |
| 269 iter != added_parts_.end(); ++iter) { |
| 270 (*iter)->PostEarlyInitialization(); |
| 271 } |
| 229 } | 272 } |
| 230 | 273 |
| 231 void BrowserMainParts::MainMessageLoopStart() { | 274 void BrowserMainParts::MainMessageLoopStart() { |
| 232 PreMainMessageLoopStart(); | 275 PreMainMessageLoopStart(); |
| 276 for (PartsList::iterator iter = added_parts_.begin(); |
| 277 iter != added_parts_.end(); ++iter) { |
| 278 (*iter)->PreMainMessageLoopStart(); |
| 279 } |
| 233 | 280 |
| 234 #if defined(OS_WIN) | 281 #if defined(OS_WIN) |
| 235 // If we're running tests (ui_task is non-null), then the ResourceBundle | 282 // If we're running tests (ui_task is non-null), then the ResourceBundle |
| 236 // has already been initialized. | 283 // has already been initialized. |
| 237 if (!parameters().ui_task) { | 284 if (!parameters().ui_task) { |
| 238 // Override the configured locale with the user's preferred UI language. | 285 // Override the configured locale with the user's preferred UI language. |
| 239 l10n_util::OverrideLocaleWithUILanguageList(); | 286 l10n_util::OverrideLocaleWithUILanguageList(); |
| 240 } | 287 } |
| 241 #endif | 288 #endif |
| 242 | 289 |
| 243 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); | 290 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); |
| 244 | 291 |
| 245 InitializeMainThread(); | 292 InitializeMainThread(); |
| 246 | 293 |
| 247 system_monitor_.reset(new base::SystemMonitor); | 294 system_monitor_.reset(new base::SystemMonitor); |
| 248 hi_res_timer_manager_.reset(new HighResolutionTimerManager); | 295 hi_res_timer_manager_.reset(new HighResolutionTimerManager); |
| 249 | 296 |
| 250 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 297 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 251 | 298 |
| 252 PostMainMessageLoopStart(); | 299 PostMainMessageLoopStart(); |
| 300 for (PartsList::iterator iter = added_parts_.begin(); |
| 301 iter != added_parts_.end(); ++iter) { |
| 302 (*iter)->PostMainMessageLoopStart(); |
| 303 } |
| 253 } | 304 } |
| 254 | 305 |
| 255 static bool g_exited_main_message_loop = false; | 306 static bool g_exited_main_message_loop = false; |
| 256 | 307 |
| 257 void BrowserMainParts::RunMainMessageLoopParts() { | 308 void BrowserMainParts::RunMainMessageLoopParts() { |
| 258 PreMainMessageLoopRun(); | 309 PreMainMessageLoopRun(); |
| 310 for (PartsList::iterator iter = added_parts_.begin(); |
| 311 iter != added_parts_.end(); ++iter) { |
| 312 (*iter)->PreMainMessageLoopRun(); |
| 313 } |
| 259 | 314 |
| 260 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 315 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
| 261 // If the UI thread blocks, the whole UI is unresponsive. | 316 // If the UI thread blocks, the whole UI is unresponsive. |
| 262 // Do not allow disk IO from the UI thread. | 317 // Do not allow disk IO from the UI thread. |
| 263 base::ThreadRestrictions::SetIOAllowed(false); | 318 base::ThreadRestrictions::SetIOAllowed(false); |
| 264 MainMessageLoopRun(); | 319 MainMessageLoopRun(); |
| 265 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 320 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
| 266 | 321 |
| 267 g_exited_main_message_loop = true; | 322 g_exited_main_message_loop = true; |
| 268 | 323 |
| 269 PostMainMessageLoopRun(); | 324 PostMainMessageLoopRun(); |
| 325 for (PartsList::iterator iter = added_parts_.begin(); |
| 326 iter != added_parts_.end(); ++iter) { |
| 327 (*iter)->PostMainMessageLoopRun(); |
| 328 } |
| 270 } | 329 } |
| 271 | 330 |
| 272 void BrowserMainParts::InitializeMainThread() { | 331 void BrowserMainParts::InitializeMainThread() { |
| 273 const char* kThreadName = "CrBrowserMain"; | 332 const char* kThreadName = "CrBrowserMain"; |
| 274 base::PlatformThread::SetName(kThreadName); | 333 base::PlatformThread::SetName(kThreadName); |
| 275 main_message_loop().set_thread_name(kThreadName); | 334 main_message_loop().set_thread_name(kThreadName); |
| 276 | 335 |
| 277 #if defined(TRACK_ALL_TASK_OBJECTS) | 336 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 278 tracked_objects::ThreadData::InitializeThreadContext(kThreadName); | 337 tracked_objects::ThreadData::InitializeThreadContext(kThreadName); |
| 279 #endif // TRACK_ALL_TASK_OBJECTS | 338 #endif // TRACK_ALL_TASK_OBJECTS |
| 280 | 339 |
| 281 // Register the main thread by instantiating it, but don't call any methods. | 340 // Register the main thread by instantiating it, but don't call any methods. |
| 282 main_thread_.reset(new BrowserThread(BrowserThread::UI, | 341 main_thread_.reset(new BrowserThread(BrowserThread::UI, |
| 283 MessageLoop::current())); | 342 MessageLoop::current())); |
| 284 } | 343 } |
| 285 | 344 |
| 286 void BrowserMainParts::InitializeToolkit() { | 345 void BrowserMainParts::InitializeToolkit() { |
| 287 // TODO(evan): this function is rather subtle, due to the variety | 346 // TODO(evan): this function is rather subtle, due to the variety |
| 288 // of intersecting ifdefs we have. To keep it easy to follow, there | 347 // of intersecting ifdefs we have. To keep it easy to follow, there |
| 289 // are no #else branches on any #ifs. | 348 // are no #else branches on any #ifs. |
| 290 | 349 // TODO(stevenjb): Move platform specific code into platform specific Parts |
| 350 // (Need to add InitializeToolkit stage to BrowserParts). |
| 291 #if defined(OS_LINUX) | 351 #if defined(OS_LINUX) |
| 292 // We want to call g_thread_init(), but in some codepaths (tests) it | 352 // We want to call g_thread_init(), but in some codepaths (tests) it |
| 293 // is possible it has already been called. In older versions of | 353 // is possible it has already been called. In older versions of |
| 294 // GTK, it is an error to call g_thread_init twice; unfortunately, | 354 // GTK, it is an error to call g_thread_init twice; unfortunately, |
| 295 // the API to tell whether it has been called already was also only | 355 // the API to tell whether it has been called already was also only |
| 296 // added in a newer version of GTK! Thankfully, this non-intuitive | 356 // added in a newer version of GTK! Thankfully, this non-intuitive |
| 297 // check is actually equivalent and sufficient to work around the | 357 // check is actually equivalent and sufficient to work around the |
| 298 // error. | 358 // error. |
| 299 if (!g_thread_supported()) | 359 if (!g_thread_supported()) |
| 300 g_thread_init(NULL); | 360 g_thread_init(NULL); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 326 INITCOMMONCONTROLSEX config; | 386 INITCOMMONCONTROLSEX config; |
| 327 config.dwSize = sizeof(config); | 387 config.dwSize = sizeof(config); |
| 328 config.dwICC = ICC_WIN95_CLASSES; | 388 config.dwICC = ICC_WIN95_CLASSES; |
| 329 if (!InitCommonControlsEx(&config)) | 389 if (!InitCommonControlsEx(&config)) |
| 330 LOG_GETLASTERROR(FATAL); | 390 LOG_GETLASTERROR(FATAL); |
| 331 #endif | 391 #endif |
| 332 | 392 |
| 333 ToolkitInitialized(); | 393 ToolkitInitialized(); |
| 334 } | 394 } |
| 335 | 395 |
| 336 void BrowserMainParts::PreEarlyInitialization() { | 396 // BrowserMainParts implementation |
| 337 } | |
| 338 | |
| 339 void BrowserMainParts::PostEarlyInitialization() { | |
| 340 } | |
| 341 | |
| 342 void BrowserMainParts::PreMainMessageLoopStart() { | |
| 343 } | |
| 344 | |
| 345 void BrowserMainParts::PostMainMessageLoopStart() { | |
| 346 } | |
| 347 | |
| 348 void BrowserMainParts::PreMainMessageLoopRun() { | |
| 349 } | |
| 350 | 397 |
| 351 void BrowserMainParts::MainMessageLoopRun() { | 398 void BrowserMainParts::MainMessageLoopRun() { |
| 352 if (parameters().ui_task) | 399 if (parameters().ui_task) |
| 353 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters().ui_task); | 400 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters().ui_task); |
| 354 | 401 |
| 355 #if defined(OS_MACOSX) | 402 #if defined(OS_MACOSX) |
| 356 MessageLoopForUI::current()->Run(); | 403 MessageLoopForUI::current()->Run(); |
| 357 #else | 404 #else |
| 358 MessageLoopForUI::current()->Run(NULL); | 405 MessageLoopForUI::current()->Run(NULL); |
| 359 #endif | 406 #endif |
| 360 } | 407 } |
| 361 | 408 |
| 362 void BrowserMainParts::PostMainMessageLoopRun() { | |
| 363 } | |
| 364 | |
| 365 void BrowserMainParts::ToolkitInitialized() { | 409 void BrowserMainParts::ToolkitInitialized() { |
| 366 } | 410 } |
| 367 | 411 |
| 368 bool ExitedMainMessageLoop() { | 412 bool ExitedMainMessageLoop() { |
| 369 return g_exited_main_message_loop; | 413 return g_exited_main_message_loop; |
| 370 } | 414 } |
| 371 | 415 |
| 372 } // namespace content | 416 } // namespace content |
| 373 | 417 |
| 374 // Main routine for running as the Browser process. | 418 // Main routine for running as the Browser process. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 base::win::ScopedCOMInitializer com_initializer; | 476 base::win::ScopedCOMInitializer com_initializer; |
| 433 #endif // OS_WIN | 477 #endif // OS_WIN |
| 434 | 478 |
| 435 base::StatisticsRecorder statistics; | 479 base::StatisticsRecorder statistics; |
| 436 | 480 |
| 437 parts->RunMainMessageLoopParts(); | 481 parts->RunMainMessageLoopParts(); |
| 438 | 482 |
| 439 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); | 483 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); |
| 440 return parts->result_code(); | 484 return parts->result_code(); |
| 441 } | 485 } |
| OLD | NEW |