| 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_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) | 151 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) |
| 152 : parameters_(parameters), | 152 : parameters_(parameters), |
| 153 parsed_command_line_(parameters.command_line), | 153 parsed_command_line_(parameters.command_line), |
| 154 result_code_(content::RESULT_CODE_NORMAL_EXIT) { | 154 result_code_(content::RESULT_CODE_NORMAL_EXIT) { |
| 155 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
| 156 OleInitialize(NULL); | 156 OleInitialize(NULL); |
| 157 #endif | 157 #endif |
| 158 } | 158 } |
| 159 | 159 |
| 160 BrowserMainLoop::~BrowserMainLoop() { | 160 BrowserMainLoop::~BrowserMainLoop() { |
| 161 // Release and destroy |parts_| before destroying other members. | 161 // Destroy added parts in reverse order. |
| 162 parts_.reset(); | 162 for (int i = static_cast<int>(parts_list_.size())-1; i >= 0; --i) |
| 163 delete parts_list_[i]; |
| 164 parts_list_.clear(); |
| 163 | 165 |
| 164 #if defined(OS_WIN) | 166 #if defined(OS_WIN) |
| 165 OleUninitialize(); | 167 OleUninitialize(); |
| 166 #endif | 168 #endif |
| 167 } | 169 } |
| 168 | 170 |
| 169 void BrowserMainLoop::Init() { | 171 void BrowserMainLoop::Init() { |
| 170 parts_.reset( | 172 GetContentClient()->browser()->CreateBrowserMainParts( |
| 171 GetContentClient()->browser()->CreateBrowserMainParts(parameters_)); | 173 parameters_, &parts_list_); |
| 172 } | 174 } |
| 173 | 175 |
| 174 // BrowserMainLoop stages ================================================== | 176 // BrowserMainLoop stages ================================================== |
| 175 | 177 |
| 176 void BrowserMainLoop::EarlyInitialization() { | 178 void BrowserMainLoop::EarlyInitialization() { |
| 177 if (parts_.get()) | 179 for (size_t i = 0; i < parts_list_.size(); ++i) |
| 178 parts_->PreEarlyInitialization(); | 180 parts_list_[i]->PreEarlyInitialization(); |
| 179 | 181 |
| 180 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
| 181 net::EnsureWinsockInit(); | 183 net::EnsureWinsockInit(); |
| 182 #endif | 184 #endif |
| 183 | 185 |
| 184 #if !defined(USE_OPENSSL) | 186 #if !defined(USE_OPENSSL) |
| 185 // Use NSS for SSL by default. | 187 // Use NSS for SSL by default. |
| 186 // The default client socket factory uses NSS for SSL by default on | 188 // The default client socket factory uses NSS for SSL by default on |
| 187 // Windows and Mac. | 189 // Windows and Mac. |
| 188 bool init_nspr = false; | 190 bool init_nspr = false; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 214 if (parsed_command_line_.HasSwitch( | 216 if (parsed_command_line_.HasSwitch( |
| 215 switches::kEnableDNSCertProvenanceChecking)) { | 217 switches::kEnableDNSCertProvenanceChecking)) { |
| 216 net::SSLConfigService::EnableDNSCertProvenanceChecking(); | 218 net::SSLConfigService::EnableDNSCertProvenanceChecking(); |
| 217 } | 219 } |
| 218 | 220 |
| 219 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't | 221 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't |
| 220 // seem dependent on SSL initialization(). | 222 // seem dependent on SSL initialization(). |
| 221 if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) | 223 if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) |
| 222 net::set_tcp_fastopen_enabled(true); | 224 net::set_tcp_fastopen_enabled(true); |
| 223 | 225 |
| 224 if (parts_.get()) | 226 for (size_t i = 0; i < parts_list_.size(); ++i) |
| 225 parts_->PostEarlyInitialization(); | 227 parts_list_[i]->PostEarlyInitialization(); |
| 226 } | 228 } |
| 227 | 229 |
| 228 void BrowserMainLoop::MainMessageLoopStart() { | 230 void BrowserMainLoop::MainMessageLoopStart() { |
| 229 if (parts_.get()) | 231 for (size_t i = 0; i < parts_list_.size(); ++i) |
| 230 parts_->PreMainMessageLoopStart(); | 232 parts_list_[i]->PreMainMessageLoopStart(); |
| 231 | 233 |
| 232 #if defined(OS_WIN) | 234 #if defined(OS_WIN) |
| 233 // If we're running tests (ui_task is non-null), then the ResourceBundle | 235 // If we're running tests (ui_task is non-null), then the ResourceBundle |
| 234 // has already been initialized. | 236 // has already been initialized. |
| 235 if (!parameters_.ui_task) { | 237 if (!parameters_.ui_task) { |
| 236 // Override the configured locale with the user's preferred UI language. | 238 // Override the configured locale with the user's preferred UI language. |
| 237 l10n_util::OverrideLocaleWithUILanguageList(); | 239 l10n_util::OverrideLocaleWithUILanguageList(); |
| 238 } | 240 } |
| 239 #endif | 241 #endif |
| 240 | 242 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 251 | 253 |
| 252 system_monitor_.reset(new base::SystemMonitor); | 254 system_monitor_.reset(new base::SystemMonitor); |
| 253 hi_res_timer_manager_.reset(new HighResolutionTimerManager); | 255 hi_res_timer_manager_.reset(new HighResolutionTimerManager); |
| 254 | 256 |
| 255 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 257 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 256 | 258 |
| 257 #if defined(OS_WIN) | 259 #if defined(OS_WIN) |
| 258 system_message_window_.reset(new SystemMessageWindowWin); | 260 system_message_window_.reset(new SystemMessageWindowWin); |
| 259 #endif | 261 #endif |
| 260 | 262 |
| 261 if (parts_.get()) | 263 for (size_t i = 0; i < parts_list_.size(); ++i) |
| 262 parts_->PostMainMessageLoopStart(); | 264 parts_list_[i]->PostMainMessageLoopStart(); |
| 263 } | 265 } |
| 264 | 266 |
| 265 void BrowserMainLoop::RunMainMessageLoopParts( | 267 void BrowserMainLoop::RunMainMessageLoopParts( |
| 266 bool* completed_main_message_loop) { | 268 bool* completed_main_message_loop) { |
| 267 if (parts_.get()) | 269 for (size_t i = 0; i < parts_list_.size(); ++i) |
| 268 parts_->PreMainMessageLoopRun(); | 270 parts_list_[i]->PreMainMessageLoopRun(); |
| 269 | 271 |
| 270 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 272 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
| 271 // If the UI thread blocks, the whole UI is unresponsive. | 273 // If the UI thread blocks, the whole UI is unresponsive. |
| 272 // Do not allow disk IO from the UI thread. | 274 // Do not allow disk IO from the UI thread. |
| 273 base::ThreadRestrictions::SetIOAllowed(false); | 275 base::ThreadRestrictions::SetIOAllowed(false); |
| 274 | 276 |
| 277 // Iterate through each of the parts. If any of them ran the main |
| 278 // message loop then they should return |true|. Otherwise |
| 279 // BrowserMainLoop::MainMessageLoopRun loop will be run. |
| 275 bool ran_main_loop = false; | 280 bool ran_main_loop = false; |
| 276 if (parts_.get()) | 281 for (size_t i = 0; i < parts_list_.size(); ++i) { |
| 277 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); | 282 int result_code = result_code_; |
| 278 | 283 if (parts_list_[i]->MainMessageLoopRun(&result_code)) { |
| 284 ran_main_loop = true; |
| 285 result_code_ = result_code; |
| 286 } |
| 287 } |
| 279 if (!ran_main_loop) | 288 if (!ran_main_loop) |
| 280 MainMessageLoopRun(); | 289 MainMessageLoopRun(); |
| 281 | 290 |
| 282 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 291 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
| 283 | 292 |
| 284 if (completed_main_message_loop) | 293 if (completed_main_message_loop) |
| 285 *completed_main_message_loop = true; | 294 *completed_main_message_loop = true; |
| 286 | 295 |
| 287 if (parts_.get()) | 296 for (size_t i = 0; i < parts_list_.size(); ++i) |
| 288 parts_->PostMainMessageLoopRun(); | 297 parts_list_[i]->PostMainMessageLoopRun(); |
| 289 } | 298 } |
| 290 | 299 |
| 291 void BrowserMainLoop::InitializeMainThread() { | 300 void BrowserMainLoop::InitializeMainThread() { |
| 292 const char* kThreadName = "CrBrowserMain"; | 301 const char* kThreadName = "CrBrowserMain"; |
| 293 base::PlatformThread::SetName(kThreadName); | 302 base::PlatformThread::SetName(kThreadName); |
| 294 main_message_loop_->set_thread_name(kThreadName); | 303 main_message_loop_->set_thread_name(kThreadName); |
| 295 | 304 |
| 296 // Register the main thread by instantiating it, but don't call any methods. | 305 // Register the main thread by instantiating it, but don't call any methods. |
| 297 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, | 306 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
| 298 MessageLoop::current())); | 307 MessageLoop::current())); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 327 | 336 |
| 328 #if defined(OS_WIN) | 337 #if defined(OS_WIN) |
| 329 // Init common control sex. | 338 // Init common control sex. |
| 330 INITCOMMONCONTROLSEX config; | 339 INITCOMMONCONTROLSEX config; |
| 331 config.dwSize = sizeof(config); | 340 config.dwSize = sizeof(config); |
| 332 config.dwICC = ICC_WIN95_CLASSES; | 341 config.dwICC = ICC_WIN95_CLASSES; |
| 333 if (!InitCommonControlsEx(&config)) | 342 if (!InitCommonControlsEx(&config)) |
| 334 LOG_GETLASTERROR(FATAL); | 343 LOG_GETLASTERROR(FATAL); |
| 335 #endif | 344 #endif |
| 336 | 345 |
| 337 if (parts_.get()) | 346 for (size_t i = 0; i < parts_list_.size(); ++i) |
| 338 parts_->ToolkitInitialized(); | 347 parts_list_[i]->ToolkitInitialized(); |
| 339 } | 348 } |
| 340 | 349 |
| 341 void BrowserMainLoop::MainMessageLoopRun() { | 350 void BrowserMainLoop::MainMessageLoopRun() { |
| 342 if (parameters_.ui_task) | 351 if (parameters_.ui_task) |
| 343 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); | 352 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); |
| 344 | 353 |
| 345 #if defined(OS_MACOSX) | 354 #if defined(OS_MACOSX) |
| 346 MessageLoopForUI::current()->Run(); | 355 MessageLoopForUI::current()->Run(); |
| 347 #else | 356 #else |
| 348 MessageLoopForUI::current()->RunWithDispatcher(NULL); | 357 MessageLoopForUI::current()->RunWithDispatcher(NULL); |
| 349 #endif | 358 #endif |
| 350 } | 359 } |
| 351 | 360 |
| 352 } // namespace content | 361 } // namespace content |
| OLD | NEW |