| OLD | NEW |
| 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 "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/base_switches.h" | 6 #include "base/base_switches.h" |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 #endif | 175 #endif |
| 176 | 176 |
| 177 base::CommandLine child_command_line(target_path); | 177 base::CommandLine child_command_line(target_path); |
| 178 // Forward the wait-for-debugger flag but nothing else - we don't want to | 178 // Forward the wait-for-debugger flag but nothing else - we don't want to |
| 179 // stamp on the platform-channel flag. | 179 // stamp on the platform-channel flag. |
| 180 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 180 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 181 switches::kWaitForDebugger)) { | 181 switches::kWaitForDebugger)) { |
| 182 child_command_line.AppendSwitch(switches::kWaitForDebugger); | 182 child_command_line.AppendSwitch(switches::kWaitForDebugger); |
| 183 } | 183 } |
| 184 | 184 |
| 185 mojo::shell::mojom::PIDReceiverPtr receiver; | |
| 186 mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request = | |
| 187 GetProxy(&receiver); | |
| 188 | |
| 189 // Create the channel to be shared with the target process. Pass one end | 185 // Create the channel to be shared with the target process. Pass one end |
| 190 // on the command line. | 186 // on the command line. |
| 191 mojo::edk::PlatformChannelPair platform_channel_pair; | 187 mojo::edk::PlatformChannelPair platform_channel_pair; |
| 192 mojo::edk::HandlePassingInformation handle_passing_info; | 188 mojo::edk::HandlePassingInformation handle_passing_info; |
| 193 platform_channel_pair.PrepareToPassClientHandleToChildProcess( | 189 platform_channel_pair.PrepareToPassClientHandleToChildProcess( |
| 194 &child_command_line, &handle_passing_info); | 190 &child_command_line, &handle_passing_info); |
| 195 | 191 |
| 196 // Generate a token for the child to find and connect to a primordial pipe | 192 // Generate a token for the child to find and connect to a primordial pipe |
| 197 // and pass that as well. | 193 // and pass that as well. |
| 198 std::string primordial_pipe_token = mojo::edk::GenerateRandomToken(); | 194 std::string primordial_pipe_token = mojo::edk::GenerateRandomToken(); |
| 199 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, | 195 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, |
| 200 primordial_pipe_token); | 196 primordial_pipe_token); |
| 201 | 197 |
| 202 // Allocate the pipe locally. | 198 // Allocate the pipe locally. |
| 203 mojo::ScopedMessagePipeHandle pipe = | 199 mojo::ScopedMessagePipeHandle pipe = |
| 204 mojo::edk::CreateParentMessagePipe(primordial_pipe_token); | 200 mojo::edk::CreateParentMessagePipe(primordial_pipe_token); |
| 205 | 201 |
| 206 mojo::shell::mojom::ShellPtr shell; | 202 mojo::shell::mojom::ShellPtr shell; |
| 207 connector()->ConnectToInterface("mojo:shell", &shell); | 203 connector()->ConnectToInterface("mojo:shell", &shell); |
| 208 | 204 |
| 209 mojo::shell::mojom::ShellClientFactoryPtr factory; | 205 mojo::shell::mojom::ShellClientFactoryPtr factory; |
| 210 factory.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClientFactory>( | 206 factory.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClientFactory>( |
| 211 std::move(pipe), 0u)); | 207 std::move(pipe), 0u)); |
| 208 mojo::shell::mojom::PIDReceiverPtr receiver; |
| 209 |
| 210 mojo::Identity target(kTestExeName, mojo::shell::mojom::kInheritUserID); |
| 211 mojo::Connector::ConnectParams params(target); |
| 212 params.set_client_process_connection(std::move(factory), |
| 213 GetProxy(&receiver)); |
| 214 scoped_ptr<mojo::Connection> connection = connector()->Connect(¶ms); |
| 212 base::RunLoop loop; | 215 base::RunLoop loop; |
| 213 mojo::Identity target(kTestExeName, mojom::kInheritUserID); | 216 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 214 shell->CreateInstance(std::move(factory), | |
| 215 mojo::shell::mojom::Identity::From(target), | |
| 216 std::move(request), | |
| 217 base::Bind(&LifecycleTest::OnConnectionCompleted, | |
| 218 base::Unretained(this), &loop)); | |
| 219 loop.Run(); | 217 loop.Run(); |
| 220 | 218 |
| 221 base::LaunchOptions options; | 219 base::LaunchOptions options; |
| 222 #if defined(OS_WIN) | 220 #if defined(OS_WIN) |
| 223 options.handles_to_inherit = &handle_passing_info; | 221 options.handles_to_inherit = &handle_passing_info; |
| 224 #elif defined(OS_POSIX) | 222 #elif defined(OS_POSIX) |
| 225 options.fds_to_remap = &handle_passing_info; | 223 options.fds_to_remap = &handle_passing_info; |
| 226 #endif | 224 #endif |
| 227 base::Process process = base::LaunchProcess(child_command_line, options); | 225 base::Process process = base::LaunchProcess(child_command_line, options); |
| 228 DCHECK(process.IsValid()); | 226 DCHECK(process.IsValid()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 251 mojom::ShellPtr shell; | 249 mojom::ShellPtr shell; |
| 252 connector()->ConnectToInterface("mojo:shell", &shell); | 250 connector()->ConnectToInterface("mojo:shell", &shell); |
| 253 mojom::InstanceListenerPtr listener; | 251 mojom::InstanceListenerPtr listener; |
| 254 base::RunLoop loop; | 252 base::RunLoop loop; |
| 255 InstanceState* state = new InstanceState(GetProxy(&listener), &loop); | 253 InstanceState* state = new InstanceState(GetProxy(&listener), &loop); |
| 256 shell->AddInstanceListener(std::move(listener)); | 254 shell->AddInstanceListener(std::move(listener)); |
| 257 loop.Run(); | 255 loop.Run(); |
| 258 return make_scoped_ptr(state); | 256 return make_scoped_ptr(state); |
| 259 } | 257 } |
| 260 | 258 |
| 261 void OnConnectionCompleted(base::RunLoop* loop, | |
| 262 mojom::ConnectResult result) { | |
| 263 loop->Quit(); | |
| 264 } | |
| 265 | |
| 266 scoped_ptr<InstanceState> instances_; | 259 scoped_ptr<InstanceState> instances_; |
| 267 | 260 |
| 268 DISALLOW_COPY_AND_ASSIGN(LifecycleTest); | 261 DISALLOW_COPY_AND_ASSIGN(LifecycleTest); |
| 269 }; | 262 }; |
| 270 | 263 |
| 271 TEST_F(LifecycleTest, Standalone_GracefulQuit) { | 264 TEST_F(LifecycleTest, Standalone_GracefulQuit) { |
| 272 test::mojom::LifecycleControlPtr lifecycle = ConnectTo(kTestAppName); | 265 test::mojom::LifecycleControlPtr lifecycle = ConnectTo(kTestAppName); |
| 273 | 266 |
| 274 EXPECT_TRUE(instances()->HasInstanceForName(kTestAppName)); | 267 EXPECT_TRUE(instances()->HasInstanceForName(kTestAppName)); |
| 275 EXPECT_EQ(1u, instances()->GetNewInstanceCount()); | 268 EXPECT_EQ(1u, instances()->GetNewInstanceCount()); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 loop.Run(); | 493 loop.Run(); |
| 501 | 494 |
| 502 WaitForInstanceDestruction(); | 495 WaitForInstanceDestruction(); |
| 503 EXPECT_FALSE(instances()->HasInstanceForName(kTestExeName)); | 496 EXPECT_FALSE(instances()->HasInstanceForName(kTestExeName)); |
| 504 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); | 497 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); |
| 505 } | 498 } |
| 506 | 499 |
| 507 | 500 |
| 508 } // namespace shell | 501 } // namespace shell |
| 509 } // namespace mojo | 502 } // namespace mojo |
| OLD | NEW |