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 "chrome/browser/media/router/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 393 |
394 PresentationFrameManager::~PresentationFrameManager() { | 394 PresentationFrameManager::~PresentationFrameManager() { |
395 for (auto& frame : presentation_frames_) | 395 for (auto& frame : presentation_frames_) |
396 frame.second->OnPresentationServiceDelegateDestroyed(); | 396 frame.second->OnPresentationServiceDelegateDestroyed(); |
397 } | 397 } |
398 | 398 |
399 void PresentationFrameManager::OnPresentationSessionStarted( | 399 void PresentationFrameManager::OnPresentationSessionStarted( |
400 const RenderFrameHostId& render_frame_host_id, | 400 const RenderFrameHostId& render_frame_host_id, |
401 const content::PresentationSessionInfo& session, | 401 const content::PresentationSessionInfo& session, |
402 const MediaRoute::Id& route_id) { | 402 const MediaRoute::Id& route_id) { |
403 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 403 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
404 presentation_frame->OnPresentationSessionStarted(session, route_id); | 404 presentation_frame->OnPresentationSessionStarted(session, route_id); |
405 } | 405 } |
406 | 406 |
407 void PresentationFrameManager::OnDefaultPresentationSessionStarted( | 407 void PresentationFrameManager::OnDefaultPresentationSessionStarted( |
408 const PresentationRequest& request, | 408 const PresentationRequest& request, |
409 const content::PresentationSessionInfo& session, | 409 const content::PresentationSessionInfo& session, |
410 const MediaRoute::Id& route_id) { | 410 const MediaRoute::Id& route_id) { |
411 auto presentation_frame = | 411 auto* presentation_frame = |
412 presentation_frames_.get(request.render_frame_host_id()); | 412 presentation_frames_.get(request.render_frame_host_id()); |
413 if (presentation_frame) | 413 if (presentation_frame) |
414 presentation_frame->OnPresentationSessionStarted(session, route_id); | 414 presentation_frame->OnPresentationSessionStarted(session, route_id); |
415 | 415 |
416 if (default_presentation_request_ && | 416 if (default_presentation_request_ && |
417 default_presentation_request_->Equals(request)) { | 417 default_presentation_request_->Equals(request)) { |
418 default_presentation_started_callback_.Run(session); | 418 default_presentation_started_callback_.Run(session); |
419 } | 419 } |
420 } | 420 } |
421 | 421 |
422 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 422 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
423 const RenderFrameHostId& render_frame_host_id, | 423 const RenderFrameHostId& render_frame_host_id, |
424 const std::string& presentation_id) const { | 424 const std::string& presentation_id) const { |
425 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 425 auto* presentation_frame = presentation_frames_.get(render_frame_host_id); |
426 return presentation_frame ? presentation_frame->GetRouteId(presentation_id) | 426 return presentation_frame ? presentation_frame->GetRouteId(presentation_id) |
427 : ""; | 427 : ""; |
428 } | 428 } |
429 | 429 |
430 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( | 430 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( |
431 const RenderFrameHostId& render_frame_host_id) const { | 431 const RenderFrameHostId& render_frame_host_id) const { |
432 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 432 auto* presentation_frame = presentation_frames_.get(render_frame_host_id); |
433 return presentation_frame ? presentation_frame->GetRouteIds() | 433 return presentation_frame ? presentation_frame->GetRouteIds() |
434 : std::vector<MediaRoute::Id>(); | 434 : std::vector<MediaRoute::Id>(); |
435 } | 435 } |
436 | 436 |
437 bool PresentationFrameManager::SetScreenAvailabilityListener( | 437 bool PresentationFrameManager::SetScreenAvailabilityListener( |
438 const RenderFrameHostId& render_frame_host_id, | 438 const RenderFrameHostId& render_frame_host_id, |
439 content::PresentationScreenAvailabilityListener* listener) { | 439 content::PresentationScreenAvailabilityListener* listener) { |
440 DCHECK(listener); | 440 DCHECK(listener); |
441 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 441 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
442 return presentation_frame->SetScreenAvailabilityListener(listener); | 442 return presentation_frame->SetScreenAvailabilityListener(listener); |
443 } | 443 } |
444 | 444 |
445 bool PresentationFrameManager::RemoveScreenAvailabilityListener( | 445 bool PresentationFrameManager::RemoveScreenAvailabilityListener( |
446 const RenderFrameHostId& render_frame_host_id, | 446 const RenderFrameHostId& render_frame_host_id, |
447 content::PresentationScreenAvailabilityListener* listener) { | 447 content::PresentationScreenAvailabilityListener* listener) { |
448 DCHECK(listener); | 448 DCHECK(listener); |
449 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 449 auto* presentation_frame = presentation_frames_.get(render_frame_host_id); |
450 return presentation_frame && | 450 return presentation_frame && |
451 presentation_frame->RemoveScreenAvailabilityListener(listener); | 451 presentation_frame->RemoveScreenAvailabilityListener(listener); |
452 } | 452 } |
453 | 453 |
454 bool PresentationFrameManager::HasScreenAvailabilityListenerForTest( | 454 bool PresentationFrameManager::HasScreenAvailabilityListenerForTest( |
455 const RenderFrameHostId& render_frame_host_id, | 455 const RenderFrameHostId& render_frame_host_id, |
456 const MediaSource::Id& source_id) const { | 456 const MediaSource::Id& source_id) const { |
457 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 457 auto* presentation_frame = presentation_frames_.get(render_frame_host_id); |
458 return presentation_frame && | 458 return presentation_frame && |
459 presentation_frame->HasScreenAvailabilityListenerForTest(source_id); | 459 presentation_frame->HasScreenAvailabilityListenerForTest(source_id); |
460 } | 460 } |
461 | 461 |
462 void PresentationFrameManager::ListenForConnectionStateChange( | 462 void PresentationFrameManager::ListenForConnectionStateChange( |
463 const RenderFrameHostId& render_frame_host_id, | 463 const RenderFrameHostId& render_frame_host_id, |
464 const content::PresentationSessionInfo& connection, | 464 const content::PresentationSessionInfo& connection, |
465 const content::PresentationConnectionStateChangedCallback& | 465 const content::PresentationConnectionStateChangedCallback& |
466 state_changed_cb) { | 466 state_changed_cb) { |
467 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 467 auto* presentation_frame = presentation_frames_.get(render_frame_host_id); |
468 if (presentation_frame) { | 468 if (presentation_frame) { |
469 presentation_frame->ListenForConnectionStateChange(connection, | 469 presentation_frame->ListenForConnectionStateChange(connection, |
470 state_changed_cb); | 470 state_changed_cb); |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 void PresentationFrameManager::ListenForSessionMessages( | 474 void PresentationFrameManager::ListenForSessionMessages( |
475 const RenderFrameHostId& render_frame_host_id, | 475 const RenderFrameHostId& render_frame_host_id, |
476 const content::PresentationSessionInfo& session, | 476 const content::PresentationSessionInfo& session, |
477 const content::PresentationSessionMessageCallback& message_cb) { | 477 const content::PresentationSessionMessageCallback& message_cb) { |
(...skipping 23 matching lines...) Expand all Loading... |
501 PresentationRequest request(render_frame_host_id, default_presentation_url, | 501 PresentationRequest request(render_frame_host_id, default_presentation_url, |
502 frame_url); | 502 frame_url); |
503 default_presentation_started_callback_ = callback; | 503 default_presentation_started_callback_ = callback; |
504 SetDefaultPresentationRequest(request); | 504 SetDefaultPresentationRequest(request); |
505 } | 505 } |
506 } | 506 } |
507 | 507 |
508 void PresentationFrameManager::AddDelegateObserver( | 508 void PresentationFrameManager::AddDelegateObserver( |
509 const RenderFrameHostId& render_frame_host_id, | 509 const RenderFrameHostId& render_frame_host_id, |
510 DelegateObserver* observer) { | 510 DelegateObserver* observer) { |
511 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 511 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
512 presentation_frame->set_delegate_observer(observer); | 512 presentation_frame->set_delegate_observer(observer); |
513 } | 513 } |
514 | 514 |
515 void PresentationFrameManager::RemoveDelegateObserver( | 515 void PresentationFrameManager::RemoveDelegateObserver( |
516 const RenderFrameHostId& render_frame_host_id) { | 516 const RenderFrameHostId& render_frame_host_id) { |
517 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 517 auto* presentation_frame = presentation_frames_.get(render_frame_host_id); |
518 if (presentation_frame) { | 518 if (presentation_frame) { |
519 presentation_frame->set_delegate_observer(nullptr); | 519 presentation_frame->set_delegate_observer(nullptr); |
520 presentation_frames_.erase(render_frame_host_id); | 520 presentation_frames_.erase(render_frame_host_id); |
521 } | 521 } |
522 } | 522 } |
523 | 523 |
524 void PresentationFrameManager::AddDefaultPresentationRequestObserver( | 524 void PresentationFrameManager::AddDefaultPresentationRequestObserver( |
525 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* | 525 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* |
526 observer) { | 526 observer) { |
527 default_presentation_request_observers_.AddObserver(observer); | 527 default_presentation_request_observers_.AddObserver(observer); |
528 } | 528 } |
529 | 529 |
530 void PresentationFrameManager::RemoveDefaultPresentationRequestObserver( | 530 void PresentationFrameManager::RemoveDefaultPresentationRequestObserver( |
531 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* | 531 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* |
532 observer) { | 532 observer) { |
533 default_presentation_request_observers_.RemoveObserver(observer); | 533 default_presentation_request_observers_.RemoveObserver(observer); |
534 } | 534 } |
535 | 535 |
536 void PresentationFrameManager::Reset( | 536 void PresentationFrameManager::Reset( |
537 const RenderFrameHostId& render_frame_host_id) { | 537 const RenderFrameHostId& render_frame_host_id) { |
538 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 538 auto* presentation_frame = presentation_frames_.get(render_frame_host_id); |
539 if (presentation_frame) | 539 if (presentation_frame) |
540 presentation_frame->Reset(); | 540 presentation_frame->Reset(); |
541 | 541 |
542 if (default_presentation_request_ && | 542 if (default_presentation_request_ && |
543 render_frame_host_id == | 543 render_frame_host_id == |
544 default_presentation_request_->render_frame_host_id()) { | 544 default_presentation_request_->render_frame_host_id()) { |
545 ClearDefaultPresentationRequest(); | 545 ClearDefaultPresentationRequest(); |
546 } | 546 } |
547 } | 547 } |
548 | 548 |
549 void PresentationFrameManager::RemoveConnection( | 549 void PresentationFrameManager::RemoveConnection( |
550 const RenderFrameHostId& render_frame_host_id, | 550 const RenderFrameHostId& render_frame_host_id, |
551 const MediaRoute::Id& route_id, | 551 const MediaRoute::Id& route_id, |
552 const std::string& presentation_id) { | 552 const std::string& presentation_id) { |
553 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 553 auto* presentation_frame = presentation_frames_.get(render_frame_host_id); |
554 if (presentation_frame) | 554 if (presentation_frame) |
555 presentation_frame->RemoveConnection(route_id, presentation_id); | 555 presentation_frame->RemoveConnection(route_id, presentation_id); |
556 } | 556 } |
557 | 557 |
558 PresentationFrame* PresentationFrameManager::GetOrAddPresentationFrame( | 558 PresentationFrame* PresentationFrameManager::GetOrAddPresentationFrame( |
559 const RenderFrameHostId& render_frame_host_id) { | 559 const RenderFrameHostId& render_frame_host_id) { |
560 if (!presentation_frames_.contains(render_frame_host_id)) { | 560 if (!presentation_frames_.contains(render_frame_host_id)) { |
561 presentation_frames_.add( | 561 presentation_frames_.add( |
562 render_frame_host_id, | 562 render_frame_host_id, |
563 std::unique_ptr<PresentationFrame>(new PresentationFrame( | 563 std::unique_ptr<PresentationFrame>(new PresentationFrame( |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 888 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
889 int render_process_id, | 889 int render_process_id, |
890 int render_frame_id, | 890 int render_frame_id, |
891 const MediaSource::Id& source_id) const { | 891 const MediaSource::Id& source_id) const { |
892 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 892 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
893 return frame_manager_->HasScreenAvailabilityListenerForTest( | 893 return frame_manager_->HasScreenAvailabilityListenerForTest( |
894 render_frame_host_id, source_id); | 894 render_frame_host_id, source_id); |
895 } | 895 } |
896 | 896 |
897 } // namespace media_router | 897 } // namespace media_router |
OLD | NEW |