| 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" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "content/browser/webui/content_web_ui_controller_factory.h" | 37 #include "content/browser/webui/content_web_ui_controller_factory.h" |
| 38 #include "content/browser/webui/url_data_manager.h" | 38 #include "content/browser/webui/url_data_manager.h" |
| 39 #include "content/public/browser/browser_main_parts.h" | 39 #include "content/public/browser/browser_main_parts.h" |
| 40 #include "content/public/browser/browser_shutdown.h" | 40 #include "content/public/browser/browser_shutdown.h" |
| 41 #include "content/public/browser/compositor_util.h" | 41 #include "content/public/browser/compositor_util.h" |
| 42 #include "content/public/browser/content_browser_client.h" | 42 #include "content/public/browser/content_browser_client.h" |
| 43 #include "content/public/browser/render_process_host.h" | 43 #include "content/public/browser/render_process_host.h" |
| 44 #include "content/public/common/content_switches.h" | 44 #include "content/public/common/content_switches.h" |
| 45 #include "content/public/common/main_function_params.h" | 45 #include "content/public/common/main_function_params.h" |
| 46 #include "content/public/common/result_codes.h" | 46 #include "content/public/common/result_codes.h" |
| 47 #include "content/public/common/startup_task_runner.h" |
| 47 #include "crypto/nss_util.h" | 48 #include "crypto/nss_util.h" |
| 48 #include "media/audio/audio_manager.h" | 49 #include "media/audio/audio_manager.h" |
| 49 #include "media/base/media.h" | 50 #include "media/base/media.h" |
| 50 #include "media/midi/midi_manager.h" | 51 #include "media/midi/midi_manager.h" |
| 51 #include "net/base/network_change_notifier.h" | 52 #include "net/base/network_change_notifier.h" |
| 52 #include "net/socket/client_socket_factory.h" | 53 #include "net/socket/client_socket_factory.h" |
| 53 #include "net/ssl/ssl_config_service.h" | 54 #include "net/ssl/ssl_config_service.h" |
| 54 #include "ui/base/clipboard/clipboard.h" | 55 #include "ui/base/clipboard/clipboard.h" |
| 55 | 56 |
| 56 #if defined(USE_AURA) | 57 #if defined(USE_AURA) |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 } | 465 } |
| 465 #endif | 466 #endif |
| 466 | 467 |
| 467 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { | 468 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { |
| 468 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:MemoryObserver") | 469 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:MemoryObserver") |
| 469 memory_observer_.reset(new MemoryObserver()); | 470 memory_observer_.reset(new MemoryObserver()); |
| 470 base::MessageLoop::current()->AddTaskObserver(memory_observer_.get()); | 471 base::MessageLoop::current()->AddTaskObserver(memory_observer_.get()); |
| 471 } | 472 } |
| 472 } | 473 } |
| 473 | 474 |
| 474 void BrowserMainLoop::CreateThreads() { | 475 |
| 475 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads") | 476 void BrowserMainLoop::PreCreateThreads() { |
| 476 | 477 |
| 477 if (parts_) { | 478 if (parts_) { |
| 478 TRACE_EVENT0("startup", | 479 TRACE_EVENT0("startup", |
| 479 "BrowserMainLoop::CreateThreads:PreCreateThreads"); | 480 "BrowserMainLoop::CreateThreads:PreCreateThreads"); |
| 480 result_code_ = parts_->PreCreateThreads(); | 481 result_code_ = parts_->PreCreateThreads(); |
| 481 } | 482 } |
| 482 | 483 |
| 483 #if defined(ENABLE_PLUGINS) | 484 #if defined(ENABLE_PLUGINS) |
| 484 // Prior to any processing happening on the io thread, we create the | 485 // Prior to any processing happening on the io thread, we create the |
| 485 // plugin service as it is predominantly used from the io thread, | 486 // plugin service as it is predominantly used from the io thread, |
| 486 // but must be created on the main thread. The service ctor is | 487 // but must be created on the main thread. The service ctor is |
| 487 // inexpensive and does not invoke the io_thread() accessor. | 488 // inexpensive and does not invoke the io_thread() accessor. |
| 488 { | 489 { |
| 489 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads:PluginService") | 490 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads:PluginService") |
| 490 PluginService::GetInstance()->Init(); | 491 PluginService::GetInstance()->Init(); |
| 491 } | 492 } |
| 492 #endif | 493 #endif |
| 493 | 494 |
| 494 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) | 495 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) |
| 495 // Single-process is an unsupported and not fully tested mode, so | 496 // Single-process is an unsupported and not fully tested mode, so |
| 496 // don't enable it for official Chrome builds (except on Android). | 497 // don't enable it for official Chrome builds (except on Android). |
| 497 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) | 498 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) |
| 498 RenderProcessHost::SetRunRendererInProcess(true); | 499 RenderProcessHost::SetRunRendererInProcess(true); |
| 499 #endif | 500 #endif |
| 501 } |
| 500 | 502 |
| 501 if (result_code_ > 0) | 503 void BrowserMainLoop::CreateStartupTasks( |
| 502 return; | 504 const scoped_refptr<StartupTaskRunner>& task_runner) { |
| 505 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks") |
| 506 |
| 507 task_runner->SetProxy(base::MessageLoop::current()->message_loop_proxy()); |
| 508 |
| 509 base::Closure pre_create_threads = |
| 510 base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); |
| 511 task_runner->AddTask(pre_create_threads); |
| 512 |
| 513 base::Closure create_threads = |
| 514 base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); |
| 515 task_runner->AddTask(create_threads); |
| 516 |
| 517 base::Closure browser_thread_started = base::Bind( |
| 518 &BrowserMainLoop::BrowserThreadsStarted, base::Unretained(this)); |
| 519 task_runner->AddTask(browser_thread_started); |
| 520 |
| 521 base::Closure pre_main_message_loop_run = base::Bind( |
| 522 &BrowserMainLoop::PreMainMessageLoopRun, base::Unretained(this)); |
| 523 task_runner->AddTask(pre_main_message_loop_run); |
| 524 |
| 525 task_runner->StartRunningTasks(); |
| 526 } |
| 527 |
| 528 void BrowserMainLoop::CreateThreads() { |
| 529 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads"); |
| 503 | 530 |
| 504 base::Thread::Options default_options; | 531 base::Thread::Options default_options; |
| 505 base::Thread::Options io_message_loop_options; | 532 base::Thread::Options io_message_loop_options; |
| 506 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 533 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 507 base::Thread::Options ui_message_loop_options; | 534 base::Thread::Options ui_message_loop_options; |
| 508 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 535 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
| 509 | 536 |
| 510 // Start threads in the order they occur in the BrowserThread::ID | 537 // Start threads in the order they occur in the BrowserThread::ID |
| 511 // enumeration, except for BrowserThread::UI which is the main | 538 // enumeration, except for BrowserThread::UI which is the main |
| 512 // thread. | 539 // thread. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 605 (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
| 579 (*thread_to_start)->StartWithOptions(*options); | 606 (*thread_to_start)->StartWithOptions(*options); |
| 580 } else { | 607 } else { |
| 581 NOTREACHED(); | 608 NOTREACHED(); |
| 582 } | 609 } |
| 583 | 610 |
| 584 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); | 611 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); |
| 585 | 612 |
| 586 } | 613 } |
| 587 | 614 |
| 588 #if !defined(OS_IOS) | 615 } |
| 589 indexed_db_thread_.reset(new base::Thread("IndexedDB")); | |
| 590 indexed_db_thread_->Start(); | |
| 591 #endif | |
| 592 | 616 |
| 593 BrowserThreadsStarted(); | 617 void BrowserMainLoop::PreMainMessageLoopRun() { |
| 594 | |
| 595 if (parts_) { | 618 if (parts_) { |
| 596 TRACE_EVENT0("startup", | 619 TRACE_EVENT0("startup", |
| 597 "BrowserMainLoop::CreateThreads:PreMainMessageLoopRun"); | 620 "BrowserMainLoop::CreateThreads:PreMainMessageLoopRun"); |
| 598 parts_->PreMainMessageLoopRun(); | 621 parts_->PreMainMessageLoopRun(); |
| 599 } | 622 } |
| 600 | 623 |
| 601 // If the UI thread blocks, the whole UI is unresponsive. | 624 // If the UI thread blocks, the whole UI is unresponsive. |
| 602 // Do not allow disk IO from the UI thread. | 625 // Do not allow disk IO from the UI thread. |
| 603 base::ThreadRestrictions::SetIOAllowed(false); | 626 base::ThreadRestrictions::SetIOAllowed(false); |
| 604 base::ThreadRestrictions::DisallowWaiting(); | 627 base::ThreadRestrictions::DisallowWaiting(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 if (main_message_loop_) | 769 if (main_message_loop_) |
| 747 main_message_loop_->set_thread_name(kThreadName); | 770 main_message_loop_->set_thread_name(kThreadName); |
| 748 | 771 |
| 749 // Register the main thread by instantiating it, but don't call any methods. | 772 // Register the main thread by instantiating it, but don't call any methods. |
| 750 main_thread_.reset( | 773 main_thread_.reset( |
| 751 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); | 774 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); |
| 752 } | 775 } |
| 753 | 776 |
| 754 void BrowserMainLoop::BrowserThreadsStarted() { | 777 void BrowserMainLoop::BrowserThreadsStarted() { |
| 755 TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted") | 778 TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted") |
| 779 |
| 780 #if !defined(OS_IOS) |
| 781 indexed_db_thread_.reset(new base::Thread("IndexedDB")); |
| 782 indexed_db_thread_->Start(); |
| 783 #endif |
| 784 |
| 756 #if defined(OS_ANDROID) | 785 #if defined(OS_ANDROID) |
| 757 // Up the priority of anything that touches with display tasks | 786 // Up the priority of anything that touches with display tasks |
| 758 // (this thread is UI thread, and io_thread_ is for IPCs). | 787 // (this thread is UI thread, and io_thread_ is for IPCs). |
| 759 io_thread_->SetPriority(base::kThreadPriority_Display); | 788 io_thread_->SetPriority(base::kThreadPriority_Display); |
| 760 base::PlatformThread::SetThreadPriority( | 789 base::PlatformThread::SetThreadPriority( |
| 761 base::PlatformThread::CurrentHandle(), | 790 base::PlatformThread::CurrentHandle(), |
| 762 base::kThreadPriority_Display); | 791 base::kThreadPriority_Display); |
| 763 #endif | 792 #endif |
| 764 | 793 |
| 765 #if !defined(OS_IOS) | 794 #if !defined(OS_IOS) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 if (parameters_.ui_task) | 916 if (parameters_.ui_task) |
| 888 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 917 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
| 889 *parameters_.ui_task); | 918 *parameters_.ui_task); |
| 890 | 919 |
| 891 base::RunLoop run_loop; | 920 base::RunLoop run_loop; |
| 892 run_loop.Run(); | 921 run_loop.Run(); |
| 893 #endif | 922 #endif |
| 894 } | 923 } |
| 895 | 924 |
| 896 } // namespace content | 925 } // namespace content |
| OLD | NEW |