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

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

Issue 2118083002: ShellClient -> Service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mus2
Patch Set: . Created 4 years, 5 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/lifecycle/parent.cc ('k') | services/shell/tests/shell/shell_unittest.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/base_switches.h" 12 #include "base/base_switches.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/process/process.h" 19 #include "base/process/process.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "mojo/edk/embedder/embedder.h" 21 #include "mojo/edk/embedder/embedder.h"
22 #include "mojo/edk/embedder/platform_channel_pair.h" 22 #include "mojo/edk/embedder/platform_channel_pair.h"
23 #include "mojo/edk/embedder/scoped_platform_handle.h" 23 #include "mojo/edk/embedder/scoped_platform_handle.h"
24 #include "mojo/public/cpp/bindings/binding_set.h" 24 #include "mojo/public/cpp/bindings/binding_set.h"
25 #include "services/shell/public/cpp/connection.h" 25 #include "services/shell/public/cpp/connection.h"
26 #include "services/shell/public/cpp/connector.h" 26 #include "services/shell/public/cpp/connector.h"
27 #include "services/shell/public/cpp/interface_factory.h" 27 #include "services/shell/public/cpp/interface_factory.h"
28 #include "services/shell/public/cpp/shell_client.h" 28 #include "services/shell/public/cpp/service.h"
29 #include "services/shell/public/interfaces/connector.mojom.h" 29 #include "services/shell/public/interfaces/connector.mojom.h"
30 #include "services/shell/public/interfaces/shell.mojom.h" 30 #include "services/shell/public/interfaces/shell.mojom.h"
31 #include "services/shell/runner/child/test_native_main.h" 31 #include "services/shell/runner/child/test_native_main.h"
32 #include "services/shell/runner/common/client_util.h" 32 #include "services/shell/runner/common/client_util.h"
33 #include "services/shell/runner/common/switches.h" 33 #include "services/shell/runner/common/switches.h"
34 #include "services/shell/runner/init.h" 34 #include "services/shell/runner/init.h"
35 #include "services/shell/tests/shell/shell_unittest.mojom.h" 35 #include "services/shell/tests/shell/shell_unittest.mojom.h"
36 36
37 namespace { 37 namespace {
38 38
39 class Driver : public shell::ShellClient, 39 class Driver : public shell::Service,
40 public shell::InterfaceFactory<shell::test::mojom::Driver>, 40 public shell::InterfaceFactory<shell::test::mojom::Driver>,
41 public shell::test::mojom::Driver { 41 public shell::test::mojom::Driver {
42 public: 42 public:
43 Driver() : weak_factory_(this) {} 43 Driver() : weak_factory_(this) {}
44 ~Driver() override {} 44 ~Driver() override {}
45 45
46 private: 46 private:
47 // shell::ShellClient: 47 // shell::Service:
48 void Initialize(shell::Connector* connector, 48 void OnStart(shell::Connector* connector,
49 const shell::Identity& identity, 49 const shell::Identity& identity,
50 uint32_t id) override { 50 uint32_t id) override {
51 base::FilePath target_path; 51 base::FilePath target_path;
52 CHECK(base::PathService::Get(base::DIR_EXE, &target_path)); 52 CHECK(base::PathService::Get(base::DIR_EXE, &target_path));
53 #if defined(OS_WIN) 53 #if defined(OS_WIN)
54 target_path = target_path.Append( 54 target_path = target_path.Append(
55 FILE_PATH_LITERAL("shell_unittest_target.exe")); 55 FILE_PATH_LITERAL("shell_unittest_target.exe"));
56 #else 56 #else
57 target_path = target_path.Append( 57 target_path = target_path.Append(
58 FILE_PATH_LITERAL("shell_unittest_target")); 58 FILE_PATH_LITERAL("shell_unittest_target"));
59 #endif 59 #endif
60 60
61 base::CommandLine child_command_line(target_path); 61 base::CommandLine child_command_line(target_path);
62 // Forward the wait-for-debugger flag but nothing else - we don't want to 62 // Forward the wait-for-debugger flag but nothing else - we don't want to
63 // stamp on the platform-channel flag. 63 // stamp on the platform-channel flag.
64 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 64 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
65 switches::kWaitForDebugger)) { 65 switches::kWaitForDebugger)) {
66 child_command_line.AppendSwitch(switches::kWaitForDebugger); 66 child_command_line.AppendSwitch(switches::kWaitForDebugger);
67 } 67 }
68 68
69 // Create the channel to be shared with the target process. Pass one end 69 // Create the channel to be shared with the target process. Pass one end
70 // on the command line. 70 // on the command line.
71 mojo::edk::PlatformChannelPair platform_channel_pair; 71 mojo::edk::PlatformChannelPair platform_channel_pair;
72 mojo::edk::HandlePassingInformation handle_passing_info; 72 mojo::edk::HandlePassingInformation handle_passing_info;
73 platform_channel_pair.PrepareToPassClientHandleToChildProcess( 73 platform_channel_pair.PrepareToPassClientHandleToChildProcess(
74 &child_command_line, &handle_passing_info); 74 &child_command_line, &handle_passing_info);
75 75
76 std::string child_token = mojo::edk::GenerateRandomToken(); 76 std::string child_token = mojo::edk::GenerateRandomToken();
77 shell::mojom::ShellClientPtr client = 77 shell::mojom::ServicePtr client =
78 shell::PassShellClientRequestOnCommandLine(&child_command_line, 78 shell::PassServiceRequestOnCommandLine(&child_command_line,
79 child_token); 79 child_token);
80 shell::mojom::PIDReceiverPtr receiver; 80 shell::mojom::PIDReceiverPtr receiver;
81 81
82 shell::Identity target("exe:shell_unittest_target", 82 shell::Identity target("exe:shell_unittest_target",
83 shell::mojom::kInheritUserID); 83 shell::mojom::kInheritUserID);
84 shell::Connector::ConnectParams params(target); 84 shell::Connector::ConnectParams params(target);
85 params.set_client_process_connection(std::move(client), 85 params.set_client_process_connection(std::move(client),
86 GetProxy(&receiver)); 86 GetProxy(&receiver));
87 std::unique_ptr<shell::Connection> connection = connector->Connect(&params); 87 std::unique_ptr<shell::Connection> connection = connector->Connect(&params);
88 connection->AddConnectionCompletedClosure( 88 connection->AddConnectionCompletedClosure(
89 base::Bind(&Driver::OnConnectionCompleted, base::Unretained(this))); 89 base::Bind(&Driver::OnConnectionCompleted, base::Unretained(this)));
90 90
91 base::LaunchOptions options; 91 base::LaunchOptions options;
92 #if defined(OS_WIN) 92 #if defined(OS_WIN)
93 options.handles_to_inherit = &handle_passing_info; 93 options.handles_to_inherit = &handle_passing_info;
94 #elif defined(OS_POSIX) 94 #elif defined(OS_POSIX)
95 options.fds_to_remap = &handle_passing_info; 95 options.fds_to_remap = &handle_passing_info;
96 #endif 96 #endif
97 target_ = base::LaunchProcess(child_command_line, options); 97 target_ = base::LaunchProcess(child_command_line, options);
98 DCHECK(target_.IsValid()); 98 DCHECK(target_.IsValid());
99 receiver->SetPID(target_.Pid()); 99 receiver->SetPID(target_.Pid());
100 mojo::edk::ChildProcessLaunched(target_.Handle(), 100 mojo::edk::ChildProcessLaunched(target_.Handle(),
101 platform_channel_pair.PassServerHandle(), 101 platform_channel_pair.PassServerHandle(),
102 child_token); 102 child_token);
103 } 103 }
104 104
105 bool AcceptConnection(shell::Connection* connection) override { 105 bool OnConnect(shell::Connection* connection) override {
106 connection->AddInterface<shell::test::mojom::Driver>(this); 106 connection->AddInterface<shell::test::mojom::Driver>(this);
107 return true; 107 return true;
108 } 108 }
109 109
110 // shell::InterfaceFactory<Driver>: 110 // shell::InterfaceFactory<Driver>:
111 void Create(shell::Connection* connection, 111 void Create(shell::Connection* connection,
112 shell::test::mojom::DriverRequest request) override { 112 shell::test::mojom::DriverRequest request) override {
113 bindings_.AddBinding(this, std::move(request)); 113 bindings_.AddBinding(this, std::move(request));
114 } 114 }
115 115
(...skipping 16 matching lines...) Expand all
132 132
133 int main(int argc, char** argv) { 133 int main(int argc, char** argv) {
134 base::AtExitManager at_exit; 134 base::AtExitManager at_exit;
135 base::CommandLine::Init(argc, argv); 135 base::CommandLine::Init(argc, argv);
136 136
137 shell::InitializeLogging(); 137 shell::InitializeLogging();
138 138
139 Driver driver; 139 Driver driver;
140 return shell::TestNativeMain(&driver); 140 return shell::TestNativeMain(&driver);
141 } 141 }
OLDNEW
« no previous file with comments | « services/shell/tests/lifecycle/parent.cc ('k') | services/shell/tests/shell/shell_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698