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

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

Issue 2080513002: Deletes mojo::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
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 InvokeNewSessionMojoCallbackWithError( 115 void InvokeNewSessionCallbackWithError(
116 const NewSessionMojoCallback& callback) { 116 const PresentationServiceImpl::NewSessionCallback& 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( 221 void PresentationServiceImpl::StartSession(const mojo::String& presentation_url,
222 const mojo::String& presentation_url, 222 const NewSessionCallback& callback) {
223 const NewSessionMojoCallback& callback) {
224 DVLOG(2) << "StartSession"; 223 DVLOG(2) << "StartSession";
225 if (!delegate_) { 224 if (!delegate_) {
226 callback.Run( 225 callback.Run(
227 blink::mojom::PresentationSessionInfoPtr(), 226 blink::mojom::PresentationSessionInfoPtr(),
228 blink::mojom::PresentationError::From(PresentationError( 227 blink::mojom::PresentationError::From(PresentationError(
229 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 228 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
230 return; 229 return;
231 } 230 }
232 231
233 // There is a StartSession request in progress. To avoid queueing up 232 // There is a StartSession request in progress. To avoid queueing up
234 // requests, the incoming request is rejected. 233 // requests, the incoming request is rejected.
235 if (start_session_request_id_ != kInvalidRequestSessionId) { 234 if (start_session_request_id_ != kInvalidRequestSessionId) {
236 InvokeNewSessionMojoCallbackWithError(callback); 235 InvokeNewSessionCallbackWithError(callback);
237 return; 236 return;
238 } 237 }
239 238
240 start_session_request_id_ = GetNextRequestSessionId(); 239 start_session_request_id_ = GetNextRequestSessionId();
241 pending_start_session_cb_.reset(new NewSessionMojoCallbackWrapper(callback)); 240 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback));
242 delegate_->StartSession( 241 delegate_->StartSession(
243 render_process_id_, render_frame_id_, presentation_url, 242 render_process_id_, render_frame_id_, presentation_url,
244 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 243 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
245 weak_factory_.GetWeakPtr(), start_session_request_id_), 244 weak_factory_.GetWeakPtr(), start_session_request_id_),
246 base::Bind(&PresentationServiceImpl::OnStartSessionError, 245 base::Bind(&PresentationServiceImpl::OnStartSessionError,
247 weak_factory_.GetWeakPtr(), start_session_request_id_)); 246 weak_factory_.GetWeakPtr(), start_session_request_id_));
248 } 247 }
249 248
250 void PresentationServiceImpl::JoinSession( 249 void PresentationServiceImpl::JoinSession(
251 const mojo::String& presentation_url, 250 const mojo::String& presentation_url,
252 const mojo::String& presentation_id, 251 const mojo::String& presentation_id,
253 const NewSessionMojoCallback& callback) { 252 const NewSessionCallback& callback) {
254 DVLOG(2) << "JoinSession"; 253 DVLOG(2) << "JoinSession";
255 if (!delegate_) { 254 if (!delegate_) {
256 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 255 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
257 blink::mojom::PresentationError::From(PresentationError( 256 blink::mojom::PresentationError::From(PresentationError(
258 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 257 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
259 "Error joining route: No matching route"))); 258 "Error joining route: No matching route")));
260 return; 259 return;
261 } 260 }
262 261
263 int request_session_id = RegisterJoinSessionCallback(callback); 262 int request_session_id = RegisterJoinSessionCallback(callback);
264 if (request_session_id == kInvalidRequestSessionId) { 263 if (request_session_id == kInvalidRequestSessionId) {
265 InvokeNewSessionMojoCallbackWithError(callback); 264 InvokeNewSessionCallbackWithError(callback);
266 return; 265 return;
267 } 266 }
268 delegate_->JoinSession( 267 delegate_->JoinSession(
269 render_process_id_, 268 render_process_id_,
270 render_frame_id_, 269 render_frame_id_,
271 presentation_url, 270 presentation_url,
272 presentation_id, 271 presentation_id,
273 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, 272 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded,
274 weak_factory_.GetWeakPtr(), request_session_id), 273 weak_factory_.GetWeakPtr(), request_session_id),
275 base::Bind(&PresentationServiceImpl::OnJoinSessionError, 274 base::Bind(&PresentationServiceImpl::OnJoinSessionError,
276 weak_factory_.GetWeakPtr(), request_session_id)); 275 weak_factory_.GetWeakPtr(), request_session_id));
277 } 276 }
278 277
279 int PresentationServiceImpl::RegisterJoinSessionCallback( 278 int PresentationServiceImpl::RegisterJoinSessionCallback(
280 const NewSessionMojoCallback& callback) { 279 const NewSessionCallback& callback) {
281 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) 280 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests)
282 return kInvalidRequestSessionId; 281 return kInvalidRequestSessionId;
283 282
284 int request_id = GetNextRequestSessionId(); 283 int request_id = GetNextRequestSessionId();
285 pending_join_session_cbs_[request_id].reset( 284 pending_join_session_cbs_[request_id].reset(
286 new NewSessionMojoCallbackWrapper(callback)); 285 new NewSessionCallbackWrapper(callback));
287 return request_id; 286 return request_id;
288 } 287 }
289 288
290 void PresentationServiceImpl::ListenForConnectionStateChange( 289 void PresentationServiceImpl::ListenForConnectionStateChange(
291 const PresentationSessionInfo& connection) { 290 const PresentationSessionInfo& connection) {
292 if (delegate_) { 291 if (delegate_) {
293 delegate_->ListenForConnectionStateChange( 292 delegate_->ListenForConnectionStateChange(
294 render_process_id_, render_frame_id_, connection, 293 render_process_id_, render_frame_id_, connection,
295 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, 294 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged,
296 weak_factory_.GetWeakPtr(), connection)); 295 weak_factory_.GetWeakPtr(), connection));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 default_presentation_url_ = new_default_url; 370 default_presentation_url_ = new_default_url;
372 delegate_->SetDefaultPresentationUrl( 371 delegate_->SetDefaultPresentationUrl(
373 render_process_id_, render_frame_id_, new_default_url, 372 render_process_id_, render_frame_id_, new_default_url,
374 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 373 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
375 weak_factory_.GetWeakPtr())); 374 weak_factory_.GetWeakPtr()));
376 } 375 }
377 376
378 void PresentationServiceImpl::SendSessionMessage( 377 void PresentationServiceImpl::SendSessionMessage(
379 blink::mojom::PresentationSessionInfoPtr session, 378 blink::mojom::PresentationSessionInfoPtr session,
380 blink::mojom::SessionMessagePtr session_message, 379 blink::mojom::SessionMessagePtr session_message,
381 const SendMessageMojoCallback& callback) { 380 const SendSessionMessageCallback& callback) {
382 DVLOG(2) << "SendSessionMessage"; 381 DVLOG(2) << "SendSessionMessage";
383 DCHECK(!session_message.is_null()); 382 DCHECK(!session_message.is_null());
384 // send_message_callback_ should be null by now, otherwise resetting of 383 // send_message_callback_ should be null by now, otherwise resetting of
385 // send_message_callback_ with new callback will drop the old callback. 384 // send_message_callback_ with new callback will drop the old callback.
386 if (!delegate_ || send_message_callback_) { 385 if (!delegate_ || send_message_callback_) {
387 callback.Run(false); 386 callback.Run(false);
388 return; 387 return;
389 } 388 }
390 389
391 send_message_callback_.reset(new SendMessageMojoCallback(callback)); 390 send_message_callback_.reset(new SendSessionMessageCallback(callback));
392 delegate_->SendMessage( 391 delegate_->SendMessage(
393 render_process_id_, render_frame_id_, 392 render_process_id_, render_frame_id_,
394 session.To<PresentationSessionInfo>(), 393 session.To<PresentationSessionInfo>(),
395 GetPresentationSessionMessage(std::move(session_message)), 394 GetPresentationSessionMessage(std::move(session_message)),
396 base::Bind(&PresentationServiceImpl::OnSendMessageCallback, 395 base::Bind(&PresentationServiceImpl::OnSendMessageCallback,
397 weak_factory_.GetWeakPtr())); 396 weak_factory_.GetWeakPtr()));
398 } 397 }
399 398
400 void PresentationServiceImpl::OnSendMessageCallback(bool sent) { 399 void PresentationServiceImpl::OnSendMessageCallback(bool sent) {
401 // It is possible that Reset() is invoked before receiving this callback. 400 // It is possible that Reset() is invoked before receiving this callback.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 void PresentationServiceImpl::ScreenAvailabilityListenerImpl 582 void PresentationServiceImpl::ScreenAvailabilityListenerImpl
584 ::OnScreenAvailabilityChanged(bool available) { 583 ::OnScreenAvailabilityChanged(bool available) {
585 service_->client_->OnScreenAvailabilityUpdated(availability_url_, available); 584 service_->client_->OnScreenAvailabilityUpdated(availability_url_, available);
586 } 585 }
587 586
588 void PresentationServiceImpl::ScreenAvailabilityListenerImpl 587 void PresentationServiceImpl::ScreenAvailabilityListenerImpl
589 ::OnScreenAvailabilityNotSupported() { 588 ::OnScreenAvailabilityNotSupported() {
590 service_->client_->OnScreenAvailabilityNotSupported(availability_url_); 589 service_->client_->OnScreenAvailabilityNotSupported(availability_url_);
591 } 590 }
592 591
593 PresentationServiceImpl::NewSessionMojoCallbackWrapper 592 PresentationServiceImpl::NewSessionCallbackWrapper
594 ::NewSessionMojoCallbackWrapper(const NewSessionMojoCallback& callback) 593 ::NewSessionCallbackWrapper(const NewSessionCallback& callback)
595 : callback_(callback) { 594 : callback_(callback) {
596 } 595 }
597 596
598 PresentationServiceImpl::NewSessionMojoCallbackWrapper 597 PresentationServiceImpl::NewSessionCallbackWrapper
599 ::~NewSessionMojoCallbackWrapper() { 598 ::~NewSessionCallbackWrapper() {
600 if (!callback_.is_null()) 599 if (!callback_.is_null())
601 InvokeNewSessionMojoCallbackWithError(callback_); 600 InvokeNewSessionCallbackWithError(callback_);
602 } 601 }
603 602
604 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( 603 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
605 blink::mojom::PresentationSessionInfoPtr session, 604 blink::mojom::PresentationSessionInfoPtr session,
606 blink::mojom::PresentationErrorPtr error) { 605 blink::mojom::PresentationErrorPtr error) {
607 DCHECK(!callback_.is_null()); 606 DCHECK(!callback_.is_null());
608 callback_.Run(std::move(session), std::move(error)); 607 callback_.Run(std::move(session), std::move(error));
609 callback_.Reset(); 608 callback_.Reset();
610 } 609 }
611 610
612 } // namespace content 611 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698