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

Side by Side Diff: services/service_manager/public/cpp/lib/callback_binder.h

Issue 2851173004: Eliminate bind callback that doesn't take a BindSourceInfo parameter. (Closed)
Patch Set: . 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_LIB_CALLBACK_BINDER_H_ 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_
6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_ 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "mojo/public/cpp/bindings/interface_request.h" 11 #include "mojo/public/cpp/bindings/interface_request.h"
12 #include "services/service_manager/public/cpp/interface_binder.h" 12 #include "services/service_manager/public/cpp/interface_binder.h"
13 13
14 namespace service_manager { 14 namespace service_manager {
15 namespace internal { 15 namespace internal {
16 16
17 template <typename Interface> 17 template <typename Interface>
18 class CallbackBinderWithSourceInfo : public InterfaceBinder { 18 class CallbackBinder : public InterfaceBinder {
19 public: 19 public:
20 using BindCallback = base::Callback<void(const BindSourceInfo&, 20 using BindCallback = base::Callback<void(const BindSourceInfo&,
21 mojo::InterfaceRequest<Interface>)>; 21 mojo::InterfaceRequest<Interface>)>;
22 22
23 CallbackBinderWithSourceInfo(
24 const BindCallback& callback,
25 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
26 : callback_(callback), task_runner_(task_runner) {}
27 ~CallbackBinderWithSourceInfo() override {}
28
29 private:
30 // InterfaceBinder:
31 void BindInterface(const BindSourceInfo& source_info,
32 const std::string& interface_name,
33 mojo::ScopedMessagePipeHandle handle) override {
34 mojo::InterfaceRequest<Interface> request =
35 mojo::MakeRequest<Interface>(std::move(handle));
36 if (task_runner_) {
37 task_runner_->PostTask(
38 FROM_HERE,
39 base::Bind(&CallbackBinderWithSourceInfo::RunCallback, callback_,
40 source_info, base::Passed(&request)));
41 } else {
42 RunCallback(callback_, source_info, std::move(request));
43 }
44 }
45
46 static void RunCallback(const BindCallback& callback,
47 const BindSourceInfo& source_info,
48 mojo::InterfaceRequest<Interface> request) {
49 callback.Run(source_info, std::move(request));
50 }
51
52 const BindCallback callback_;
53 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
54 DISALLOW_COPY_AND_ASSIGN(CallbackBinderWithSourceInfo);
55 };
56
57 template <typename Interface>
58 class CallbackBinder : public InterfaceBinder {
59 public:
60 using BindCallback = base::Callback<void(mojo::InterfaceRequest<Interface>)>;
61
62 CallbackBinder(const BindCallback& callback, 23 CallbackBinder(const BindCallback& callback,
63 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) 24 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
64 : callback_(callback), task_runner_(task_runner) {} 25 : callback_(callback), task_runner_(task_runner) {}
65 ~CallbackBinder() override {} 26 ~CallbackBinder() override {}
66 27
67 private: 28 private:
68 // InterfaceBinder: 29 // InterfaceBinder:
69 void BindInterface(const BindSourceInfo& source_info, 30 void BindInterface(const BindSourceInfo& source_info,
70 const std::string& interface_name, 31 const std::string& interface_name,
71 mojo::ScopedMessagePipeHandle handle) override { 32 mojo::ScopedMessagePipeHandle handle) override {
72 mojo::InterfaceRequest<Interface> request = 33 mojo::InterfaceRequest<Interface> request =
73 mojo::MakeRequest<Interface>(std::move(handle)); 34 mojo::MakeRequest<Interface>(std::move(handle));
74 if (task_runner_) { 35 if (task_runner_) {
75 task_runner_->PostTask(FROM_HERE, 36 task_runner_->PostTask(FROM_HERE,
76 base::Bind(&CallbackBinder::RunCallback, callback_, 37 base::Bind(&CallbackBinder::RunCallback, callback_,
77 base::Passed(&request))); 38 source_info, base::Passed(&request)));
78 } else { 39 } else {
79 RunCallback(callback_, std::move(request)); 40 RunCallback(callback_, source_info, std::move(request));
80 } 41 }
81 } 42 }
82 43
83 static void RunCallback(const BindCallback& callback, 44 static void RunCallback(const BindCallback& callback,
45 const BindSourceInfo& source_info,
84 mojo::InterfaceRequest<Interface> request) { 46 mojo::InterfaceRequest<Interface> request) {
85 callback.Run(std::move(request)); 47 callback.Run(source_info, std::move(request));
86 } 48 }
87 49
88 const BindCallback callback_; 50 const BindCallback callback_;
89 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
90 DISALLOW_COPY_AND_ASSIGN(CallbackBinder); 52 DISALLOW_COPY_AND_ASSIGN(CallbackBinder);
91 }; 53 };
92 54
93 class GenericCallbackBinder : public InterfaceBinder { 55 class GenericCallbackBinder : public InterfaceBinder {
94 public: 56 public:
95 using BindCallback = base::Callback<void(mojo::ScopedMessagePipeHandle)>; 57 using BindCallback = base::Callback<void(mojo::ScopedMessagePipeHandle)>;
(...skipping 14 matching lines...) Expand all
110 72
111 const BindCallback callback_; 73 const BindCallback callback_;
112 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 74 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
113 DISALLOW_COPY_AND_ASSIGN(GenericCallbackBinder); 75 DISALLOW_COPY_AND_ASSIGN(GenericCallbackBinder);
114 }; 76 };
115 77
116 } // namespace internal 78 } // namespace internal
117 } // namespace service_manager 79 } // namespace service_manager
118 80
119 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_ 81 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/interface_provider.h ('k') | services/shape_detection/barcode_detection_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698