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

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

Issue 2660263002: [Media>Session] Pause all players for non-routed frames when receiving PAUSE action (Closed)
Patch Set: added comments and tests Created 3 years, 10 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
« no previous file with comments | « no previous file | content/browser/media/session/media_session_impl_service_routing_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 void MediaSessionImpl::OnMediaSessionActionsChanged( 604 void MediaSessionImpl::OnMediaSessionActionsChanged(
605 MediaSessionServiceImpl* service) { 605 MediaSessionServiceImpl* service) {
606 if (service != routed_service_) 606 if (service != routed_service_)
607 return; 607 return;
608 608
609 NotifyMediaSessionActionsChange(routed_service_->actions()); 609 NotifyMediaSessionActionsChange(routed_service_->actions());
610 } 610 }
611 611
612 void MediaSessionImpl::DidReceiveAction( 612 void MediaSessionImpl::DidReceiveAction(
613 blink::mojom::MediaSessionAction action) { 613 blink::mojom::MediaSessionAction action) {
614 // Pause all players in non-routed frames if the action is PAUSE.
615 //
616 // This is the default PAUSE action handler as mentioned in the Media Session
617 // API spec. The reason for pausing all players in all other sessions is to
618 // avoid the players in other frames keep the session active so that the UI
619 // will always show the pause button but it does not pause anything (as the
620 // routed frame already pauses when responding to the PAUSE action while other
621 // frames does not).
622 //
623 // TODO(zqzhang): Currently, this might not work well on desktop as Pepper and
624 // OneShot players are not really suspended, so that the session is still
625 // active after this. See https://crbug.com/619084 and
626 // https://crbug.com/596516.
627 if (blink::mojom::MediaSessionAction::PAUSE == action) {
628 RenderFrameHost* rfh_of_routed_service =
629 routed_service_->GetRenderFrameHost();
630 for (const auto& player : normal_players_) {
631 if (player.observer->GetRenderFrameHost() != rfh_of_routed_service)
632 player.observer->OnSuspend(player.player_id);
633 }
634 for (const auto& player : pepper_players_) {
635 if (player.observer->GetRenderFrameHost() != rfh_of_routed_service)
mlamouri (slow - plz ping) 2017/02/10 14:17:43 styte: you need { } because the statement is in tw
Zhiqiang Zhang (Slow) 2017/02/10 14:25:58 Done.
636 player.observer->OnSetVolumeMultiplier(
637 player.player_id, kDuckingVolumeMultiplier);
638 }
639 for (const auto& player : one_shot_players_) {
640 if (player.observer->GetRenderFrameHost() != rfh_of_routed_service)
641 player.observer->OnSuspend(player.player_id);
642 }
643 }
644
614 if (!routed_service_) 645 if (!routed_service_)
615 return; 646 return;
616 647
617 routed_service_->GetClient()->DidReceiveAction(action); 648 routed_service_->GetClient()->DidReceiveAction(action);
618 } 649 }
619 650
620 bool MediaSessionImpl::IsServiceActiveForRenderFrameHost(RenderFrameHost* rfh) { 651 bool MediaSessionImpl::IsServiceActiveForRenderFrameHost(RenderFrameHost* rfh) {
621 return services_.find(rfh) != services_.end(); 652 return services_.find(rfh) != services_.end();
622 } 653 }
623 654
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 if (!IsServiceActiveForRenderFrameHost(frame)) 699 if (!IsServiceActiveForRenderFrameHost(frame))
669 continue; 700 continue;
670 best_frame = frame; 701 best_frame = frame;
671 min_depth = depth; 702 min_depth = depth;
672 } 703 }
673 704
674 return best_frame ? services_[best_frame] : nullptr; 705 return best_frame ? services_[best_frame] : nullptr;
675 } 706 }
676 707
677 } // namespace content 708 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/media/session/media_session_impl_service_routing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698