OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.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/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/pending_task.h" | 14 #include "base/pending_task.h" |
15 #include "base/power_monitor/power_monitor.h" | 15 #include "base/power_monitor/power_monitor.h" |
16 #include "base/process/process_metrics.h" | 16 #include "base/process/process_metrics.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/system_monitor/system_monitor.h" | 19 #include "base/system_monitor/system_monitor.h" |
20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
21 #include "base/timer/hi_res_timer_manager.h" | 21 #include "base/timer/hi_res_timer_manager.h" |
22 #include "content/browser/browser_startup_configuration.h" | |
22 #include "content/browser/browser_thread_impl.h" | 23 #include "content/browser/browser_thread_impl.h" |
23 #include "content/browser/device_orientation/device_motion_service.h" | 24 #include "content/browser/device_orientation/device_motion_service.h" |
24 #include "content/browser/download/save_file_manager.h" | 25 #include "content/browser/download/save_file_manager.h" |
25 #include "content/browser/gamepad/gamepad_service.h" | 26 #include "content/browser/gamepad/gamepad_service.h" |
26 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 27 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
27 #include "content/browser/gpu/gpu_data_manager_impl.h" | 28 #include "content/browser/gpu/gpu_data_manager_impl.h" |
28 #include "content/browser/gpu/gpu_process_host.h" | 29 #include "content/browser/gpu/gpu_process_host.h" |
29 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 30 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
30 #include "content/browser/histogram_synchronizer.h" | 31 #include "content/browser/histogram_synchronizer.h" |
31 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 32 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
32 #include "content/browser/net/browser_online_state_observer.h" | 33 #include "content/browser/net/browser_online_state_observer.h" |
33 #include "content/browser/plugin_service_impl.h" | 34 #include "content/browser/plugin_service_impl.h" |
34 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" | 35 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" |
35 #include "content/browser/renderer_host/media/media_stream_manager.h" | 36 #include "content/browser/renderer_host/media/media_stream_manager.h" |
36 #include "content/browser/speech/speech_recognition_manager_impl.h" | 37 #include "content/browser/speech/speech_recognition_manager_impl.h" |
38 #include "content/browser/startup_task_runner.h" | |
37 #include "content/browser/tracing/trace_controller_impl.h" | 39 #include "content/browser/tracing/trace_controller_impl.h" |
38 #include "content/browser/webui/content_web_ui_controller_factory.h" | 40 #include "content/browser/webui/content_web_ui_controller_factory.h" |
39 #include "content/browser/webui/url_data_manager.h" | 41 #include "content/browser/webui/url_data_manager.h" |
40 #include "content/public/browser/browser_main_parts.h" | 42 #include "content/public/browser/browser_main_parts.h" |
41 #include "content/public/browser/browser_shutdown.h" | 43 #include "content/public/browser/browser_shutdown.h" |
42 #include "content/public/browser/compositor_util.h" | 44 #include "content/public/browser/compositor_util.h" |
43 #include "content/public/browser/content_browser_client.h" | 45 #include "content/public/browser/content_browser_client.h" |
44 #include "content/public/browser/render_process_host.h" | 46 #include "content/public/browser/render_process_host.h" |
45 #include "content/public/common/content_switches.h" | 47 #include "content/public/common/content_switches.h" |
46 #include "content/public/common/main_function_params.h" | 48 #include "content/public/common/main_function_params.h" |
47 #include "content/public/common/result_codes.h" | 49 #include "content/public/common/result_codes.h" |
50 #include "content/browser/startup_task_runner.h" | |
48 #include "crypto/nss_util.h" | 51 #include "crypto/nss_util.h" |
49 #include "media/audio/audio_manager.h" | 52 #include "media/audio/audio_manager.h" |
50 #include "media/base/media.h" | 53 #include "media/base/media.h" |
51 #include "media/midi/midi_manager.h" | 54 #include "media/midi/midi_manager.h" |
52 #include "net/base/network_change_notifier.h" | 55 #include "net/base/network_change_notifier.h" |
53 #include "net/socket/client_socket_factory.h" | 56 #include "net/socket/client_socket_factory.h" |
54 #include "net/ssl/ssl_config_service.h" | 57 #include "net/ssl/ssl_config_service.h" |
55 #include "ui/base/clipboard/clipboard.h" | 58 #include "ui/base/clipboard/clipboard.h" |
56 | 59 |
57 #if defined(USE_AURA) | 60 #if defined(USE_AURA) |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 479 |
477 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 480 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
478 trace_memory_controller_.reset(new base::debug::TraceMemoryController( | 481 trace_memory_controller_.reset(new base::debug::TraceMemoryController( |
479 base::MessageLoop::current()->message_loop_proxy(), | 482 base::MessageLoop::current()->message_loop_proxy(), |
480 ::HeapProfilerWithPseudoStackStart, | 483 ::HeapProfilerWithPseudoStackStart, |
481 ::HeapProfilerStop, | 484 ::HeapProfilerStop, |
482 ::GetHeapProfile)); | 485 ::GetHeapProfile)); |
483 #endif | 486 #endif |
484 } | 487 } |
485 | 488 |
486 void BrowserMainLoop::CreateThreads() { | 489 int BrowserMainLoop::PreCreateThreads() { |
487 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads") | |
488 | 490 |
489 if (parts_) { | 491 if (parts_) { |
490 TRACE_EVENT0("startup", | 492 TRACE_EVENT0("startup", |
491 "BrowserMainLoop::CreateThreads:PreCreateThreads"); | 493 "BrowserMainLoop::CreateThreads:PreCreateThreads"); |
492 result_code_ = parts_->PreCreateThreads(); | 494 result_code_ = parts_->PreCreateThreads(); |
493 } | 495 } |
494 | 496 |
495 #if defined(ENABLE_PLUGINS) | 497 #if defined(ENABLE_PLUGINS) |
496 // Prior to any processing happening on the io thread, we create the | 498 // Prior to any processing happening on the io thread, we create the |
497 // plugin service as it is predominantly used from the io thread, | 499 // plugin service as it is predominantly used from the io thread, |
498 // but must be created on the main thread. The service ctor is | 500 // but must be created on the main thread. The service ctor is |
499 // inexpensive and does not invoke the io_thread() accessor. | 501 // inexpensive and does not invoke the io_thread() accessor. |
500 { | 502 { |
501 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads:PluginService") | 503 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads:PluginService") |
502 PluginService::GetInstance()->Init(); | 504 PluginService::GetInstance()->Init(); |
503 } | 505 } |
504 #endif | 506 #endif |
505 | 507 |
506 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) | 508 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) |
507 // Single-process is an unsupported and not fully tested mode, so | 509 // Single-process is an unsupported and not fully tested mode, so |
508 // don't enable it for official Chrome builds (except on Android). | 510 // don't enable it for official Chrome builds (except on Android). |
509 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) | 511 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) |
510 RenderProcessHost::SetRunRendererInProcess(true); | 512 RenderProcessHost::SetRunRendererInProcess(true); |
511 #endif | 513 #endif |
514 return result_code_; | |
515 } | |
512 | 516 |
513 if (result_code_ > 0) | 517 void BrowserMainLoop::CreateStartupTasks() { |
514 return; | 518 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks") |
519 | |
520 scoped_refptr<StartupTaskRunner> task_runner = | |
Yaron
2013/07/30 00:06:24
Again, can't this be owned by BrowserMainRunnerImp
aberent
2013/07/30 15:01:54
I assume you are suggesting making this a class me
Yaron
2013/07/30 18:53:22
Err, you're right that I should've said BrowserMai
| |
521 new StartupTaskRunner(BrowserMayStartAsynchronously(), | |
522 BrowserStartupComplete, | |
523 base::MessageLoop::current()->message_loop_proxy()); | |
524 | |
525 StartupTask pre_create_threads = | |
526 base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); | |
527 task_runner->AddTask(pre_create_threads); | |
528 | |
529 StartupTask create_threads = | |
530 base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); | |
531 task_runner->AddTask(create_threads); | |
532 | |
533 StartupTask browser_thread_started = base::Bind( | |
534 &BrowserMainLoop::BrowserThreadsStarted, base::Unretained(this)); | |
535 task_runner->AddTask(browser_thread_started); | |
536 | |
537 StartupTask pre_main_message_loop_run = base::Bind( | |
538 &BrowserMainLoop::PreMainMessageLoopRun, base::Unretained(this)); | |
539 task_runner->AddTask(pre_main_message_loop_run); | |
540 | |
541 task_runner->StartRunningTasks(); | |
542 } | |
543 | |
544 int BrowserMainLoop::CreateThreads() { | |
545 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads"); | |
515 | 546 |
516 base::Thread::Options default_options; | 547 base::Thread::Options default_options; |
517 base::Thread::Options io_message_loop_options; | 548 base::Thread::Options io_message_loop_options; |
518 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 549 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
519 base::Thread::Options ui_message_loop_options; | 550 base::Thread::Options ui_message_loop_options; |
520 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 551 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
521 | 552 |
522 // Start threads in the order they occur in the BrowserThread::ID | 553 // Start threads in the order they occur in the BrowserThread::ID |
523 // enumeration, except for BrowserThread::UI which is the main | 554 // enumeration, except for BrowserThread::UI which is the main |
524 // thread. | 555 // thread. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 if (thread_to_start) { | 620 if (thread_to_start) { |
590 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 621 (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
591 (*thread_to_start)->StartWithOptions(*options); | 622 (*thread_to_start)->StartWithOptions(*options); |
592 } else { | 623 } else { |
593 NOTREACHED(); | 624 NOTREACHED(); |
594 } | 625 } |
595 | 626 |
596 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); | 627 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); |
597 | 628 |
598 } | 629 } |
630 return result_code_; | |
631 } | |
599 | 632 |
600 #if !defined(OS_IOS) | 633 int BrowserMainLoop::PreMainMessageLoopRun() { |
601 indexed_db_thread_.reset(new base::Thread("IndexedDB")); | |
602 indexed_db_thread_->Start(); | |
603 #endif | |
604 | |
605 BrowserThreadsStarted(); | |
606 | |
607 if (parts_) { | 634 if (parts_) { |
608 TRACE_EVENT0("startup", | 635 TRACE_EVENT0("startup", |
609 "BrowserMainLoop::CreateThreads:PreMainMessageLoopRun"); | 636 "BrowserMainLoop::CreateThreads:PreMainMessageLoopRun"); |
610 parts_->PreMainMessageLoopRun(); | 637 parts_->PreMainMessageLoopRun(); |
611 } | 638 } |
612 | 639 |
613 // If the UI thread blocks, the whole UI is unresponsive. | 640 // If the UI thread blocks, the whole UI is unresponsive. |
614 // Do not allow disk IO from the UI thread. | 641 // Do not allow disk IO from the UI thread. |
615 base::ThreadRestrictions::SetIOAllowed(false); | 642 base::ThreadRestrictions::SetIOAllowed(false); |
616 base::ThreadRestrictions::DisallowWaiting(); | 643 base::ThreadRestrictions::DisallowWaiting(); |
644 return result_code_; | |
617 } | 645 } |
618 | 646 |
619 void BrowserMainLoop::RunMainMessageLoopParts() { | 647 void BrowserMainLoop::RunMainMessageLoopParts() { |
620 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 648 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
621 | 649 |
622 bool ran_main_loop = false; | 650 bool ran_main_loop = false; |
623 if (parts_) | 651 if (parts_) |
624 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); | 652 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); |
625 | 653 |
626 if (!ran_main_loop) | 654 if (!ran_main_loop) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 const char* kThreadName = "CrBrowserMain"; | 786 const char* kThreadName = "CrBrowserMain"; |
759 base::PlatformThread::SetName(kThreadName); | 787 base::PlatformThread::SetName(kThreadName); |
760 if (main_message_loop_) | 788 if (main_message_loop_) |
761 main_message_loop_->set_thread_name(kThreadName); | 789 main_message_loop_->set_thread_name(kThreadName); |
762 | 790 |
763 // Register the main thread by instantiating it, but don't call any methods. | 791 // Register the main thread by instantiating it, but don't call any methods. |
764 main_thread_.reset( | 792 main_thread_.reset( |
765 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); | 793 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); |
766 } | 794 } |
767 | 795 |
768 void BrowserMainLoop::BrowserThreadsStarted() { | 796 int BrowserMainLoop::BrowserThreadsStarted() { |
769 TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted") | 797 TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted") |
798 | |
799 #if !defined(OS_IOS) | |
800 indexed_db_thread_.reset(new base::Thread("IndexedDB")); | |
801 indexed_db_thread_->Start(); | |
802 #endif | |
803 | |
770 #if defined(OS_ANDROID) | 804 #if defined(OS_ANDROID) |
771 // Up the priority of anything that touches with display tasks | 805 // Up the priority of anything that touches with display tasks |
772 // (this thread is UI thread, and io_thread_ is for IPCs). | 806 // (this thread is UI thread, and io_thread_ is for IPCs). |
773 io_thread_->SetPriority(base::kThreadPriority_Display); | 807 io_thread_->SetPriority(base::kThreadPriority_Display); |
774 base::PlatformThread::SetThreadPriority( | 808 base::PlatformThread::SetThreadPriority( |
775 base::PlatformThread::CurrentHandle(), | 809 base::PlatformThread::CurrentHandle(), |
776 base::kThreadPriority_Display); | 810 base::kThreadPriority_Display); |
777 #endif | 811 #endif |
778 | 812 |
779 #if !defined(OS_IOS) | 813 #if !defined(OS_IOS) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 !parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { | 871 !parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { |
838 TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process", | 872 TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process", |
839 TRACE_EVENT_SCOPE_THREAD); | 873 TRACE_EVENT_SCOPE_THREAD); |
840 BrowserThread::PostTask( | 874 BrowserThread::PostTask( |
841 BrowserThread::IO, FROM_HERE, base::Bind( | 875 BrowserThread::IO, FROM_HERE, base::Bind( |
842 base::IgnoreResult(&GpuProcessHost::Get), | 876 base::IgnoreResult(&GpuProcessHost::Get), |
843 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 877 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
844 CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); | 878 CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); |
845 } | 879 } |
846 #endif // !defined(OS_IOS) | 880 #endif // !defined(OS_IOS) |
881 return result_code_; | |
847 } | 882 } |
848 | 883 |
849 void BrowserMainLoop::InitializeToolkit() { | 884 void BrowserMainLoop::InitializeToolkit() { |
850 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit") | 885 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit") |
851 // TODO(evan): this function is rather subtle, due to the variety | 886 // TODO(evan): this function is rather subtle, due to the variety |
852 // of intersecting ifdefs we have. To keep it easy to follow, there | 887 // of intersecting ifdefs we have. To keep it easy to follow, there |
853 // are no #else branches on any #ifs. | 888 // are no #else branches on any #ifs. |
854 // TODO(stevenjb): Move platform specific code into platform specific Parts | 889 // TODO(stevenjb): Move platform specific code into platform specific Parts |
855 // (Need to add InitializeToolkit stage to BrowserParts). | 890 // (Need to add InitializeToolkit stage to BrowserParts). |
856 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 891 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 if (parameters_.ui_task) | 936 if (parameters_.ui_task) |
902 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 937 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
903 *parameters_.ui_task); | 938 *parameters_.ui_task); |
904 | 939 |
905 base::RunLoop run_loop; | 940 base::RunLoop run_loop; |
906 run_loop.Run(); | 941 run_loop.Run(); |
907 #endif | 942 #endif |
908 } | 943 } |
909 | 944 |
910 } // namespace content | 945 } // namespace content |
OLD | NEW |