Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 236813002: Move Mojo channel initialization closer to IPC::Channel setup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixup Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "content/browser/histogram_message_filter.h" 58 #include "content/browser/histogram_message_filter.h"
59 #include "content/browser/indexed_db/indexed_db_context_impl.h" 59 #include "content/browser/indexed_db/indexed_db_context_impl.h"
60 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 60 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
61 #include "content/browser/loader/resource_message_filter.h" 61 #include "content/browser/loader/resource_message_filter.h"
62 #include "content/browser/loader/resource_scheduler_filter.h" 62 #include "content/browser/loader/resource_scheduler_filter.h"
63 #include "content/browser/media/android/browser_demuxer_android.h" 63 #include "content/browser/media/android/browser_demuxer_android.h"
64 #include "content/browser/media/capture/audio_mirroring_manager.h" 64 #include "content/browser/media/capture/audio_mirroring_manager.h"
65 #include "content/browser/media/media_internals.h" 65 #include "content/browser/media/media_internals.h"
66 #include "content/browser/message_port_message_filter.h" 66 #include "content/browser/message_port_message_filter.h"
67 #include "content/browser/mime_registry_message_filter.h" 67 #include "content/browser/mime_registry_message_filter.h"
68 #include "content/browser/mojo/mojo_application_host.h"
68 #include "content/browser/plugin_service_impl.h" 69 #include "content/browser/plugin_service_impl.h"
69 #include "content/browser/profiler_message_filter.h" 70 #include "content/browser/profiler_message_filter.h"
70 #include "content/browser/push_messaging_message_filter.h" 71 #include "content/browser/push_messaging_message_filter.h"
71 #include "content/browser/quota_dispatcher_host.h" 72 #include "content/browser/quota_dispatcher_host.h"
72 #include "content/browser/renderer_host/clipboard_message_filter.h" 73 #include "content/browser/renderer_host/clipboard_message_filter.h"
73 #include "content/browser/renderer_host/database_message_filter.h" 74 #include "content/browser/renderer_host/database_message_filter.h"
74 #include "content/browser/renderer_host/file_utilities_message_filter.h" 75 #include "content/browser/renderer_host/file_utilities_message_filter.h"
75 #include "content/browser/renderer_host/gamepad_browser_message_filter.h" 76 #include "content/browser/renderer_host/gamepad_browser_message_filter.h"
76 #include "content/browser/renderer_host/gpu_message_filter.h" 77 #include "content/browser/renderer_host/gpu_message_filter.h"
77 #include "content/browser/renderer_host/media/audio_input_renderer_host.h" 78 #include "content/browser/renderer_host/media/audio_input_renderer_host.h"
78 #include "content/browser/renderer_host/media/audio_renderer_host.h" 79 #include "content/browser/renderer_host/media/audio_renderer_host.h"
79 #include "content/browser/renderer_host/media/device_request_message_filter.h" 80 #include "content/browser/renderer_host/media/device_request_message_filter.h"
80 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" 81 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
81 #include "content/browser/renderer_host/media/midi_dispatcher_host.h" 82 #include "content/browser/renderer_host/media/midi_dispatcher_host.h"
82 #include "content/browser/renderer_host/media/midi_host.h" 83 #include "content/browser/renderer_host/media/midi_host.h"
83 #include "content/browser/renderer_host/media/peer_connection_tracker_host.h" 84 #include "content/browser/renderer_host/media/peer_connection_tracker_host.h"
84 #include "content/browser/renderer_host/media/video_capture_host.h" 85 #include "content/browser/renderer_host/media/video_capture_host.h"
85 #include "content/browser/renderer_host/memory_benchmark_message_filter.h" 86 #include "content/browser/renderer_host/memory_benchmark_message_filter.h"
86 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" 87 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h"
87 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" 88 #include "content/browser/renderer_host/pepper/pepper_message_filter.h"
88 #include "content/browser/renderer_host/pepper/pepper_renderer_connection.h" 89 #include "content/browser/renderer_host/pepper/pepper_renderer_connection.h"
89 #include "content/browser/renderer_host/render_message_filter.h" 90 #include "content/browser/renderer_host/render_message_filter.h"
90 #include "content/browser/renderer_host/render_process_host_mojo_impl.h"
91 #include "content/browser/renderer_host/render_view_host_delegate.h" 91 #include "content/browser/renderer_host/render_view_host_delegate.h"
92 #include "content/browser/renderer_host/render_view_host_impl.h" 92 #include "content/browser/renderer_host/render_view_host_impl.h"
93 #include "content/browser/renderer_host/render_widget_helper.h" 93 #include "content/browser/renderer_host/render_widget_helper.h"
94 #include "content/browser/renderer_host/render_widget_host_impl.h" 94 #include "content/browser/renderer_host/render_widget_host_impl.h"
95 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" 95 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h"
96 #include "content/browser/renderer_host/text_input_client_message_filter.h" 96 #include "content/browser/renderer_host/text_input_client_message_filter.h"
97 #include "content/browser/renderer_host/websocket_dispatcher_host.h" 97 #include "content/browser/renderer_host/websocket_dispatcher_host.h"
98 #include "content/browser/resolve_proxy_msg_helper.h" 98 #include "content/browser/resolve_proxy_msg_helper.h"
99 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h" 99 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h"
100 #include "content/browser/service_worker/service_worker_context_wrapper.h" 100 #include "content/browser/service_worker/service_worker_context_wrapper.h"
101 #include "content/browser/service_worker/service_worker_dispatcher_host.h" 101 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
102 #include "content/browser/shared_worker/shared_worker_message_filter.h" 102 #include "content/browser/shared_worker/shared_worker_message_filter.h"
103 #include "content/browser/speech/input_tag_speech_dispatcher_host.h" 103 #include "content/browser/speech/input_tag_speech_dispatcher_host.h"
104 #include "content/browser/speech/speech_recognition_dispatcher_host.h" 104 #include "content/browser/speech/speech_recognition_dispatcher_host.h"
105 #include "content/browser/storage_partition_impl.h" 105 #include "content/browser/storage_partition_impl.h"
106 #include "content/browser/streams/stream_context.h" 106 #include "content/browser/streams/stream_context.h"
107 #include "content/browser/tracing/trace_message_filter.h" 107 #include "content/browser/tracing/trace_message_filter.h"
108 #include "content/browser/vibration/vibration_message_filter.h" 108 #include "content/browser/vibration/vibration_message_filter.h"
109 #include "content/browser/webui/web_ui_controller_factory_registry.h" 109 #include "content/browser/webui/web_ui_controller_factory_registry.h"
110 #include "content/browser/worker_host/worker_message_filter.h" 110 #include "content/browser/worker_host/worker_message_filter.h"
111 #include "content/browser/worker_host/worker_storage_partition.h" 111 #include "content/browser/worker_host/worker_storage_partition.h"
112 #include "content/common/child_process_host_impl.h" 112 #include "content/common/child_process_host_impl.h"
113 #include "content/common/child_process_messages.h" 113 #include "content/common/child_process_messages.h"
114 #include "content/common/content_switches_internal.h" 114 #include "content/common/content_switches_internal.h"
115 #include "content/common/gpu/gpu_messages.h" 115 #include "content/common/gpu/gpu_messages.h"
116 #include "content/common/mojo/mojo_messages.h"
116 #include "content/common/resource_messages.h" 117 #include "content/common/resource_messages.h"
117 #include "content/common/view_messages.h" 118 #include "content/common/view_messages.h"
118 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" 119 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
119 #include "content/public/browser/browser_context.h" 120 #include "content/public/browser/browser_context.h"
120 #include "content/public/browser/content_browser_client.h" 121 #include "content/public/browser/content_browser_client.h"
121 #include "content/public/browser/notification_service.h" 122 #include "content/public/browser/notification_service.h"
122 #include "content/public/browser/notification_types.h" 123 #include "content/public/browser/notification_types.h"
123 #include "content/public/browser/render_process_host_factory.h" 124 #include "content/public/browser/render_process_host_factory.h"
124 #include "content/public/browser/render_process_host_observer.h" 125 #include "content/public/browser/render_process_host_observer.h"
125 #include "content/public/browser/render_widget_host.h" 126 #include "content/public/browser/render_widget_host.h"
126 #include "content/public/browser/render_widget_host_iterator.h" 127 #include "content/public/browser/render_widget_host_iterator.h"
127 #include "content/public/browser/resource_context.h" 128 #include "content/public/browser/resource_context.h"
128 #include "content/public/browser/user_metrics.h" 129 #include "content/public/browser/user_metrics.h"
129 #include "content/public/browser/worker_service.h" 130 #include "content/public/browser/worker_service.h"
130 #include "content/public/common/content_constants.h" 131 #include "content/public/common/content_constants.h"
131 #include "content/public/common/content_switches.h" 132 #include "content/public/common/content_switches.h"
132 #include "content/public/common/process_type.h" 133 #include "content/public/common/process_type.h"
133 #include "content/public/common/result_codes.h" 134 #include "content/public/common/result_codes.h"
134 #include "content/public/common/sandboxed_process_launcher_delegate.h" 135 #include "content/public/common/sandboxed_process_launcher_delegate.h"
135 #include "content/public/common/url_constants.h" 136 #include "content/public/common/url_constants.h"
136 #include "gpu/command_buffer/service/gpu_switches.h" 137 #include "gpu/command_buffer/service/gpu_switches.h"
137 #include "ipc/ipc_channel.h" 138 #include "ipc/ipc_channel.h"
138 #include "ipc/ipc_logging.h" 139 #include "ipc/ipc_logging.h"
139 #include "ipc/ipc_switches.h" 140 #include "ipc/ipc_switches.h"
140 #include "media/base/media_switches.h" 141 #include "media/base/media_switches.h"
142 #include "mojo/embedder/platform_channel_pair.h"
143 #include "mojo/public/cpp/bindings/allocation_scope.h"
141 #include "net/url_request/url_request_context_getter.h" 144 #include "net/url_request/url_request_context_getter.h"
142 #include "ppapi/shared_impl/ppapi_switches.h" 145 #include "ppapi/shared_impl/ppapi_switches.h"
143 #include "third_party/skia/include/core/SkBitmap.h" 146 #include "third_party/skia/include/core/SkBitmap.h"
144 #include "ui/base/ui_base_switches.h" 147 #include "ui/base/ui_base_switches.h"
145 #include "ui/events/event_switches.h" 148 #include "ui/events/event_switches.h"
146 #include "ui/gfx/switches.h" 149 #include "ui/gfx/switches.h"
147 #include "ui/gl/gl_switches.h" 150 #include "ui/gl/gl_switches.h"
148 #include "ui/native_theme/native_theme_switches.h" 151 #include "ui/native_theme/native_theme_switches.h"
149 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" 152 #include "webkit/browser/fileapi/sandbox_file_system_backend.h"
150 #include "webkit/common/resource_type.h" 153 #include "webkit/common/resource_type.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 544
542 // Setup the IPC channel. 545 // Setup the IPC channel.
543 const std::string channel_id = 546 const std::string channel_id =
544 IPC::Channel::GenerateVerifiedChannelID(std::string()); 547 IPC::Channel::GenerateVerifiedChannelID(std::string());
545 channel_.reset( 548 channel_.reset(
546 new IPC::ChannelProxy(channel_id, 549 new IPC::ChannelProxy(channel_id,
547 IPC::Channel::MODE_SERVER, 550 IPC::Channel::MODE_SERVER,
548 this, 551 this,
549 BrowserThread::GetMessageLoopProxyForThread( 552 BrowserThread::GetMessageLoopProxyForThread(
550 BrowserThread::IO).get())); 553 BrowserThread::IO).get()));
554 InitializeMojo();
sky 2014/04/16 17:18:10 We don't need to wait for process to launch?
darin (slow to review) 2014/04/16 23:26:04 No, we don't. This is all just setting up the chan
551 555
552 // Call the embedder first so that their IPC filters have priority. 556 // Call the embedder first so that their IPC filters have priority.
553 GetContentClient()->browser()->RenderProcessWillLaunch(this); 557 GetContentClient()->browser()->RenderProcessWillLaunch(this);
554 558
555 CreateMessageFilters(); 559 CreateMessageFilters();
556 560
557 if (run_renderer_in_process()) { 561 if (run_renderer_in_process()) {
558 DCHECK(g_renderer_main_thread_factory); 562 DCHECK(g_renderer_main_thread_factory);
559 // Crank up a thread and run the initialization there. With the way that 563 // Crank up a thread and run the initialization there. With the way that
560 // messages flow between the browser and renderer, this thread is required 564 // messages flow between the browser and renderer, this thread is required
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 605
602 if (!gpu_observer_registered_) { 606 if (!gpu_observer_registered_) {
603 gpu_observer_registered_ = true; 607 gpu_observer_registered_ = true;
604 GpuDataManagerImpl::GetInstance()->AddObserver(this); 608 GpuDataManagerImpl::GetInstance()->AddObserver(this);
605 } 609 }
606 610
607 is_initialized_ = true; 611 is_initialized_ = true;
608 return true; 612 return true;
609 } 613 }
610 614
615 void RenderProcessHostImpl::InitializeMojo() {
616 mojo_application_host_.reset(new MojoApplicationHost());
617 mojo_application_host_->Init();
618
619 mojo::InterfacePipe<IRenderProcess, mojo::AnyInterface> pipe;
620 render_process_.reset(pipe.handle_to_self.Pass(), this);
621
622 // TODO(darin): Figure out what URL to use for the RenderProcess service.
623 mojo::AllocationScope scope;
624 mojo_application_host_->shell_client()->AcceptConnection(
625 "content:render_process", pipe.handle_to_peer.Pass());
626 }
627
611 void RenderProcessHostImpl::CreateMessageFilters() { 628 void RenderProcessHostImpl::CreateMessageFilters() {
612 DCHECK_CURRENTLY_ON(BrowserThread::UI); 629 DCHECK_CURRENTLY_ON(BrowserThread::UI);
613 AddFilter(new ResourceSchedulerFilter(GetID())); 630 AddFilter(new ResourceSchedulerFilter(GetID()));
614 MediaInternals* media_internals = MediaInternals::GetInstance(); 631 MediaInternals* media_internals = MediaInternals::GetInstance();
615 media::AudioManager* audio_manager = 632 media::AudioManager* audio_manager =
616 BrowserMainLoop::GetInstance()->audio_manager(); 633 BrowserMainLoop::GetInstance()->audio_manager();
617 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages 634 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages
618 // from guests. 635 // from guests.
619 if (supports_browser_plugin_) { 636 if (supports_browser_plugin_) {
620 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( 637 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter(
(...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 while (!iter.IsAtEnd()) { 1927 while (!iter.IsAtEnd()) {
1911 iter.GetCurrentValue()->OnMessageReceived( 1928 iter.GetCurrentValue()->OnMessageReceived(
1912 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), 1929 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(),
1913 static_cast<int>(status), 1930 static_cast<int>(status),
1914 exit_code)); 1931 exit_code));
1915 iter.Advance(); 1932 iter.Advance();
1916 } 1933 }
1917 1934
1918 ClearTransportDIBCache(); 1935 ClearTransportDIBCache();
1919 1936
1920 render_process_host_mojo_.reset(); 1937 render_process_.reset();
1938 mojo_application_host_.reset();
1921 1939
1922 // It's possible that one of the calls out to the observers might have caused 1940 // It's possible that one of the calls out to the observers might have caused
1923 // this object to be no longer needed. 1941 // this object to be no longer needed.
1924 if (delayed_cleanup_needed_) 1942 if (delayed_cleanup_needed_)
1925 Cleanup(); 1943 Cleanup();
1926 1944
1927 // This object is not deleted at this point and might be reused later. 1945 // This object is not deleted at this point and might be reused later.
1928 // TODO(darin): clean this up 1946 // TODO(darin): clean this up
1929 } 1947 }
1930 1948
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 // with state that must be there before any JavaScript executes. 2063 // with state that must be there before any JavaScript executes.
2046 // 2064 //
2047 // The queued messages contain such things as "navigate". If this notification 2065 // The queued messages contain such things as "navigate". If this notification
2048 // was after, we can end up executing JavaScript before the initialization 2066 // was after, we can end up executing JavaScript before the initialization
2049 // happens. 2067 // happens.
2050 NotificationService::current()->Notify( 2068 NotificationService::current()->Notify(
2051 NOTIFICATION_RENDERER_PROCESS_CREATED, 2069 NOTIFICATION_RENDERER_PROCESS_CREATED,
2052 Source<RenderProcessHost>(this), 2070 Source<RenderProcessHost>(this),
2053 NotificationService::NoDetails()); 2071 NotificationService::NoDetails());
2054 2072
2073 // Let the Mojo system get setup on the child process side before any other
2074 // IPCs arrive. This way those may safely generate Mojo-related RPCs.
2075 mojo_application_host_->Activate(this, GetHandle());
2076
2055 while (!queued_messages_.empty()) { 2077 while (!queued_messages_.empty()) {
2056 Send(queued_messages_.front()); 2078 Send(queued_messages_.front());
2057 queued_messages_.pop(); 2079 queued_messages_.pop();
2058 } 2080 }
2059 2081
2060 #if defined(ENABLE_WEBRTC) 2082 #if defined(ENABLE_WEBRTC)
2061 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) 2083 if (WebRTCInternals::GetInstance()->aec_dump_enabled())
2062 EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path()); 2084 EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path());
2063 #endif 2085 #endif
2064
2065 if (render_process_host_mojo_.get())
2066 render_process_host_mojo_->OnProcessLaunched();
2067 } 2086 }
2068 2087
2069 scoped_refptr<AudioRendererHost> 2088 scoped_refptr<AudioRendererHost>
2070 RenderProcessHostImpl::audio_renderer_host() const { 2089 RenderProcessHostImpl::audio_renderer_host() const {
2071 return audio_renderer_host_; 2090 return audio_renderer_host_;
2072 } 2091 }
2073 2092
2074 void RenderProcessHostImpl::OnUserMetricsRecordAction( 2093 void RenderProcessHostImpl::OnUserMetricsRecordAction(
2075 const std::string& action) { 2094 const std::string& action) {
2076 RecordComputedAction(action); 2095 RecordComputedAction(action);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2133 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2152 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2134 DCHECK_GT(worker_ref_count_, 0); 2153 DCHECK_GT(worker_ref_count_, 0);
2135 --worker_ref_count_; 2154 --worker_ref_count_;
2136 if (worker_ref_count_ == 0) 2155 if (worker_ref_count_ == 0)
2137 Cleanup(); 2156 Cleanup();
2138 } 2157 }
2139 2158
2140 void RenderProcessHostImpl::SetWebUIHandle( 2159 void RenderProcessHostImpl::SetWebUIHandle(
2141 int32 view_routing_id, 2160 int32 view_routing_id,
2142 mojo::ScopedMessagePipeHandle handle) { 2161 mojo::ScopedMessagePipeHandle handle) {
2143 if (!render_process_host_mojo_) 2162 DCHECK(!render_process_.is_null());
2144 render_process_host_mojo_.reset(new RenderProcessHostMojoImpl(this)); 2163 render_process_->SetWebUIHandle(view_routing_id, handle.Pass());
2145 render_process_host_mojo_->SetWebUIHandle(view_routing_id, handle.Pass());
2146 } 2164 }
2147 2165
2148 } // namespace content 2166 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698