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

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

Issue 1882423004: Move shell service to toplevel shell namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
« no previous file with comments | « services/shell/tests/util.h ('k') | services/tracing/main.cc » ('j') | 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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/process/process.h" 15 #include "base/process/process.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "mojo/edk/embedder/embedder.h" 17 #include "mojo/edk/embedder/embedder.h"
18 #include "mojo/edk/embedder/platform_channel_pair.h" 18 #include "mojo/edk/embedder/platform_channel_pair.h"
19 #include "mojo/edk/embedder/scoped_platform_handle.h" 19 #include "mojo/edk/embedder/scoped_platform_handle.h"
20 #include "services/shell/public/cpp/connection.h" 20 #include "services/shell/public/cpp/connection.h"
21 #include "services/shell/public/cpp/connector.h" 21 #include "services/shell/public/cpp/connector.h"
22 #include "services/shell/public/interfaces/connector.mojom.h" 22 #include "services/shell/public/interfaces/connector.mojom.h"
23 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" 23 #include "services/shell/public/interfaces/shell_client_factory.mojom.h"
24 #include "services/shell/runner/common/switches.h" 24 #include "services/shell/runner/common/switches.h"
25 25
26 namespace mojo {
27 namespace shell { 26 namespace shell {
28 namespace test { 27 namespace test {
28
29 namespace { 29 namespace {
30
30 void QuitLoop(base::RunLoop* loop) { 31 void QuitLoop(base::RunLoop* loop) {
31 loop->Quit(); 32 loop->Quit();
32 } 33 }
34
33 } // namespace 35 } // namespace
34 36
35 scoped_ptr<Connection> LaunchAndConnectToProcess( 37 std::unique_ptr<Connection> LaunchAndConnectToProcess(
36 const std::string& target_exe_name, 38 const std::string& target_exe_name,
37 const Identity target, 39 const Identity target,
38 mojo::Connector* connector, 40 shell::Connector* connector,
39 base::Process* process) { 41 base::Process* process) {
40 base::FilePath target_path; 42 base::FilePath target_path;
41 CHECK(base::PathService::Get(base::DIR_EXE, &target_path)); 43 CHECK(base::PathService::Get(base::DIR_EXE, &target_path));
42 target_path = target_path.AppendASCII(target_exe_name); 44 target_path = target_path.AppendASCII(target_exe_name);
43 45
44 base::CommandLine child_command_line(target_path); 46 base::CommandLine child_command_line(target_path);
45 // Forward the wait-for-debugger flag but nothing else - we don't want to 47 // Forward the wait-for-debugger flag but nothing else - we don't want to
46 // stamp on the platform-channel flag. 48 // stamp on the platform-channel flag.
47 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 49 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
48 switches::kWaitForDebugger)) { 50 switches::kWaitForDebugger)) {
(...skipping 10 matching lines...) Expand all
59 // 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
60 // and pass that as well. 62 // and pass that as well.
61 std::string primordial_pipe_token = mojo::edk::GenerateRandomToken(); 63 std::string primordial_pipe_token = mojo::edk::GenerateRandomToken();
62 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, 64 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken,
63 primordial_pipe_token); 65 primordial_pipe_token);
64 66
65 // Allocate the pipe locally. 67 // Allocate the pipe locally.
66 mojo::ScopedMessagePipeHandle pipe = 68 mojo::ScopedMessagePipeHandle pipe =
67 mojo::edk::CreateParentMessagePipe(primordial_pipe_token); 69 mojo::edk::CreateParentMessagePipe(primordial_pipe_token);
68 70
69 mojo::shell::mojom::ShellClientPtr client; 71 shell::mojom::ShellClientPtr client;
70 client.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClient>( 72 client.Bind(
71 std::move(pipe), 0u)); 73 mojo::InterfacePtrInfo<shell::mojom::ShellClient>(std::move(pipe), 0u));
72 mojo::shell::mojom::PIDReceiverPtr receiver; 74 shell::mojom::PIDReceiverPtr receiver;
73 75
74 mojo::Connector::ConnectParams params(target); 76 shell::Connector::ConnectParams params(target);
75 params.set_client_process_connection(std::move(client), GetProxy(&receiver)); 77 params.set_client_process_connection(std::move(client), GetProxy(&receiver));
76 scoped_ptr<mojo::Connection> connection = connector->Connect(&params); 78 std::unique_ptr<shell::Connection> connection = connector->Connect(&params);
77 { 79 {
78 base::RunLoop loop; 80 base::RunLoop loop;
79 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); 81 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
80 base::MessageLoop::ScopedNestableTaskAllower allow( 82 base::MessageLoop::ScopedNestableTaskAllower allow(
81 base::MessageLoop::current()); 83 base::MessageLoop::current());
82 loop.Run(); 84 loop.Run();
83 } 85 }
84 86
85 base::LaunchOptions options; 87 base::LaunchOptions options;
86 #if defined(OS_WIN) 88 #if defined(OS_WIN)
87 options.handles_to_inherit = &handle_passing_info; 89 options.handles_to_inherit = &handle_passing_info;
88 #elif defined(OS_POSIX) 90 #elif defined(OS_POSIX)
89 options.fds_to_remap = &handle_passing_info; 91 options.fds_to_remap = &handle_passing_info;
90 #endif 92 #endif
91 *process = base::LaunchProcess(child_command_line, options); 93 *process = base::LaunchProcess(child_command_line, options);
92 DCHECK(process->IsValid()); 94 DCHECK(process->IsValid());
93 receiver->SetPID(process->Pid()); 95 receiver->SetPID(process->Pid());
94 mojo::edk::ChildProcessLaunched(process->Handle(), 96 mojo::edk::ChildProcessLaunched(process->Handle(),
95 platform_channel_pair.PassServerHandle()); 97 platform_channel_pair.PassServerHandle());
96 return connection; 98 return connection;
97 } 99 }
98 100
99 } // namespace test 101 } // namespace test
100 } // namespace shell 102 } // namespace shell
101 } // namespace mojo
OLDNEW
« no previous file with comments | « services/shell/tests/util.h ('k') | services/tracing/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698