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

Side by Side Diff: mojo/public/cpp/bindings/lib/router.cc

Issue 2114523002: Move more Mojo bindings helpers out of internal namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@group-controller
Patch Set: rebase 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
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 #include "mojo/public/cpp/bindings/lib/router.h" 5 #include "mojo/public/cpp/bindings/lib/router.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 task_runner_->PostTask(FROM_HERE, 53 task_runner_->PostTask(FROM_HERE,
54 base::Bind(&Router::RaiseError, router_)); 54 base::Bind(&Router::RaiseError, router_));
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 // MessageReceiver implementation: 59 // MessageReceiver implementation:
60 bool Accept(Message* message) override { 60 bool Accept(Message* message) override {
61 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 61 DCHECK(task_runner_->RunsTasksOnCurrentThread());
62 accept_was_invoked_ = true; 62 accept_was_invoked_ = true;
63 DCHECK(message->has_flag(kMessageIsResponse)); 63 DCHECK(message->has_flag(Message::kFlagIsResponse));
64 64
65 bool result = false; 65 bool result = false;
66 66
67 if (router_) 67 if (router_)
68 result = router_->Accept(message); 68 result = router_->Accept(message);
69 69
70 return result; 70 return result;
71 } 71 }
72 72
73 // MessageReceiverWithStatus implementation: 73 // MessageReceiverWithStatus implementation:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 connector_.AllowWokenUpBySyncWatchOnSameThread(); 135 connector_.AllowWokenUpBySyncWatchOnSameThread();
136 connector_.set_incoming_receiver(filters_.GetHead()); 136 connector_.set_incoming_receiver(filters_.GetHead());
137 connector_.set_connection_error_handler( 137 connector_.set_connection_error_handler(
138 base::Bind(&Router::OnConnectionError, base::Unretained(this))); 138 base::Bind(&Router::OnConnectionError, base::Unretained(this)));
139 } 139 }
140 140
141 Router::~Router() {} 141 Router::~Router() {}
142 142
143 bool Router::Accept(Message* message) { 143 bool Router::Accept(Message* message) {
144 DCHECK(thread_checker_.CalledOnValidThread()); 144 DCHECK(thread_checker_.CalledOnValidThread());
145 DCHECK(!message->has_flag(kMessageExpectsResponse)); 145 DCHECK(!message->has_flag(Message::kFlagExpectsResponse));
146 return connector_.Accept(message); 146 return connector_.Accept(message);
147 } 147 }
148 148
149 bool Router::AcceptWithResponder(Message* message, MessageReceiver* responder) { 149 bool Router::AcceptWithResponder(Message* message, MessageReceiver* responder) {
150 DCHECK(thread_checker_.CalledOnValidThread()); 150 DCHECK(thread_checker_.CalledOnValidThread());
151 DCHECK(message->has_flag(kMessageExpectsResponse)); 151 DCHECK(message->has_flag(Message::kFlagExpectsResponse));
152 152
153 // Reserve 0 in case we want it to convey special meaning in the future. 153 // Reserve 0 in case we want it to convey special meaning in the future.
154 uint64_t request_id = next_request_id_++; 154 uint64_t request_id = next_request_id_++;
155 if (request_id == 0) 155 if (request_id == 0)
156 request_id = next_request_id_++; 156 request_id = next_request_id_++;
157 157
158 bool is_sync = message->has_flag(kMessageIsSync); 158 bool is_sync = message->has_flag(Message::kFlagIsSync);
159 message->set_request_id(request_id); 159 message->set_request_id(request_id);
160 if (!connector_.Accept(message)) 160 if (!connector_.Accept(message))
161 return false; 161 return false;
162 162
163 if (!is_sync) { 163 if (!is_sync) {
164 // We assume ownership of |responder|. 164 // We assume ownership of |responder|.
165 async_responders_[request_id] = base::WrapUnique(responder); 165 async_responders_[request_id] = base::WrapUnique(responder);
166 return true; 166 return true;
167 } 167 }
168 168
(...skipping 26 matching lines...) Expand all
195 DCHECK(thread_checker_.CalledOnValidThread()); 195 DCHECK(thread_checker_.CalledOnValidThread());
196 testing_mode_ = true; 196 testing_mode_ = true;
197 connector_.set_enforce_errors_from_incoming_receiver(false); 197 connector_.set_enforce_errors_from_incoming_receiver(false);
198 } 198 }
199 199
200 bool Router::HandleIncomingMessage(Message* message) { 200 bool Router::HandleIncomingMessage(Message* message) {
201 DCHECK(thread_checker_.CalledOnValidThread()); 201 DCHECK(thread_checker_.CalledOnValidThread());
202 202
203 const bool during_sync_call = 203 const bool during_sync_call =
204 connector_.during_sync_handle_watcher_callback(); 204 connector_.during_sync_handle_watcher_callback();
205 if (!message->has_flag(kMessageIsSync) && 205 if (!message->has_flag(Message::kFlagIsSync) &&
206 (during_sync_call || !pending_messages_.empty())) { 206 (during_sync_call || !pending_messages_.empty())) {
207 std::unique_ptr<Message> pending_message(new Message); 207 std::unique_ptr<Message> pending_message(new Message);
208 message->MoveTo(pending_message.get()); 208 message->MoveTo(pending_message.get());
209 pending_messages_.push(std::move(pending_message)); 209 pending_messages_.push(std::move(pending_message));
210 210
211 if (!pending_task_for_messages_) { 211 if (!pending_task_for_messages_) {
212 pending_task_for_messages_ = true; 212 pending_task_for_messages_ = true;
213 connector_.task_runner()->PostTask( 213 connector_.task_runner()->PostTask(
214 FROM_HERE, base::Bind(&Router::HandleQueuedMessages, 214 FROM_HERE, base::Bind(&Router::HandleQueuedMessages,
215 weak_factory_.GetWeakPtr())); 215 weak_factory_.GetWeakPtr()));
(...skipping 27 matching lines...) Expand all
243 pending_task_for_messages_ = false; 243 pending_task_for_messages_ = false;
244 244
245 // We may have already seen a connection error from the connector, but 245 // We may have already seen a connection error from the connector, but
246 // haven't notified the user because we want to process all the queued 246 // haven't notified the user because we want to process all the queued
247 // messages first. We should do it now. 247 // messages first. We should do it now.
248 if (connector_.encountered_error() && !encountered_error_) 248 if (connector_.encountered_error() && !encountered_error_)
249 OnConnectionError(); 249 OnConnectionError();
250 } 250 }
251 251
252 bool Router::HandleMessageInternal(Message* message) { 252 bool Router::HandleMessageInternal(Message* message) {
253 if (message->has_flag(kMessageExpectsResponse)) { 253 if (message->has_flag(Message::kFlagExpectsResponse)) {
254 if (!incoming_receiver_) 254 if (!incoming_receiver_)
255 return false; 255 return false;
256 256
257 MessageReceiverWithStatus* responder = new ResponderThunk( 257 MessageReceiverWithStatus* responder = new ResponderThunk(
258 weak_factory_.GetWeakPtr(), connector_.task_runner()); 258 weak_factory_.GetWeakPtr(), connector_.task_runner());
259 bool ok = incoming_receiver_->AcceptWithResponder(message, responder); 259 bool ok = incoming_receiver_->AcceptWithResponder(message, responder);
260 if (!ok) 260 if (!ok)
261 delete responder; 261 delete responder;
262 return ok; 262 return ok;
263 263
264 } else if (message->has_flag(kMessageIsResponse)) { 264 } else if (message->has_flag(Message::kFlagIsResponse)) {
265 uint64_t request_id = message->request_id(); 265 uint64_t request_id = message->request_id();
266 266
267 if (message->has_flag(kMessageIsSync)) { 267 if (message->has_flag(Message::kFlagIsSync)) {
268 auto it = sync_responses_.find(request_id); 268 auto it = sync_responses_.find(request_id);
269 if (it == sync_responses_.end()) { 269 if (it == sync_responses_.end()) {
270 DCHECK(testing_mode_); 270 DCHECK(testing_mode_);
271 return false; 271 return false;
272 } 272 }
273 it->second->response.reset(new Message()); 273 it->second->response.reset(new Message());
274 message->MoveTo(it->second->response.get()); 274 message->MoveTo(it->second->response.get());
275 *it->second->response_received = true; 275 *it->second->response_received = true;
276 return true; 276 return true;
277 } 277 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 encountered_error_ = true; 315 encountered_error_ = true;
316 if (!error_handler_.is_null()) 316 if (!error_handler_.is_null())
317 error_handler_.Run(); 317 error_handler_.Run();
318 } 318 }
319 319
320 // ---------------------------------------------------------------------------- 320 // ----------------------------------------------------------------------------
321 321
322 } // namespace internal 322 } // namespace internal
323 } // namespace mojo 323 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.h ('k') | mojo/public/cpp/bindings/lib/sync_handle_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698