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 "ipc/mojo/ipc_channel_mojo_host.h" | 140 #include "ipc/mojo/ipc_channel_mojo_host.h" |
141 #include "media/base/media_switches.h" | 141 #include "media/base/media_switches.h" |
142 #include "net/url_request/url_request_context_getter.h" | 142 #include "net/url_request/url_request_context_getter.h" |
143 #include "ppapi/shared_impl/ppapi_switches.h" | 143 #include "ppapi/shared_impl/ppapi_switches.h" |
144 #include "storage/browser/fileapi/sandbox_file_system_backend.h" | 144 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 BrowserContext* browser_context, | 432 BrowserContext* browser_context, |
433 StoragePartitionImpl* storage_partition_impl, | 433 StoragePartitionImpl* storage_partition_impl, |
434 bool is_isolated_guest) | 434 bool is_isolated_guest) |
435 : fast_shutdown_started_(false), | 435 : fast_shutdown_started_(false), |
436 deleting_soon_(false), | 436 deleting_soon_(false), |
437 #ifndef NDEBUG | 437 #ifndef NDEBUG |
438 is_self_deleted_(false), | 438 is_self_deleted_(false), |
439 #endif | 439 #endif |
440 pending_views_(0), | 440 pending_views_(0), |
441 mojo_application_host_(new MojoApplicationHost), | 441 mojo_application_host_(new MojoApplicationHost), |
442 mojo_activation_required_(false), | |
443 visible_widgets_(0), | 442 visible_widgets_(0), |
444 backgrounded_(true), | 443 backgrounded_(true), |
445 is_initialized_(false), | 444 is_initialized_(false), |
446 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 445 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
447 browser_context_(browser_context), | 446 browser_context_(browser_context), |
448 storage_partition_impl_(storage_partition_impl), | 447 storage_partition_impl_(storage_partition_impl), |
449 sudden_termination_allowed_(true), | 448 sudden_termination_allowed_(true), |
450 ignore_input_events_(false), | 449 ignore_input_events_(false), |
451 is_isolated_guest_(is_isolated_guest), | 450 is_isolated_guest_(is_isolated_guest), |
452 gpu_observer_registered_(false), | 451 gpu_observer_registered_(false), |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 IPC::Channel::GenerateVerifiedChannelID(std::string()); | 579 IPC::Channel::GenerateVerifiedChannelID(std::string()); |
581 channel_ = CreateChannelProxy(channel_id); | 580 channel_ = CreateChannelProxy(channel_id); |
582 | 581 |
583 // Setup the Mojo channel. | 582 // Setup the Mojo channel. |
584 mojo_application_host_->Init(); | 583 mojo_application_host_->Init(); |
585 | 584 |
586 // Call the embedder first so that their IPC filters have priority. | 585 // Call the embedder first so that their IPC filters have priority. |
587 GetContentClient()->browser()->RenderProcessWillLaunch(this); | 586 GetContentClient()->browser()->RenderProcessWillLaunch(this); |
588 | 587 |
589 CreateMessageFilters(); | 588 CreateMessageFilters(); |
589 RegisterMojoServices(); | |
590 | 590 |
591 if (run_renderer_in_process()) { | 591 if (run_renderer_in_process()) { |
592 DCHECK(g_renderer_main_thread_factory); | 592 DCHECK(g_renderer_main_thread_factory); |
593 // Crank up a thread and run the initialization there. With the way that | 593 // Crank up a thread and run the initialization there. With the way that |
594 // messages flow between the browser and renderer, this thread is required | 594 // messages flow between the browser and renderer, this thread is required |
595 // to prevent a deadlock in single-process mode. Since the primordial | 595 // to prevent a deadlock in single-process mode. Since the primordial |
596 // thread in the renderer process runs the WebKit code and can sometimes | 596 // thread in the renderer process runs the WebKit code and can sometimes |
597 // make blocking calls to the UI thread (i.e. this thread), they need to run | 597 // make blocking calls to the UI thread (i.e. this thread), they need to run |
598 // on separate threads. | 598 // on separate threads. |
599 in_process_renderer_.reset(g_renderer_main_thread_factory(channel_id)); | 599 in_process_renderer_.reset(g_renderer_main_thread_factory(channel_id)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 gpu_observer_registered_ = true; | 637 gpu_observer_registered_ = true; |
638 GpuDataManagerImpl::GetInstance()->AddObserver(this); | 638 GpuDataManagerImpl::GetInstance()->AddObserver(this); |
639 } | 639 } |
640 | 640 |
641 power_monitor_broadcaster_.Init(); | 641 power_monitor_broadcaster_.Init(); |
642 | 642 |
643 is_initialized_ = true; | 643 is_initialized_ = true; |
644 return true; | 644 return true; |
645 } | 645 } |
646 | 646 |
647 void RenderProcessHostImpl::MaybeActivateMojo() { | |
648 // TODO(darin): Following security review, we can unconditionally initialize | |
649 // Mojo in all renderers. We will then be able to directly call Activate() | |
650 // from OnProcessLaunched. | |
651 if (!mojo_activation_required_) | |
652 return; // Waiting on someone to require Mojo. | |
653 | |
654 if (!GetHandle()) | |
655 return; // Waiting on renderer startup. | |
656 | |
657 if (!mojo_application_host_->did_activate()) | |
658 mojo_application_host_->Activate(this, GetHandle()); | |
659 } | |
660 | |
661 bool RenderProcessHostImpl::ShouldUseMojoChannel() const { | 647 bool RenderProcessHostImpl::ShouldUseMojoChannel() const { |
662 const base::CommandLine& command_line = | 648 const base::CommandLine& command_line = |
663 *base::CommandLine::ForCurrentProcess(); | 649 *base::CommandLine::ForCurrentProcess(); |
664 return command_line.HasSwitch(switches::kEnableRendererMojoChannel); | 650 return command_line.HasSwitch(switches::kEnableRendererMojoChannel); |
665 } | 651 } |
666 | 652 |
667 scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( | 653 scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( |
668 const std::string& channel_id) { | 654 const std::string& channel_id) { |
669 scoped_refptr<base::SingleThreadTaskRunner> runner = | 655 scoped_refptr<base::SingleThreadTaskRunner> runner = |
670 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 656 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 AddFilter(new ProfilerMessageFilter(PROCESS_TYPE_RENDERER)); | 866 AddFilter(new ProfilerMessageFilter(PROCESS_TYPE_RENDERER)); |
881 AddFilter(new HistogramMessageFilter()); | 867 AddFilter(new HistogramMessageFilter()); |
882 #if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) | 868 #if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) |
883 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 869 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
884 switches::kEnableMemoryBenchmarking)) | 870 switches::kEnableMemoryBenchmarking)) |
885 AddFilter(new MemoryBenchmarkMessageFilter()); | 871 AddFilter(new MemoryBenchmarkMessageFilter()); |
886 #endif | 872 #endif |
887 AddFilter(new VibrationMessageFilter()); | 873 AddFilter(new VibrationMessageFilter()); |
888 AddFilter(new PushMessagingMessageFilter( | 874 AddFilter(new PushMessagingMessageFilter( |
889 GetID(), storage_partition_impl_->GetServiceWorkerContext())); | 875 GetID(), storage_partition_impl_->GetServiceWorkerContext())); |
890 AddFilter(new BatteryStatusMessageFilter()); | |
891 #if defined(OS_ANDROID) | 876 #if defined(OS_ANDROID) |
892 AddFilter(new ScreenOrientationMessageFilterAndroid()); | 877 AddFilter(new ScreenOrientationMessageFilterAndroid()); |
893 #endif | 878 #endif |
894 } | 879 } |
895 | 880 |
881 void RenderProcessHostImpl::RegisterMojoServices() { | |
882 mojo_application_host_->service_registry()->AddService( | |
883 base::Bind(&device::BatteryMonitorImpl::Create)); | |
884 } | |
885 | |
896 int RenderProcessHostImpl::GetNextRoutingID() { | 886 int RenderProcessHostImpl::GetNextRoutingID() { |
897 return widget_helper_->GetNextRoutingID(); | 887 return widget_helper_->GetNextRoutingID(); |
898 } | 888 } |
899 | 889 |
900 | |
901 void RenderProcessHostImpl::ResumeDeferredNavigation( | 890 void RenderProcessHostImpl::ResumeDeferredNavigation( |
902 const GlobalRequestID& request_id) { | 891 const GlobalRequestID& request_id) { |
903 widget_helper_->ResumeDeferredNavigation(request_id); | 892 widget_helper_->ResumeDeferredNavigation(request_id); |
904 } | 893 } |
905 | 894 |
906 void RenderProcessHostImpl::ResumeResponseDeferredAtStart( | 895 void RenderProcessHostImpl::ResumeResponseDeferredAtStart( |
907 const GlobalRequestID& request_id) { | 896 const GlobalRequestID& request_id) { |
908 widget_helper_->ResumeResponseDeferredAtStart(request_id); | 897 widget_helper_->ResumeResponseDeferredAtStart(request_id); |
909 } | 898 } |
910 | 899 |
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1929 IDMap<IPC::Listener>::iterator iter(&listeners_); | 1918 IDMap<IPC::Listener>::iterator iter(&listeners_); |
1930 while (!iter.IsAtEnd()) { | 1919 while (!iter.IsAtEnd()) { |
1931 iter.GetCurrentValue()->OnMessageReceived( | 1920 iter.GetCurrentValue()->OnMessageReceived( |
1932 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), | 1921 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), |
1933 static_cast<int>(status), | 1922 static_cast<int>(status), |
1934 exit_code)); | 1923 exit_code)); |
1935 iter.Advance(); | 1924 iter.Advance(); |
1936 } | 1925 } |
1937 | 1926 |
1938 mojo_application_host_.reset(new MojoApplicationHost); | 1927 mojo_application_host_.reset(new MojoApplicationHost); |
1939 mojo_activation_required_ = false; | |
1940 | 1928 |
1941 // It's possible that one of the calls out to the observers might have caused | 1929 // It's possible that one of the calls out to the observers might have caused |
1942 // this object to be no longer needed. | 1930 // this object to be no longer needed. |
1943 if (delayed_cleanup_needed_) | 1931 if (delayed_cleanup_needed_) |
1944 Cleanup(); | 1932 Cleanup(); |
1945 | 1933 |
1946 // This object is not deleted at this point and might be reused later. | 1934 // This object is not deleted at this point and might be reused later. |
1947 // TODO(darin): clean this up | 1935 // TODO(darin): clean this up |
1948 } | 1936 } |
1949 | 1937 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2096 // was after, we can end up executing JavaScript before the initialization | 2084 // was after, we can end up executing JavaScript before the initialization |
2097 // happens. | 2085 // happens. |
2098 NotificationService::current()->Notify( | 2086 NotificationService::current()->Notify( |
2099 NOTIFICATION_RENDERER_PROCESS_CREATED, | 2087 NOTIFICATION_RENDERER_PROCESS_CREATED, |
2100 Source<RenderProcessHost>(this), | 2088 Source<RenderProcessHost>(this), |
2101 NotificationService::NoDetails()); | 2089 NotificationService::NoDetails()); |
2102 | 2090 |
2103 // Allow Mojo to be setup before the renderer sees any Chrome IPC messages. | 2091 // Allow Mojo to be setup before the renderer sees any Chrome IPC messages. |
2104 // This way, Mojo can be safely used from the renderer in response to any | 2092 // This way, Mojo can be safely used from the renderer in response to any |
2105 // Chrome IPC message. | 2093 // Chrome IPC message. |
2106 MaybeActivateMojo(); | 2094 mojo_application_host_->Activate(this, GetHandle()); |
timvolodine
2014/09/30 16:26:01
as qsr@ already mentioned on my patch this appears
ppi
2014/10/06 13:50:02
Yup, both patches need to wait for the fix before
| |
2107 | 2095 |
2108 if (channel_mojo_host_) | 2096 if (channel_mojo_host_) |
2109 channel_mojo_host_->OnClientLaunched(GetHandle()); | 2097 channel_mojo_host_->OnClientLaunched(GetHandle()); |
2110 | 2098 |
2111 while (!queued_messages_.empty()) { | 2099 while (!queued_messages_.empty()) { |
2112 Send(queued_messages_.front()); | 2100 Send(queued_messages_.front()); |
2113 queued_messages_.pop(); | 2101 queued_messages_.pop(); |
2114 } | 2102 } |
2115 | 2103 |
2116 #if defined(ENABLE_WEBRTC) | 2104 #if defined(ENABLE_WEBRTC) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2240 } | 2228 } |
2241 | 2229 |
2242 void RenderProcessHostImpl::DecrementWorkerRefCount() { | 2230 void RenderProcessHostImpl::DecrementWorkerRefCount() { |
2243 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2231 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2244 DCHECK_GT(worker_ref_count_, 0); | 2232 DCHECK_GT(worker_ref_count_, 0); |
2245 --worker_ref_count_; | 2233 --worker_ref_count_; |
2246 if (worker_ref_count_ == 0) | 2234 if (worker_ref_count_ == 0) |
2247 Cleanup(); | 2235 Cleanup(); |
2248 } | 2236 } |
2249 | 2237 |
2250 void RenderProcessHostImpl::EnsureMojoActivated() { | |
2251 mojo_activation_required_ = true; | |
2252 MaybeActivateMojo(); | |
2253 } | |
2254 | |
2255 } // namespace content | 2238 } // namespace content |
OLD | NEW |