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

Side by Side Diff: mojo/public/cpp/bindings/strong_binding.h

Issue 2062333002: mojo::Callback -> base::Callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 | « mojo/public/cpp/bindings/lib/shared_ptr.h ('k') | mojo/public/cpp/bindings/tests/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 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 MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "mojo/public/cpp/bindings/binding.h" 13 #include "mojo/public/cpp/bindings/binding.h"
13 #include "mojo/public/cpp/bindings/callback.h" 14 #include "mojo/public/cpp/bindings/callback.h"
14 #include "mojo/public/cpp/bindings/interface_ptr.h" 15 #include "mojo/public/cpp/bindings/interface_ptr.h"
15 #include "mojo/public/cpp/bindings/interface_request.h" 16 #include "mojo/public/cpp/bindings/interface_request.h"
16 #include "mojo/public/cpp/bindings/lib/filter_chain.h" 17 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
17 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" 18 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
18 #include "mojo/public/cpp/bindings/lib/router.h" 19 #include "mojo/public/cpp/bindings/lib/router.h"
19 #include "mojo/public/cpp/system/core.h" 20 #include "mojo/public/cpp/system/core.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 StrongBinding(Interface* impl, InterfaceRequest<Interface> request) 66 StrongBinding(Interface* impl, InterfaceRequest<Interface> request)
66 : StrongBinding(impl) { 67 : StrongBinding(impl) {
67 Bind(std::move(request)); 68 Bind(std::move(request));
68 } 69 }
69 70
70 ~StrongBinding() {} 71 ~StrongBinding() {}
71 72
72 void Bind(ScopedMessagePipeHandle handle) { 73 void Bind(ScopedMessagePipeHandle handle) {
73 DCHECK(!binding_.is_bound()); 74 DCHECK(!binding_.is_bound());
74 binding_.Bind(std::move(handle)); 75 binding_.Bind(std::move(handle));
75 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 76 binding_.set_connection_error_handler(
77 base::Bind(&StrongBinding::OnConnectionError, base::Unretained(this)));
76 } 78 }
77 79
78 void Bind(InterfacePtr<Interface>* ptr) { 80 void Bind(InterfacePtr<Interface>* ptr) {
79 DCHECK(!binding_.is_bound()); 81 DCHECK(!binding_.is_bound());
80 binding_.Bind(ptr); 82 binding_.Bind(ptr);
81 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 83 binding_.set_connection_error_handler(
84 base::Bind(&StrongBinding::OnConnectionError, base::Unretained(this)));
82 } 85 }
83 86
84 void Bind(InterfaceRequest<Interface> request) { 87 void Bind(InterfaceRequest<Interface> request) {
85 DCHECK(!binding_.is_bound()); 88 DCHECK(!binding_.is_bound());
86 binding_.Bind(std::move(request)); 89 binding_.Bind(std::move(request));
87 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 90 binding_.set_connection_error_handler(
91 base::Bind(&StrongBinding::OnConnectionError, base::Unretained(this)));
88 } 92 }
89 93
90 bool WaitForIncomingMethodCall() { 94 bool WaitForIncomingMethodCall() {
91 return binding_.WaitForIncomingMethodCall(); 95 return binding_.WaitForIncomingMethodCall();
92 } 96 }
93 97
94 // Note: The error handler must not delete the interface implementation. 98 // Note: The error handler must not delete the interface implementation.
95 // 99 //
96 // This method may only be called after this StrongBinding has been bound to a 100 // This method may only be called after this StrongBinding has been bound to a
97 // message pipe. 101 // message pipe.
98 void set_connection_error_handler(const Closure& error_handler) { 102 void set_connection_error_handler(const Closure& error_handler) {
99 DCHECK(binding_.is_bound()); 103 DCHECK(binding_.is_bound());
100 connection_error_handler_ = error_handler; 104 connection_error_handler_ = error_handler;
101 } 105 }
102 106
103 Interface* impl() { return binding_.impl(); } 107 Interface* impl() { return binding_.impl(); }
104 // Exposed for testing, should not generally be used. 108 // Exposed for testing, should not generally be used.
105 internal::Router* internal_router() { return binding_.internal_router(); } 109 internal::Router* internal_router() { return binding_.internal_router(); }
106 110
107 void OnConnectionError() { 111 void OnConnectionError() {
108 connection_error_handler_.Run(); 112 if (!connection_error_handler_.is_null())
113 connection_error_handler_.Run();
109 delete binding_.impl(); 114 delete binding_.impl();
110 } 115 }
111 116
112 private: 117 private:
113 Closure connection_error_handler_; 118 Closure connection_error_handler_;
114 Binding<Interface> binding_; 119 Binding<Interface> binding_;
115 120
116 DISALLOW_COPY_AND_ASSIGN(StrongBinding); 121 DISALLOW_COPY_AND_ASSIGN(StrongBinding);
117 }; 122 };
118 123
119 } // namespace mojo 124 } // namespace mojo
120 125
121 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ 126 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/shared_ptr.h ('k') | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698