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

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

Issue 2119963002: Move mus to //services/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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 | « services/navigation/view_impl.cc ('k') | services/ui/BUILD.gn » ('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 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_SHELL_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_ 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_
6 #define SERVICES_SHELL_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_ 6 #define SERVICES_SHELL_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"
(...skipping 11 matching lines...) Expand all
22 base::Callback<void(mojo::InterfaceRequest<Interface>)>; 22 base::Callback<void(mojo::InterfaceRequest<Interface>)>;
23 23
24 explicit CallbackBinder( 24 explicit CallbackBinder(
25 const BindCallback& callback, 25 const BindCallback& callback,
26 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) 26 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
27 : callback_(callback), task_runner_(task_runner) {} 27 : callback_(callback), task_runner_(task_runner) {}
28 ~CallbackBinder() override {} 28 ~CallbackBinder() override {}
29 29
30 private: 30 private:
31 // InterfaceBinder: 31 // InterfaceBinder:
32 void BindInterface(Connection* connection, 32 void BindInterface(
33 Connection* connection,
33 const std::string& interface_name, 34 const std::string& interface_name,
34 mojo::ScopedMessagePipeHandle handle) override { 35 mojo::ScopedMessagePipeHandle handle) override {
35 mojo::InterfaceRequest<Interface> request = 36 mojo::InterfaceRequest<Interface> request =
36 mojo::MakeRequest<Interface>(std::move(handle)); 37 mojo::MakeRequest<Interface>(std::move(handle));
37 if (task_runner_) { 38 if (task_runner_) {
38 task_runner_->PostTask( 39 task_runner_->PostTask(
39 FROM_HERE, 40 FROM_HERE,
40 base::Bind(&CallbackBinder::RunCallbackOnTaskRunner, callback_, 41 base::Bind(&CallbackBinder::RunCallbackOnTaskRunner, callback_,
41 base::Passed(&request))); 42 base::Passed(&request)));
42 return; 43 return;
43 } 44 }
44 callback_.Run(std::move(request)); 45 callback_.Run(std::move(request));
45 } 46 }
46 47
47 static void RunCallbackOnTaskRunner( 48 static void RunCallbackOnTaskRunner(
48 const BindCallback& callback, 49 const BindCallback& callback,
49 mojo::InterfaceRequest<Interface> client) { 50 mojo::InterfaceRequest<Interface> client) {
50 callback.Run(std::move(client)); 51 callback.Run(std::move(client));
51 } 52 }
52 53
53 const BindCallback callback_; 54 const BindCallback callback_;
54 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
55 DISALLOW_COPY_AND_ASSIGN(CallbackBinder); 56 DISALLOW_COPY_AND_ASSIGN(CallbackBinder);
56 }; 57 };
57 58
58 class GenericCallbackBinder : public InterfaceBinder { 59 class GenericCallbackBinder : public InterfaceBinder {
59 public: 60 public:
60 // Method that binds a request for Interface.
61 using BindCallback = base::Callback<void(mojo::ScopedMessagePipeHandle)>; 61 using BindCallback = base::Callback<void(mojo::ScopedMessagePipeHandle)>;
62 62
63 explicit GenericCallbackBinder( 63 explicit GenericCallbackBinder(
64 const BindCallback& callback, 64 const BindCallback& callback,
65 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); 65 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
66 ~GenericCallbackBinder() override; 66 ~GenericCallbackBinder() override;
67 67
68 private: 68 private:
69 // InterfaceBinder: 69 // InterfaceBinder:
70 void BindInterface( 70 void BindInterface(Connection* connection,
71 Connection* connection, 71 const std::string& interface_name,
72 const std::string& interface_name,
73 mojo::ScopedMessagePipeHandle handle) override; 72 mojo::ScopedMessagePipeHandle handle) override;
74 73
75 static void RunCallbackOnTaskRunner( 74 static void RunCallbackOnTaskRunner(
76 const BindCallback& callback, 75 const BindCallback& callback,
77 mojo::ScopedMessagePipeHandle client_handle); 76 mojo::ScopedMessagePipeHandle client_handle);
78 77
79 const BindCallback callback_; 78 const BindCallback callback_;
80 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 79 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
81 DISALLOW_COPY_AND_ASSIGN(GenericCallbackBinder); 80 DISALLOW_COPY_AND_ASSIGN(GenericCallbackBinder);
82 }; 81 };
83 82
84 } // namespace internal 83 } // namespace internal
85 } // namespace shell 84 } // namespace shell
86 85
87 #endif // SERVICES_SHELL_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_ 86 #endif // SERVICES_SHELL_PUBLIC_CPP_LIB_CALLBACK_BINDER_H_
OLDNEW
« no previous file with comments | « services/navigation/view_impl.cc ('k') | services/ui/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698