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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 name_(name), | 41 name_(name), |
42 request_(std::move(request)) { | 42 request_(std::move(request)) { |
43 Start(); | 43 Start(); |
44 } | 44 } |
45 ~ProvidedShellClient() override { | 45 ~ProvidedShellClient() override { |
46 Join(); | 46 Join(); |
47 } | 47 } |
48 | 48 |
49 private: | 49 private: |
50 // mojo::ShellClient: | 50 // mojo::ShellClient: |
51 void Initialize(Connector* connector, const std::string& url, | 51 void Initialize(Connector* connector, const std::string& name, |
52 uint32_t id, uint32_t user_id) override { | 52 uint32_t id, uint32_t user_id) override { |
53 bindings_.set_connection_error_handler( | 53 bindings_.set_connection_error_handler( |
54 base::Bind(&ProvidedShellClient::OnConnectionError, | 54 base::Bind(&ProvidedShellClient::OnConnectionError, |
55 base::Unretained(this))); | 55 base::Unretained(this))); |
56 } | 56 } |
57 bool AcceptConnection(Connection* connection) override { | 57 bool AcceptConnection(Connection* connection) override { |
58 connection->AddInterface<test::mojom::PackageTestService>( | 58 connection->AddInterface<test::mojom::PackageTestService>( |
59 this); | 59 this); |
60 return true; | 60 return true; |
61 } | 61 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 public InterfaceFactory<mojom::ShellClientFactory>, | 95 public InterfaceFactory<mojom::ShellClientFactory>, |
96 public InterfaceFactory<test::mojom::PackageTestService>, | 96 public InterfaceFactory<test::mojom::PackageTestService>, |
97 public mojom::ShellClientFactory, | 97 public mojom::ShellClientFactory, |
98 public test::mojom::PackageTestService { | 98 public test::mojom::PackageTestService { |
99 public: | 99 public: |
100 PackageTestShellClient() {} | 100 PackageTestShellClient() {} |
101 ~PackageTestShellClient() override {} | 101 ~PackageTestShellClient() override {} |
102 | 102 |
103 private: | 103 private: |
104 // mojo::ShellClient: | 104 // mojo::ShellClient: |
105 void Initialize(Connector* connector, const std::string& url, | 105 void Initialize(Connector* connector, const std::string& name, |
106 uint32_t id, uint32_t user_id) override { | 106 uint32_t id, uint32_t user_id) override { |
107 bindings_.set_connection_error_handler( | 107 bindings_.set_connection_error_handler( |
108 base::Bind(&PackageTestShellClient::OnConnectionError, | 108 base::Bind(&PackageTestShellClient::OnConnectionError, |
109 base::Unretained(this))); | 109 base::Unretained(this))); |
110 } | 110 } |
111 bool AcceptConnection(Connection* connection) override { | 111 bool AcceptConnection(Connection* connection) override { |
112 connection->AddInterface<ShellClientFactory>(this); | 112 connection->AddInterface<ShellClientFactory>(this); |
113 connection->AddInterface<test::mojom::PackageTestService>(this); | 113 connection->AddInterface<test::mojom::PackageTestService>(this); |
114 return true; | 114 return true; |
115 } | 115 } |
(...skipping 12 matching lines...) Expand all Loading... |
128 } | 128 } |
129 | 129 |
130 // InterfaceFactory<test::mojom::PackageTestService>: | 130 // InterfaceFactory<test::mojom::PackageTestService>: |
131 void Create(Connection* connection, | 131 void Create(Connection* connection, |
132 test::mojom::PackageTestServiceRequest request) override { | 132 test::mojom::PackageTestServiceRequest request) override { |
133 bindings_.AddBinding(this, std::move(request)); | 133 bindings_.AddBinding(this, std::move(request)); |
134 } | 134 } |
135 | 135 |
136 // mojom::ShellClientFactory: | 136 // mojom::ShellClientFactory: |
137 void CreateShellClient(mojom::ShellClientRequest request, | 137 void CreateShellClient(mojom::ShellClientRequest request, |
138 const String& url) override { | 138 const String& name) override { |
139 if (url == "mojo://package_test_a/") | 139 if (name == "mojo:package_test_a") |
140 new ProvidedShellClient("A", std::move(request)); | 140 new ProvidedShellClient("A", std::move(request)); |
141 else if (url == "mojo://package_test_b/") | 141 else if (name == "mojo:package_test_b") |
142 new ProvidedShellClient("B", std::move(request)); | 142 new ProvidedShellClient("B", std::move(request)); |
143 } | 143 } |
144 | 144 |
145 // test::mojom::PackageTestService: | 145 // test::mojom::PackageTestService: |
146 void GetName(const GetNameCallback& callback) override { | 146 void GetName(const GetNameCallback& callback) override { |
147 callback.Run("ROOT"); | 147 callback.Run("ROOT"); |
148 } | 148 } |
149 | 149 |
150 void OnConnectionError() { | 150 void OnConnectionError() { |
151 if (bindings_.empty()) | 151 if (bindings_.empty()) |
152 base::MessageLoop::current()->QuitWhenIdle(); | 152 base::MessageLoop::current()->QuitWhenIdle(); |
153 } | 153 } |
154 | 154 |
155 std::vector<scoped_ptr<ShellClient>> delegates_; | 155 std::vector<scoped_ptr<ShellClient>> delegates_; |
156 BindingSet<mojom::ShellClientFactory> shell_client_factory_bindings_; | 156 BindingSet<mojom::ShellClientFactory> shell_client_factory_bindings_; |
157 BindingSet<test::mojom::PackageTestService> bindings_; | 157 BindingSet<test::mojom::PackageTestService> bindings_; |
158 | 158 |
159 DISALLOW_COPY_AND_ASSIGN(PackageTestShellClient); | 159 DISALLOW_COPY_AND_ASSIGN(PackageTestShellClient); |
160 }; | 160 }; |
161 | 161 |
162 } // namespace shell | 162 } // namespace shell |
163 } // namespace mojo | 163 } // namespace mojo |
164 | 164 |
165 | 165 |
166 MojoResult MojoMain(MojoHandle shell_handle) { | 166 MojoResult MojoMain(MojoHandle shell_handle) { |
167 MojoResult rv = mojo::ApplicationRunner( | 167 MojoResult rv = mojo::ApplicationRunner( |
168 new mojo::shell::PackageTestShellClient).Run(shell_handle); | 168 new mojo::shell::PackageTestShellClient).Run(shell_handle); |
169 return rv; | 169 return rv; |
170 } | 170 } |
OLD | NEW |