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