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.
5 #ifndef CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_
6 #define CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_
13 #include "base/callback.h"
14 #include "base/compiler_specific.h"
15 #include "base/memory/weak_ptr.h"
16 #include "content/public/common/service_registry.h"
17 #include "mojo/application/public/interfaces/service_provider.mojom.h"
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
19 #include "third_party/mojo/src/mojo/public/cpp/system/core.h"
23 class CONTENT_EXPORT ServiceRegistryImpl
24 : public ServiceRegistry
,
25 public NON_EXPORTED_BASE(mojo::ServiceProvider
) {
27 ServiceRegistryImpl();
28 ~ServiceRegistryImpl() override
;
30 // Binds this ServiceProvider implementation to a message pipe endpoint.
31 void Bind(mojo::InterfaceRequest
<mojo::ServiceProvider
> request
);
33 // Binds to a remote ServiceProvider. This will expose added services to the
34 // remote ServiceProvider with the corresponding handle and enable
35 // ConnectToRemoteService to provide access to services exposed by the remote
37 void BindRemoteServiceProvider(mojo::ServiceProviderPtr service_provider
);
39 // ServiceRegistry overrides.
40 void AddService(const std::string
& service_name
,
41 const base::Callback
<void(mojo::ScopedMessagePipeHandle
)>
42 service_factory
) override
;
43 void RemoveService(const std::string
& service_name
) override
;
44 void ConnectToRemoteService(const base::StringPiece
& service_name
,
45 mojo::ScopedMessagePipeHandle handle
) override
;
49 base::WeakPtr
<ServiceRegistry
> GetWeakPtr();
52 // mojo::ServiceProvider overrides.
53 void ConnectToService(const mojo::String
& name
,
54 mojo::ScopedMessagePipeHandle client_handle
) override
;
56 void OnConnectionError();
58 mojo::Binding
<mojo::ServiceProvider
> binding_
;
59 mojo::ServiceProviderPtr remote_provider_
;
61 std::map
<std::string
, base::Callback
<void(mojo::ScopedMessagePipeHandle
)> >
63 std::queue
<std::pair
<std::string
, mojo::MessagePipeHandle
> >
66 base::WeakPtrFactory
<ServiceRegistry
> weak_factory_
;
69 } // namespace content
71 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_