| 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" |
| 6 |
| 7 #include <utility> |
| 8 |
| 5 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 6 #include "base/bind.h" | 10 #include "base/bind.h" |
| 7 #include "base/macros.h" | 11 #include "base/macros.h" |
| 8 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 9 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/public/cpp/application/application_connection.h" | 14 #include "mojo/public/cpp/application/application_connection.h" |
| 11 #include "mojo/public/cpp/application/application_delegate.h" | 15 #include "mojo/public/cpp/application/application_delegate.h" |
| 12 #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" |
| 13 #include "mojo/public/cpp/application/interface_factory.h" | 18 #include "mojo/public/cpp/application/interface_factory.h" |
| 19 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" | 20 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 15 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 21 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| 16 #include "shell/application_manager/application_loader.h" | 22 #include "shell/application_manager/application_loader.h" |
| 17 #include "shell/application_manager/application_manager.h" | |
| 18 #include "shell/application_manager/test.mojom.h" | 23 #include "shell/application_manager/test.mojom.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 25 |
| 21 using mojo::Application; | 26 using mojo::Application; |
| 22 using mojo::ApplicationConnection; | 27 using mojo::ApplicationConnection; |
| 23 using mojo::ApplicationDelegate; | 28 using mojo::ApplicationDelegate; |
| 24 using mojo::ApplicationImpl; | 29 using mojo::ApplicationImpl; |
| 25 using mojo::Callback; | 30 using mojo::Callback; |
| 26 using mojo::InterfaceFactory; | 31 using mojo::InterfaceFactory; |
| 27 using mojo::InterfaceRequest; | 32 using mojo::InterfaceRequest; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 int num_c_deletes_; | 239 int num_c_deletes_; |
| 235 bool tester_called_quit_; | 240 bool tester_called_quit_; |
| 236 bool a_called_quit_; | 241 bool a_called_quit_; |
| 237 | 242 |
| 238 base::MessageLoop* loop_; | 243 base::MessageLoop* loop_; |
| 239 }; | 244 }; |
| 240 | 245 |
| 241 // Used to test that the requestor url will be correctly passed. | 246 // Used to test that the requestor url will be correctly passed. |
| 242 class TestAImpl : public TestA { | 247 class TestAImpl : public TestA { |
| 243 public: | 248 public: |
| 244 TestAImpl(ApplicationConnection* b_connection, | 249 TestAImpl(mojo::InterfaceHandle<mojo::ServiceProvider> b_sp_handle, |
| 245 TesterContext* test_context, | 250 TesterContext* test_context, |
| 246 InterfaceRequest<TestA> request) | 251 InterfaceRequest<TestA> request) |
| 247 : test_context_(test_context), binding_(this, request.Pass()) { | 252 : test_context_(test_context), binding_(this, request.Pass()) { |
| 248 b_connection->ConnectToService(&b_); | 253 auto b_sp = mojo::ServiceProviderPtr::Create(b_sp_handle.Pass()); |
| 254 mojo::ConnectToService(b_sp.get(), GetProxy(&b_)); |
| 249 } | 255 } |
| 250 | 256 |
| 251 ~TestAImpl() override { | 257 ~TestAImpl() override { |
| 252 test_context_->IncrementNumADeletes(); | 258 test_context_->IncrementNumADeletes(); |
| 253 if (base::MessageLoop::current()->is_running()) | 259 if (base::MessageLoop::current()->is_running()) |
| 254 Quit(); | 260 Quit(); |
| 255 } | 261 } |
| 256 | 262 |
| 257 private: | 263 private: |
| 258 void CallB() override { | 264 void CallB() override { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // If we're coming from A, then add B, otherwise A. | 358 // If we're coming from A, then add B, otherwise A. |
| 353 if (connection->GetRemoteApplicationURL() == kTestAURLString) | 359 if (connection->GetRemoteApplicationURL() == kTestAURLString) |
| 354 connection->AddService<TestB>(this); | 360 connection->AddService<TestB>(this); |
| 355 else | 361 else |
| 356 connection->AddService<TestA>(this); | 362 connection->AddService<TestA>(this); |
| 357 return true; | 363 return true; |
| 358 } | 364 } |
| 359 | 365 |
| 360 void Create(ApplicationConnection* connection, | 366 void Create(ApplicationConnection* connection, |
| 361 InterfaceRequest<TestA> request) override { | 367 InterfaceRequest<TestA> request) override { |
| 362 ApplicationConnection* b_connection = | 368 mojo::InterfaceHandle<mojo::ServiceProvider> incoming_sp_handle; |
| 363 app_->ConnectToApplicationDeprecated(kTestBURLString); | 369 mojo::InterfaceHandle<mojo::ServiceProvider> outgoing_sp_handle; |
| 364 b_connection->AddService<TestC>(this); | 370 mojo::InterfaceRequest<mojo::ServiceProvider> outgoing_sp_request = |
| 371 GetProxy(&outgoing_sp_handle); |
| 372 app_->shell()->ConnectToApplication(kTestBURLString, |
| 373 GetProxy(&incoming_sp_handle), |
| 374 outgoing_sp_handle.Pass()); |
| 375 std::unique_ptr<mojo::ServiceProviderImpl> outgoing_sp_impl( |
| 376 new mojo::ServiceProviderImpl(outgoing_sp_request.Pass())); |
| 377 outgoing_sp_impl->AddService<TestC>(this); |
| 378 outgoing_sp_impls_for_b_.push_back(std::move(outgoing_sp_impl)); |
| 365 a_bindings_.push_back( | 379 a_bindings_.push_back( |
| 366 new TestAImpl(b_connection, context_, request.Pass())); | 380 new TestAImpl(incoming_sp_handle.Pass(), context_, request.Pass())); |
| 367 } | 381 } |
| 368 | 382 |
| 369 void Create(ApplicationConnection* connection, | 383 void Create(ApplicationConnection* connection, |
| 370 InterfaceRequest<TestB> request) override { | 384 InterfaceRequest<TestB> request) override { |
| 371 new TestBImpl(connection, context_, request.Pass()); | 385 new TestBImpl(connection, context_, request.Pass()); |
| 372 } | 386 } |
| 373 | 387 |
| 374 void Create(ApplicationConnection* connection, | 388 void Create(ApplicationConnection* connection, |
| 375 InterfaceRequest<TestC> request) override { | 389 InterfaceRequest<TestC> request) override { |
| 376 new TestCImpl(connection, context_, request.Pass()); | 390 new TestCImpl(connection, context_, request.Pass()); |
| 377 } | 391 } |
| 378 | 392 |
| 379 TesterContext* context_; | 393 TesterContext* context_; |
| 380 scoped_ptr<ApplicationImpl> app_; | 394 scoped_ptr<ApplicationImpl> app_; |
| 381 std::string requestor_url_; | 395 std::string requestor_url_; |
| 396 std::vector<std::unique_ptr<mojo::ServiceProviderImpl>> |
| 397 outgoing_sp_impls_for_b_; |
| 382 ScopedVector<TestAImpl> a_bindings_; | 398 ScopedVector<TestAImpl> a_bindings_; |
| 383 }; | 399 }; |
| 384 | 400 |
| 385 class TestDelegate : public ApplicationManager::Delegate { | 401 class TestDelegate : public ApplicationManager::Delegate { |
| 386 public: | 402 public: |
| 387 void AddMapping(const GURL& from, const GURL& to) { mappings_[from] = to; } | 403 void AddMapping(const GURL& from, const GURL& to) { mappings_[from] = to; } |
| 388 | 404 |
| 389 // ApplicationManager::Delegate | 405 // ApplicationManager::Delegate |
| 390 GURL ResolveMappings(const GURL& url) override { | 406 GURL ResolveMappings(const GURL& url) override { |
| 391 auto it = mappings_.find(url); | 407 auto it = mappings_.find(url); |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 bool called = false; | 856 bool called = false; |
| 841 application_manager_->ConnectToApplication( | 857 application_manager_->ConnectToApplication( |
| 842 GURL("test:test"), GURL(), nullptr, nullptr, | 858 GURL("test:test"), GURL(), nullptr, nullptr, |
| 843 base::Bind(&QuitClosure, base::Unretained(&called))); | 859 base::Bind(&QuitClosure, base::Unretained(&called))); |
| 844 loop_.Run(); | 860 loop_.Run(); |
| 845 EXPECT_TRUE(called); | 861 EXPECT_TRUE(called); |
| 846 } | 862 } |
| 847 | 863 |
| 848 } // namespace | 864 } // namespace |
| 849 } // namespace shell | 865 } // namespace shell |
| OLD | NEW |