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

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

Issue 2420253002: Rename shell namespace to service_manager (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 unified diff | Download patch
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"
(...skipping 18 matching lines...) Expand all
29 #include "services/service_manager/public/interfaces/connector.mojom.h" 29 #include "services/service_manager/public/interfaces/connector.mojom.h"
30 #include "services/service_manager/public/interfaces/service_manager.mojom.h" 30 #include "services/service_manager/public/interfaces/service_manager.mojom.h"
31 #include "services/service_manager/runner/child/test_native_main.h" 31 #include "services/service_manager/runner/child/test_native_main.h"
32 #include "services/service_manager/runner/common/client_util.h" 32 #include "services/service_manager/runner/common/client_util.h"
33 #include "services/service_manager/runner/common/switches.h" 33 #include "services/service_manager/runner/common/switches.h"
34 #include "services/service_manager/runner/init.h" 34 #include "services/service_manager/runner/init.h"
35 #include "services/service_manager/tests/shell/shell_unittest.mojom.h" 35 #include "services/service_manager/tests/shell/shell_unittest.mojom.h"
36 36
37 namespace { 37 namespace {
38 38
39 class Driver : public shell::Service, 39 class Driver : public service_manager::Service,
40 public shell::InterfaceFactory<shell::test::mojom::Driver>, 40 public service_manager::InterfaceFactory<
41 public shell::test::mojom::Driver { 41 service_manager::test::mojom::Driver>,
42 public service_manager::test::mojom::Driver {
42 public: 43 public:
43 Driver() : weak_factory_(this) {} 44 Driver() : weak_factory_(this) {}
44 ~Driver() override {} 45 ~Driver() override {}
45 46
46 private: 47 private:
47 // shell::Service: 48 // service_manager::Service:
48 void OnStart(const shell::Identity& identity) override { 49 void OnStart(const service_manager::Identity& identity) override {
49 base::FilePath target_path; 50 base::FilePath target_path;
50 CHECK(base::PathService::Get(base::DIR_EXE, &target_path)); 51 CHECK(base::PathService::Get(base::DIR_EXE, &target_path));
51 #if defined(OS_WIN) 52 #if defined(OS_WIN)
52 target_path = target_path.Append( 53 target_path = target_path.Append(
53 FILE_PATH_LITERAL("shell_unittest_target.exe")); 54 FILE_PATH_LITERAL("shell_unittest_target.exe"));
54 #else 55 #else
55 target_path = target_path.Append( 56 target_path = target_path.Append(
56 FILE_PATH_LITERAL("shell_unittest_target")); 57 FILE_PATH_LITERAL("shell_unittest_target"));
57 #endif 58 #endif
58 59
59 base::CommandLine child_command_line(target_path); 60 base::CommandLine child_command_line(target_path);
60 // Forward the wait-for-debugger flag but nothing else - we don't want to 61 // Forward the wait-for-debugger flag but nothing else - we don't want to
61 // stamp on the platform-channel flag. 62 // stamp on the platform-channel flag.
62 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 63 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
63 switches::kWaitForDebugger)) { 64 switches::kWaitForDebugger)) {
64 child_command_line.AppendSwitch(switches::kWaitForDebugger); 65 child_command_line.AppendSwitch(switches::kWaitForDebugger);
65 } 66 }
66 67
67 // Create the channel to be shared with the target process. Pass one end 68 // Create the channel to be shared with the target process. Pass one end
68 // on the command line. 69 // on the command line.
69 mojo::edk::PlatformChannelPair platform_channel_pair; 70 mojo::edk::PlatformChannelPair platform_channel_pair;
70 mojo::edk::HandlePassingInformation handle_passing_info; 71 mojo::edk::HandlePassingInformation handle_passing_info;
71 platform_channel_pair.PrepareToPassClientHandleToChildProcess( 72 platform_channel_pair.PrepareToPassClientHandleToChildProcess(
72 &child_command_line, &handle_passing_info); 73 &child_command_line, &handle_passing_info);
73 74
74 std::string child_token = mojo::edk::GenerateRandomToken(); 75 std::string child_token = mojo::edk::GenerateRandomToken();
75 shell::mojom::ServicePtr client = 76 service_manager::mojom::ServicePtr client =
76 shell::PassServiceRequestOnCommandLine(&child_command_line, 77 service_manager::PassServiceRequestOnCommandLine(&child_command_line,
77 child_token); 78 child_token);
78 shell::mojom::PIDReceiverPtr receiver; 79 service_manager::mojom::PIDReceiverPtr receiver;
79 80
80 shell::Identity target("exe:shell_unittest_target", 81 service_manager::Identity target("exe:shell_unittest_target",
81 shell::mojom::kInheritUserID); 82 service_manager::mojom::kInheritUserID);
82 shell::Connector::ConnectParams params(target); 83 service_manager::Connector::ConnectParams params(target);
83 params.set_client_process_connection(std::move(client), 84 params.set_client_process_connection(std::move(client),
84 GetProxy(&receiver)); 85 GetProxy(&receiver));
85 std::unique_ptr<shell::Connection> connection = 86 std::unique_ptr<service_manager::Connection> connection =
86 connector()->Connect(&params); 87 connector()->Connect(&params);
87 connection->AddConnectionCompletedClosure( 88 connection->AddConnectionCompletedClosure(
88 base::Bind(&Driver::OnConnectionCompleted, base::Unretained(this))); 89 base::Bind(&Driver::OnConnectionCompleted, base::Unretained(this)));
89 90
90 base::LaunchOptions options; 91 base::LaunchOptions options;
91 #if defined(OS_WIN) 92 #if defined(OS_WIN)
92 options.handles_to_inherit = &handle_passing_info; 93 options.handles_to_inherit = &handle_passing_info;
93 #elif defined(OS_POSIX) 94 #elif defined(OS_POSIX)
94 options.fds_to_remap = &handle_passing_info; 95 options.fds_to_remap = &handle_passing_info;
95 #endif 96 #endif
96 target_ = base::LaunchProcess(child_command_line, options); 97 target_ = base::LaunchProcess(child_command_line, options);
97 DCHECK(target_.IsValid()); 98 DCHECK(target_.IsValid());
98 receiver->SetPID(target_.Pid()); 99 receiver->SetPID(target_.Pid());
99 mojo::edk::ChildProcessLaunched(target_.Handle(), 100 mojo::edk::ChildProcessLaunched(target_.Handle(),
100 platform_channel_pair.PassServerHandle(), 101 platform_channel_pair.PassServerHandle(),
101 child_token); 102 child_token);
102 } 103 }
103 104
104 bool OnConnect(const shell::Identity& remote_identity, 105 bool OnConnect(const service_manager::Identity& remote_identity,
105 shell::InterfaceRegistry* registry) override { 106 service_manager::InterfaceRegistry* registry) override {
106 registry->AddInterface<shell::test::mojom::Driver>(this); 107 registry->AddInterface<service_manager::test::mojom::Driver>(this);
107 return true; 108 return true;
108 } 109 }
109 110
110 // shell::InterfaceFactory<Driver>: 111 // service_manager::InterfaceFactory<Driver>:
111 void Create(const shell::Identity& remote_identity, 112 void Create(const service_manager::Identity& remote_identity,
112 shell::test::mojom::DriverRequest request) override { 113 service_manager::test::mojom::DriverRequest request) override {
113 bindings_.AddBinding(this, std::move(request)); 114 bindings_.AddBinding(this, std::move(request));
114 } 115 }
115 116
116 // Driver: 117 // Driver:
117 void QuitDriver() override { 118 void QuitDriver() override {
118 target_.Terminate(0, false); 119 target_.Terminate(0, false);
119 base::MessageLoop::current()->QuitWhenIdle(); 120 base::MessageLoop::current()->QuitWhenIdle();
120 } 121 }
121 122
122 void OnConnectionCompleted() {} 123 void OnConnectionCompleted() {}
123 124
124 base::Process target_; 125 base::Process target_;
125 mojo::BindingSet<shell::test::mojom::Driver> bindings_; 126 mojo::BindingSet<service_manager::test::mojom::Driver> bindings_;
126 base::WeakPtrFactory<Driver> weak_factory_; 127 base::WeakPtrFactory<Driver> weak_factory_;
127 128
128 DISALLOW_COPY_AND_ASSIGN(Driver); 129 DISALLOW_COPY_AND_ASSIGN(Driver);
129 }; 130 };
130 131
131 } // namespace 132 } // namespace
132 133
133 int main(int argc, char** argv) { 134 int main(int argc, char** argv) {
134 base::AtExitManager at_exit; 135 base::AtExitManager at_exit;
135 base::CommandLine::Init(argc, argv); 136 base::CommandLine::Init(argc, argv);
136 137
137 shell::InitializeLogging(); 138 service_manager::InitializeLogging();
138 139
139 Driver driver; 140 Driver driver;
140 return shell::TestNativeMain(&driver); 141 return service_manager::TestNativeMain(&driver);
141 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698