OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "shell/application_manager/application_manager.h" | 5 #include "shell/application_manager/application_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "mojo/public/cpp/application/application_connection.h" | 14 #include "mojo/public/cpp/application/application_connection.h" |
15 #include "mojo/public/cpp/application/application_delegate.h" | 15 #include "mojo/public/cpp/application/application_delegate.h" |
16 #include "mojo/public/cpp/application/application_impl.h" | 16 #include "mojo/public/cpp/application/application_impl.h" |
17 #include "mojo/public/cpp/application/connect.h" | 17 #include "mojo/public/cpp/application/connect.h" |
18 #include "mojo/public/cpp/application/interface_factory.h" | 18 #include "mojo/public/cpp/application/interface_factory.h" |
19 #include "mojo/public/cpp/bindings/strong_binding.h" | 19 #include "mojo/public/cpp/bindings/strong_binding.h" |
20 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 20 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
21 #include "shell/application_manager/application_loader.h" | 21 #include "shell/application_manager/application_loader.h" |
22 #include "shell/application_manager/test.mojom.h" | 22 #include "shell/application_manager/test.mojom.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 using mojo::Application; | 25 using mojo::Application; |
26 using mojo::ApplicationConnection; | 26 using mojo::ApplicationConnection; |
27 using mojo::ApplicationDelegate; | 27 using mojo::ApplicationDelegate; |
28 using mojo::ApplicationImpl; | 28 using mojo::ApplicationImpl; |
29 using mojo::Callback; | 29 using mojo::Callback; |
| 30 using mojo::ConnectionContext; |
30 using mojo::InterfaceFactory; | 31 using mojo::InterfaceFactory; |
31 using mojo::InterfaceRequest; | 32 using mojo::InterfaceRequest; |
32 using mojo::StrongBinding; | 33 using mojo::StrongBinding; |
33 | 34 |
34 namespace shell { | 35 namespace shell { |
35 namespace { | 36 namespace { |
36 | 37 |
37 const char kTestURLString[] = "test:testService"; | 38 const char kTestURLString[] = "test:testService"; |
38 const char kTestAURLString[] = "test:TestA"; | 39 const char kTestAURLString[] = "test:TestA"; |
39 const char kTestBURLString[] = "test:TestB"; | 40 const char kTestBURLString[] = "test:TestB"; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 test_app_.reset(new ApplicationImpl(this, application_request.Pass())); | 123 test_app_.reset(new ApplicationImpl(this, application_request.Pass())); |
123 } | 124 } |
124 | 125 |
125 // ApplicationDelegate implementation. | 126 // ApplicationDelegate implementation. |
126 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 127 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
127 connection->AddService(this); | 128 connection->AddService(this); |
128 return true; | 129 return true; |
129 } | 130 } |
130 | 131 |
131 // InterfaceFactory implementation. | 132 // InterfaceFactory implementation. |
132 void Create(ApplicationConnection* connection, | 133 void Create(const ConnectionContext& connection_context, |
133 InterfaceRequest<TestService> request) override { | 134 InterfaceRequest<TestService> request) override { |
134 new TestServiceImpl(context_, request.Pass()); | 135 new TestServiceImpl(context_, request.Pass()); |
135 } | 136 } |
136 | 137 |
137 scoped_ptr<ApplicationImpl> test_app_; | 138 scoped_ptr<ApplicationImpl> test_app_; |
138 TestContext* context_; | 139 TestContext* context_; |
139 int num_loads_; | 140 int num_loads_; |
140 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); | 141 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); |
141 }; | 142 }; |
142 | 143 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 test_context_->QuitSoon(); | 271 test_context_->QuitSoon(); |
271 } | 272 } |
272 | 273 |
273 TesterContext* test_context_; | 274 TesterContext* test_context_; |
274 TestBPtr b_; | 275 TestBPtr b_; |
275 StrongBinding<TestA> binding_; | 276 StrongBinding<TestA> binding_; |
276 }; | 277 }; |
277 | 278 |
278 class TestBImpl : public TestB { | 279 class TestBImpl : public TestB { |
279 public: | 280 public: |
280 TestBImpl(ApplicationConnection* connection, | 281 TestBImpl(TesterContext* test_context, InterfaceRequest<TestB> request) |
281 TesterContext* test_context, | |
282 InterfaceRequest<TestB> request) | |
283 : test_context_(test_context), binding_(this, request.Pass()) {} | 282 : test_context_(test_context), binding_(this, request.Pass()) {} |
284 | 283 |
285 ~TestBImpl() override { | 284 ~TestBImpl() override { |
286 test_context_->IncrementNumBDeletes(); | 285 test_context_->IncrementNumBDeletes(); |
287 if (base::MessageLoop::current()->is_running()) | 286 if (base::MessageLoop::current()->is_running()) |
288 base::MessageLoop::current()->Quit(); | 287 base::MessageLoop::current()->Quit(); |
289 test_context_->QuitSoon(); | 288 test_context_->QuitSoon(); |
290 } | 289 } |
291 | 290 |
292 private: | 291 private: |
(...skipping 30 matching lines...) Expand all Loading... |
323 return false; | 322 return false; |
324 } | 323 } |
325 // If we're coming from A, then add B, otherwise A. | 324 // If we're coming from A, then add B, otherwise A. |
326 if (connection->GetRemoteApplicationURL() == kTestAURLString) | 325 if (connection->GetRemoteApplicationURL() == kTestAURLString) |
327 connection->AddService<TestB>(this); | 326 connection->AddService<TestB>(this); |
328 else | 327 else |
329 connection->AddService<TestA>(this); | 328 connection->AddService<TestA>(this); |
330 return true; | 329 return true; |
331 } | 330 } |
332 | 331 |
333 void Create(ApplicationConnection* connection, | 332 void Create(const ConnectionContext& connection_context, |
334 InterfaceRequest<TestA> request) override { | 333 InterfaceRequest<TestA> request) override { |
335 mojo::InterfaceHandle<mojo::ServiceProvider> incoming_sp_handle; | 334 mojo::InterfaceHandle<mojo::ServiceProvider> incoming_sp_handle; |
336 app_->shell()->ConnectToApplication(kTestBURLString, | 335 app_->shell()->ConnectToApplication(kTestBURLString, |
337 GetProxy(&incoming_sp_handle), nullptr); | 336 GetProxy(&incoming_sp_handle), nullptr); |
338 a_bindings_.push_back( | 337 a_bindings_.push_back( |
339 new TestAImpl(incoming_sp_handle.Pass(), context_, request.Pass())); | 338 new TestAImpl(incoming_sp_handle.Pass(), context_, request.Pass())); |
340 } | 339 } |
341 | 340 |
342 void Create(ApplicationConnection* connection, | 341 void Create(const ConnectionContext& connection_context, |
343 InterfaceRequest<TestB> request) override { | 342 InterfaceRequest<TestB> request) override { |
344 new TestBImpl(connection, context_, request.Pass()); | 343 new TestBImpl(context_, request.Pass()); |
345 } | 344 } |
346 | 345 |
347 TesterContext* context_; | 346 TesterContext* context_; |
348 scoped_ptr<ApplicationImpl> app_; | 347 scoped_ptr<ApplicationImpl> app_; |
349 std::string requestor_url_; | 348 std::string requestor_url_; |
350 ScopedVector<TestAImpl> a_bindings_; | 349 ScopedVector<TestAImpl> a_bindings_; |
351 }; | 350 }; |
352 | 351 |
353 class TestDelegate : public ApplicationManager::Delegate { | 352 class TestDelegate : public ApplicationManager::Delegate { |
354 public: | 353 public: |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 bool called = false; | 789 bool called = false; |
791 application_manager_->ConnectToApplication( | 790 application_manager_->ConnectToApplication( |
792 GURL("test:test"), GURL(), nullptr, | 791 GURL("test:test"), GURL(), nullptr, |
793 base::Bind(&QuitClosure, base::Unretained(&called))); | 792 base::Bind(&QuitClosure, base::Unretained(&called))); |
794 loop_.Run(); | 793 loop_.Run(); |
795 EXPECT_TRUE(called); | 794 EXPECT_TRUE(called); |
796 } | 795 } |
797 | 796 |
798 } // namespace | 797 } // namespace |
799 } // namespace shell | 798 } // namespace shell |
OLD | NEW |