Commit f87f5257 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Media Session] Move switches to service

Move the media session and audio focus related switches to
the media session service.

BUG=875004

Change-Id: I54dad1eb47ac6288895ea3cac3824b181080f3e3
Reviewed-on: https://chromium-review.googlesource.com/1188747Reviewed-by: default avatarStephen Lanham <slan@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587676}
parent 0309a55c
......@@ -60,6 +60,7 @@ include_rules = [
"+services/data_decoder/public",
"+services/device/public",
"+services/identity/public",
"+services/media_session/public",
"+services/metrics/metrics_mojo_service.h",
"+services/metrics/public",
"+services/network/ignore_errors_cert_verifier.h",
......
......@@ -122,6 +122,7 @@
#include "ppapi/buildflags/buildflags.h"
#include "printing/buildflags/buildflags.h"
#include "services/device/public/cpp/device_features.h"
#include "services/media_session/public/cpp/switches.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_switches.h"
#include "services/resource_coordinator/public/cpp/resource_coordinator_features.h"
......@@ -775,11 +776,12 @@ const FeatureEntry::Choice kTLS13VariantChoices[] = {
#if !defined(OS_ANDROID)
const FeatureEntry::Choice kEnableAudioFocusChoices[] = {
{flag_descriptions::kEnableAudioFocusDisabled, "", ""},
{flag_descriptions::kEnableAudioFocusEnabled, switches::kEnableAudioFocus,
""},
{flag_descriptions::kEnableAudioFocusEnabled,
media_session::switches::kEnableAudioFocus, ""},
#if BUILDFLAG(ENABLE_PLUGINS)
{flag_descriptions::kEnableAudioFocusEnabledDuckFlash,
switches::kEnableAudioFocus, switches::kEnableAudioFocusDuckFlash},
media_session::switches::kEnableAudioFocus,
media_session::switches::kEnableAudioFocusDuckFlash},
#endif // BUILDFLAG(ENABLE_PLUGINS)
};
#endif // !defined(OS_ANDROID)
......
......@@ -78,7 +78,7 @@
#include "extensions/common/host_id.h"
#include "mash/public/mojom/launchable.mojom.h"
#include "media/audio/sounds/sounds_manager.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/accessibility/ax_enum_util.h"
#include "ui/base/ime/chromeos/extension_ime_util.h"
......@@ -1244,9 +1244,9 @@ void AccessibilityManager::PostLoadChromeVox() {
}
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
::switches::kEnableAudioFocus)) {
media_session::switches::kEnableAudioFocus)) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
::switches::kEnableAudioFocus);
media_session::switches::kEnableAudioFocus);
}
}
......
......@@ -37,6 +37,7 @@ include_rules = [
"+media/mojo",
"+mojo/public",
"+net",
"+services/media_session/public",
"+services/network/public/cpp",
"+services/service_manager/public",
"+services/service_manager/embedder",
......
......@@ -64,6 +64,7 @@
#include "gpu/command_buffer/service/gpu_switches.h"
#include "media/base/media.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/compositor_switches.h"
......@@ -231,7 +232,7 @@ const DefaultCommandLineSwitch kDefaultSwitches[] = {
// GPU shader disk cache disabling is largely to conserve disk space.
{switches::kDisableGpuShaderDiskCache, ""},
// Enable media sessions by default (even on non-Android platforms).
{switches::kEnableInternalMediaSession, ""},
{media_session::switches::kEnableInternalMediaSession, ""},
#endif
#if BUILDFLAG(IS_CAST_AUDIO_ONLY)
{switches::kDisableGpu, ""},
......
......@@ -138,6 +138,7 @@ jumbo_source_set("browser") {
"//services/device/public/mojom:generic_sensor",
"//services/file:lib",
"//services/file/public/mojom",
"//services/media_session/public/cpp",
"//services/media_session/public/mojom",
"//services/metrics",
"//services/metrics/public/cpp:metrics_cpp",
......
......@@ -25,6 +25,7 @@
#include "media/base/channel_layout.h"
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -309,7 +310,7 @@ class MediaInternalsAudioFocusTest : public testing::Test,
base::Unretained(this));
scoped_command_line_.GetProcessCommandLine()->AppendSwitch(
switches::kEnableAudioFocus);
media_session::switches::kEnableAudioFocus);
content::MediaInternals::GetInstance()->AddUpdateCallback(update_cb_);
browser_context_.reset(new TestBrowserContext());
......
......@@ -4,9 +4,8 @@
#include "content/browser/media/session/audio_focus_delegate.h"
#include "base/command_line.h"
#include "content/browser/media/session/audio_focus_manager.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h"
namespace content {
......@@ -35,11 +34,6 @@ class AudioFocusDelegateDefault : public AudioFocusDelegate {
AudioFocusType audio_focus_type_if_disabled_;
};
bool IsAudioFocusEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableAudioFocus);
}
} // anonymous namespace
AudioFocusDelegateDefault::AudioFocusDelegateDefault(
......@@ -52,7 +46,7 @@ bool AudioFocusDelegateDefault::RequestAudioFocus(
AudioFocusType audio_focus_type) {
audio_focus_type_if_disabled_ = audio_focus_type;
if (!IsAudioFocusEnabled())
if (!media_session::IsAudioFocusEnabled())
return true;
AudioFocusManager::GetInstance()->RequestAudioFocus(media_session_,
......@@ -65,7 +59,7 @@ void AudioFocusDelegateDefault::AbandonAudioFocus() {
}
AudioFocusType AudioFocusDelegateDefault::GetCurrentFocusType() const {
if (IsAudioFocusEnabled()) {
if (media_session::IsAudioFocusEnabled()) {
return AudioFocusManager::GetInstance()->GetFocusTypeForSession(
media_session_);
}
......
......@@ -8,14 +8,14 @@
#include "content/public/test/content_browser_test.h"
#include "content/shell/browser/shell.h"
#include "media/base/media_content_type.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
namespace content {
class AudioFocusDelegateDefaultBrowserTest : public ContentBrowserTest {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kEnableAudioFocus);
command_line->AppendSwitch(media_session::switches::kEnableAudioFocus);
}
void Run(WebContents* start_contents, WebContents* interrupt_contents) {
......
......@@ -17,7 +17,7 @@
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/test/test_web_contents.h"
#include "media/base/media_content_type.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h"
namespace content {
......@@ -68,7 +68,7 @@ class AudioFocusManagerTest : public testing::Test {
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableAudioFocus);
media_session::switches::kEnableAudioFocus);
rph_factory_.reset(new MockRenderProcessHostFactory());
RenderProcessHostImpl::set_render_process_host_factory_for_testing(
rph_factory_.get());
......
......@@ -15,6 +15,7 @@
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
namespace content {
......@@ -36,7 +37,7 @@ class MediaSessionBrowserTest : public ContentBrowserTest {
void EnableInternalMediaSesion() {
#if !defined(OS_ANDROID)
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableInternalMediaSession);
media_session::switches::kEnableInternalMediaSession);
#endif // !defined(OS_ANDROID)
}
......
......@@ -4,28 +4,11 @@
#include "content/browser/media/session/media_session_controllers_manager.h"
#include "base/command_line.h"
#include "content/browser/media/session/media_session_controller.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
namespace content {
namespace {
bool IsMediaSessionEnabled() {
// Media session is enabled on Android and Chrome OS to allow control of media
// players as needed.
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
return true;
#else
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
return command_line->HasSwitch(switches::kEnableInternalMediaSession) ||
command_line->HasSwitch(switches::kEnableAudioFocus);
#endif
}
} // anonymous namespace
MediaSessionControllersManager::MediaSessionControllersManager(
MediaWebContentsObserver* media_web_contents_observer)
: media_web_contents_observer_(media_web_contents_observer) {}
......@@ -34,7 +17,7 @@ MediaSessionControllersManager::~MediaSessionControllersManager() = default;
void MediaSessionControllersManager::RenderFrameDeleted(
RenderFrameHost* render_frame_host) {
if (!IsMediaSessionEnabled())
if (!media_session::IsMediaSessionEnabled())
return;
for (auto it = controllers_map_.begin(); it != controllers_map_.end();) {
......@@ -50,7 +33,7 @@ bool MediaSessionControllersManager::RequestPlay(
bool has_audio,
bool is_remote,
media::MediaContentType media_content_type) {
if (!IsMediaSessionEnabled())
if (!media_session::IsMediaSessionEnabled())
return true;
// Since we don't remove session instances on pause, there may be an existing
......@@ -78,7 +61,7 @@ bool MediaSessionControllersManager::RequestPlay(
}
void MediaSessionControllersManager::OnPause(const MediaPlayerId& id) {
if (!IsMediaSessionEnabled())
if (!media_session::IsMediaSessionEnabled())
return;
auto it = controllers_map_.find(id);
......@@ -89,13 +72,13 @@ void MediaSessionControllersManager::OnPause(const MediaPlayerId& id) {
}
void MediaSessionControllersManager::OnEnd(const MediaPlayerId& id) {
if (!IsMediaSessionEnabled())
if (!media_session::IsMediaSessionEnabled())
return;
controllers_map_.erase(id);
}
void MediaSessionControllersManager::WebContentsMutedStateChanged(bool muted) {
if (!IsMediaSessionEnabled())
if (!media_session::IsMediaSessionEnabled())
return;
for (auto& entry : controllers_map_)
......
......@@ -10,7 +10,7 @@
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "media/base/media_content_type.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -46,11 +46,11 @@ class MediaSessionControllersManagerTest
#if !defined(OS_ANDROID)
if (IsInternalMediaSessionEnabled()) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableInternalMediaSession);
media_session::switches::kEnableInternalMediaSession);
}
if (IsAudioFocusEnabled()) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableAudioFocus);
media_session::switches::kEnableAudioFocus);
}
#endif
......
......@@ -20,6 +20,7 @@
#include "content/public/test/test_navigation_observer.h"
#include "content/shell/browser/shell.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
......@@ -107,7 +108,7 @@ class MediaSessionImplVisibilityBrowserTest
switches::kAutoplayPolicy,
switches::autoplay::kNoUserGestureRequiredPolicy);
#if !defined(OS_ANDROID)
command_line->AppendSwitch(switches::kEnableAudioFocus);
command_line->AppendSwitch(media_session::switches::kEnableAudioFocus);
#endif // !defined(OS_ANDROID)
VisibilityTestData params = GetVisibilityTestData();
......
......@@ -11,7 +11,7 @@
#include "content/common/frame_messages.h"
#include "ipc/ipc_message_macros.h"
#include "media/base/media_content_type.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
namespace content {
......@@ -75,8 +75,9 @@ void PepperPlaybackObserver::PepperStartsPlayback(
MediaSessionImpl::Get(contents_)->AddPlayer(
players_map_[id].get(), PepperPlayerDelegate::kPlayerId,
media::IsAudioFocusDuckFlashEnabled() ? media::MediaContentType::Pepper
: media::MediaContentType::OneShot);
media_session::IsAudioFocusDuckFlashEnabled()
? media::MediaContentType::Pepper
: media::MediaContentType::OneShot);
}
void PepperPlaybackObserver::PepperStopsPlayback(
......
......@@ -8,7 +8,7 @@
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/media/session/pepper_playback_observer.h"
#include "content/common/frame_messages.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/switches.h"
namespace content {
......@@ -28,7 +28,7 @@ PepperPlayerDelegate::PepperPlayerDelegate(
PepperPlayerDelegate::~PepperPlayerDelegate() = default;
void PepperPlayerDelegate::OnSuspend(int player_id) {
if (!media::IsAudioFocusDuckFlashEnabled())
if (!media_session::IsAudioFocusDuckFlashEnabled())
return;
// Pepper player cannot be really suspended. Duck the volume instead.
......@@ -37,7 +37,7 @@ void PepperPlayerDelegate::OnSuspend(int player_id) {
}
void PepperPlayerDelegate::OnResume(int player_id) {
if (!media::IsAudioFocusDuckFlashEnabled())
if (!media_session::IsAudioFocusDuckFlashEnabled())
return;
DCHECK_EQ(player_id, kPlayerId);
......@@ -56,7 +56,7 @@ void PepperPlayerDelegate::OnSeekBackward(int player_id,
void PepperPlayerDelegate::OnSetVolumeMultiplier(int player_id,
double volume_multiplier) {
if (!media::IsAudioFocusDuckFlashEnabled())
if (!media_session::IsAudioFocusDuckFlashEnabled())
return;
DCHECK_EQ(player_id, kPlayerId);
......
......@@ -340,6 +340,7 @@ jumbo_source_set("browser_sources") {
"//media/mojo/interfaces:remoting",
"//mojo/public/cpp/bindings",
"//mojo/public/cpp/system",
"//services/media_session/public/cpp",
"//services/media_session/public/mojom",
"//services/network/public/mojom",
"//services/resource_coordinator/public/cpp:resource_coordinator_cpp",
......
......@@ -81,15 +81,6 @@ const char kUseCras[] = "use-cras";
const char kUnsafelyAllowProtectedMediaIdentifierForDomain[] =
"unsafely-allow-protected-media-identifier-for-domain";
// Enable a internal audio focus management between tabs in such a way that two
// tabs can't play on top of each other.
// The allowed values are: "" (empty) or |kEnableAudioFocusDuckFlash|.
const char kEnableAudioFocus[] = "enable-audio-focus";
// This value is used as an option for |kEnableAudioFocus|. Flash will
// be ducked when losing audio focus.
const char kEnableAudioFocusDuckFlash[] = "duck-flash";
#if BUILDFLAG(ENABLE_RUNTIME_MEDIA_RENDERER_SELECTION)
// Rather than use the renderer hosted remotely in the media service, fall back
// to the default renderer within content_renderer. Does not change the behavior
......@@ -181,12 +172,6 @@ const char kOverrideEnabledCdmInterfaceVersion[] =
const char kOverrideHardwareSecureCodecsForTesting[] =
"override-hardware-secure-codecs-for-testing";
#if !defined(OS_ANDROID)
// Turns on the internal media session backend. This should be used by embedders
// that want to control the media playback with the media session interfaces.
const char kEnableInternalMediaSession[] = "enable-internal-media-session";
#endif // !defined(OS_ANDROID)
namespace autoplay {
// Autoplay policy that requires a document user activation.
......@@ -431,12 +416,6 @@ std::string GetEffectiveAutoplayPolicy(const base::CommandLine& command_line) {
#endif
}
MEDIA_EXPORT bool IsAudioFocusDuckFlashEnabled() {
return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kEnableAudioFocus) ==
switches::kEnableAudioFocusDuckFlash;
}
// Adds icons to the overflow menu on the native media controls.
const base::Feature kOverflowIconsForMediaControls{
"OverflowIconsForMediaControls", base::FEATURE_ENABLED_BY_DEFAULT};
......
......@@ -56,9 +56,6 @@ MEDIA_EXPORT extern const char kUseCras[];
MEDIA_EXPORT extern const char
kUnsafelyAllowProtectedMediaIdentifierForDomain[];
MEDIA_EXPORT extern const char kEnableAudioFocus[];
MEDIA_EXPORT extern const char kEnableAudioFocusDuckFlash[];
#if BUILDFLAG(ENABLE_RUNTIME_MEDIA_RENDERER_SELECTION)
MEDIA_EXPORT extern const char kDisableMojoRenderer[];
#endif // BUILDFLAG(ENABLE_RUNTIME_MEDIA_RENDERER_SELECTION)
......@@ -85,10 +82,6 @@ MEDIA_EXPORT extern const char kClearKeyCdmPathForTesting[];
MEDIA_EXPORT extern const char kOverrideEnabledCdmInterfaceVersion[];
MEDIA_EXPORT extern const char kOverrideHardwareSecureCodecsForTesting[];
#if !defined(OS_ANDROID)
MEDIA_EXPORT extern const char kEnableInternalMediaSession[];
#endif // !defined(OS_ANDROID)
namespace autoplay {
MEDIA_EXPORT extern const char kDocumentUserActivationRequiredPolicy[];
......@@ -165,10 +158,6 @@ MEDIA_EXPORT extern const base::Feature kDirectShowGetPhotoState;
MEDIA_EXPORT std::string GetEffectiveAutoplayPolicy(
const base::CommandLine& command_line);
// Based on the command line of the current process, determine if
// audio focus duck flash should be enabled.
MEDIA_EXPORT bool IsAudioFocusDuckFlashEnabled();
MEDIA_EXPORT bool IsVideoCaptureAcceleratedJpegDecodingEnabled();
} // namespace media
......
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
component("cpp") {
output_name = "media_session_cpp"
sources = [
"switches.cc",
"switches.h",
]
deps = [
"//base",
]
defines = [ "IS_MEDIA_SESSION_CPP_IMPL" ]
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/media_session/public/cpp/switches.h"
#include "base/command_line.h"
#include "build/build_config.h"
namespace media_session {
namespace switches {
// Enable a internal audio focus management between tabs in such a way that two
// tabs can't play on top of each other.
// The allowed values are: "" (empty) or |switches::kEnableAudioFocusDuckFlash|.
const char kEnableAudioFocus[] = "enable-audio-focus";
// This value is used as an option for |kEnableAudioFocus|. Flash will
// be ducked when losing audio focus.
const char kEnableAudioFocusDuckFlash[] = "duck-flash";
#if !defined(OS_ANDROID)
// Turns on the internal media session backend. This should be used by embedders
// that want to control the media playback with the media session interfaces.
const char kEnableInternalMediaSession[] = "enable-internal-media-session";
#endif // !defined(OS_ANDROID)
} // namespace switches
bool IsAudioFocusEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableAudioFocus);
}
bool IsAudioFocusDuckFlashEnabled() {
return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kEnableAudioFocus) ==
switches::kEnableAudioFocusDuckFlash;
}
bool IsMediaSessionEnabled() {
// Media session is enabled on Android and Chrome OS to allow control of media
// players as needed.
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
return true;
#else
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
return command_line->HasSwitch(
media_session::switches::kEnableInternalMediaSession) ||
IsAudioFocusEnabled();
#endif
}
} // namespace media_session
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_MEDIA_SESSION_PUBLIC_CPP_SWITCHES_H_
#define SERVICES_MEDIA_SESSION_PUBLIC_CPP_SWITCHES_H_
#include "base/component_export.h"
#include "build/build_config.h"
namespace media_session {
namespace switches {
COMPONENT_EXPORT(MEDIA_SESSION_CPP) extern const char kEnableAudioFocus[];
COMPONENT_EXPORT(MEDIA_SESSION_CPP)
extern const char kEnableAudioFocusDuckFlash[];
#if !defined(OS_ANDROID)
COMPONENT_EXPORT(MEDIA_SESSION_CPP)
extern const char kEnableInternalMediaSession[];
#endif // !defined(OS_ANDROID)
} // namespace switches
COMPONENT_EXPORT(MEDIA_SESSION_CPP) bool IsAudioFocusEnabled();
// Based on the command line of the current process, determine if
// audio focus duck flash should be enabled.
COMPONENT_EXPORT(MEDIA_SESSION_CPP) bool IsAudioFocusDuckFlashEnabled();
COMPONENT_EXPORT(MEDIA_SESSION_CPP) bool IsMediaSessionEnabled();
} // namespace media_session
#endif // SERVICES_MEDIA_SESSION_PUBLIC_CPP_SWITCHES_H_
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