| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 session->Initialize(); | 85 session->Initialize(); |
| 86 } | 86 } |
| 87 return session; | 87 return session; |
| 88 } | 88 } |
| 89 | 89 |
| 90 MediaSessionImpl::~MediaSessionImpl() { | 90 MediaSessionImpl::~MediaSessionImpl() { |
| 91 DCHECK(normal_players_.empty()); | 91 DCHECK(normal_players_.empty()); |
| 92 DCHECK(pepper_players_.empty()); | 92 DCHECK(pepper_players_.empty()); |
| 93 DCHECK(one_shot_players_.empty()); | 93 DCHECK(one_shot_players_.empty()); |
| 94 DCHECK(audio_focus_state_ == State::INACTIVE); | 94 DCHECK(audio_focus_state_ == State::INACTIVE); |
| 95 for (auto& observer : observers_) | 95 for (auto& observer : observers()) |
| 96 observer.MediaSessionDestroyed(); | 96 observer.MediaSessionDestroyed(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void MediaSessionImpl::WebContentsDestroyed() { | 99 void MediaSessionImpl::WebContentsDestroyed() { |
| 100 // This should only work for tests. In production, all the players should have | 100 // This should only work for tests. In production, all the players should have |
| 101 // already been removed before WebContents is destroyed. | 101 // already been removed before WebContents is destroyed. |
| 102 | 102 |
| 103 // TODO(zqzhang): refactor MediaSessionImpl, maybe move the interface used to | 103 // TODO(zqzhang): refactor MediaSessionImpl, maybe move the interface used to |
| 104 // talk with AudioFocusManager out to a seperate class. The AudioFocusManager | 104 // talk with AudioFocusManager out to a seperate class. The AudioFocusManager |
| 105 // unit tests then could mock the interface and abandon audio focus when | 105 // unit tests then could mock the interface and abandon audio focus when |
| 106 // WebContents is destroyed. See https://crbug.com/651069 | 106 // WebContents is destroyed. See https://crbug.com/651069 |
| 107 normal_players_.clear(); | 107 normal_players_.clear(); |
| 108 pepper_players_.clear(); | 108 pepper_players_.clear(); |
| 109 one_shot_players_.clear(); | 109 one_shot_players_.clear(); |
| 110 AbandonSystemAudioFocusIfNeeded(); | 110 AbandonSystemAudioFocusIfNeeded(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void MediaSessionImpl::AddObserver(MediaSessionObserver* observer) { | |
| 114 observers_.AddObserver(observer); | |
| 115 } | |
| 116 | |
| 117 void MediaSessionImpl::RemoveObserver(MediaSessionObserver* observer) { | |
| 118 observers_.RemoveObserver(observer); | |
| 119 } | |
| 120 | |
| 121 void MediaSessionImpl::NotifyMediaSessionMetadataChange( | 113 void MediaSessionImpl::NotifyMediaSessionMetadataChange( |
| 122 const base::Optional<MediaMetadata>& metadata) { | 114 const base::Optional<MediaMetadata>& metadata) { |
| 123 for (auto& observer : observers_) | 115 for (auto& observer : observers()) |
| 124 observer.MediaSessionMetadataChanged(metadata); | 116 observer.MediaSessionMetadataChanged(metadata); |
| 125 } | 117 } |
| 126 | 118 |
| 127 void MediaSessionImpl::NotifyMediaSessionActionsChange( | 119 void MediaSessionImpl::NotifyMediaSessionActionsChange( |
| 128 const std::set<blink::mojom::MediaSessionAction>& actions) { | 120 const std::set<blink::mojom::MediaSessionAction>& actions) { |
| 129 for (auto& observer : observers_) | 121 for (auto& observer : observers()) |
| 130 observer.MediaSessionActionsChanged(actions); | 122 observer.MediaSessionActionsChanged(actions); |
| 131 } | 123 } |
| 132 | 124 |
| 133 bool MediaSessionImpl::AddPlayer(MediaSessionPlayerObserver* observer, | 125 bool MediaSessionImpl::AddPlayer(MediaSessionPlayerObserver* observer, |
| 134 int player_id, | 126 int player_id, |
| 135 media::MediaContentType media_content_type) { | 127 media::MediaContentType media_content_type) { |
| 136 if (media_content_type == media::MediaContentType::OneShot) | 128 if (media_content_type == media::MediaContentType::OneShot) |
| 137 return AddOneShotPlayer(observer, player_id); | 129 return AddOneShotPlayer(observer, player_id); |
| 138 if (media_content_type == media::MediaContentType::Pepper) | 130 if (media_content_type == media::MediaContentType::Pepper) |
| 139 return AddPepperPlayer(observer, player_id); | 131 return AddPepperPlayer(observer, player_id); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // | 509 // |
| 518 // TODO(zqzhang): Maybe also compute for IsControllable()? See | 510 // TODO(zqzhang): Maybe also compute for IsControllable()? See |
| 519 // https://crbug.com/674983 | 511 // https://crbug.com/674983 |
| 520 if (routed_service_ && | 512 if (routed_service_ && |
| 521 routed_service_->playback_state() == | 513 routed_service_->playback_state() == |
| 522 blink::mojom::MediaSessionPlaybackState::PLAYING) { | 514 blink::mojom::MediaSessionPlaybackState::PLAYING) { |
| 523 is_actually_suspended = false; | 515 is_actually_suspended = false; |
| 524 } | 516 } |
| 525 | 517 |
| 526 media_session_state_listeners_.Notify(audio_focus_state_); | 518 media_session_state_listeners_.Notify(audio_focus_state_); |
| 527 for (auto& observer : observers_) | 519 for (auto& observer : observers()) |
| 528 observer.MediaSessionStateChanged(IsControllable(), is_actually_suspended); | 520 observer.MediaSessionStateChanged(IsControllable(), is_actually_suspended); |
| 529 } | 521 } |
| 530 | 522 |
| 531 void MediaSessionImpl::SetAudioFocusState(State audio_focus_state) { | 523 void MediaSessionImpl::SetAudioFocusState(State audio_focus_state) { |
| 532 if (audio_focus_state == audio_focus_state_) | 524 if (audio_focus_state == audio_focus_state_) |
| 533 return; | 525 return; |
| 534 | 526 |
| 535 audio_focus_state_ = audio_focus_state; | 527 audio_focus_state_ = audio_focus_state; |
| 536 switch (audio_focus_state_) { | 528 switch (audio_focus_state_) { |
| 537 case State::ACTIVE: | 529 case State::ACTIVE: |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 if (!IsServiceActiveForRenderFrameHost(frame)) | 660 if (!IsServiceActiveForRenderFrameHost(frame)) |
| 669 continue; | 661 continue; |
| 670 best_frame = frame; | 662 best_frame = frame; |
| 671 min_depth = depth; | 663 min_depth = depth; |
| 672 } | 664 } |
| 673 | 665 |
| 674 return best_frame ? services_[best_frame] : nullptr; | 666 return best_frame ? services_[best_frame] : nullptr; |
| 675 } | 667 } |
| 676 | 668 |
| 677 } // namespace content | 669 } // namespace content |
| OLD | NEW |