Index: content/public/common/service_registry.h |
diff --git a/content/public/common/service_registry.h b/content/public/common/service_registry.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c1da2f3083bcef9ed930d415bc0d24ab53b95bc9 |
--- /dev/null |
+++ b/content/public/common/service_registry.h |
@@ -0,0 +1,57 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
+#define CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
+ |
+#include <string> |
+ |
+#include "base/callback.h" |
+#include "base/strings/string_piece.h" |
+#include "mojo/public/cpp/bindings/interface_ptr.h" |
+#include "mojo/public/cpp/system/core.h" |
+ |
+namespace content { |
+ |
+// A ServiceRegistry exposes local services that have been added using |
+// AddService to a paired remote ServiceRegistry and provides local access to |
+// services exposed by the remote ServiceRegistry through ConnectTo. |
+class ServiceRegistry { |
+ public: |
+ virtual ~ServiceRegistry() {} |
+ |
+ // 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.
|
+ // InterfaceProvider. |
+ template <typename Interface> |
+ 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.
|
+ service_factory) { |
+ AddService(Interface::Name_, service_factory); |
+ } |
+ virtual void AddService( |
+ const std::string& service_name, |
+ const base::Callback<void(mojo::ScopedMessagePipeHandle)> |
+ service_factory) = 0; |
+ |
+ // Remove future access to the service implementing Interface. Existing |
+ // connections to the service are unaffected. |
+ template <typename Interface> |
+ void RemoveService() { |
+ RemoveService(Interface::Name_); |
+ } |
+ virtual void RemoveService(const std::string& service_name) = 0; |
+ |
+ // Connect to an interface provided by the remote interface provider. |
+ template <typename Interface> |
+ void GetInterface(mojo::InterfacePtr<Interface>* ptr) { |
+ mojo::MessagePipe pipe; |
+ ptr->Bind(pipe.handle0.Pass()); |
+ GetInterface(Interface::Name_, pipe.handle1.Pass()); |
+ } |
+ virtual void GetInterface(const base::StringPiece& name, |
+ mojo::ScopedMessagePipeHandle handle) = 0; |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |