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

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

Issue 2583463002: [MediaSession] Add playbackState attribute to Blink MediaSession and use it to determine playback s… (Closed)
Patch Set: rebased Created 4 years 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 SetAudioFocusState(audio_focus_state); 291 SetAudioFocusState(audio_focus_state);
292 292
293 if (audio_focus_state_ != State::ACTIVE) 293 if (audio_focus_state_ != State::ACTIVE)
294 return; 294 return;
295 } 295 }
296 296
297 OnResumeInternal(suspend_type); 297 OnResumeInternal(suspend_type);
298 } 298 }
299 299
300 void MediaSessionImpl::Suspend(SuspendType suspend_type) { 300 void MediaSessionImpl::Suspend(SuspendType suspend_type) {
301 DCHECK(!IsSuspended()); 301 if (IsSuspended())
302 return;
302 303
303 OnSuspendInternal(suspend_type, State::SUSPENDED); 304 OnSuspendInternal(suspend_type, State::SUSPENDED);
304 } 305 }
305 306
306 void MediaSessionImpl::Stop(SuspendType suspend_type) { 307 void MediaSessionImpl::Stop(SuspendType suspend_type) {
307 DCHECK(audio_focus_state_ != State::INACTIVE); 308 DCHECK(audio_focus_state_ != State::INACTIVE);
308 DCHECK(suspend_type != SuspendType::CONTENT); 309 DCHECK(suspend_type != SuspendType::CONTENT);
309 DCHECK(!HasPepper()); 310 DCHECK(!HasPepper());
310 311
311 // TODO(mlamouri): merge the logic between UI and SYSTEM. 312 // TODO(mlamouri): merge the logic between UI and SYSTEM.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 !pepper_players_.empty() || !one_shot_players_.empty()) { 504 !pepper_players_.empty() || !one_shot_players_.empty()) {
504 return; 505 return;
505 } 506 }
506 delegate_->AbandonAudioFocus(); 507 delegate_->AbandonAudioFocus();
507 508
508 SetAudioFocusState(State::INACTIVE); 509 SetAudioFocusState(State::INACTIVE);
509 NotifyAboutStateChange(); 510 NotifyAboutStateChange();
510 } 511 }
511 512
512 void MediaSessionImpl::NotifyAboutStateChange() { 513 void MediaSessionImpl::NotifyAboutStateChange() {
514 bool is_actually_suspended = IsSuspended();
515 // Compute the actual playback state using both the MediaSessionService state
516 // and real state.
517 //
518 // TODO(zqzhang): Maybe also compute for IsControllable()? See
519 // https://crbug.com/674983
520 if (routed_service_ &&
521 routed_service_->playback_state() ==
522 blink::mojom::MediaSessionPlaybackState::PLAYING) {
523 is_actually_suspended = false;
524 }
525
513 media_session_state_listeners_.Notify(audio_focus_state_); 526 media_session_state_listeners_.Notify(audio_focus_state_);
514 for (auto& observer : observers_) 527 for (auto& observer : observers_)
515 observer.MediaSessionStateChanged(IsControllable(), IsSuspended()); 528 observer.MediaSessionStateChanged(IsControllable(), is_actually_suspended);
516 } 529 }
517 530
518 void MediaSessionImpl::SetAudioFocusState(State audio_focus_state) { 531 void MediaSessionImpl::SetAudioFocusState(State audio_focus_state) {
519 if (audio_focus_state == audio_focus_state_) 532 if (audio_focus_state == audio_focus_state_)
520 return; 533 return;
521 534
522 audio_focus_state_ = audio_focus_state; 535 audio_focus_state_ = audio_focus_state;
523 switch (audio_focus_state_) { 536 switch (audio_focus_state_) {
524 case State::ACTIVE: 537 case State::ACTIVE:
525 uma_helper_.OnSessionActive(); 538 uma_helper_.OnSessionActive();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 572 }
560 573
561 // MediaSessionService-related methods 574 // MediaSessionService-related methods
562 575
563 void MediaSessionImpl::OnServiceCreated(MediaSessionServiceImpl* service) { 576 void MediaSessionImpl::OnServiceCreated(MediaSessionServiceImpl* service) {
564 services_[service->GetRenderFrameHost()] = service; 577 services_[service->GetRenderFrameHost()] = service;
565 } 578 }
566 579
567 void MediaSessionImpl::OnServiceDestroyed(MediaSessionServiceImpl* service) { 580 void MediaSessionImpl::OnServiceDestroyed(MediaSessionServiceImpl* service) {
568 services_.erase(service->GetRenderFrameHost()); 581 services_.erase(service->GetRenderFrameHost());
582 if (routed_service_ == service) {
583 routed_service_ = nullptr;
584 UpdateRoutedService();
585 }
586 }
587
588 void MediaSessionImpl::OnMediaSessionPlaybackStateChanged(
589 MediaSessionServiceImpl* service) {
590 if (service != routed_service_)
591 return;
592 NotifyAboutStateChange();
569 } 593 }
570 594
571 void MediaSessionImpl::OnMediaSessionMetadataChanged( 595 void MediaSessionImpl::OnMediaSessionMetadataChanged(
572 MediaSessionServiceImpl* service) { 596 MediaSessionServiceImpl* service) {
573 if (service != routed_service_) 597 if (service != routed_service_)
574 return; 598 return;
575 599
576 NotifyMediaSessionMetadataChange(routed_service_->metadata()); 600 NotifyMediaSessionMetadataChange(routed_service_->metadata());
577 } 601 }
578 602
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if (!IsServiceActiveForRenderFrameHost(frame)) 675 if (!IsServiceActiveForRenderFrameHost(frame))
652 continue; 676 continue;
653 best_frame = frame; 677 best_frame = frame;
654 min_depth = depth; 678 min_depth = depth;
655 } 679 }
656 680
657 return best_frame ? services_[best_frame] : nullptr; 681 return best_frame ? services_[best_frame] : nullptr;
658 } 682 }
659 683
660 } // namespace content 684 } // 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