OLD | NEW |
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 <utility> | 10 #include <utility> |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 const NewSessionCallback& callback) { | 295 const NewSessionCallback& callback) { |
296 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) | 296 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) |
297 return kInvalidRequestSessionId; | 297 return kInvalidRequestSessionId; |
298 | 298 |
299 int request_id = GetNextRequestSessionId(); | 299 int request_id = GetNextRequestSessionId(); |
300 pending_join_session_cbs_[request_id].reset( | 300 pending_join_session_cbs_[request_id].reset( |
301 new NewSessionCallbackWrapper(callback)); | 301 new NewSessionCallbackWrapper(callback)); |
302 return request_id; | 302 return request_id; |
303 } | 303 } |
304 | 304 |
305 void PresentationServiceImpl::ListenForConnectionStateChangeAndChangeState( | 305 void PresentationServiceImpl::ListenForConnectionStateChange( |
306 const PresentationSessionInfo& connection) { | 306 const PresentationSessionInfo& connection) { |
307 if (controller_delegate_) { | 307 if (controller_delegate_) { |
308 controller_delegate_->ListenForConnectionStateChange( | 308 controller_delegate_->ListenForConnectionStateChange( |
309 render_process_id_, render_frame_id_, connection, | 309 render_process_id_, render_frame_id_, connection, |
310 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, | 310 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, |
311 weak_factory_.GetWeakPtr(), connection)); | 311 weak_factory_.GetWeakPtr(), connection)); |
312 OnConnectionStateChanged(connection, | |
313 PresentationConnectionStateChangeInfo( | |
314 PRESENTATION_CONNECTION_STATE_CONNECTED)); | |
315 } | 312 } |
316 } | 313 } |
317 | 314 |
318 void PresentationServiceImpl::OnStartSessionSucceeded( | 315 void PresentationServiceImpl::OnStartSessionSucceeded( |
319 int request_session_id, | 316 int request_session_id, |
320 const PresentationSessionInfo& session_info) { | 317 const PresentationSessionInfo& session_info) { |
321 if (request_session_id != start_session_request_id_) | 318 if (request_session_id != start_session_request_id_) |
322 return; | 319 return; |
323 | 320 |
324 CHECK(pending_start_session_cb_.get()); | 321 CHECK(pending_start_session_cb_.get()); |
325 pending_start_session_cb_->Run( | 322 pending_start_session_cb_->Run( |
326 blink::mojom::PresentationSessionInfo::From(session_info), | 323 blink::mojom::PresentationSessionInfo::From(session_info), |
327 blink::mojom::PresentationErrorPtr()); | 324 blink::mojom::PresentationErrorPtr()); |
328 ListenForConnectionStateChangeAndChangeState(session_info); | 325 ListenForConnectionStateChange(session_info); |
329 pending_start_session_cb_.reset(); | 326 pending_start_session_cb_.reset(); |
330 start_session_request_id_ = kInvalidRequestSessionId; | 327 start_session_request_id_ = kInvalidRequestSessionId; |
331 } | 328 } |
332 | 329 |
333 void PresentationServiceImpl::OnStartSessionError( | 330 void PresentationServiceImpl::OnStartSessionError( |
334 int request_session_id, | 331 int request_session_id, |
335 const PresentationError& error) { | 332 const PresentationError& error) { |
336 if (request_session_id != start_session_request_id_) | 333 if (request_session_id != start_session_request_id_) |
337 return; | 334 return; |
338 | 335 |
339 CHECK(pending_start_session_cb_.get()); | 336 CHECK(pending_start_session_cb_.get()); |
340 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), | 337 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), |
341 blink::mojom::PresentationError::From(error)); | 338 blink::mojom::PresentationError::From(error)); |
342 pending_start_session_cb_.reset(); | 339 pending_start_session_cb_.reset(); |
343 start_session_request_id_ = kInvalidRequestSessionId; | 340 start_session_request_id_ = kInvalidRequestSessionId; |
344 } | 341 } |
345 | 342 |
346 void PresentationServiceImpl::OnJoinSessionSucceeded( | 343 void PresentationServiceImpl::OnJoinSessionSucceeded( |
347 int request_session_id, | 344 int request_session_id, |
348 const PresentationSessionInfo& session_info) { | 345 const PresentationSessionInfo& session_info) { |
349 if (RunAndEraseJoinSessionMojoCallback( | 346 if (RunAndEraseJoinSessionMojoCallback( |
350 request_session_id, | 347 request_session_id, |
351 blink::mojom::PresentationSessionInfo::From(session_info), | 348 blink::mojom::PresentationSessionInfo::From(session_info), |
352 blink::mojom::PresentationErrorPtr())) { | 349 blink::mojom::PresentationErrorPtr())) { |
353 ListenForConnectionStateChangeAndChangeState(session_info); | 350 ListenForConnectionStateChange(session_info); |
354 } | 351 } |
355 } | 352 } |
356 | 353 |
357 void PresentationServiceImpl::OnJoinSessionError( | 354 void PresentationServiceImpl::OnJoinSessionError( |
358 int request_session_id, | 355 int request_session_id, |
359 const PresentationError& error) { | 356 const PresentationError& error) { |
360 RunAndEraseJoinSessionMojoCallback( | 357 RunAndEraseJoinSessionMojoCallback( |
361 request_session_id, blink::mojom::PresentationSessionInfoPtr(), | 358 request_session_id, blink::mojom::PresentationSessionInfoPtr(), |
362 blink::mojom::PresentationError::From(error)); | 359 blink::mojom::PresentationError::From(error)); |
363 } | 360 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 489 |
493 void PresentationServiceImpl::SetPresentationConnection( | 490 void PresentationServiceImpl::SetPresentationConnection( |
494 blink::mojom::PresentationSessionInfoPtr session, | 491 blink::mojom::PresentationSessionInfoPtr session, |
495 blink::mojom::PresentationConnectionPtr connection) { | 492 blink::mojom::PresentationConnectionPtr connection) { |
496 DVLOG(2) << "SetPresentationConnection"; | 493 DVLOG(2) << "SetPresentationConnection"; |
497 | 494 |
498 if (!controller_delegate_) | 495 if (!controller_delegate_) |
499 return; | 496 return; |
500 | 497 |
501 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); | 498 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); |
502 controller_delegate_->ConnectToOffscreenPresentation( | 499 controller_delegate_->ConnectToPresentation(render_process_id_, |
503 render_process_id_, render_frame_id_, session_info, | 500 render_frame_id_, session_info, |
504 std::move(connection)); | 501 std::move(connection)); |
505 } | 502 } |
506 | 503 |
507 void PresentationServiceImpl::OnSessionMessages( | 504 void PresentationServiceImpl::OnSessionMessages( |
508 const PresentationSessionInfo& session, | 505 const PresentationSessionInfo& session, |
509 const ScopedVector<PresentationSessionMessage>& messages, | 506 const ScopedVector<PresentationSessionMessage>& messages, |
510 bool pass_ownership) { | 507 bool pass_ownership) { |
511 DCHECK(client_); | 508 DCHECK(client_); |
512 DVLOG(2) << "OnSessionMessages" | 509 DVLOG(2) << "OnSessionMessages" |
513 << " [id]: " << session.presentation_id; | 510 << " [id]: " << session.presentation_id; |
514 std::vector<blink::mojom::SessionMessagePtr> mojo_messages(messages.size()); | 511 std::vector<blink::mojom::SessionMessagePtr> mojo_messages(messages.size()); |
515 std::transform(messages.begin(), messages.end(), mojo_messages.begin(), | 512 std::transform(messages.begin(), messages.end(), mojo_messages.begin(), |
516 [pass_ownership](PresentationSessionMessage* message) { | 513 [pass_ownership](PresentationSessionMessage* message) { |
517 return ToMojoSessionMessage(message, pass_ownership); | 514 return ToMojoSessionMessage(message, pass_ownership); |
518 }); | 515 }); |
519 | 516 |
520 client_->OnSessionMessagesReceived( | 517 client_->OnSessionMessagesReceived( |
521 blink::mojom::PresentationSessionInfo::From(session), | 518 blink::mojom::PresentationSessionInfo::From(session), |
522 std::move(mojo_messages)); | 519 std::move(mojo_messages)); |
523 } | 520 } |
524 | 521 |
525 void PresentationServiceImpl::OnReceiverConnectionAvailable( | 522 void PresentationServiceImpl::OnReceiverConnectionAvailable( |
526 const content::PresentationSessionInfo& session_info, | 523 const content::PresentationSessionInfo& session_info, |
527 PresentationConnectionPtr&& controller) { | 524 PresentationConnectionPtr&& controller) { |
528 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable"; | 525 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable"; |
| 526 |
| 527 client_->OnReceiverConnectionAvailable( |
| 528 blink::mojom::PresentationSessionInfo::From(session_info), |
| 529 std::move(controller)); |
529 } | 530 } |
530 | 531 |
531 void PresentationServiceImpl::DidNavigateAnyFrame( | 532 void PresentationServiceImpl::DidNavigateAnyFrame( |
532 content::RenderFrameHost* render_frame_host, | 533 content::RenderFrameHost* render_frame_host, |
533 const content::LoadCommittedDetails& details, | 534 const content::LoadCommittedDetails& details, |
534 const content::FrameNavigateParams& params) { | 535 const content::FrameNavigateParams& params) { |
535 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; | 536 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; |
536 if (!FrameMatches(render_frame_host)) | 537 if (!FrameMatches(render_frame_host)) |
537 return; | 538 return; |
538 | 539 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 controller_delegate_ = nullptr; | 606 controller_delegate_ = nullptr; |
606 receiver_delegate_ = nullptr; | 607 receiver_delegate_ = nullptr; |
607 Reset(); | 608 Reset(); |
608 } | 609 } |
609 | 610 |
610 void PresentationServiceImpl::OnDefaultPresentationStarted( | 611 void PresentationServiceImpl::OnDefaultPresentationStarted( |
611 const PresentationSessionInfo& connection) { | 612 const PresentationSessionInfo& connection) { |
612 DCHECK(client_.get()); | 613 DCHECK(client_.get()); |
613 client_->OnDefaultSessionStarted( | 614 client_->OnDefaultSessionStarted( |
614 blink::mojom::PresentationSessionInfo::From(connection)); | 615 blink::mojom::PresentationSessionInfo::From(connection)); |
615 ListenForConnectionStateChangeAndChangeState(connection); | 616 ListenForConnectionStateChange(connection); |
616 } | 617 } |
617 | 618 |
618 PresentationServiceImpl::ScreenAvailabilityListenerImpl:: | 619 PresentationServiceImpl::ScreenAvailabilityListenerImpl:: |
619 ScreenAvailabilityListenerImpl(const GURL& availability_url, | 620 ScreenAvailabilityListenerImpl(const GURL& availability_url, |
620 PresentationServiceImpl* service) | 621 PresentationServiceImpl* service) |
621 : availability_url_(availability_url), service_(service) { | 622 : availability_url_(availability_url), service_(service) { |
622 DCHECK(service_); | 623 DCHECK(service_); |
623 DCHECK(service_->client_.get()); | 624 DCHECK(service_->client_.get()); |
624 } | 625 } |
625 | 626 |
(...skipping 29 matching lines...) Expand all Loading... |
655 | 656 |
656 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( | 657 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( |
657 blink::mojom::PresentationSessionInfoPtr session, | 658 blink::mojom::PresentationSessionInfoPtr session, |
658 blink::mojom::PresentationErrorPtr error) { | 659 blink::mojom::PresentationErrorPtr error) { |
659 DCHECK(!callback_.is_null()); | 660 DCHECK(!callback_.is_null()); |
660 callback_.Run(std::move(session), std::move(error)); | 661 callback_.Run(std::move(session), std::move(error)); |
661 callback_.Reset(); | 662 callback_.Reset(); |
662 } | 663 } |
663 | 664 |
664 } // namespace content | 665 } // namespace content |
OLD | NEW |