[Global Media Controls] Don't update active media session on tab focus

This CL removes the MediaSessionImpl logic that requests audio focus
when the WebContents is focused. This logic was there to ensure that a
focused tab playing audio would have the active Media Session, but we
have decided to not have that functionality.

Bug: 923208
Change-Id: Idb5977d425e51f01b9c291d52f3183e2983ae220
Reviewed-on: https://chromium-review.googlesource.com/c/1437534
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Reviewed-by: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: Mounir Lamouri <mlamouri@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#627094}(cherry picked from commit 03bc24e5096e4a27487f4a318627ea068979e6be)
Reviewed-on: https://chromium-review.googlesource.com/c/1450303
Reviewed-by: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/branch-heads/3683@{#123}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
diff --git a/content/browser/media/session/media_session_impl.cc b/content/browser/media/session/media_session_impl.cc
index 1eda393..8d468fb 100644
--- a/content/browser/media/session/media_session_impl.cc
+++ b/content/browser/media/session/media_session_impl.cc
@@ -185,17 +185,6 @@
   NotifyMediaSessionMetadataChange();
 }
 
-void MediaSessionImpl::OnWebContentsFocused(
-    RenderWidgetHost* render_widget_host) {
-#if !defined(OS_ANDROID)
-  // If we have just gained focus and we have audio focus we should re-request
-  // system audio focus. This will ensure this media session is towards the top
-  // of the stack if we have multiple sessions active at the same time.
-  if (audio_focus_state_ == State::ACTIVE)
-    RequestSystemAudioFocus(desired_audio_focus_type_);
-#endif
-}
-
 void MediaSessionImpl::AddObserver(MediaSessionObserver* observer) {
   observers_.AddObserver(observer);
   NotifyAddedObserver(observer);
diff --git a/content/browser/media/session/media_session_impl.h b/content/browser/media/session/media_session_impl.h
index 3a65669..cc5ba99 100644
--- a/content/browser/media/session/media_session_impl.h
+++ b/content/browser/media/session/media_session_impl.h
@@ -136,7 +136,6 @@
   void WebContentsDestroyed() override;
   void RenderFrameDeleted(RenderFrameHost* rfh) override;
   void DidFinishNavigation(NavigationHandle* navigation_handle) override;
-  void OnWebContentsFocused(RenderWidgetHost* render_widget_host) override;
 
   // MediaSessionService-related methods
 
diff --git a/content/browser/media/session/media_session_impl_unittest.cc b/content/browser/media/session/media_session_impl_unittest.cc
index df048f7..97596a1 100644
--- a/content/browser/media/session/media_session_impl_unittest.cc
+++ b/content/browser/media/session/media_session_impl_unittest.cc
@@ -575,7 +575,7 @@
   }
 }
 
-TEST_F(MediaSessionImplTest, RequestAudioFocus_OnFocus_Active) {
+TEST_F(MediaSessionImplTest, TabFocusDoesNotCauseAudioFocus) {
   MockAudioFocusDelegate* delegate = new MockAudioFocusDelegate();
   SetDelegateForTests(GetMediaSession(), delegate);
 
@@ -588,39 +588,6 @@
 
   EXPECT_EQ(1, delegate->request_audio_focus_count());
   GetMediaSession()->OnWebContentsFocused(nullptr);
-  EXPECT_EQ(2, delegate->request_audio_focus_count());
-}
-
-TEST_F(MediaSessionImplTest, RequestAudioFocus_OnFocus_Inactive) {
-  MockAudioFocusDelegate* delegate = new MockAudioFocusDelegate();
-  SetDelegateForTests(GetMediaSession(), delegate);
-  EXPECT_EQ(MediaSessionInfo::SessionState::kInactive,
-            GetState(GetMediaSession()));
-
-  EXPECT_EQ(0, delegate->request_audio_focus_count());
-  GetMediaSession()->OnWebContentsFocused(nullptr);
-  EXPECT_EQ(0, delegate->request_audio_focus_count());
-}
-
-TEST_F(MediaSessionImplTest, RequestAudioFocus_OnFocus_Suspended) {
-  MockAudioFocusDelegate* delegate = new MockAudioFocusDelegate();
-  SetDelegateForTests(GetMediaSession(), delegate);
-
-  {
-    MockMediaSessionMojoObserver observer(*GetMediaSession());
-    RequestAudioFocus(GetMediaSession(), AudioFocusType::kGain);
-    FlushForTesting(GetMediaSession());
-    observer.WaitForState(MediaSessionInfo::SessionState::kActive);
-  }
-
-  {
-    MockMediaSessionMojoObserver observer(*GetMediaSession());
-    GetMediaSession()->Suspend(MediaSession::SuspendType::kSystem);
-    observer.WaitForState(MediaSessionInfo::SessionState::kSuspended);
-  }
-
-  EXPECT_EQ(1, delegate->request_audio_focus_count());
-  GetMediaSession()->OnWebContentsFocused(nullptr);
   EXPECT_EQ(1, delegate->request_audio_focus_count());
 }