| 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/media/session/media_session_impl.h" | 5 #include "content/browser/media/session/media_session_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include "content/browser/media/session/audio_focus_delegate.h" | 8 #include "content/browser/media/session/audio_focus_delegate.h" |
| 9 #include "content/browser/media/session/media_session_controller.h" | 9 #include "content/browser/media/session/media_session_controller.h" |
| 10 #include "content/browser/media/session/media_session_player_observer.h" | 10 #include "content/browser/media/session/media_session_player_observer.h" |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 one_shot_players_.insert(PlayerIdentifier(observer, player_id)); | 568 one_shot_players_.insert(PlayerIdentifier(observer, player_id)); |
| 569 NotifyAboutStateChange(); | 569 NotifyAboutStateChange(); |
| 570 | 570 |
| 571 return true; | 571 return true; |
| 572 } | 572 } |
| 573 | 573 |
| 574 // MediaSessionService-related methods | 574 // MediaSessionService-related methods |
| 575 | 575 |
| 576 void MediaSessionImpl::OnServiceCreated(MediaSessionServiceImpl* service) { | 576 void MediaSessionImpl::OnServiceCreated(MediaSessionServiceImpl* service) { |
| 577 services_[service->GetRenderFrameHost()] = service; | 577 services_[service->GetRenderFrameHost()] = service; |
| 578 UpdateRoutedService(); |
| 578 } | 579 } |
| 579 | 580 |
| 580 void MediaSessionImpl::OnServiceDestroyed(MediaSessionServiceImpl* service) { | 581 void MediaSessionImpl::OnServiceDestroyed(MediaSessionServiceImpl* service) { |
| 581 services_.erase(service->GetRenderFrameHost()); | 582 services_.erase(service->GetRenderFrameHost()); |
| 582 if (routed_service_ == service) { | 583 if (routed_service_ == service) { |
| 583 routed_service_ = nullptr; | 584 routed_service_ = nullptr; |
| 584 UpdateRoutedService(); | 585 UpdateRoutedService(); |
| 585 } | 586 } |
| 586 } | 587 } |
| 587 | 588 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 610 | 611 |
| 611 void MediaSessionImpl::DidReceiveAction( | 612 void MediaSessionImpl::DidReceiveAction( |
| 612 blink::mojom::MediaSessionAction action) { | 613 blink::mojom::MediaSessionAction action) { |
| 613 if (!routed_service_) | 614 if (!routed_service_) |
| 614 return; | 615 return; |
| 615 | 616 |
| 616 routed_service_->GetClient()->DidReceiveAction(action); | 617 routed_service_->GetClient()->DidReceiveAction(action); |
| 617 } | 618 } |
| 618 | 619 |
| 619 bool MediaSessionImpl::IsServiceActiveForRenderFrameHost(RenderFrameHost* rfh) { | 620 bool MediaSessionImpl::IsServiceActiveForRenderFrameHost(RenderFrameHost* rfh) { |
| 620 if (!services_.count(rfh)) | 621 return services_.find(rfh) != services_.end(); |
| 621 return false; | |
| 622 | |
| 623 return services_[rfh]->metadata().has_value() || | |
| 624 !services_[rfh]->actions().empty(); | |
| 625 } | 622 } |
| 626 | 623 |
| 627 void MediaSessionImpl::UpdateRoutedService() { | 624 void MediaSessionImpl::UpdateRoutedService() { |
| 628 MediaSessionServiceImpl* new_service = ComputeServiceForRouting(); | 625 MediaSessionServiceImpl* new_service = ComputeServiceForRouting(); |
| 629 if (new_service == routed_service_) | 626 if (new_service == routed_service_) |
| 630 return; | 627 return; |
| 631 | 628 |
| 632 routed_service_ = new_service; | 629 routed_service_ = new_service; |
| 633 if (routed_service_) { | 630 if (routed_service_) { |
| 634 NotifyMediaSessionMetadataChange(routed_service_->metadata()); | 631 NotifyMediaSessionMetadataChange(routed_service_->metadata()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 if (!IsServiceActiveForRenderFrameHost(frame)) | 672 if (!IsServiceActiveForRenderFrameHost(frame)) |
| 676 continue; | 673 continue; |
| 677 best_frame = frame; | 674 best_frame = frame; |
| 678 min_depth = depth; | 675 min_depth = depth; |
| 679 } | 676 } |
| 680 | 677 |
| 681 return best_frame ? services_[best_frame] : nullptr; | 678 return best_frame ? services_[best_frame] : nullptr; |
| 682 } | 679 } |
| 683 | 680 |
| 684 } // namespace content | 681 } // namespace content |
| OLD | NEW |