| 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.h" | 11 #include "base/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/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/system_monitor/system_monitor.h" | 18 #include "base/system_monitor/system_monitor.h" |
| 19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| 20 #include "base/timer/hi_res_timer_manager.h" | 20 #include "base/timer/hi_res_timer_manager.h" |
| 21 #include "content/browser/browser_thread_impl.h" | 21 #include "content/browser/browser_thread_impl.h" |
| 22 #include "content/browser/device_orientation/device_motion_service.h" | 22 #include "content/browser/device_orientation/device_motion_service.h" |
| 23 #include "content/browser/download/save_file_manager.h" | 23 #include "content/browser/download/save_file_manager.h" |
| 24 #include "content/browser/gamepad/gamepad_service.h" | 24 #include "content/browser/gamepad/gamepad_service.h" |
| 25 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 25 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 26 #include "content/browser/gpu/gpu_data_manager_impl.h" | 26 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 27 #include "content/browser/gpu/gpu_process_host.h" | 27 #include "content/browser/gpu/gpu_process_host.h" |
| 28 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 28 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 29 #include "content/browser/histogram_synchronizer.h" | 29 #include "content/browser/histogram_synchronizer.h" |
| 30 #include "content/browser/in_process_webkit/webkit_thread.h" | |
| 31 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 30 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 32 #include "content/browser/net/browser_online_state_observer.h" | 31 #include "content/browser/net/browser_online_state_observer.h" |
| 33 #include "content/browser/plugin_service_impl.h" | 32 #include "content/browser/plugin_service_impl.h" |
| 34 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" | 33 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" |
| 35 #include "content/browser/renderer_host/media/media_stream_manager.h" | 34 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 36 #include "content/browser/speech/speech_recognition_manager_impl.h" | 35 #include "content/browser/speech/speech_recognition_manager_impl.h" |
| 37 #include "content/browser/tracing/trace_controller_impl.h" | 36 #include "content/browser/tracing/trace_controller_impl.h" |
| 38 #include "content/browser/webui/content_web_ui_controller_factory.h" | 37 #include "content/browser/webui/content_web_ui_controller_factory.h" |
| 39 #include "content/browser/webui/url_data_manager.h" | 38 #include "content/browser/webui/url_data_manager.h" |
| 40 #include "content/public/browser/browser_main_parts.h" | 39 #include "content/public/browser/browser_main_parts.h" |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; | 523 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; |
| 525 base::Thread::Options* options = &default_options; | 524 base::Thread::Options* options = &default_options; |
| 526 | 525 |
| 527 switch (thread_id) { | 526 switch (thread_id) { |
| 528 case BrowserThread::DB: | 527 case BrowserThread::DB: |
| 529 TRACE_EVENT_BEGIN1("startup", | 528 TRACE_EVENT_BEGIN1("startup", |
| 530 "BrowserMainLoop::CreateThreads:start", | 529 "BrowserMainLoop::CreateThreads:start", |
| 531 "Thread", "BrowserThread::DB"); | 530 "Thread", "BrowserThread::DB"); |
| 532 thread_to_start = &db_thread_; | 531 thread_to_start = &db_thread_; |
| 533 break; | 532 break; |
| 534 case BrowserThread::WEBKIT_DEPRECATED: | |
| 535 // Special case as WebKitThread is a separate | |
| 536 // type. |thread_to_start| is not used in this case. | |
| 537 TRACE_EVENT_BEGIN1("startup", | |
| 538 "BrowserMainLoop::CreateThreads:start", | |
| 539 "Thread", "BrowserThread::WEBKIT_DEPRECATED"); | |
| 540 break; | |
| 541 case BrowserThread::FILE_USER_BLOCKING: | 533 case BrowserThread::FILE_USER_BLOCKING: |
| 542 TRACE_EVENT_BEGIN1("startup", | 534 TRACE_EVENT_BEGIN1("startup", |
| 543 "BrowserMainLoop::CreateThreads:start", | 535 "BrowserMainLoop::CreateThreads:start", |
| 544 "Thread", "BrowserThread::FILE_USER_BLOCKING"); | 536 "Thread", "BrowserThread::FILE_USER_BLOCKING"); |
| 545 thread_to_start = &file_user_blocking_thread_; | 537 thread_to_start = &file_user_blocking_thread_; |
| 546 break; | 538 break; |
| 547 case BrowserThread::FILE: | 539 case BrowserThread::FILE: |
| 548 TRACE_EVENT_BEGIN1("startup", | 540 TRACE_EVENT_BEGIN1("startup", |
| 549 "BrowserMainLoop::CreateThreads:start", | 541 "BrowserMainLoop::CreateThreads:start", |
| 550 "Thread", "BrowserThread::FILE"); | 542 "Thread", "BrowserThread::FILE"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 580 break; | 572 break; |
| 581 case BrowserThread::UI: | 573 case BrowserThread::UI: |
| 582 case BrowserThread::ID_COUNT: | 574 case BrowserThread::ID_COUNT: |
| 583 default: | 575 default: |
| 584 NOTREACHED(); | 576 NOTREACHED(); |
| 585 break; | 577 break; |
| 586 } | 578 } |
| 587 | 579 |
| 588 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 580 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
| 589 | 581 |
| 590 if (thread_id == BrowserThread::WEBKIT_DEPRECATED) { | 582 if (thread_to_start) { |
| 591 #if !defined(OS_IOS) | |
| 592 webkit_thread_.reset(new WebKitThread); | |
| 593 webkit_thread_->Initialize(); | |
| 594 #endif | |
| 595 } else if (thread_to_start) { | |
| 596 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 583 (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
| 597 (*thread_to_start)->StartWithOptions(*options); | 584 (*thread_to_start)->StartWithOptions(*options); |
| 598 } else { | 585 } else { |
| 599 NOTREACHED(); | 586 NOTREACHED(); |
| 600 } | 587 } |
| 601 | 588 |
| 602 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); | 589 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); |
| 603 | 590 |
| 604 } | 591 } |
| 605 | 592 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 // BrowserThread::ID list. The rationale for the order is as | 674 // BrowserThread::ID list. The rationale for the order is as |
| 688 // follows (need to be filled in a bit): | 675 // follows (need to be filled in a bit): |
| 689 // | 676 // |
| 690 // | 677 // |
| 691 // - The IO thread is the only user of the CACHE thread. | 678 // - The IO thread is the only user of the CACHE thread. |
| 692 // | 679 // |
| 693 // - The PROCESS_LAUNCHER thread must be stopped after IO in case | 680 // - The PROCESS_LAUNCHER thread must be stopped after IO in case |
| 694 // the IO thread posted a task to terminate a process on the | 681 // the IO thread posted a task to terminate a process on the |
| 695 // process launcher thread. | 682 // process launcher thread. |
| 696 // | 683 // |
| 697 // - (Not sure why FILE needs to stop before WEBKIT.) | |
| 698 // | |
| 699 // - The WEBKIT thread (which currently is the responsibility of | |
| 700 // the embedder to stop, by destroying ResourceDispatcherHost | |
| 701 // before the DB thread is stopped) | |
| 702 // | |
| 703 // - (Not sure why DB stops last.) | 684 // - (Not sure why DB stops last.) |
| 704 switch (thread_id) { | 685 switch (thread_id) { |
| 705 case BrowserThread::DB: | 686 case BrowserThread::DB: |
| 706 db_thread_.reset(); | 687 db_thread_.reset(); |
| 707 break; | 688 break; |
| 708 case BrowserThread::WEBKIT_DEPRECATED: | |
| 709 // Special case as WebKitThread is a separate | |
| 710 // type. |thread_to_stop| is not used in this case. | |
| 711 | |
| 712 // Need to destroy ResourceDispatcherHost before PluginService | |
| 713 // and since it caches a pointer to it. | |
| 714 resource_dispatcher_host_.reset(); | |
| 715 #if !defined(OS_IOS) | |
| 716 webkit_thread_.reset(); | |
| 717 #endif | |
| 718 break; | |
| 719 case BrowserThread::FILE_USER_BLOCKING: | 689 case BrowserThread::FILE_USER_BLOCKING: |
| 720 file_user_blocking_thread_.reset(); | 690 file_user_blocking_thread_.reset(); |
| 721 break; | 691 break; |
| 722 case BrowserThread::FILE: | 692 case BrowserThread::FILE: |
| 723 #if !defined(OS_IOS) | 693 #if !defined(OS_IOS) |
| 724 // Clean up state that lives on or uses the file_thread_ before | 694 // Clean up state that lives on or uses the file_thread_ before |
| 725 // it goes away. | 695 // it goes away. |
| 726 if (resource_dispatcher_host_) | 696 if (resource_dispatcher_host_) |
| 727 resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); | 697 resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); |
| 728 #endif // !defined(OS_IOS) | 698 #endif // !defined(OS_IOS) |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 if (parameters_.ui_task) | 892 if (parameters_.ui_task) |
| 923 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 893 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
| 924 *parameters_.ui_task); | 894 *parameters_.ui_task); |
| 925 | 895 |
| 926 base::RunLoop run_loop; | 896 base::RunLoop run_loop; |
| 927 run_loop.Run(); | 897 run_loop.Run(); |
| 928 #endif | 898 #endif |
| 929 } | 899 } |
| 930 | 900 |
| 931 } // namespace content | 901 } // namespace content |
| OLD | NEW |