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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
7 | 7 |
8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "base/strings/string_number_conversions.h" | 33 #include "base/strings/string_number_conversions.h" |
34 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
35 #include "base/supports_user_data.h" | 35 #include "base/supports_user_data.h" |
36 #include "base/sys_info.h" | 36 #include "base/sys_info.h" |
37 #include "base/threading/thread.h" | 37 #include "base/threading/thread.h" |
38 #include "base/threading/thread_restrictions.h" | 38 #include "base/threading/thread_restrictions.h" |
39 #include "base/tracked_objects.h" | 39 #include "base/tracked_objects.h" |
40 #include "cc/base/switches.h" | 40 #include "cc/base/switches.h" |
41 #include "content/browser/appcache/appcache_dispatcher_host.h" | 41 #include "content/browser/appcache/appcache_dispatcher_host.h" |
42 #include "content/browser/appcache/chrome_appcache_service.h" | 42 #include "content/browser/appcache/chrome_appcache_service.h" |
43 #include "content/browser/battery_status/battery_status_message_filter.h" | |
44 #include "content/browser/browser_child_process_host_impl.h" | 43 #include "content/browser/browser_child_process_host_impl.h" |
45 #include "content/browser/browser_main.h" | 44 #include "content/browser/browser_main.h" |
46 #include "content/browser/browser_main_loop.h" | 45 #include "content/browser/browser_main_loop.h" |
47 #include "content/browser/browser_plugin/browser_plugin_message_filter.h" | 46 #include "content/browser/browser_plugin/browser_plugin_message_filter.h" |
48 #include "content/browser/child_process_security_policy_impl.h" | 47 #include "content/browser/child_process_security_policy_impl.h" |
49 #include "content/browser/device_sensors/device_light_message_filter.h" | 48 #include "content/browser/device_sensors/device_light_message_filter.h" |
50 #include "content/browser/device_sensors/device_motion_message_filter.h" | 49 #include "content/browser/device_sensors/device_motion_message_filter.h" |
51 #include "content/browser/device_sensors/device_orientation_message_filter.h" | 50 #include "content/browser/device_sensors/device_orientation_message_filter.h" |
52 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" | 51 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
53 #include "content/browser/dom_storage/dom_storage_message_filter.h" | 52 #include "content/browser/dom_storage/dom_storage_message_filter.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 #include "content/public/browser/resource_context.h" | 124 #include "content/public/browser/resource_context.h" |
126 #include "content/public/browser/user_metrics.h" | 125 #include "content/public/browser/user_metrics.h" |
127 #include "content/public/browser/worker_service.h" | 126 #include "content/public/browser/worker_service.h" |
128 #include "content/public/common/content_constants.h" | 127 #include "content/public/common/content_constants.h" |
129 #include "content/public/common/content_switches.h" | 128 #include "content/public/common/content_switches.h" |
130 #include "content/public/common/process_type.h" | 129 #include "content/public/common/process_type.h" |
131 #include "content/public/common/resource_type.h" | 130 #include "content/public/common/resource_type.h" |
132 #include "content/public/common/result_codes.h" | 131 #include "content/public/common/result_codes.h" |
133 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 132 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
134 #include "content/public/common/url_constants.h" | 133 #include "content/public/common/url_constants.h" |
| 134 #include "device/battery/battery_monitor_impl.h" |
135 #include "gpu/command_buffer/service/gpu_switches.h" | 135 #include "gpu/command_buffer/service/gpu_switches.h" |
136 #include "ipc/ipc_channel.h" | 136 #include "ipc/ipc_channel.h" |
137 #include "ipc/ipc_logging.h" | 137 #include "ipc/ipc_logging.h" |
138 #include "ipc/ipc_switches.h" | 138 #include "ipc/ipc_switches.h" |
139 #include "ipc/mojo/ipc_channel_mojo.h" | 139 #include "ipc/mojo/ipc_channel_mojo.h" |
140 #include "media/base/media_switches.h" | 140 #include "media/base/media_switches.h" |
141 #include "net/url_request/url_request_context_getter.h" | 141 #include "net/url_request/url_request_context_getter.h" |
142 #include "ppapi/shared_impl/ppapi_switches.h" | 142 #include "ppapi/shared_impl/ppapi_switches.h" |
143 #include "storage/browser/fileapi/sandbox_file_system_backend.h" | 143 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
144 #include "third_party/skia/include/core/SkBitmap.h" | 144 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 BrowserContext* browser_context, | 431 BrowserContext* browser_context, |
432 StoragePartitionImpl* storage_partition_impl, | 432 StoragePartitionImpl* storage_partition_impl, |
433 bool is_isolated_guest) | 433 bool is_isolated_guest) |
434 : fast_shutdown_started_(false), | 434 : fast_shutdown_started_(false), |
435 deleting_soon_(false), | 435 deleting_soon_(false), |
436 #ifndef NDEBUG | 436 #ifndef NDEBUG |
437 is_self_deleted_(false), | 437 is_self_deleted_(false), |
438 #endif | 438 #endif |
439 pending_views_(0), | 439 pending_views_(0), |
440 mojo_application_host_(new MojoApplicationHost), | 440 mojo_application_host_(new MojoApplicationHost), |
441 mojo_activation_required_(false), | |
442 visible_widgets_(0), | 441 visible_widgets_(0), |
443 backgrounded_(true), | 442 backgrounded_(true), |
444 is_initialized_(false), | 443 is_initialized_(false), |
445 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 444 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
446 browser_context_(browser_context), | 445 browser_context_(browser_context), |
447 storage_partition_impl_(storage_partition_impl), | 446 storage_partition_impl_(storage_partition_impl), |
448 sudden_termination_allowed_(true), | 447 sudden_termination_allowed_(true), |
449 ignore_input_events_(false), | 448 ignore_input_events_(false), |
450 is_isolated_guest_(is_isolated_guest), | 449 is_isolated_guest_(is_isolated_guest), |
451 gpu_observer_registered_(false), | 450 gpu_observer_registered_(false), |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 IPC::Channel::GenerateVerifiedChannelID(std::string()); | 578 IPC::Channel::GenerateVerifiedChannelID(std::string()); |
580 channel_ = CreateChannelProxy(channel_id); | 579 channel_ = CreateChannelProxy(channel_id); |
581 | 580 |
582 // Setup the Mojo channel. | 581 // Setup the Mojo channel. |
583 mojo_application_host_->Init(); | 582 mojo_application_host_->Init(); |
584 | 583 |
585 // Call the embedder first so that their IPC filters have priority. | 584 // Call the embedder first so that their IPC filters have priority. |
586 GetContentClient()->browser()->RenderProcessWillLaunch(this); | 585 GetContentClient()->browser()->RenderProcessWillLaunch(this); |
587 | 586 |
588 CreateMessageFilters(); | 587 CreateMessageFilters(); |
| 588 RegisterMojoServices(); |
589 | 589 |
590 if (run_renderer_in_process()) { | 590 if (run_renderer_in_process()) { |
591 DCHECK(g_renderer_main_thread_factory); | 591 DCHECK(g_renderer_main_thread_factory); |
592 // Crank up a thread and run the initialization there. With the way that | 592 // Crank up a thread and run the initialization there. With the way that |
593 // messages flow between the browser and renderer, this thread is required | 593 // messages flow between the browser and renderer, this thread is required |
594 // to prevent a deadlock in single-process mode. Since the primordial | 594 // to prevent a deadlock in single-process mode. Since the primordial |
595 // thread in the renderer process runs the WebKit code and can sometimes | 595 // thread in the renderer process runs the WebKit code and can sometimes |
596 // make blocking calls to the UI thread (i.e. this thread), they need to run | 596 // make blocking calls to the UI thread (i.e. this thread), they need to run |
597 // on separate threads. | 597 // on separate threads. |
598 in_process_renderer_.reset(g_renderer_main_thread_factory(channel_id)); | 598 in_process_renderer_.reset(g_renderer_main_thread_factory(channel_id)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 gpu_observer_registered_ = true; | 636 gpu_observer_registered_ = true; |
637 GpuDataManagerImpl::GetInstance()->AddObserver(this); | 637 GpuDataManagerImpl::GetInstance()->AddObserver(this); |
638 } | 638 } |
639 | 639 |
640 power_monitor_broadcaster_.Init(); | 640 power_monitor_broadcaster_.Init(); |
641 | 641 |
642 is_initialized_ = true; | 642 is_initialized_ = true; |
643 return true; | 643 return true; |
644 } | 644 } |
645 | 645 |
646 void RenderProcessHostImpl::MaybeActivateMojo() { | |
647 // TODO(darin): Following security review, we can unconditionally initialize | |
648 // Mojo in all renderers. We will then be able to directly call Activate() | |
649 // from OnProcessLaunched. | |
650 if (!mojo_activation_required_) | |
651 return; // Waiting on someone to require Mojo. | |
652 | |
653 if (!GetHandle()) | |
654 return; // Waiting on renderer startup. | |
655 | |
656 if (!mojo_application_host_->did_activate()) | |
657 mojo_application_host_->Activate(this, GetHandle()); | |
658 } | |
659 | |
660 bool RenderProcessHostImpl::ShouldUseMojoChannel() const { | 646 bool RenderProcessHostImpl::ShouldUseMojoChannel() const { |
661 const base::CommandLine& command_line = | 647 const base::CommandLine& command_line = |
662 *base::CommandLine::ForCurrentProcess(); | 648 *base::CommandLine::ForCurrentProcess(); |
663 return command_line.HasSwitch(switches::kEnableRendererMojoChannel); | 649 return command_line.HasSwitch(switches::kEnableRendererMojoChannel); |
664 } | 650 } |
665 | 651 |
666 scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( | 652 scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( |
667 const std::string& channel_id) { | 653 const std::string& channel_id) { |
668 scoped_refptr<base::SingleThreadTaskRunner> runner = | 654 scoped_refptr<base::SingleThreadTaskRunner> runner = |
669 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 655 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 AddFilter(new ProfilerMessageFilter(PROCESS_TYPE_RENDERER)); | 859 AddFilter(new ProfilerMessageFilter(PROCESS_TYPE_RENDERER)); |
874 AddFilter(new HistogramMessageFilter()); | 860 AddFilter(new HistogramMessageFilter()); |
875 #if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) | 861 #if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) |
876 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 862 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
877 switches::kEnableMemoryBenchmarking)) | 863 switches::kEnableMemoryBenchmarking)) |
878 AddFilter(new MemoryBenchmarkMessageFilter()); | 864 AddFilter(new MemoryBenchmarkMessageFilter()); |
879 #endif | 865 #endif |
880 AddFilter(new VibrationMessageFilter()); | 866 AddFilter(new VibrationMessageFilter()); |
881 AddFilter(new PushMessagingMessageFilter( | 867 AddFilter(new PushMessagingMessageFilter( |
882 GetID(), storage_partition_impl_->GetServiceWorkerContext())); | 868 GetID(), storage_partition_impl_->GetServiceWorkerContext())); |
883 AddFilter(new BatteryStatusMessageFilter()); | |
884 #if defined(OS_ANDROID) | 869 #if defined(OS_ANDROID) |
885 AddFilter(new ScreenOrientationMessageFilterAndroid()); | 870 AddFilter(new ScreenOrientationMessageFilterAndroid()); |
886 #endif | 871 #endif |
887 } | 872 } |
888 | 873 |
| 874 void RenderProcessHostImpl::RegisterMojoServices() { |
| 875 mojo_application_host_->service_registry()->AddService( |
| 876 base::Bind(&device::BatteryMonitorImpl::Create)); |
| 877 } |
| 878 |
889 int RenderProcessHostImpl::GetNextRoutingID() { | 879 int RenderProcessHostImpl::GetNextRoutingID() { |
890 return widget_helper_->GetNextRoutingID(); | 880 return widget_helper_->GetNextRoutingID(); |
891 } | 881 } |
892 | 882 |
893 | |
894 void RenderProcessHostImpl::ResumeDeferredNavigation( | 883 void RenderProcessHostImpl::ResumeDeferredNavigation( |
895 const GlobalRequestID& request_id) { | 884 const GlobalRequestID& request_id) { |
896 widget_helper_->ResumeDeferredNavigation(request_id); | 885 widget_helper_->ResumeDeferredNavigation(request_id); |
897 } | 886 } |
898 | 887 |
899 void RenderProcessHostImpl::ResumeResponseDeferredAtStart( | 888 void RenderProcessHostImpl::ResumeResponseDeferredAtStart( |
900 const GlobalRequestID& request_id) { | 889 const GlobalRequestID& request_id) { |
901 widget_helper_->ResumeResponseDeferredAtStart(request_id); | 890 widget_helper_->ResumeResponseDeferredAtStart(request_id); |
902 } | 891 } |
903 | 892 |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1921 IDMap<IPC::Listener>::iterator iter(&listeners_); | 1910 IDMap<IPC::Listener>::iterator iter(&listeners_); |
1922 while (!iter.IsAtEnd()) { | 1911 while (!iter.IsAtEnd()) { |
1923 iter.GetCurrentValue()->OnMessageReceived( | 1912 iter.GetCurrentValue()->OnMessageReceived( |
1924 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), | 1913 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), |
1925 static_cast<int>(status), | 1914 static_cast<int>(status), |
1926 exit_code)); | 1915 exit_code)); |
1927 iter.Advance(); | 1916 iter.Advance(); |
1928 } | 1917 } |
1929 | 1918 |
1930 mojo_application_host_.reset(new MojoApplicationHost); | 1919 mojo_application_host_.reset(new MojoApplicationHost); |
1931 mojo_activation_required_ = false; | |
1932 | 1920 |
1933 // It's possible that one of the calls out to the observers might have caused | 1921 // It's possible that one of the calls out to the observers might have caused |
1934 // this object to be no longer needed. | 1922 // this object to be no longer needed. |
1935 if (delayed_cleanup_needed_) | 1923 if (delayed_cleanup_needed_) |
1936 Cleanup(); | 1924 Cleanup(); |
1937 | 1925 |
1938 // This object is not deleted at this point and might be reused later. | 1926 // This object is not deleted at this point and might be reused later. |
1939 // TODO(darin): clean this up | 1927 // TODO(darin): clean this up |
1940 } | 1928 } |
1941 | 1929 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2088 // was after, we can end up executing JavaScript before the initialization | 2076 // was after, we can end up executing JavaScript before the initialization |
2089 // happens. | 2077 // happens. |
2090 NotificationService::current()->Notify( | 2078 NotificationService::current()->Notify( |
2091 NOTIFICATION_RENDERER_PROCESS_CREATED, | 2079 NOTIFICATION_RENDERER_PROCESS_CREATED, |
2092 Source<RenderProcessHost>(this), | 2080 Source<RenderProcessHost>(this), |
2093 NotificationService::NoDetails()); | 2081 NotificationService::NoDetails()); |
2094 | 2082 |
2095 // Allow Mojo to be setup before the renderer sees any Chrome IPC messages. | 2083 // Allow Mojo to be setup before the renderer sees any Chrome IPC messages. |
2096 // This way, Mojo can be safely used from the renderer in response to any | 2084 // This way, Mojo can be safely used from the renderer in response to any |
2097 // Chrome IPC message. | 2085 // Chrome IPC message. |
2098 MaybeActivateMojo(); | 2086 mojo_application_host_->Activate(this, GetHandle()); |
2099 | 2087 |
2100 while (!queued_messages_.empty()) { | 2088 while (!queued_messages_.empty()) { |
2101 Send(queued_messages_.front()); | 2089 Send(queued_messages_.front()); |
2102 queued_messages_.pop(); | 2090 queued_messages_.pop(); |
2103 } | 2091 } |
2104 | 2092 |
2105 #if defined(ENABLE_WEBRTC) | 2093 #if defined(ENABLE_WEBRTC) |
2106 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) | 2094 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) |
2107 EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path()); | 2095 EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path()); |
2108 #endif | 2096 #endif |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 } | 2217 } |
2230 | 2218 |
2231 void RenderProcessHostImpl::DecrementWorkerRefCount() { | 2219 void RenderProcessHostImpl::DecrementWorkerRefCount() { |
2232 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2220 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2233 DCHECK_GT(worker_ref_count_, 0); | 2221 DCHECK_GT(worker_ref_count_, 0); |
2234 --worker_ref_count_; | 2222 --worker_ref_count_; |
2235 if (worker_ref_count_ == 0) | 2223 if (worker_ref_count_ == 0) |
2236 Cleanup(); | 2224 Cleanup(); |
2237 } | 2225 } |
2238 | 2226 |
2239 void RenderProcessHostImpl::EnsureMojoActivated() { | |
2240 mojo_activation_required_ = true; | |
2241 MaybeActivateMojo(); | |
2242 } | |
2243 | |
2244 } // namespace content | 2227 } // namespace content |
OLD | NEW |