Commit 43939c76 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Media Controller] Forward next and prev to service

If the media session feature is enabled then use the
media session service to control playback when the
next/previous track media keys are pressed.

BUG=894255

Change-Id: I0bd99bad14ce9973d10f2c4567dd487bda0ac436
Reviewed-on: https://chromium-review.googlesource.com/c/1289149
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603566}
parent 4eee31cd
......@@ -1603,11 +1603,18 @@ TEST_P(MediaSessionAcceleratorTest, MediaPlaybackAcceleratorsBehavior) {
TEST_P(MediaSessionAcceleratorTest, MediaGlobalAccelerators_NextTrack) {
EXPECT_EQ(0, client()->handle_media_next_track_count());
EXPECT_EQ(0, controller()->next_track_count());
ProcessInController(ui::Accelerator(ui::VKEY_MEDIA_NEXT_TRACK, ui::EF_NONE));
Shell::Get()->media_controller()->FlushForTesting();
EXPECT_EQ(1, client()->handle_media_next_track_count());
if (service_enabled()) {
EXPECT_EQ(0, client()->handle_media_next_track_count());
EXPECT_EQ(1, controller()->next_track_count());
} else {
EXPECT_EQ(1, client()->handle_media_next_track_count());
EXPECT_EQ(0, controller()->next_track_count());
}
}
TEST_P(MediaSessionAcceleratorTest, MediaGlobalAccelerators_PlayPause) {
......@@ -1628,11 +1635,18 @@ TEST_P(MediaSessionAcceleratorTest, MediaGlobalAccelerators_PlayPause) {
TEST_P(MediaSessionAcceleratorTest, MediaGlobalAccelerators_PrevTrack) {
EXPECT_EQ(0, client()->handle_media_prev_track_count());
EXPECT_EQ(0, controller()->previous_track_count());
ProcessInController(ui::Accelerator(ui::VKEY_MEDIA_PREV_TRACK, ui::EF_NONE));
Shell::Get()->media_controller()->FlushForTesting();
EXPECT_EQ(1, client()->handle_media_prev_track_count());
if (service_enabled()) {
EXPECT_EQ(0, client()->handle_media_prev_track_count());
EXPECT_EQ(1, controller()->previous_track_count());
} else {
EXPECT_EQ(1, client()->handle_media_prev_track_count());
EXPECT_EQ(0, controller()->previous_track_count());
}
}
} // namespace ash
......@@ -52,14 +52,26 @@ void MediaController::HandleMediaPlayPause() {
}
void MediaController::HandleMediaNextTrack() {
// TODO(beccahughes): Add media session service integration.
// If media session media key handling is enabled. Fire next track using the
// media session service.
if (base::FeatureList::IsEnabled(features::kMediaSessionAccelerators)) {
if (GetMediaSessionController())
GetMediaSessionController()->NextTrack();
return;
}
if (client_)
client_->HandleMediaNextTrack();
}
void MediaController::HandleMediaPrevTrack() {
// TODO(beccahughes): Add media session service integration.
// If media session media key handling is enabled. Fire previous track using
// the media session service.
if (base::FeatureList::IsEnabled(features::kMediaSessionAccelerators)) {
if (GetMediaSessionController())
GetMediaSessionController()->PreviousTrack();
return;
}
if (client_)
client_->HandleMediaPrevTrack();
......
......@@ -52,14 +52,14 @@ class ASH_EXPORT MediaController : public mojom::MediaController {
const base::flat_map<AccountId, mojom::MediaCaptureState>& capture_states)
override;
// If media session accelerators are enabled then this method will use the
// If media session accelerators are enabled then these methods will use the
// media session service to control playback. Otherwise it will forward to
// |client_|.
void HandleMediaPlayPause();
// Methods that forward to |client_|.
void HandleMediaNextTrack();
void HandleMediaPrevTrack();
// Methods that forward to |client_|.
void RequestCaptureState();
void SuspendMediaSessions();
......
......@@ -21,5 +21,13 @@ void TestMediaController::ToggleSuspendResume() {
++toggle_suspend_resume_count_;
}
void TestMediaController::PreviousTrack() {
++previous_track_count_;
}
void TestMediaController::NextTrack() {
++next_track_count_;
}
} // namespace test
} // namespace media_session
......@@ -26,15 +26,20 @@ class COMPONENT_EXPORT(MEDIA_SESSION_TEST_SUPPORT_CPP) TestMediaController
void Resume() override {}
void ToggleSuspendResume() override;
void AddObserver(mojom::MediaSessionObserverPtr) override {}
void PreviousTrack() override {}
void NextTrack() override {}
void PreviousTrack() override;
void NextTrack() override;
int toggle_suspend_resume_count() const {
return toggle_suspend_resume_count_;
}
int previous_track_count() const { return previous_track_count_; }
int next_track_count() const { return next_track_count_; }
private:
int toggle_suspend_resume_count_ = 0;
int previous_track_count_ = 0;
int next_track_count_ = 0;
mojo::Binding<mojom::MediaController> binding_{this};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment