Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_PUBLIC_APPLICATION_EXPORTED_SERVICE_REGISTRY_H_ | |
| 6 #define MOJO_PUBLIC_APPLICATION_EXPORTED_SERVICE_REGISTRY_H_ | |
| 7 | |
| 8 #include "mojo/public/cpp/application/lib/service_connector.h" | |
| 9 #include "mojo/public/interfaces/application/service_provider.mojom.h" | |
| 10 | |
| 11 namespace mojo { | |
| 12 namespace internal { | |
| 13 class ServiceConnectorBase; | |
| 14 } | |
| 15 | |
|
DaveMoore
2014/08/06 21:34:59
Nit: Please provide a comment. On quick inspection
| |
| 16 class RemoteServiceProvider : public ServiceProvider { | |
|
darin (slow to review)
2014/08/06 22:13:29
nit: break this class out into its own .h and .cc
| |
| 17 public: | |
| 18 explicit RemoteServiceProvider(ServiceProvider* service_provider) | |
|
darin (slow to review)
2014/08/06 22:13:29
technically, this is more of a ServiceProvider thu
| |
| 19 : service_provider_(service_provider) {} | |
| 20 virtual ~RemoteServiceProvider() {} | |
| 21 | |
| 22 void Clear() { | |
| 23 service_provider_ = NULL; | |
| 24 } | |
| 25 | |
| 26 virtual void ConnectToService( | |
| 27 const String& service_name, | |
| 28 ScopedMessagePipeHandle client_handle) MOJO_OVERRIDE { | |
| 29 if (service_provider_) | |
| 30 service_provider_->ConnectToService(service_name, client_handle.Pass()); | |
| 31 } | |
| 32 | |
| 33 private: | |
| 34 ServiceProvider* service_provider_; | |
| 35 | |
| 36 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteServiceProvider); | |
| 37 }; | |
| 38 | |
| 39 class ExportedServiceRegistry : public InterfaceImpl<ServiceProvider> { | |
|
darin (slow to review)
2014/08/06 22:13:29
nit: an Impl suffix might be nice here just to pre
| |
| 40 public: | |
| 41 ExportedServiceRegistry(); | |
| 42 virtual ~ExportedServiceRegistry(); | |
| 43 | |
| 44 template <typename Interface> | |
| 45 void AddService(InterfaceFactory<Interface>* factory) { | |
| 46 AddServiceConnector( | |
| 47 new internal::InterfaceFactoryConnector<Interface>(factory)); | |
| 48 } | |
| 49 | |
| 50 void set_remote(RemoteServiceProvider* remote) { remote_ = remote; } | |
|
darin (slow to review)
2014/08/06 22:13:29
hmm, it's not clear what the remote service provid
| |
| 51 | |
| 52 private: | |
| 53 typedef std::map<std::string, internal::ServiceConnectorBase*> | |
| 54 NameToServiceConnectorMap; | |
| 55 | |
| 56 // Overridden from ServiceProvider: | |
| 57 virtual void ConnectToService( | |
| 58 const String& service_name, | |
| 59 ScopedMessagePipeHandle client_handle) MOJO_OVERRIDE; | |
| 60 | |
| 61 // Overridden from InterfaceImpl: | |
| 62 virtual void OnConnectionError() MOJO_OVERRIDE { | |
| 63 if (remote_) | |
|
darin (slow to review)
2014/08/06 22:13:29
nit:
if (remote_) {
remote_->Clear();
remote_
| |
| 64 remote_->Clear(); | |
| 65 remote_ = NULL; | |
| 66 } | |
| 67 | |
| 68 void AddServiceConnector( | |
| 69 internal::ServiceConnectorBase* service_connector); | |
| 70 void RemoveServiceConnector( | |
| 71 internal::ServiceConnectorBase* service_connector); | |
| 72 | |
| 73 NameToServiceConnectorMap service_connectors_; | |
| 74 | |
| 75 RemoteServiceProvider* remote_; | |
| 76 | |
| 77 MOJO_DISALLOW_COPY_AND_ASSIGN(ExportedServiceRegistry); | |
| 78 }; | |
| 79 | |
| 80 } // namespace mojo | |
| 81 | |
| 82 #endif // MOJO_PUBLIC_APPLICATION_EXPORTED_SERVICE_REGISTRY_H_ | |
| OLD | NEW |