| 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/service_provider_impl.h" | 5 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 6 | 6 |
| 7 #include "mojo/public/cpp/application/lib/service_connector.h" | 7 #include "mojo/public/cpp/application/lib/service_connector.h" |
| 8 #include "mojo/public/cpp/application/lib/weak_service_provider.h" | 8 #include "mojo/public/cpp/application/lib/weak_service_provider.h" |
| 9 #include "mojo/public/cpp/environment/logging.h" | 9 #include "mojo/public/cpp/environment/logging.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 | 12 |
| 13 ServiceProviderImpl::ServiceProviderImpl() : remote_(NULL) { | 13 ServiceProviderImpl::ServiceProviderImpl() |
| 14 : application_connection_(NULL), remote_(NULL) { |
| 15 } |
| 16 |
| 17 ServiceProviderImpl::ServiceProviderImpl( |
| 18 ApplicationConnection* application_connection) |
| 19 : application_connection_(application_connection), remote_(NULL) { |
| 14 } | 20 } |
| 15 | 21 |
| 16 ServiceProviderImpl::~ServiceProviderImpl() { | 22 ServiceProviderImpl::~ServiceProviderImpl() { |
| 17 } | 23 } |
| 18 | 24 |
| 19 ServiceProvider* ServiceProviderImpl::CreateRemoteServiceProvider() { | 25 ServiceProvider* ServiceProviderImpl::CreateRemoteServiceProvider() { |
| 20 // TODO(beng): it sure would be nice if this method could return a scoped_ptr. | 26 // TODO(beng): it sure would be nice if this method could return a scoped_ptr. |
| 21 MOJO_DCHECK(!remote_); | 27 MOJO_DCHECK(!remote_); |
| 22 remote_ = new internal::WeakServiceProvider(this, client()); | 28 remote_ = new internal::WeakServiceProvider(this, client()); |
| 23 return remote_; | 29 return remote_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 } | 44 } |
| 39 | 45 |
| 40 void ServiceProviderImpl::OnConnectionError() { | 46 void ServiceProviderImpl::OnConnectionError() { |
| 41 ClearRemote(); | 47 ClearRemote(); |
| 42 } | 48 } |
| 43 | 49 |
| 44 void ServiceProviderImpl::AddServiceConnector( | 50 void ServiceProviderImpl::AddServiceConnector( |
| 45 internal::ServiceConnectorBase* service_connector) { | 51 internal::ServiceConnectorBase* service_connector) { |
| 46 RemoveServiceConnector(service_connector); | 52 RemoveServiceConnector(service_connector); |
| 47 service_connectors_[service_connector->name()] = service_connector; | 53 service_connectors_[service_connector->name()] = service_connector; |
| 48 // TODO(beng): perhaps take app connection thru ctor?? | 54 service_connector->set_application_connection(application_connection_); |
| 49 service_connector->set_application_connection(NULL); | |
| 50 } | 55 } |
| 51 | 56 |
| 52 void ServiceProviderImpl::RemoveServiceConnector( | 57 void ServiceProviderImpl::RemoveServiceConnector( |
| 53 internal::ServiceConnectorBase* service_connector) { | 58 internal::ServiceConnectorBase* service_connector) { |
| 54 NameToServiceConnectorMap::iterator it = | 59 NameToServiceConnectorMap::iterator it = |
| 55 service_connectors_.find(service_connector->name()); | 60 service_connectors_.find(service_connector->name()); |
| 56 if (it == service_connectors_.end()) | 61 if (it == service_connectors_.end()) |
| 57 return; | 62 return; |
| 58 delete it->second; | 63 delete it->second; |
| 59 service_connectors_.erase(it); | 64 service_connectors_.erase(it); |
| 60 } | 65 } |
| 61 | 66 |
| 62 void ServiceProviderImpl::ClearRemote() { | 67 void ServiceProviderImpl::ClearRemote() { |
| 63 if (remote_) { | 68 if (remote_) { |
| 64 remote_->Clear(); | 69 remote_->Clear(); |
| 65 remote_ = NULL; | 70 remote_ = NULL; |
| 66 } | 71 } |
| 67 } | 72 } |
| 68 | 73 |
| 69 } // namespace mojo | 74 } // namespace mojo |
| OLD | NEW |