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 "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
18 #include "third_party/mojo/src/mojo/public/cpp/system/core.h"
19 #include "third_party/mojo/src/mojo/public/interfaces/application/service_provider.mojom.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
;
47 base::WeakPtr
<ServiceRegistry
> GetWeakPtr();
50 // mojo::ServiceProvider overrides.
51 void ConnectToService(const mojo::String
& name
,
52 mojo::ScopedMessagePipeHandle client_handle
) override
;
54 mojo::Binding
<mojo::ServiceProvider
> binding_
;
55 mojo::ServiceProviderPtr remote_provider_
;
57 std::map
<std::string
, base::Callback
<void(mojo::ScopedMessagePipeHandle
)> >
59 std::queue
<std::pair
<std::string
, mojo::MessagePipeHandle
> >
62 base::WeakPtrFactory
<ServiceRegistry
> weak_factory_
;
65 } // namespace content
67 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_