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

Side by Side Diff: services/service_manager/public/cpp/binder_registry.h

Issue 2859343003: Enable overriding interface binders for any services running in current process. (Closed)
Patch Set: Address nit Created 3 years, 7 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_
6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "mojo/public/cpp/system/message_pipe.h" 15 #include "mojo/public/cpp/system/message_pipe.h"
16 #include "services/service_manager/public/cpp/interface_binder.h" 16 #include "services/service_manager/public/cpp/interface_binder.h"
17 17
18 namespace service_manager { 18 namespace service_manager {
19 19
20 class InterfaceBinder;
21 struct BindSourceInfo; 20 struct BindSourceInfo;
22 21
23 class BinderRegistry { 22 class BinderRegistry {
24 public: 23 public:
25 using Binder = base::Callback<void(const std::string&, 24 using Binder = base::Callback<void(const BindSourceInfo&,
26 mojo::ScopedMessagePipeHandle)>; 25 const std::string&,
26 mojo::ScopedMessagePipeHandle)>;
27 27
28 BinderRegistry(); 28 BinderRegistry();
29 ~BinderRegistry(); 29 ~BinderRegistry();
30 30
31 template <typename Interface> 31 template <typename Interface>
32 void AddInterface( 32 void AddInterface(
33 const base::Callback<void(const BindSourceInfo&, 33 const base::Callback<void(const BindSourceInfo&,
34 mojo::InterfaceRequest<Interface>)>& callback, 34 mojo::InterfaceRequest<Interface>)>& callback,
35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner =
36 nullptr) { 36 nullptr) {
37 SetInterfaceBinder( 37 SetInterfaceBinder(
38 Interface::Name_, 38 Interface::Name_,
39 base::MakeUnique<CallbackBinder<Interface>>(callback, task_runner)); 39 base::MakeUnique<CallbackBinder<Interface>>(callback, task_runner));
40 } 40 }
41 void AddInterface( 41 void AddInterface(
42 const std::string& interface_name, 42 const std::string& interface_name,
43 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback, 43 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback,
44 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = nullptr); 44 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = nullptr);
45 45
46 void AddInterface(
47 const std::string& interface_name,
48 const Binder& binder_callback,
49 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = nullptr);
50
46 // Removes the specified interface from the registry. This has no effect on 51 // Removes the specified interface from the registry. This has no effect on
47 // bindings already completed. 52 // bindings already completed.
48 template <typename Interface> 53 template <typename Interface>
49 void RemoveInterface() { 54 void RemoveInterface() {
50 RemoveInterface(Interface::Name_); 55 RemoveInterface(Interface::Name_);
51 } 56 }
52 void RemoveInterface(const std::string& interface_name); 57 void RemoveInterface(const std::string& interface_name);
53 58
54 // Returns true if an InterfaceBinder is registered for |interface_name|. 59 // Returns true if an InterfaceBinder is registered for |interface_name|.
55 bool CanBindInterface(const std::string& interface_name) const; 60 bool CanBindInterface(const std::string& interface_name) const;
(...skipping 18 matching lines...) Expand all
74 79
75 base::WeakPtrFactory<BinderRegistry> weak_factory_; 80 base::WeakPtrFactory<BinderRegistry> weak_factory_;
76 81
77 DISALLOW_COPY_AND_ASSIGN(BinderRegistry); 82 DISALLOW_COPY_AND_ASSIGN(BinderRegistry);
78 }; 83 };
79 84
80 85
81 } // namespace service_manager 86 } // namespace service_manager
82 87
83 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ 88 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698