Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: content/browser/media/session/media_session_impl.cc

Issue 2758773003: Clean up MediaSessionImpl state interfaces (Closed)
Patch Set: fixed build Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 294 }
295 295
296 // If the player is a one-shot player, just remove it since it is not expected 296 // If the player is a one-shot player, just remove it since it is not expected
297 // to resume a one-shot player via resuming MediaSession. 297 // to resume a one-shot player via resuming MediaSession.
298 if (one_shot_players_.count(identifier)) { 298 if (one_shot_players_.count(identifier)) {
299 RemovePlayer(observer, player_id); 299 RemovePlayer(observer, player_id);
300 return; 300 return;
301 } 301 }
302 302
303 // Otherwise, suspend the session. 303 // Otherwise, suspend the session.
304 DCHECK(!IsSuspended()); 304 DCHECK(IsActive());
305 OnSuspendInternal(SuspendType::CONTENT, State::SUSPENDED); 305 OnSuspendInternal(SuspendType::CONTENT, State::SUSPENDED);
306 } 306 }
307 307
308 void MediaSessionImpl::Resume(SuspendType suspend_type) { 308 void MediaSessionImpl::Resume(SuspendType suspend_type) {
309 DCHECK(IsReallySuspended()); 309 DCHECK(IsSuspended());
310 310
311 // When the resume requests comes from another source than system, audio focus 311 // When the resume requests comes from another source than system, audio focus
312 // must be requested. 312 // must be requested.
313 if (suspend_type != SuspendType::SYSTEM) { 313 if (suspend_type != SuspendType::SYSTEM) {
314 // Request audio focus again in case we lost it because another app started 314 // Request audio focus again in case we lost it because another app started
315 // playing while the playback was paused. 315 // playing while the playback was paused.
316 State audio_focus_state = RequestSystemAudioFocus(audio_focus_type_) 316 State audio_focus_state = RequestSystemAudioFocus(audio_focus_type_)
317 ? State::ACTIVE 317 ? State::ACTIVE
318 : State::INACTIVE; 318 : State::INACTIVE;
319 SetAudioFocusState(audio_focus_state); 319 SetAudioFocusState(audio_focus_state);
320 320
321 if (audio_focus_state_ != State::ACTIVE) 321 if (audio_focus_state_ != State::ACTIVE)
322 return; 322 return;
323 } 323 }
324 324
325 OnResumeInternal(suspend_type); 325 OnResumeInternal(suspend_type);
326 } 326 }
327 327
328 void MediaSessionImpl::Suspend(SuspendType suspend_type) { 328 void MediaSessionImpl::Suspend(SuspendType suspend_type) {
329 if (IsSuspended()) 329 if (!IsActive())
330 return; 330 return;
331 331
332 OnSuspendInternal(suspend_type, State::SUSPENDED); 332 OnSuspendInternal(suspend_type, State::SUSPENDED);
333 } 333 }
334 334
335 void MediaSessionImpl::Stop(SuspendType suspend_type) { 335 void MediaSessionImpl::Stop(SuspendType suspend_type) {
336 DCHECK(audio_focus_state_ != State::INACTIVE); 336 DCHECK(audio_focus_state_ != State::INACTIVE);
337 DCHECK(suspend_type != SuspendType::CONTENT); 337 DCHECK(suspend_type != SuspendType::CONTENT);
338 DCHECK(!HasPepper()); 338 DCHECK(!HasPepper());
339 339
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 374 }
375 375
376 double MediaSessionImpl::GetVolumeMultiplier() const { 376 double MediaSessionImpl::GetVolumeMultiplier() const {
377 return is_ducking_ ? kDuckingVolumeMultiplier : kDefaultVolumeMultiplier; 377 return is_ducking_ ? kDuckingVolumeMultiplier : kDefaultVolumeMultiplier;
378 } 378 }
379 379
380 bool MediaSessionImpl::IsActive() const { 380 bool MediaSessionImpl::IsActive() const {
381 return audio_focus_state_ == State::ACTIVE; 381 return audio_focus_state_ == State::ACTIVE;
382 } 382 }
383 383
384 bool MediaSessionImpl::IsReallySuspended() const { 384 bool MediaSessionImpl::IsSuspended() const {
385 return audio_focus_state_ == State::SUSPENDED; 385 return audio_focus_state_ == State::SUSPENDED;
386 } 386 }
387 387
388 bool MediaSessionImpl::IsSuspended() const {
389 // TODO(mlamouri): should be == State::SUSPENDED.
390 return audio_focus_state_ != State::ACTIVE;
391 }
392
393 bool MediaSessionImpl::IsControllable() const { 388 bool MediaSessionImpl::IsControllable() const {
394 // Only media session having focus Gain can be controllable unless it is 389 // Only media session having focus Gain can be controllable unless it is
395 // inactive. Also, the session will be uncontrollable if it contains one-shot 390 // inactive. Also, the session will be uncontrollable if it contains one-shot
396 // players. 391 // players.
397 return audio_focus_state_ != State::INACTIVE && 392 return audio_focus_state_ != State::INACTIVE &&
398 audio_focus_type_ == AudioFocusManager::AudioFocusType::Gain && 393 audio_focus_type_ == AudioFocusManager::AudioFocusType::Gain &&
399 one_shot_players_.empty(); 394 one_shot_players_.empty();
400 } 395 }
401 396
402 bool MediaSessionImpl::IsActuallyPaused() const { 397 bool MediaSessionImpl::IsActuallyPaused() const {
(...skipping 13 matching lines...) Expand all
416 MediaSessionImpl::RegisterMediaSessionStateChangedCallbackForTest( 411 MediaSessionImpl::RegisterMediaSessionStateChangedCallbackForTest(
417 const StateChangedCallback& cb) { 412 const StateChangedCallback& cb) {
418 return media_session_state_listeners_.Add(cb); 413 return media_session_state_listeners_.Add(cb);
419 } 414 }
420 415
421 void MediaSessionImpl::SetDelegateForTests( 416 void MediaSessionImpl::SetDelegateForTests(
422 std::unique_ptr<AudioFocusDelegate> delegate) { 417 std::unique_ptr<AudioFocusDelegate> delegate) {
423 delegate_ = std::move(delegate); 418 delegate_ = std::move(delegate);
424 } 419 }
425 420
426 bool MediaSessionImpl::IsActiveForTest() const {
427 return audio_focus_state_ == State::ACTIVE;
428 }
429
430 MediaSessionUmaHelper* MediaSessionImpl::uma_helper_for_test() { 421 MediaSessionUmaHelper* MediaSessionImpl::uma_helper_for_test() {
431 return &uma_helper_; 422 return &uma_helper_;
432 } 423 }
433 424
434 void MediaSessionImpl::RemoveAllPlayersForTest() { 425 void MediaSessionImpl::RemoveAllPlayersForTest() {
435 normal_players_.clear(); 426 normal_players_.clear();
436 pepper_players_.clear(); 427 pepper_players_.clear();
437 one_shot_players_.clear(); 428 one_shot_players_.clear();
438 AbandonSystemAudioFocusIfNeeded(); 429 AbandonSystemAudioFocusIfNeeded();
439 } 430 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 if (!IsServiceActiveForRenderFrameHost(frame)) 722 if (!IsServiceActiveForRenderFrameHost(frame))
732 continue; 723 continue;
733 best_frame = frame; 724 best_frame = frame;
734 min_depth = depth; 725 min_depth = depth;
735 } 726 }
736 727
737 return best_frame ? services_[best_frame] : nullptr; 728 return best_frame ? services_[best_frame] : nullptr;
738 } 729 }
739 730
740 } // namespace content 731 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/session/media_session_impl.h ('k') | content/browser/media/session/media_session_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698