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

Side by Side Diff: services/shell/tests/util.cc

Issue 2019973002: [mojo-edk] Bind a child token to child launches and port reservations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 unified diff | Download patch
« no previous file with comments | « services/shell/tests/shell/driver.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "services/shell/tests/util.h" 5 #include "services/shell/tests/util.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/base_switches.h" 8 #include "base/base_switches.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 platform_channel_pair.PrepareToPassClientHandleToChildProcess( 58 platform_channel_pair.PrepareToPassClientHandleToChildProcess(
59 &child_command_line, &handle_passing_info); 59 &child_command_line, &handle_passing_info);
60 60
61 // Generate a token for the child to find and connect to a primordial pipe 61 // Generate a token for the child to find and connect to a primordial pipe
62 // and pass that as well. 62 // and pass that as well.
63 std::string primordial_pipe_token = mojo::edk::GenerateRandomToken(); 63 std::string primordial_pipe_token = mojo::edk::GenerateRandomToken();
64 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, 64 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken,
65 primordial_pipe_token); 65 primordial_pipe_token);
66 66
67 // Allocate the pipe locally. 67 // Allocate the pipe locally.
68 std::string child_token = mojo::edk::GenerateRandomToken();
68 mojo::ScopedMessagePipeHandle pipe = 69 mojo::ScopedMessagePipeHandle pipe =
69 mojo::edk::CreateParentMessagePipe(primordial_pipe_token); 70 mojo::edk::CreateParentMessagePipe(primordial_pipe_token, child_token);
70 71
71 shell::mojom::ShellClientPtr client; 72 shell::mojom::ShellClientPtr client;
72 client.Bind( 73 client.Bind(
73 mojo::InterfacePtrInfo<shell::mojom::ShellClient>(std::move(pipe), 0u)); 74 mojo::InterfacePtrInfo<shell::mojom::ShellClient>(std::move(pipe), 0u));
74 shell::mojom::PIDReceiverPtr receiver; 75 shell::mojom::PIDReceiverPtr receiver;
75 76
76 shell::Connector::ConnectParams params(target); 77 shell::Connector::ConnectParams params(target);
77 params.set_client_process_connection(std::move(client), GetProxy(&receiver)); 78 params.set_client_process_connection(std::move(client), GetProxy(&receiver));
78 std::unique_ptr<shell::Connection> connection = connector->Connect(&params); 79 std::unique_ptr<shell::Connection> connection = connector->Connect(&params);
79 { 80 {
80 base::RunLoop loop; 81 base::RunLoop loop;
81 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); 82 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
82 base::MessageLoop::ScopedNestableTaskAllower allow( 83 base::MessageLoop::ScopedNestableTaskAllower allow(
83 base::MessageLoop::current()); 84 base::MessageLoop::current());
84 loop.Run(); 85 loop.Run();
85 } 86 }
86 87
87 base::LaunchOptions options; 88 base::LaunchOptions options;
88 #if defined(OS_WIN) 89 #if defined(OS_WIN)
89 options.handles_to_inherit = &handle_passing_info; 90 options.handles_to_inherit = &handle_passing_info;
90 #elif defined(OS_POSIX) 91 #elif defined(OS_POSIX)
91 options.fds_to_remap = &handle_passing_info; 92 options.fds_to_remap = &handle_passing_info;
92 #endif 93 #endif
93 *process = base::LaunchProcess(child_command_line, options); 94 *process = base::LaunchProcess(child_command_line, options);
94 DCHECK(process->IsValid()); 95 DCHECK(process->IsValid());
95 receiver->SetPID(process->Pid()); 96 receiver->SetPID(process->Pid());
96 mojo::edk::ChildProcessLaunched(process->Handle(), 97 mojo::edk::ChildProcessLaunched(process->Handle(),
97 platform_channel_pair.PassServerHandle()); 98 platform_channel_pair.PassServerHandle(),
99 child_token);
98 return connection; 100 return connection;
99 } 101 }
100 102
101 } // namespace test 103 } // namespace test
102 } // namespace shell 104 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/tests/shell/driver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698