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

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

Issue 2389193004: Always use ChannelMojo for content child processes. (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 #include "gpu/GLES2/gl2extchromium.h" 165 #include "gpu/GLES2/gl2extchromium.h"
166 #include "gpu/command_buffer/client/gpu_switches.h" 166 #include "gpu/command_buffer/client/gpu_switches.h"
167 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 167 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
168 #include "gpu/command_buffer/service/gpu_switches.h" 168 #include "gpu/command_buffer/service/gpu_switches.h"
169 #include "ipc/attachment_broker.h" 169 #include "ipc/attachment_broker.h"
170 #include "ipc/attachment_broker_privileged.h" 170 #include "ipc/attachment_broker_privileged.h"
171 #include "ipc/ipc.mojom.h" 171 #include "ipc/ipc.mojom.h"
172 #include "ipc/ipc_channel.h" 172 #include "ipc/ipc_channel.h"
173 #include "ipc/ipc_channel_mojo.h" 173 #include "ipc/ipc_channel_mojo.h"
174 #include "ipc/ipc_logging.h" 174 #include "ipc/ipc_logging.h"
175 #include "ipc/ipc_switches.h"
176 #include "media/base/media_switches.h" 175 #include "media/base/media_switches.h"
177 #include "mojo/edk/embedder/embedder.h" 176 #include "mojo/edk/embedder/embedder.h"
178 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" 177 #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
179 #include "net/url_request/url_request_context_getter.h" 178 #include "net/url_request/url_request_context_getter.h"
180 #include "ppapi/shared_impl/ppapi_switches.h" 179 #include "ppapi/shared_impl/ppapi_switches.h"
181 #include "services/shell/public/cpp/connection.h" 180 #include "services/shell/public/cpp/connection.h"
182 #include "services/shell/public/cpp/interface_provider.h" 181 #include "services/shell/public/cpp/interface_provider.h"
183 #include "services/shell/public/cpp/interface_registry.h" 182 #include "services/shell/public/cpp/interface_registry.h"
184 #include "services/shell/runner/common/switches.h" 183 #include "services/shell/runner/common/switches.h"
185 #include "storage/browser/fileapi/sandbox_file_system_backend.h" 184 #include "storage/browser/fileapi/sandbox_file_system_backend.h"
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 // Find the renderer before creating the channel so if this fails early we 869 // Find the renderer before creating the channel so if this fails early we
871 // return without creating the channel. 870 // return without creating the channel.
872 base::FilePath renderer_path = ChildProcessHost::GetChildPath(flags); 871 base::FilePath renderer_path = ChildProcessHost::GetChildPath(flags);
873 if (renderer_path.empty()) 872 if (renderer_path.empty())
874 return false; 873 return false;
875 874
876 channel_connected_ = false; 875 channel_connected_ = false;
877 sent_render_process_ready_ = false; 876 sent_render_process_ready_ = false;
878 877
879 // Setup the IPC channel. 878 // Setup the IPC channel.
880 const std::string channel_id = 879 channel_ = CreateChannelProxy();
881 IPC::Channel::GenerateVerifiedChannelID(std::string());
882 channel_ = CreateChannelProxy(channel_id);
883 880
884 // Note that Channel send is effectively paused and unpaused at various points 881 // Note that Channel send is effectively paused and unpaused at various points
885 // during startup, and existing code relies on a fragile relative message 882 // during startup, and existing code relies on a fragile relative message
886 // ordering resulting from some early messages being queued until process 883 // ordering resulting from some early messages being queued until process
887 // launch while others are sent immediately. 884 // launch while others are sent immediately.
888 // 885 //
889 // We acquire a few associated interface proxies here -- before the channel is 886 // We acquire a few associated interface proxies here -- before the channel is
890 // paused -- to ensure that subsequent initialization messages on those 887 // paused -- to ensure that subsequent initialization messages on those
891 // interfaces behave properly. Specifically, this avoids the risk of an 888 // interfaces behave properly. Specifically, this avoids the risk of an
892 // interface being requested while the Channel is paused, effectively 889 // interface being requested while the Channel is paused, effectively
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 if (run_renderer_in_process()) { 923 if (run_renderer_in_process()) {
927 DCHECK(g_renderer_main_thread_factory); 924 DCHECK(g_renderer_main_thread_factory);
928 // Crank up a thread and run the initialization there. With the way that 925 // Crank up a thread and run the initialization there. With the way that
929 // messages flow between the browser and renderer, this thread is required 926 // messages flow between the browser and renderer, this thread is required
930 // to prevent a deadlock in single-process mode. Since the primordial 927 // to prevent a deadlock in single-process mode. Since the primordial
931 // thread in the renderer process runs the WebKit code and can sometimes 928 // thread in the renderer process runs the WebKit code and can sometimes
932 // make blocking calls to the UI thread (i.e. this thread), they need to run 929 // make blocking calls to the UI thread (i.e. this thread), they need to run
933 // on separate threads. 930 // on separate threads.
934 in_process_renderer_.reset( 931 in_process_renderer_.reset(
935 g_renderer_main_thread_factory(InProcessChildThreadParams( 932 g_renderer_main_thread_factory(InProcessChildThreadParams(
936 channel_id,
937 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), 933 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
938 mojo_child_connection_->service_token()))); 934 mojo_child_connection_->service_token())));
939 935
940 base::Thread::Options options; 936 base::Thread::Options options;
941 #if defined(OS_WIN) && !defined(OS_MACOSX) 937 #if defined(OS_WIN) && !defined(OS_MACOSX)
942 // In-process plugins require this to be a UI message loop. 938 // In-process plugins require this to be a UI message loop.
943 options.message_loop_type = base::MessageLoop::TYPE_UI; 939 options.message_loop_type = base::MessageLoop::TYPE_UI;
944 #else 940 #else
945 // We can't have multiple UI loops on Linux and Android, so we don't support 941 // We can't have multiple UI loops on Linux and Android, so we don't support
946 // in-process plugins. 942 // in-process plugins.
(...skipping 10 matching lines...) Expand all
957 953
958 g_in_process_thread = in_process_renderer_->message_loop(); 954 g_in_process_thread = in_process_renderer_->message_loop();
959 955
960 } else { 956 } else {
961 // Build command line for renderer. We call AppendRendererCommandLine() 957 // Build command line for renderer. We call AppendRendererCommandLine()
962 // first so the process type argument will appear first. 958 // first so the process type argument will appear first.
963 base::CommandLine* cmd_line = new base::CommandLine(renderer_path); 959 base::CommandLine* cmd_line = new base::CommandLine(renderer_path);
964 if (!renderer_prefix.empty()) 960 if (!renderer_prefix.empty())
965 cmd_line->PrependWrapper(renderer_prefix); 961 cmd_line->PrependWrapper(renderer_prefix);
966 AppendRendererCommandLine(cmd_line); 962 AppendRendererCommandLine(cmd_line);
967 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id);
968 963
969 // Spawn the child process asynchronously to avoid blocking the UI thread. 964 // Spawn the child process asynchronously to avoid blocking the UI thread.
970 // As long as there's no renderer prefix, we can use the zygote process 965 // As long as there's no renderer prefix, we can use the zygote process
971 // at this stage. 966 // at this stage.
972 child_process_launcher_.reset(new ChildProcessLauncher( 967 child_process_launcher_.reset(new ChildProcessLauncher(
973 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, 968 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line,
974 GetID(), this, child_token_, 969 GetID(), this, child_token_,
975 base::Bind(&RenderProcessHostImpl::OnMojoError, 970 base::Bind(&RenderProcessHostImpl::OnMojoError,
976 weak_factory_.GetWeakPtr(), 971 weak_factory_.GetWeakPtr(),
977 base::ThreadTaskRunnerHandle::Get()))); 972 base::ThreadTaskRunnerHandle::Get())));
(...skipping 15 matching lines...) Expand all
993 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); 988 ui::GpuSwitchingManager::GetInstance()->AddObserver(this);
994 } 989 }
995 990
996 power_monitor_broadcaster_.Init(); 991 power_monitor_broadcaster_.Init();
997 992
998 is_initialized_ = true; 993 is_initialized_ = true;
999 init_time_ = base::TimeTicks::Now(); 994 init_time_ = base::TimeTicks::Now();
1000 return true; 995 return true;
1001 } 996 }
1002 997
1003 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( 998 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy() {
1004 const std::string& channel_id) {
1005 scoped_refptr<base::SingleThreadTaskRunner> runner = 999 scoped_refptr<base::SingleThreadTaskRunner> runner =
1006 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); 1000 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
1007 IPC::mojom::ChannelBootstrapPtr bootstrap; 1001 IPC::mojom::ChannelBootstrapPtr bootstrap;
1008 GetRemoteInterfaces()->GetInterface(&bootstrap); 1002 GetRemoteInterfaces()->GetInterface(&bootstrap);
1009 std::unique_ptr<IPC::ChannelFactory> channel_factory = 1003 std::unique_ptr<IPC::ChannelFactory> channel_factory =
1010 IPC::ChannelMojo::CreateServerFactory( 1004 IPC::ChannelMojo::CreateServerFactory(
1011 bootstrap.PassInterface().PassHandle(), runner); 1005 bootstrap.PassInterface().PassHandle(), runner);
1012 1006
1013 std::unique_ptr<IPC::ChannelProxy> channel; 1007 std::unique_ptr<IPC::ChannelProxy> channel;
1014 // Do NOT expand ifdef or run time condition checks here! Synchronous 1008 // Do NOT expand ifdef or run time condition checks here! Synchronous
(...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after
3046 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 3040 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
3047 3041
3048 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 3042 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
3049 // enough information here so that we can determine what the bad message was. 3043 // enough information here so that we can determine what the bad message was.
3050 base::debug::Alias(&error); 3044 base::debug::Alias(&error);
3051 bad_message::ReceivedBadMessage(process.get(), 3045 bad_message::ReceivedBadMessage(process.get(),
3052 bad_message::RPH_MOJO_PROCESS_ERROR); 3046 bad_message::RPH_MOJO_PROCESS_ERROR);
3053 } 3047 }
3054 3048
3055 } // namespace content 3049 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/browser/utility_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698