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