Chromium Code Reviews| 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.h" | 5 #include "mojo/public/cpp/application/application.h" |
| 6 | 6 |
| 7 namespace mojo { | 7 namespace mojo { |
| 8 | 8 |
| 9 Application::Application() {} | 9 Application::Application() : service_registry_(this) {} |
| 10 | 10 |
| 11 Application::Application(ScopedMessagePipeHandle service_provider_handle) | 11 Application::Application(ScopedMessagePipeHandle service_provider_handle) |
| 12 : internal::ServiceConnectorBase::Owner(service_provider_handle.Pass()) { | 12 : service_registry_(this, service_provider_handle.Pass()) {} |
| 13 | |
| 14 Application::Application(MojoHandle service_provider_handle) | |
| 15 : service_registry_( | |
| 16 this, | |
|
darin (slow to review)
2014/06/12 16:11:51
nit: 4 spaces indent from "service_registry_"?
DaveMoore
2014/06/12 16:28:14
Done.
| |
| 17 mojo::MakeScopedHandle( | |
| 18 MessagePipeHandle(service_provider_handle)).Pass()) {} | |
| 19 | |
| 20 Application::~Application() {} | |
| 21 | |
| 22 bool Application::IsConnectionValid(const mojo::String& service_name, | |
| 23 const mojo::String& requestor_url) { | |
| 24 return true; | |
| 13 } | 25 } |
| 14 | 26 |
| 15 Application::Application(MojoHandle service_provider_handle) | 27 void Application::BindServiceProvider( |
| 16 : internal::ServiceConnectorBase::Owner( | 28 ScopedMessagePipeHandle service_provider_handle) { |
| 17 mojo::MakeScopedHandle( | 29 service_registry_.BindServiceProvider(service_provider_handle.Pass()); |
| 18 MessagePipeHandle(service_provider_handle)).Pass()) {} | |
| 19 | |
| 20 Application::~Application() { | |
| 21 for (NameToServiceConnectorMap::iterator i = | |
| 22 name_to_service_connector_.begin(); | |
| 23 i != name_to_service_connector_.end(); ++i) { | |
| 24 delete i->second; | |
| 25 } | |
| 26 name_to_service_connector_.clear(); | |
| 27 } | 30 } |
| 28 | 31 |
| 29 void Application::Initialize() {} | 32 void Application::Initialize() {} |
| 30 | 33 |
| 31 void Application::AddServiceConnector( | |
| 32 internal::ServiceConnectorBase* service_connector) { | |
| 33 name_to_service_connector_[service_connector->name()] = service_connector; | |
| 34 set_service_connector_owner(service_connector, this); | |
| 35 } | |
| 36 | |
| 37 void Application::RemoveServiceConnector( | |
| 38 internal::ServiceConnectorBase* service_connector) { | |
| 39 NameToServiceConnectorMap::iterator it = | |
| 40 name_to_service_connector_.find(service_connector->name()); | |
| 41 assert(it != name_to_service_connector_.end()); | |
| 42 delete it->second; | |
| 43 name_to_service_connector_.erase(it); | |
| 44 if (name_to_service_connector_.empty()) | |
| 45 service_provider_.reset(); | |
| 46 } | |
| 47 | |
| 48 void Application::BindServiceProvider( | |
| 49 ScopedMessagePipeHandle service_provider_handle) { | |
| 50 service_provider_.Bind(service_provider_handle.Pass()); | |
| 51 service_provider_.set_client(this); | |
| 52 } | |
| 53 | |
| 54 void Application::ConnectToService(const mojo::String& service_url, | |
| 55 const mojo::String& service_name, | |
| 56 ScopedMessagePipeHandle client_handle, | |
| 57 const mojo::String& requestor_url) { | |
| 58 internal::ServiceConnectorBase* service_connector = | |
| 59 name_to_service_connector_[service_name]; | |
| 60 assert(service_connector); | |
| 61 // requestor_url is ignored because the service_connector stores the url | |
| 62 // of the requestor safely. | |
| 63 return service_connector->ConnectToService( | |
| 64 service_url, service_name, client_handle.Pass()); | |
| 65 } | |
| 66 | |
| 67 } // namespace mojo | 34 } // namespace mojo |
| OLD | NEW |