| 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 #ifndef CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
| 6 #define CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 6 #define CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 #include "mojo/public/cpp/bindings/interface_ptr.h" | 15 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 15 #include "mojo/public/cpp/bindings/interface_request.h" | 16 #include "mojo/public/cpp/bindings/interface_request.h" |
| 16 #include "mojo/public/cpp/system/core.h" | 17 #include "mojo/public/cpp/system/core.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 // A ServiceRegistry exposes local services that have been added using | 21 // A ServiceRegistry exposes local services that have been added using |
| 21 // AddService to a paired remote ServiceRegistry and provides local access to | 22 // AddService to a paired remote ServiceRegistry and provides local access to |
| (...skipping 29 matching lines...) Expand all Loading... |
| 51 // Connect to an interface provided by the remote interface provider. | 52 // Connect to an interface provided by the remote interface provider. |
| 52 template <typename Interface> | 53 template <typename Interface> |
| 53 void GetRemoteInterface(mojo::InterfacePtr<Interface>* ptr) { | 54 void GetRemoteInterface(mojo::InterfacePtr<Interface>* ptr) { |
| 54 mojo::MessagePipe pipe; | 55 mojo::MessagePipe pipe; |
| 55 ptr->Bind(pipe.handle0.Pass()); | 56 ptr->Bind(pipe.handle0.Pass()); |
| 56 GetRemoteInterface(Interface::Name_, pipe.handle1.Pass()); | 57 GetRemoteInterface(Interface::Name_, pipe.handle1.Pass()); |
| 57 } | 58 } |
| 58 virtual void GetRemoteInterface(const base::StringPiece& name, | 59 virtual void GetRemoteInterface(const base::StringPiece& name, |
| 59 mojo::ScopedMessagePipeHandle handle) = 0; | 60 mojo::ScopedMessagePipeHandle handle) = 0; |
| 60 | 61 |
| 62 virtual base::WeakPtr<ServiceRegistry> GetWeakPtr() = 0; |
| 63 |
| 61 private: | 64 private: |
| 62 template <typename Interface> | 65 template <typename Interface> |
| 63 static void ForwardToServiceFactory( | 66 static void ForwardToServiceFactory( |
| 64 const base::Callback<void(mojo::InterfaceRequest<Interface>)> | 67 const base::Callback<void(mojo::InterfaceRequest<Interface>)> |
| 65 service_factory, | 68 service_factory, |
| 66 mojo::ScopedMessagePipeHandle handle) { | 69 mojo::ScopedMessagePipeHandle handle) { |
| 67 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); | 70 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); |
| 68 } | 71 } |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 } // namespace content | 74 } // namespace content |
| 72 | 75 |
| 73 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 76 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
| OLD | NEW |