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

Unified Diff: chrome/service/service_utility_process_host.cc

Issue 2084453002: Initialise and use ChannelMojo to the service utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/service/service_utility_process_host.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/service/service_utility_process_host.cc
diff --git a/chrome/service/service_utility_process_host.cc b/chrome/service/service_utility_process_host.cc
index 089229cfeb5bf768ecbe3e94ce9db9c6d8fff85d..51f8f51eefd652b6a2a28a732ebb5ee14d2a1506 100644
--- a/chrome/service/service_utility_process_host.cc
+++ b/chrome/service/service_utility_process_host.cc
@@ -19,17 +19,24 @@
#include "base/macros.h"
#include "base/metrics/histogram.h"
#include "base/process/launch.h"
+#include "base/strings/string_number_conversions.h"
#include "base/task_runner_util.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "base/win/win_util.h"
#include "build/build_config.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_utility_printing_messages.h"
#include "content/public/common/child_process_host.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/mojo_channel_switches.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/sandbox_init.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "ipc/ipc_switches.h"
+#include "mojo/edk/embedder/embedder.h"
+#include "mojo/edk/embedder/named_platform_channel_pair.h"
+#include "mojo/edk/embedder/platform_channel_pair.h"
+#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "printing/emf_win.h"
#include "sandbox/win/src/sandbox_policy.h"
#include "sandbox/win/src/sandbox_types.h"
@@ -162,6 +169,7 @@ ServiceUtilityProcessHost::ServiceUtilityProcessHost(
: client_(client),
client_task_runner_(client_task_runner),
waiting_for_reply_(false),
+ mojo_child_token_(mojo::edk::GenerateRandomToken()),
weak_ptr_factory_(this) {
child_process_host_.reset(ChildProcessHost::Create(this));
}
@@ -212,8 +220,9 @@ bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults(
}
bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) {
- std::string channel_id = child_process_host_->CreateChannel();
- if (channel_id.empty())
+ std::string mojo_channel_token =
+ child_process_host_->CreateChannelMojo(mojo_child_token_);
+ if (mojo_channel_token.empty())
return false;
base::FilePath exe_path = GetUtilityProcessCmd();
@@ -224,7 +233,7 @@ bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) {
base::CommandLine cmd_line(exe_path);
cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess);
- cmd_line.AppendSwitchASCII(switches::kProcessChannelID, channel_id);
+ cmd_line.AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token);
cmd_line.AppendSwitch(switches::kLang);
cmd_line.AppendArg(switches::kPrefetchArgumentOther);
@@ -238,21 +247,45 @@ bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) {
bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line,
bool no_sandbox) {
+ mojo::edk::ScopedPlatformHandle parent_handle;
+ bool success = false;
if (no_sandbox) {
+ mojo::edk::NamedPlatformChannelPair named_pair;
+ parent_handle = named_pair.PassServerHandle();
+ named_pair.PrepareToPassClientHandleToChildProcess(cmd_line);
+
cmd_line->AppendSwitch(switches::kNoSandbox);
process_ = base::LaunchProcess(*cmd_line, base::LaunchOptions());
- return process_.IsValid();
+ success = process_.IsValid();
} else {
+ mojo::edk::PlatformChannelPair channel_pair;
+ parent_handle = channel_pair.PassServerHandle();
+ mojo::edk::ScopedPlatformHandle client_handle =
+ channel_pair.PassClientHandle();
+ base::HandlesToInheritVector handles;
+ handles.push_back(client_handle.get().handle);
+ cmd_line->AppendSwitchASCII(
+ mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch,
+ base::UintToString(base::win::HandleToUint32(handles[0])));
+
ServiceSandboxedProcessLauncherDelegate delegate;
base::Process process;
sandbox::ResultCode result = content::StartSandboxedProcess(
- &delegate, cmd_line, base::HandlesToInheritVector(), &process);
+ &delegate, cmd_line, handles, &process);
if (result == sandbox::SBOX_ALL_OK) {
process_ = std::move(process);
- return true;
+ success = true;
}
- return false;
}
+
+ if (success) {
+ mojo::edk::ChildProcessLaunched(process_.Handle(),
+ std::move(parent_handle),
+ mojo_child_token_);
+ } else {
+ mojo::edk::ChildProcessLaunchFailed(mojo_child_token_);
+ }
+ return success;
}
bool ServiceUtilityProcessHost::Send(IPC::Message* msg) {
« no previous file with comments | « chrome/service/service_utility_process_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698