| 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.h" | 5 #include "content/browser/media/session/media_session.h" |
| 6 | 6 |
| 7 #include "content/browser/media/session/media_session_delegate.h" | 7 #include "content/browser/media/session/media_session_delegate.h" |
| 8 #include "content/browser/media/session/media_session_observer.h" | 8 #include "content/browser/media/session/media_session_observer.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // TODO(mlamouri): should be == State::SUSPENDED. | 202 // TODO(mlamouri): should be == State::SUSPENDED. |
| 203 return audio_focus_state_ != State::ACTIVE; | 203 return audio_focus_state_ != State::ACTIVE; |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool MediaSession::IsControllable() const { | 206 bool MediaSession::IsControllable() const { |
| 207 // Only content type media session can be controllable unless it is inactive. | 207 // Only content type media session can be controllable unless it is inactive. |
| 208 return audio_focus_state_ != State::INACTIVE && | 208 return audio_focus_state_ != State::INACTIVE && |
| 209 audio_focus_type_ == Type::Content; | 209 audio_focus_type_ == Type::Content; |
| 210 } | 210 } |
| 211 | 211 |
| 212 scoped_ptr<base::CallbackList<void(MediaSession::State)>::Subscription> |
| 213 MediaSession::RegisterMediaSessionStateChangedCallbackForTest( |
| 214 const StateChangedCallback& cb) { |
| 215 return media_session_state_listeners_.Add(cb); |
| 216 } |
| 217 |
| 212 void MediaSession::SetDelegateForTests( | 218 void MediaSession::SetDelegateForTests( |
| 213 scoped_ptr<MediaSessionDelegate> delegate) { | 219 scoped_ptr<MediaSessionDelegate> delegate) { |
| 214 delegate_ = std::move(delegate); | 220 delegate_ = std::move(delegate); |
| 215 } | 221 } |
| 216 | 222 |
| 217 bool MediaSession::IsActiveForTest() const { | 223 bool MediaSession::IsActiveForTest() const { |
| 218 return audio_focus_state_ == State::ACTIVE; | 224 return audio_focus_state_ == State::ACTIVE; |
| 219 } | 225 } |
| 220 | 226 |
| 221 MediaSession::Type MediaSession::audio_focus_type_for_test() const { | 227 MediaSession::Type MediaSession::audio_focus_type_for_test() const { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (audio_focus_state_ == State::INACTIVE || !players_.empty()) | 316 if (audio_focus_state_ == State::INACTIVE || !players_.empty()) |
| 311 return; | 317 return; |
| 312 | 318 |
| 313 delegate_->AbandonAudioFocus(); | 319 delegate_->AbandonAudioFocus(); |
| 314 | 320 |
| 315 SetAudioFocusState(State::INACTIVE); | 321 SetAudioFocusState(State::INACTIVE); |
| 316 UpdateWebContents(); | 322 UpdateWebContents(); |
| 317 } | 323 } |
| 318 | 324 |
| 319 void MediaSession::UpdateWebContents() { | 325 void MediaSession::UpdateWebContents() { |
| 326 media_session_state_listeners_.Notify(audio_focus_state_); |
| 320 static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); | 327 static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); |
| 321 } | 328 } |
| 322 | 329 |
| 323 void MediaSession::SetAudioFocusState(State audio_focus_state) { | 330 void MediaSession::SetAudioFocusState(State audio_focus_state) { |
| 324 if (audio_focus_state == audio_focus_state_) | 331 if (audio_focus_state == audio_focus_state_) |
| 325 return; | 332 return; |
| 326 | 333 |
| 327 audio_focus_state_ = audio_focus_state; | 334 audio_focus_state_ = audio_focus_state; |
| 328 switch (audio_focus_state_) { | 335 switch (audio_focus_state_) { |
| 329 case State::ACTIVE: | 336 case State::ACTIVE: |
| 330 uma_helper_.OnSessionActive(); | 337 uma_helper_.OnSessionActive(); |
| 331 break; | 338 break; |
| 332 case State::SUSPENDED: | 339 case State::SUSPENDED: |
| 333 uma_helper_.OnSessionSuspended(); | 340 uma_helper_.OnSessionSuspended(); |
| 334 break; | 341 break; |
| 335 case State::INACTIVE: | 342 case State::INACTIVE: |
| 336 uma_helper_.OnSessionInactive(); | 343 uma_helper_.OnSessionInactive(); |
| 337 break; | 344 break; |
| 338 } | 345 } |
| 339 } | 346 } |
| 340 | 347 |
| 341 } // namespace content | 348 } // namespace content |
| OLD | NEW |