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

Side by Side Diff: mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h

Issue 2080083002: Revert of Deletes mojo::Callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/interface_ptr.h ('k') | mojo/public/cpp/bindings/lib/binding_state.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> // For |std::swap()|. 10 #include <algorithm> // For |std::swap()|.
11 #include <memory> 11 #include <memory>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback_forward.h"
16 #include "base/macros.h" 15 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
18 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
19 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
20 #include "mojo/public/cpp/bindings/associated_group.h" 19 #include "mojo/public/cpp/bindings/associated_group.h"
21 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 20 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
21 #include "mojo/public/cpp/bindings/callback.h"
22 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" 22 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
23 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" 23 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h"
24 #include "mojo/public/cpp/bindings/lib/interface_id.h" 24 #include "mojo/public/cpp/bindings/lib/interface_id.h"
25 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 25 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
26 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 26 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
27 #include "mojo/public/cpp/system/message_pipe.h" 27 #include "mojo/public/cpp/system/message_pipe.h"
28 28
29 namespace mojo { 29 namespace mojo {
30 namespace internal { 30 namespace internal {
31 31
(...skipping 12 matching lines...) Expand all
44 return proxy_.get(); 44 return proxy_.get();
45 } 45 }
46 46
47 uint32_t version() const { return version_; } 47 uint32_t version() const { return version_; }
48 48
49 uint32_t interface_id() const { 49 uint32_t interface_id() const {
50 DCHECK(is_bound()); 50 DCHECK(is_bound());
51 return endpoint_client_->interface_id(); 51 return endpoint_client_->interface_id();
52 } 52 }
53 53
54 void QueryVersion(const base::Callback<void(uint32_t)>& callback) { 54 void QueryVersion(const Callback<void(uint32_t)>& callback) {
55 // Do a static cast in case the interface contains methods with the same 55 // Do a static cast in case the interface contains methods with the same
56 // name. It is safe to capture |this| because the callback won't be run 56 // name. It is safe to capture |this| because the callback won't be run
57 // after this object goes away. 57 // after this object goes away.
58 static_cast<ControlMessageProxy*>(proxy_.get()) 58 static_cast<ControlMessageProxy*>(proxy_.get())
59 ->QueryVersion(base::Bind(&AssociatedInterfacePtrState::OnQueryVersion, 59 ->QueryVersion(base::Bind(&AssociatedInterfacePtrState::OnQueryVersion,
60 base::Unretained(this), callback)); 60 base::Unretained(this), callback));
61 } 61 }
62 62
63 void RequireVersion(uint32_t version) { 63 void RequireVersion(uint32_t version) {
64 if (version <= version_) 64 if (version <= version_)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 proxy_.reset(); 101 proxy_.reset();
102 return AssociatedInterfacePtrInfo<Interface>(std::move(handle), version_); 102 return AssociatedInterfacePtrInfo<Interface>(std::move(handle), version_);
103 } 103 }
104 104
105 bool is_bound() const { return !!endpoint_client_; } 105 bool is_bound() const { return !!endpoint_client_; }
106 106
107 bool encountered_error() const { 107 bool encountered_error() const {
108 return endpoint_client_ ? endpoint_client_->encountered_error() : false; 108 return endpoint_client_ ? endpoint_client_->encountered_error() : false;
109 } 109 }
110 110
111 void set_connection_error_handler(const base::Closure& error_handler) { 111 void set_connection_error_handler(const Closure& error_handler) {
112 DCHECK(endpoint_client_); 112 DCHECK(endpoint_client_);
113 endpoint_client_->set_connection_error_handler(error_handler); 113 endpoint_client_->set_connection_error_handler(error_handler);
114 } 114 }
115 115
116 // Returns true if bound and awaiting a response to a message. 116 // Returns true if bound and awaiting a response to a message.
117 bool has_pending_callbacks() const { 117 bool has_pending_callbacks() const {
118 return endpoint_client_ && endpoint_client_->has_pending_responders(); 118 return endpoint_client_ && endpoint_client_->has_pending_responders();
119 } 119 }
120 120
121 AssociatedGroup* associated_group() { 121 AssociatedGroup* associated_group() {
122 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; 122 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr;
123 } 123 }
124 124
125 private: 125 private:
126 using Proxy = typename Interface::Proxy_; 126 using Proxy = typename Interface::Proxy_;
127 127
128 void OnQueryVersion(const base::Callback<void(uint32_t)>& callback, 128 void OnQueryVersion(const Callback<void(uint32_t)>& callback,
129 uint32_t version) { 129 uint32_t version) {
130 version_ = version; 130 version_ = version;
131 callback.Run(version); 131 callback.Run(version);
132 } 132 }
133 133
134 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; 134 std::unique_ptr<InterfaceEndpointClient> endpoint_client_;
135 std::unique_ptr<Proxy> proxy_; 135 std::unique_ptr<Proxy> proxy_;
136 136
137 uint32_t version_; 137 uint32_t version_;
138 138
139 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState); 139 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState);
140 }; 140 };
141 141
142 } // namespace internal 142 } // namespace internal
143 } // namespace mojo 143 } // namespace mojo
144 144
145 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ 145 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/interface_ptr.h ('k') | mojo/public/cpp/bindings/lib/binding_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698