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

Side by Side Diff: content/browser/presentation/presentation_service_impl.cc

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
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 #include "content/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 output->data.reset(new std::vector<uint8_t>); 105 output->data.reset(new std::vector<uint8_t>);
106 input->data.Swap(output->data.get()); 106 input->data.Swap(output->data.get());
107 return output; 107 return output;
108 } 108 }
109 } 109 }
110 110
111 NOTREACHED() << "Invalid presentation message type " << input->type; 111 NOTREACHED() << "Invalid presentation message type " << input->type;
112 return output; 112 return output;
113 } 113 }
114 114
115 void InvokeNewSessionCallbackWithError( 115 void InvokeNewSessionMojoCallbackWithError(
116 const PresentationServiceImpl::NewSessionCallback& callback) { 116 const NewSessionMojoCallback& callback) {
117 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 117 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
118 blink::mojom::PresentationError::From(PresentationError( 118 blink::mojom::PresentationError::From(PresentationError(
119 PRESENTATION_ERROR_UNKNOWN, "Internal error"))); 119 PRESENTATION_ERROR_UNKNOWN, "Internal error")));
120 } 120 }
121 121
122 } // namespace 122 } // namespace
123 123
124 PresentationServiceImpl::PresentationServiceImpl( 124 PresentationServiceImpl::PresentationServiceImpl(
125 RenderFrameHost* render_frame_host, 125 RenderFrameHost* render_frame_host,
126 WebContents* web_contents, 126 WebContents* web_contents,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 const std::string& availability_url = url.get(); 211 const std::string& availability_url = url.get();
212 auto listener_it = screen_availability_listeners_.find(availability_url); 212 auto listener_it = screen_availability_listeners_.find(availability_url);
213 if (listener_it == screen_availability_listeners_.end()) 213 if (listener_it == screen_availability_listeners_.end())
214 return; 214 return;
215 215
216 delegate_->RemoveScreenAvailabilityListener( 216 delegate_->RemoveScreenAvailabilityListener(
217 render_process_id_, render_frame_id_, listener_it->second.get()); 217 render_process_id_, render_frame_id_, listener_it->second.get());
218 screen_availability_listeners_.erase(listener_it); 218 screen_availability_listeners_.erase(listener_it);
219 } 219 }
220 220
221 void PresentationServiceImpl::StartSession(const mojo::String& presentation_url, 221 void PresentationServiceImpl::StartSession(
222 const NewSessionCallback& callback) { 222 const mojo::String& presentation_url,
223 const NewSessionMojoCallback& callback) {
223 DVLOG(2) << "StartSession"; 224 DVLOG(2) << "StartSession";
224 if (!delegate_) { 225 if (!delegate_) {
225 callback.Run( 226 callback.Run(
226 blink::mojom::PresentationSessionInfoPtr(), 227 blink::mojom::PresentationSessionInfoPtr(),
227 blink::mojom::PresentationError::From(PresentationError( 228 blink::mojom::PresentationError::From(PresentationError(
228 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 229 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
229 return; 230 return;
230 } 231 }
231 232
232 // There is a StartSession request in progress. To avoid queueing up 233 // There is a StartSession request in progress. To avoid queueing up
233 // requests, the incoming request is rejected. 234 // requests, the incoming request is rejected.
234 if (start_session_request_id_ != kInvalidRequestSessionId) { 235 if (start_session_request_id_ != kInvalidRequestSessionId) {
235 InvokeNewSessionCallbackWithError(callback); 236 InvokeNewSessionMojoCallbackWithError(callback);
236 return; 237 return;
237 } 238 }
238 239
239 start_session_request_id_ = GetNextRequestSessionId(); 240 start_session_request_id_ = GetNextRequestSessionId();
240 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); 241 pending_start_session_cb_.reset(new NewSessionMojoCallbackWrapper(callback));
241 delegate_->StartSession( 242 delegate_->StartSession(
242 render_process_id_, render_frame_id_, presentation_url, 243 render_process_id_, render_frame_id_, presentation_url,
243 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 244 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
244 weak_factory_.GetWeakPtr(), start_session_request_id_), 245 weak_factory_.GetWeakPtr(), start_session_request_id_),
245 base::Bind(&PresentationServiceImpl::OnStartSessionError, 246 base::Bind(&PresentationServiceImpl::OnStartSessionError,
246 weak_factory_.GetWeakPtr(), start_session_request_id_)); 247 weak_factory_.GetWeakPtr(), start_session_request_id_));
247 } 248 }
248 249
249 void PresentationServiceImpl::JoinSession( 250 void PresentationServiceImpl::JoinSession(
250 const mojo::String& presentation_url, 251 const mojo::String& presentation_url,
251 const mojo::String& presentation_id, 252 const mojo::String& presentation_id,
252 const NewSessionCallback& callback) { 253 const NewSessionMojoCallback& callback) {
253 DVLOG(2) << "JoinSession"; 254 DVLOG(2) << "JoinSession";
254 if (!delegate_) { 255 if (!delegate_) {
255 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 256 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
256 blink::mojom::PresentationError::From(PresentationError( 257 blink::mojom::PresentationError::From(PresentationError(
257 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 258 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
258 "Error joining route: No matching route"))); 259 "Error joining route: No matching route")));
259 return; 260 return;
260 } 261 }
261 262
262 int request_session_id = RegisterJoinSessionCallback(callback); 263 int request_session_id = RegisterJoinSessionCallback(callback);
263 if (request_session_id == kInvalidRequestSessionId) { 264 if (request_session_id == kInvalidRequestSessionId) {
264 InvokeNewSessionCallbackWithError(callback); 265 InvokeNewSessionMojoCallbackWithError(callback);
265 return; 266 return;
266 } 267 }
267 delegate_->JoinSession( 268 delegate_->JoinSession(
268 render_process_id_, 269 render_process_id_,
269 render_frame_id_, 270 render_frame_id_,
270 presentation_url, 271 presentation_url,
271 presentation_id, 272 presentation_id,
272 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, 273 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded,
273 weak_factory_.GetWeakPtr(), request_session_id), 274 weak_factory_.GetWeakPtr(), request_session_id),
274 base::Bind(&PresentationServiceImpl::OnJoinSessionError, 275 base::Bind(&PresentationServiceImpl::OnJoinSessionError,
275 weak_factory_.GetWeakPtr(), request_session_id)); 276 weak_factory_.GetWeakPtr(), request_session_id));
276 } 277 }
277 278
278 int PresentationServiceImpl::RegisterJoinSessionCallback( 279 int PresentationServiceImpl::RegisterJoinSessionCallback(
279 const NewSessionCallback& callback) { 280 const NewSessionMojoCallback& callback) {
280 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) 281 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests)
281 return kInvalidRequestSessionId; 282 return kInvalidRequestSessionId;
282 283
283 int request_id = GetNextRequestSessionId(); 284 int request_id = GetNextRequestSessionId();
284 pending_join_session_cbs_[request_id].reset( 285 pending_join_session_cbs_[request_id].reset(
285 new NewSessionCallbackWrapper(callback)); 286 new NewSessionMojoCallbackWrapper(callback));
286 return request_id; 287 return request_id;
287 } 288 }
288 289
289 void PresentationServiceImpl::ListenForConnectionStateChange( 290 void PresentationServiceImpl::ListenForConnectionStateChange(
290 const PresentationSessionInfo& connection) { 291 const PresentationSessionInfo& connection) {
291 if (delegate_) { 292 if (delegate_) {
292 delegate_->ListenForConnectionStateChange( 293 delegate_->ListenForConnectionStateChange(
293 render_process_id_, render_frame_id_, connection, 294 render_process_id_, render_frame_id_, connection,
294 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, 295 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged,
295 weak_factory_.GetWeakPtr(), connection)); 296 weak_factory_.GetWeakPtr(), connection));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 default_presentation_url_ = new_default_url; 371 default_presentation_url_ = new_default_url;
371 delegate_->SetDefaultPresentationUrl( 372 delegate_->SetDefaultPresentationUrl(
372 render_process_id_, render_frame_id_, new_default_url, 373 render_process_id_, render_frame_id_, new_default_url,
373 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 374 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
374 weak_factory_.GetWeakPtr())); 375 weak_factory_.GetWeakPtr()));
375 } 376 }
376 377
377 void PresentationServiceImpl::SendSessionMessage( 378 void PresentationServiceImpl::SendSessionMessage(
378 blink::mojom::PresentationSessionInfoPtr session, 379 blink::mojom::PresentationSessionInfoPtr session,
379 blink::mojom::SessionMessagePtr session_message, 380 blink::mojom::SessionMessagePtr session_message,
380 const SendSessionMessageCallback& callback) { 381 const SendMessageMojoCallback& callback) {
381 DVLOG(2) << "SendSessionMessage"; 382 DVLOG(2) << "SendSessionMessage";
382 DCHECK(!session_message.is_null()); 383 DCHECK(!session_message.is_null());
383 // send_message_callback_ should be null by now, otherwise resetting of 384 // send_message_callback_ should be null by now, otherwise resetting of
384 // send_message_callback_ with new callback will drop the old callback. 385 // send_message_callback_ with new callback will drop the old callback.
385 if (!delegate_ || send_message_callback_) { 386 if (!delegate_ || send_message_callback_) {
386 callback.Run(false); 387 callback.Run(false);
387 return; 388 return;
388 } 389 }
389 390
390 send_message_callback_.reset(new SendSessionMessageCallback(callback)); 391 send_message_callback_.reset(new SendMessageMojoCallback(callback));
391 delegate_->SendMessage( 392 delegate_->SendMessage(
392 render_process_id_, render_frame_id_, 393 render_process_id_, render_frame_id_,
393 session.To<PresentationSessionInfo>(), 394 session.To<PresentationSessionInfo>(),
394 GetPresentationSessionMessage(std::move(session_message)), 395 GetPresentationSessionMessage(std::move(session_message)),
395 base::Bind(&PresentationServiceImpl::OnSendMessageCallback, 396 base::Bind(&PresentationServiceImpl::OnSendMessageCallback,
396 weak_factory_.GetWeakPtr())); 397 weak_factory_.GetWeakPtr()));
397 } 398 }
398 399
399 void PresentationServiceImpl::OnSendMessageCallback(bool sent) { 400 void PresentationServiceImpl::OnSendMessageCallback(bool sent) {
400 // It is possible that Reset() is invoked before receiving this callback. 401 // It is possible that Reset() is invoked before receiving this callback.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 void PresentationServiceImpl::ScreenAvailabilityListenerImpl 583 void PresentationServiceImpl::ScreenAvailabilityListenerImpl
583 ::OnScreenAvailabilityChanged(bool available) { 584 ::OnScreenAvailabilityChanged(bool available) {
584 service_->client_->OnScreenAvailabilityUpdated(availability_url_, available); 585 service_->client_->OnScreenAvailabilityUpdated(availability_url_, available);
585 } 586 }
586 587
587 void PresentationServiceImpl::ScreenAvailabilityListenerImpl 588 void PresentationServiceImpl::ScreenAvailabilityListenerImpl
588 ::OnScreenAvailabilityNotSupported() { 589 ::OnScreenAvailabilityNotSupported() {
589 service_->client_->OnScreenAvailabilityNotSupported(availability_url_); 590 service_->client_->OnScreenAvailabilityNotSupported(availability_url_);
590 } 591 }
591 592
592 PresentationServiceImpl::NewSessionCallbackWrapper 593 PresentationServiceImpl::NewSessionMojoCallbackWrapper
593 ::NewSessionCallbackWrapper(const NewSessionCallback& callback) 594 ::NewSessionMojoCallbackWrapper(const NewSessionMojoCallback& callback)
594 : callback_(callback) { 595 : callback_(callback) {
595 } 596 }
596 597
597 PresentationServiceImpl::NewSessionCallbackWrapper 598 PresentationServiceImpl::NewSessionMojoCallbackWrapper
598 ::~NewSessionCallbackWrapper() { 599 ::~NewSessionMojoCallbackWrapper() {
599 if (!callback_.is_null()) 600 if (!callback_.is_null())
600 InvokeNewSessionCallbackWithError(callback_); 601 InvokeNewSessionMojoCallbackWithError(callback_);
601 } 602 }
602 603
603 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 604 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run(
604 blink::mojom::PresentationSessionInfoPtr session, 605 blink::mojom::PresentationSessionInfoPtr session,
605 blink::mojom::PresentationErrorPtr error) { 606 blink::mojom::PresentationErrorPtr error) {
606 DCHECK(!callback_.is_null()); 607 DCHECK(!callback_.is_null());
607 callback_.Run(std::move(session), std::move(error)); 608 callback_.Run(std::move(session), std::move(error));
608 callback_.Reset(); 609 callback_.Reset();
609 } 610 }
610 611
611 } // namespace content 612 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698