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" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/system_monitor/system_monitor.h" | 13 #include "base/system_monitor/system_monitor.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 15 #include "base/tracked_objects.h" |
15 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
16 #include "content/browser/content_browser_client.h" | 17 #include "content/browser/content_browser_client.h" |
17 #include "content/common/hi_res_timer_manager.h" | 18 #include "content/common/hi_res_timer_manager.h" |
18 #include "content/common/main_function_params.h" | 19 #include "content/common/main_function_params.h" |
19 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
20 #include "content/common/result_codes.h" | 21 #include "content/common/result_codes.h" |
21 #include "content/common/sandbox_policy.h" | 22 #include "content/common/sandbox_policy.h" |
22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
23 #include "crypto/nss_util.h" | 24 #include "crypto/nss_util.h" |
24 #include "net/base/network_change_notifier.h" | 25 #include "net/base/network_change_notifier.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // 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 |
235 // has already been initialized. | 236 // has already been initialized. |
236 if (!parameters().ui_task) { | 237 if (!parameters().ui_task) { |
237 // Override the configured locale with the user's preferred UI language. | 238 // Override the configured locale with the user's preferred UI language. |
238 l10n_util::OverrideLocaleWithUILanguageList(); | 239 l10n_util::OverrideLocaleWithUILanguageList(); |
239 } | 240 } |
240 #endif | 241 #endif |
241 | 242 |
242 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); | 243 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); |
243 | 244 |
244 // TODO(viettrungluu): should these really go before setting the thread name? | 245 InitializeMainThread(); |
| 246 |
245 system_monitor_.reset(new base::SystemMonitor); | 247 system_monitor_.reset(new base::SystemMonitor); |
246 hi_res_timer_manager_.reset(new HighResolutionTimerManager); | 248 hi_res_timer_manager_.reset(new HighResolutionTimerManager); |
247 | 249 |
248 InitializeMainThread(); | |
249 | |
250 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 250 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
251 | 251 |
252 PostMainMessageLoopStart(); | 252 PostMainMessageLoopStart(); |
253 } | 253 } |
254 | 254 |
255 static bool g_exited_main_message_loop = false; | 255 static bool g_exited_main_message_loop = false; |
256 | 256 |
257 void BrowserMainParts::RunMainMessageLoopParts() { | 257 void BrowserMainParts::RunMainMessageLoopParts() { |
258 PreMainMessageLoopRun(); | 258 PreMainMessageLoopRun(); |
259 | 259 |
260 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 260 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
261 // If the UI thread blocks, the whole UI is unresponsive. | 261 // If the UI thread blocks, the whole UI is unresponsive. |
262 // Do not allow disk IO from the UI thread. | 262 // Do not allow disk IO from the UI thread. |
263 base::ThreadRestrictions::SetIOAllowed(false); | 263 base::ThreadRestrictions::SetIOAllowed(false); |
264 MainMessageLoopRun(); | 264 MainMessageLoopRun(); |
265 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 265 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
266 | 266 |
267 g_exited_main_message_loop = true; | 267 g_exited_main_message_loop = true; |
268 | 268 |
269 PostMainMessageLoopRun(); | 269 PostMainMessageLoopRun(); |
270 } | 270 } |
271 | 271 |
272 void BrowserMainParts::InitializeMainThread() { | 272 void BrowserMainParts::InitializeMainThread() { |
273 const char* kThreadName = "CrBrowserMain"; | 273 const char* kThreadName = "CrBrowserMain"; |
274 base::PlatformThread::SetName(kThreadName); | 274 base::PlatformThread::SetName(kThreadName); |
275 main_message_loop().set_thread_name(kThreadName); | 275 main_message_loop().set_thread_name(kThreadName); |
276 | 276 |
| 277 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 278 tracked_objects::ThreadData::InitializeThreadContext(kThreadName); |
| 279 #endif // TRACK_ALL_TASK_OBJECTS |
| 280 |
277 // Register the main thread by instantiating it, but don't call any methods. | 281 // Register the main thread by instantiating it, but don't call any methods. |
278 main_thread_.reset(new BrowserThread(BrowserThread::UI, | 282 main_thread_.reset(new BrowserThread(BrowserThread::UI, |
279 MessageLoop::current())); | 283 MessageLoop::current())); |
280 } | 284 } |
281 | 285 |
282 void BrowserMainParts::InitializeToolkit() { | 286 void BrowserMainParts::InitializeToolkit() { |
283 // TODO(evan): this function is rather subtle, due to the variety | 287 // TODO(evan): this function is rather subtle, due to the variety |
284 // of intersecting ifdefs we have. To keep it easy to follow, there | 288 // of intersecting ifdefs we have. To keep it easy to follow, there |
285 // are no #else branches on any #ifs. | 289 // are no #else branches on any #ifs. |
286 | 290 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 base::win::ScopedCOMInitializer com_initializer; | 432 base::win::ScopedCOMInitializer com_initializer; |
429 #endif // OS_WIN | 433 #endif // OS_WIN |
430 | 434 |
431 base::StatisticsRecorder statistics; | 435 base::StatisticsRecorder statistics; |
432 | 436 |
433 parts->RunMainMessageLoopParts(); | 437 parts->RunMainMessageLoopParts(); |
434 | 438 |
435 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); | 439 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); |
436 return parts->result_code(); | 440 return parts->result_code(); |
437 } | 441 } |
OLD | NEW |