| 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 "mojo/public/cpp/application/application_impl.h" | 5 #include "mojo/public/cpp/application/application_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "mojo/public/cpp/application/application_delegate.h" | 9 #include "mojo/public/cpp/application/application_delegate.h" |
| 10 #include "mojo/public/cpp/application/lib/service_registry.h" | 10 #include "mojo/public/cpp/application/lib/service_registry.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 MOJO_CHECK(shell_); | 30 MOJO_CHECK(shell_); |
| 31 MessagePipe pipe; | 31 MessagePipe pipe; |
| 32 shell_->CreateApplicationConnector( | 32 shell_->CreateApplicationConnector( |
| 33 MakeRequest<ApplicationConnector>(pipe.handle1.Pass())); | 33 MakeRequest<ApplicationConnector>(pipe.handle1.Pass())); |
| 34 return InterfaceHandle<ApplicationConnector>(pipe.handle0.Pass(), 0u); | 34 return InterfaceHandle<ApplicationConnector>(pipe.handle0.Pass(), 0u); |
| 35 } | 35 } |
| 36 | 36 |
| 37 ApplicationConnection* ApplicationImpl::ConnectToApplication( | 37 ApplicationConnection* ApplicationImpl::ConnectToApplication( |
| 38 const String& application_url) { | 38 const String& application_url) { |
| 39 MOJO_CHECK(shell_); | 39 MOJO_CHECK(shell_); |
| 40 ServiceProviderPtr local_services; | 40 InterfaceHandle<ServiceProvider> local_services; |
| 41 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); | 41 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); |
| 42 ServiceProviderPtr remote_services; | 42 ServiceProviderPtr remote_services; |
| 43 shell_->ConnectToApplication(application_url, GetProxy(&remote_services), | 43 shell_->ConnectToApplication(application_url, GetProxy(&remote_services), |
| 44 local_services.Pass()); | 44 std::move(local_services)); |
| 45 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 45 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
| 46 this, application_url, application_url, remote_services.Pass(), | 46 this, application_url, application_url, remote_services.Pass(), |
| 47 local_request.Pass()); | 47 local_request.Pass()); |
| 48 outgoing_service_registries_.emplace_back(registry); | 48 outgoing_service_registries_.emplace_back(registry); |
| 49 return registry; | 49 return registry; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void ApplicationImpl::WaitForInitialize() { | 52 void ApplicationImpl::WaitForInitialize() { |
| 53 if (!shell_) | 53 if (!shell_) |
| 54 binding_.WaitForIncomingMethodCall(); | 54 binding_.WaitForIncomingMethodCall(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ApplicationImpl::UnbindConnections( | 57 void ApplicationImpl::UnbindConnections( |
| 58 InterfaceRequest<Application>* application_request, | 58 InterfaceRequest<Application>* application_request, |
| 59 ShellPtr* shell) { | 59 ShellPtr* shell) { |
| 60 *application_request = binding_.Unbind(); | 60 *application_request = binding_.Unbind(); |
| 61 shell->Bind(shell_.PassInterfaceHandle()); | 61 shell->Bind(shell_.PassInterfaceHandle()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ApplicationImpl::Initialize(ShellPtr shell, | 64 void ApplicationImpl::Initialize(InterfaceHandle<Shell> shell, |
| 65 Array<String> args, | 65 Array<String> args, |
| 66 const mojo::String& url) { | 66 const mojo::String& url) { |
| 67 shell_ = shell.Pass(); | 67 shell_ = ShellPtr::Create(std::move(shell)); |
| 68 shell_.set_connection_error_handler([this]() { | 68 shell_.set_connection_error_handler([this]() { |
| 69 delegate_->Quit(); | 69 delegate_->Quit(); |
| 70 incoming_service_registries_.clear(); | 70 incoming_service_registries_.clear(); |
| 71 outgoing_service_registries_.clear(); | 71 outgoing_service_registries_.clear(); |
| 72 Terminate(); | 72 Terminate(); |
| 73 }); | 73 }); |
| 74 url_ = url; | 74 url_ = url; |
| 75 args_ = args.To<std::vector<std::string>>(); | 75 args_ = args.To<std::vector<std::string>>(); |
| 76 delegate_->Initialize(this); | 76 delegate_->Initialize(this); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ApplicationImpl::AcceptConnection( | 79 void ApplicationImpl::AcceptConnection( |
| 80 const String& requestor_url, | 80 const String& requestor_url, |
| 81 InterfaceRequest<ServiceProvider> services, | 81 InterfaceRequest<ServiceProvider> services, |
| 82 ServiceProviderPtr exposed_services, | 82 InterfaceHandle<ServiceProvider> exposed_services, |
| 83 const String& url) { | 83 const String& url) { |
| 84 std::unique_ptr<internal::ServiceRegistry> registry( | 84 std::unique_ptr<internal::ServiceRegistry> registry( |
| 85 new internal::ServiceRegistry(this, url, requestor_url, | 85 new internal::ServiceRegistry(this, url, requestor_url, |
| 86 exposed_services.Pass(), services.Pass())); | 86 std::move(exposed_services), |
| 87 services.Pass())); |
| 87 if (!delegate_->ConfigureIncomingConnection(registry.get())) | 88 if (!delegate_->ConfigureIncomingConnection(registry.get())) |
| 88 return; | 89 return; |
| 89 incoming_service_registries_.push_back(std::move(registry)); | 90 incoming_service_registries_.push_back(std::move(registry)); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void ApplicationImpl::RequestQuit() { | 93 void ApplicationImpl::RequestQuit() { |
| 93 delegate_->Quit(); | 94 delegate_->Quit(); |
| 94 Terminate(); | 95 Terminate(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 } // namespace mojo | 98 } // namespace mojo |
| OLD | NEW |