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 CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | |
| 6 #define CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/strings/string_piece.h" | |
| 12 #include "mojo/public/cpp/bindings/interface_ptr.h" | |
| 13 #include "mojo/public/cpp/system/core.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 // A ServiceRegistry exposes local services that have been added using | |
| 18 // AddService to a paired remote ServiceRegistry and provides local access to | |
| 19 // services exposed by the remote ServiceRegistry through ConnectTo. | |
| 20 class ServiceRegistry { | |
| 21 public: | |
| 22 virtual ~ServiceRegistry() {} | |
| 23 | |
| 24 // Make the service created by |service_factory| available to the remote | |
|
darin (slow to review)
2014/06/12 05:27:12
nit: Would help to clarify that the callback is ru
Sam McNally
2014/06/12 08:56:40
Done.
| |
| 25 // InterfaceProvider. | |
| 26 template <typename Interface> | |
| 27 void AddService(const base::Callback<void(mojo::ScopedMessagePipeHandle)> | |
|
darin (slow to review)
2014/06/12 05:27:12
Since we know the interface here, I wonder if it m
Sam McNally
2014/06/12 08:56:40
Done.
| |
| 28 service_factory) { | |
| 29 AddService(Interface::Name_, service_factory); | |
| 30 } | |
| 31 virtual void AddService( | |
| 32 const std::string& service_name, | |
| 33 const base::Callback<void(mojo::ScopedMessagePipeHandle)> | |
| 34 service_factory) = 0; | |
| 35 | |
| 36 // Remove future access to the service implementing Interface. Existing | |
| 37 // connections to the service are unaffected. | |
| 38 template <typename Interface> | |
| 39 void RemoveService() { | |
| 40 RemoveService(Interface::Name_); | |
| 41 } | |
| 42 virtual void RemoveService(const std::string& service_name) = 0; | |
| 43 | |
| 44 // Connect to an interface provided by the remote interface provider. | |
| 45 template <typename Interface> | |
| 46 void GetInterface(mojo::InterfacePtr<Interface>* ptr) { | |
| 47 mojo::MessagePipe pipe; | |
| 48 ptr->Bind(pipe.handle0.Pass()); | |
| 49 GetInterface(Interface::Name_, pipe.handle1.Pass()); | |
| 50 } | |
| 51 virtual void GetInterface(const base::StringPiece& name, | |
| 52 mojo::ScopedMessagePipeHandle handle) = 0; | |
| 53 }; | |
| 54 | |
| 55 } // namespace content | |
| 56 | |
| 57 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | |
| OLD | NEW |