Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: content/common/mojo/service_registry_impl.h

Issue 1470153002: [mojo] Enable ServiceRegistryImpl to override remote services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-testing-3
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/common/mojo/service_registry_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ 5 #ifndef CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_
6 #define CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ 6 #define CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "content/public/common/service_registry.h" 16 #include "content/public/common/service_registry.h"
17 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/public/cpp/system/core.h" 18 #include "mojo/public/cpp/system/core.h"
19 #include "mojo/shell/public/interfaces/service_provider.mojom.h" 19 #include "mojo/shell/public/interfaces/service_provider.mojom.h"
20 20
21 namespace content { 21 namespace content {
22 22
23 class CONTENT_EXPORT ServiceRegistryImpl 23 class CONTENT_EXPORT ServiceRegistryImpl
24 : public ServiceRegistry, 24 : public ServiceRegistry,
25 public NON_EXPORTED_BASE(mojo::ServiceProvider) { 25 public NON_EXPORTED_BASE(mojo::ServiceProvider) {
26 public: 26 public:
27 using ServiceFactory = base::Callback<void(mojo::ScopedMessagePipeHandle)>;
28
27 ServiceRegistryImpl(); 29 ServiceRegistryImpl();
28 ~ServiceRegistryImpl() override; 30 ~ServiceRegistryImpl() override;
29 31
30 // Binds this ServiceProvider implementation to a message pipe endpoint. 32 // Binds this ServiceProvider implementation to a message pipe endpoint.
31 void Bind(mojo::InterfaceRequest<mojo::ServiceProvider> request); 33 void Bind(mojo::InterfaceRequest<mojo::ServiceProvider> request);
32 34
33 // Binds to a remote ServiceProvider. This will expose added services to the 35 // Binds to a remote ServiceProvider. This will expose added services to the
34 // remote ServiceProvider with the corresponding handle and enable 36 // remote ServiceProvider with the corresponding handle and enable
35 // ConnectToRemoteService to provide access to services exposed by the remote 37 // ConnectToRemoteService to provide access to services exposed by the remote
36 // ServiceProvider. 38 // ServiceProvider.
37 void BindRemoteServiceProvider(mojo::ServiceProviderPtr service_provider); 39 void BindRemoteServiceProvider(mojo::ServiceProviderPtr service_provider);
38 40
41 // Registers a local service factory to intercept ConnectToRemoteService
42 // requests instead of actually connecting to the remote registry. Used only
43 // for testing.
44 void AddServiceOverrideForTesting(const std::string& service_name,
45 const ServiceFactory& service_factory);
46
39 // ServiceRegistry overrides. 47 // ServiceRegistry overrides.
40 void AddService(const std::string& service_name, 48 void AddService(const std::string& service_name,
41 const base::Callback<void(mojo::ScopedMessagePipeHandle)> 49 const ServiceFactory service_factory) override;
42 service_factory) override;
43 void RemoveService(const std::string& service_name) override; 50 void RemoveService(const std::string& service_name) override;
44 void ConnectToRemoteService(const base::StringPiece& service_name, 51 void ConnectToRemoteService(const base::StringPiece& service_name,
45 mojo::ScopedMessagePipeHandle handle) override; 52 mojo::ScopedMessagePipeHandle handle) override;
46 53
47 bool IsBound() const; 54 bool IsBound() const;
48 55
49 base::WeakPtr<ServiceRegistry> GetWeakPtr(); 56 base::WeakPtr<ServiceRegistry> GetWeakPtr();
50 57
51 private: 58 private:
52 // mojo::ServiceProvider overrides. 59 // mojo::ServiceProvider overrides.
53 void ConnectToService(const mojo::String& name, 60 void ConnectToService(const mojo::String& name,
54 mojo::ScopedMessagePipeHandle client_handle) override; 61 mojo::ScopedMessagePipeHandle client_handle) override;
55 62
56 void OnConnectionError(); 63 void OnConnectionError();
57 64
58 mojo::Binding<mojo::ServiceProvider> binding_; 65 mojo::Binding<mojo::ServiceProvider> binding_;
59 mojo::ServiceProviderPtr remote_provider_; 66 mojo::ServiceProviderPtr remote_provider_;
60 67
61 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > 68 std::map<std::string, ServiceFactory> service_factories_;
62 service_factories_;
63 std::queue<std::pair<std::string, mojo::MessagePipeHandle> > 69 std::queue<std::pair<std::string, mojo::MessagePipeHandle> >
64 pending_connects_; 70 pending_connects_;
65 71
72 std::map<std::string, ServiceFactory> service_overrides_;
73
66 base::WeakPtrFactory<ServiceRegistry> weak_factory_; 74 base::WeakPtrFactory<ServiceRegistry> weak_factory_;
67 }; 75 };
68 76
69 } // namespace content 77 } // namespace content
70 78
71 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ 79 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/mojo/service_registry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698