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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.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/process/process.h" | 10 #include "base/process/process.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 class Driver : public shell::Service, | 25 class Driver : public shell::Service, |
26 public shell::InterfaceFactory<ClientProcessTest>, | 26 public shell::InterfaceFactory<ClientProcessTest>, |
27 public ClientProcessTest { | 27 public ClientProcessTest { |
28 public: | 28 public: |
29 Driver() {} | 29 Driver() {} |
30 ~Driver() override {} | 30 ~Driver() override {} |
31 | 31 |
32 private: | 32 private: |
33 // shell::Service: | 33 // shell::Service: |
34 void OnStart(shell::Connector* connector, | |
35 const shell::Identity& identity, | |
36 uint32_t id) override { | |
37 connector_ = connector; | |
38 } | |
39 bool OnConnect(shell::Connection* connection) override { | 34 bool OnConnect(shell::Connection* connection) override { |
40 connection->AddInterface<ClientProcessTest>(this); | 35 connection->AddInterface<ClientProcessTest>(this); |
41 return true; | 36 return true; |
42 } | 37 } |
43 bool OnStop() override { | 38 bool OnStop() override { |
44 // TODO(rockot): http://crbug.com/596621. Should be able to remove this | 39 // TODO(rockot): http://crbug.com/596621. Should be able to remove this |
45 // override entirely. | 40 // override entirely. |
46 _exit(1); | 41 _exit(1); |
47 } | 42 } |
48 | 43 |
49 // shell::InterfaceFactory<ConnectTestService>: | 44 // shell::InterfaceFactory<ConnectTestService>: |
50 void Create(const shell::Identity& remote_identity, | 45 void Create(const shell::Identity& remote_identity, |
51 ClientProcessTestRequest request) override { | 46 ClientProcessTestRequest request) override { |
52 bindings_.AddBinding(this, std::move(request)); | 47 bindings_.AddBinding(this, std::move(request)); |
53 } | 48 } |
54 | 49 |
55 // test::mojom::ClientProcessTest: | 50 // test::mojom::ClientProcessTest: |
56 void LaunchAndConnectToProcess( | 51 void LaunchAndConnectToProcess( |
57 const LaunchAndConnectToProcessCallback& callback) override { | 52 const LaunchAndConnectToProcessCallback& callback) override { |
58 base::Process process; | 53 base::Process process; |
59 std::unique_ptr<shell::Connection> connection = | 54 std::unique_ptr<shell::Connection> connection = |
60 shell::test::LaunchAndConnectToProcess( | 55 shell::test::LaunchAndConnectToProcess( |
61 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
62 "connect_test_exe.exe", | 57 "connect_test_exe.exe", |
63 #else | 58 #else |
64 "connect_test_exe", | 59 "connect_test_exe", |
65 #endif | 60 #endif |
66 shell::Identity("exe:connect_test_exe", | 61 shell::Identity("exe:connect_test_exe", |
67 shell::mojom::kInheritUserID), | 62 shell::mojom::kInheritUserID), |
68 connector_, &process); | 63 connector(), &process); |
69 callback.Run(static_cast<int32_t>(connection->GetResult()), | 64 callback.Run(static_cast<int32_t>(connection->GetResult()), |
70 shell::mojom::Identity::From(connection->GetRemoteIdentity())); | 65 shell::mojom::Identity::From(connection->GetRemoteIdentity())); |
71 } | 66 } |
72 | 67 |
73 shell::Connector* connector_ = nullptr; | |
74 mojo::BindingSet<ClientProcessTest> bindings_; | 68 mojo::BindingSet<ClientProcessTest> bindings_; |
75 | 69 |
76 DISALLOW_COPY_AND_ASSIGN(Driver); | 70 DISALLOW_COPY_AND_ASSIGN(Driver); |
77 }; | 71 }; |
78 | 72 |
79 } // namespace | 73 } // namespace |
80 | 74 |
81 int main(int argc, char** argv) { | 75 int main(int argc, char** argv) { |
82 base::AtExitManager at_exit; | 76 base::AtExitManager at_exit; |
83 base::CommandLine::Init(argc, argv); | 77 base::CommandLine::Init(argc, argv); |
84 | 78 |
85 shell::InitializeLogging(); | 79 shell::InitializeLogging(); |
86 | 80 |
87 Driver driver; | 81 Driver driver; |
88 return shell::TestNativeMain(&driver); | 82 return shell::TestNativeMain(&driver); |
89 } | 83 } |
OLD | NEW |