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

Unified Diff: remoting/host/win/unprivileged_process_delegate.cc

Issue 2451203002: Revert of Use ChannelMojo between the remoting daemon and network 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/win/unprivileged_process_delegate.cc
diff --git a/remoting/host/win/unprivileged_process_delegate.cc b/remoting/host/win/unprivileged_process_delegate.cc
index c938561034d91e32291cfeaddb9bb04cd352de97..9a7f2ab0ff7780d58308d3c88e0d6f73e1b2243e 100644
--- a/remoting/host/win/unprivileged_process_delegate.cc
+++ b/remoting/host/win/unprivileged_process_delegate.cc
@@ -26,9 +26,8 @@
#include "ipc/ipc_channel.h"
#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_message.h"
-#include "mojo/edk/embedder/embedder.h"
-#include "mojo/edk/embedder/platform_channel_pair.h"
#include "remoting/base/typed_buffer.h"
+#include "remoting/host/ipc_util.h"
#include "remoting/host/switches.h"
#include "remoting/host/win/launch_process_with_token.h"
#include "remoting/host/win/security_descriptor.h"
@@ -240,6 +239,8 @@
event_handler_ = event_handler;
+ std::unique_ptr<IPC::ChannelProxy> server;
+
// Create a restricted token that will be used to run the worker process.
ScopedHandle token;
if (!CreateRestrictedToken(&token)) {
@@ -276,50 +277,47 @@
thread_attributes.lpSecurityDescriptor = thread_sd.get();
thread_attributes.bInheritHandle = FALSE;
- // Create our own window station and desktop accessible by |logon_sid|.
- WindowStationAndDesktop handles;
- if (!CreateWindowStationAndDesktop(std::move(logon_sid), &handles)) {
- PLOG(ERROR) << "Failed to create a window station and desktop";
- ReportFatalError();
- return;
- }
-
- const std::string mojo_child_token = mojo::edk::GenerateRandomToken();
- const std::string mojo_message_pipe_token = mojo::edk::GenerateRandomToken();
-
- std::unique_ptr<IPC::ChannelProxy> server =
- base::MakeUnique<IPC::ChannelProxy>(this, io_task_runner_);
- IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel(
- server.get(), io_task_runner_);
- server->Init(mojo::edk::CreateParentMessagePipe(mojo_message_pipe_token,
- mojo_child_token)
- .release(),
- IPC::Channel::MODE_SERVER, /*create_pipe_now=*/true);
- base::CommandLine command_line(target_command_->argv());
- command_line.AppendSwitchASCII(kMojoPipeToken, mojo_message_pipe_token);
-
- base::HandlesToInheritVector handles_to_inherit = {
- handles.desktop(), handles.window_station(),
- };
- mojo::edk::PlatformChannelPair mojo_channel;
- mojo_channel.PrepareToPassClientHandleToChildProcess(&command_line,
- &handles_to_inherit);
-
- // Try to launch the worker process. The launched process inherits
- // the window station, desktop and pipe handles, created above.
ScopedHandle worker_process;
- ScopedHandle worker_thread;
- if (!LaunchProcessWithToken(
- command_line.GetProgram(), command_line.GetCommandLineString(),
- token.Get(), &process_attributes, &thread_attributes,
- handles_to_inherit, /* creation_flags= */ 0,
- /* thread_attributes= */ nullptr, &worker_process, &worker_thread)) {
- mojo::edk::ChildProcessLaunchFailed(mojo_child_token);
- ReportFatalError();
- return;
- }
- mojo::edk::ChildProcessLaunched(
- worker_process.Get(), mojo_channel.PassServerHandle(), mojo_child_token);
+ {
+ // Take a lock when any inheritable handles are open to make sure that only
+ // one process inherits them.
+ base::AutoLock lock(g_inherit_handles_lock.Get());
+
+ // Create a connected IPC channel.
+ base::File client;
+ if (!CreateConnectedIpcChannel(io_task_runner_, this, &client, &server)) {
+ ReportFatalError();
+ return;
+ }
+
+ // Convert the handle value into a decimal integer. Handle values are 32bit
+ // even on 64bit platforms.
+ std::string pipe_handle = base::StringPrintf(
+ "%d", reinterpret_cast<ULONG_PTR>(client.GetPlatformFile()));
+
+ // Pass the IPC channel via the command line.
+ base::CommandLine command_line(target_command_->argv());
+ command_line.AppendSwitchASCII(kDaemonPipeSwitchName, pipe_handle);
+
+ // Create our own window station and desktop accessible by |logon_sid|.
+ WindowStationAndDesktop handles;
+ if (!CreateWindowStationAndDesktop(std::move(logon_sid), &handles)) {
+ PLOG(ERROR) << "Failed to create a window station and desktop";
+ ReportFatalError();
+ return;
+ }
+
+ // Try to launch the worker process. The launched process inherits
+ // the window station, desktop and pipe handles, created above.
+ ScopedHandle worker_thread;
+ if (!LaunchProcessWithToken(
+ command_line.GetProgram(), command_line.GetCommandLineString(),
+ token.Get(), &process_attributes, &thread_attributes, true, 0,
+ nullptr, &worker_process, &worker_thread)) {
+ ReportFatalError();
+ return;
+ }
+ }
channel_ = std::move(server);
« no previous file with comments | « remoting/host/win/launch_process_with_token.cc ('k') | remoting/host/win/worker_process_launcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698