Commit 7d9d666d authored by Tommy Steimel's avatar Tommy Steimel Committed by Chromium LUCI CQ

MPRIS: Use correct product name for Identity

This CL refactors the System Media Controls to use the product name
from media::AudioManager::GetGlobalAppName() instead of inferring the
product name from branding buildflags.

Bug: 942114
Change-Id: Idd1c77ae90b7a89d676e391f83623ab8c4d33a1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2607504
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845920}
parent bdb876e8
......@@ -111,6 +111,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/profiler/thread_profiler.h"
#include "chrome/common/profiler/thread_profiler_configuration.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/installer/util/google_update_settings.h"
#include "components/device_event_log/device_event_log.h"
......@@ -164,6 +165,7 @@
#include "content/public/common/main_function_params.h"
#include "content/public/common/profiling.h"
#include "extensions/buildflags/buildflags.h"
#include "media/audio/audio_manager.h"
#include "media/base/localized_strings.h"
#include "media/media_buildflags.h"
#include "net/base/net_module.h"
......@@ -175,6 +177,7 @@
#include "rlz/buildflags/buildflags.h"
#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
#include "third_party/blink/public/common/experiments/memory_ablation_experiment.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -191,7 +194,6 @@
#include "chrome/browser/ui/uma_browsing_activity_observer.h"
#include "chrome/browser/upgrade_detector/upgrade_detector.h"
#include "chrome/browser/usb/web_usb_detector.h"
#include "ui/base/l10n/l10n_util.h"
#endif // defined(OS_ANDROID)
#if !defined(OS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)
......@@ -1058,6 +1060,9 @@ void ChromeBrowserMainParts::PreMainMessageLoopRun() {
void ChromeBrowserMainParts::PreProfileInit() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreProfileInit");
media::AudioManager::SetGlobalAppName(
l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME));
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PreProfileInit();
......
......@@ -22,7 +22,6 @@
#include "content/public/browser/browser_task_traits.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/bluez_dbus_thread_manager.h"
#include "media/audio/audio_manager.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
......@@ -57,9 +56,6 @@ void ChromeBrowserMainPartsLinux::PreProfileInit() {
base::BindOnce(base::IgnoreResult(&base::GetLinuxDistro)));
#endif
media::AudioManager::SetGlobalAppName(
l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME));
#if !BUILDFLAG(IS_CHROMEOS_ASH)
// Set up crypt config. This should be kept in sync with the OSCrypt parts of
// SystemNetworkContextManager::OnNetworkServiceCreated.
......
......@@ -21,7 +21,6 @@ component("system_media_controls") {
public_deps = [ "//skia" ]
# TODO(https://crbug.com/949596): Move MPRIS and Now Playing here.
if (is_win) {
sources = [
"win/system_media_controls_win.cc",
......
......@@ -12,8 +12,8 @@
#include "base/callback_helpers.h"
#include "base/process/process.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/branding_buildflags.h"
#include "components/dbus/properties/dbus_properties.h"
#include "components/dbus/properties/success_barrier_callback.h"
#include "components/dbus/thread_linux/dbus_thread_linux.h"
......@@ -27,8 +27,10 @@
namespace system_media_controls {
// static
std::unique_ptr<SystemMediaControls> SystemMediaControls::Create() {
auto service = std::make_unique<internal::SystemMediaControlsLinux>();
std::unique_ptr<SystemMediaControls> SystemMediaControls::Create(
const std::string& product_name) {
auto service =
std::make_unique<internal::SystemMediaControlsLinux>(product_name);
service->StartService();
return std::move(service);
}
......@@ -41,20 +43,17 @@ constexpr int kNumMethodsToExport = 11;
} // namespace
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
const char kMprisAPIServiceNamePrefix[] =
"org.mpris.MediaPlayer2.chrome.instance";
#else
const char kMprisAPIServiceNamePrefix[] =
"org.mpris.MediaPlayer2.chromium.instance";
#endif
const char kMprisAPIServiceNameFormatString[] =
"org.mpris.MediaPlayer2.chromium.instance%i";
const char kMprisAPIObjectPath[] = "/org/mpris/MediaPlayer2";
const char kMprisAPIInterfaceName[] = "org.mpris.MediaPlayer2";
const char kMprisAPIPlayerInterfaceName[] = "org.mpris.MediaPlayer2.Player";
SystemMediaControlsLinux::SystemMediaControlsLinux()
: service_name_(std::string(kMprisAPIServiceNamePrefix) +
base::NumberToString(base::Process::Current().Pid())) {}
SystemMediaControlsLinux::SystemMediaControlsLinux(
const std::string& product_name)
: product_name_(product_name),
service_name_(base::StringPrintf(kMprisAPIServiceNameFormatString,
base::Process::Current().Pid())) {}
SystemMediaControlsLinux::~SystemMediaControlsLinux() {
if (bus_) {
......@@ -152,11 +151,7 @@ void SystemMediaControlsLinux::InitializeProperties() {
set_property("CanRaise", DbusBoolean(false));
set_property("HasTrackList", DbusBoolean(false));
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
set_property("Identity", DbusString("Chrome"));
#else
set_property("Identity", DbusString("Chromium"));
#endif
set_property("Identity", DbusString(product_name_));
set_property("SupportedUriSchemes", DbusArray<DbusString>());
set_property("SupportedMimeTypes", DbusArray<DbusString>());
......
......@@ -31,7 +31,7 @@ class SystemMediaControlsObserver;
namespace internal {
COMPONENT_EXPORT(SYSTEM_MEDIA_CONTROLS)
extern const char kMprisAPIServiceNamePrefix[];
extern const char kMprisAPIServiceNameFormatString[];
COMPONENT_EXPORT(SYSTEM_MEDIA_CONTROLS) extern const char kMprisAPIObjectPath[];
COMPONENT_EXPORT(SYSTEM_MEDIA_CONTROLS)
extern const char kMprisAPIInterfaceName[];
......@@ -43,7 +43,7 @@ extern const char kMprisAPIPlayerInterfaceName[];
class COMPONENT_EXPORT(SYSTEM_MEDIA_CONTROLS) SystemMediaControlsLinux
: public SystemMediaControls {
public:
SystemMediaControlsLinux();
explicit SystemMediaControlsLinux(const std::string& product_name);
~SystemMediaControlsLinux() override;
// Starts the DBus service.
......@@ -104,6 +104,8 @@ class COMPONENT_EXPORT(SYSTEM_MEDIA_CONTROLS) SystemMediaControlsLinux
void SetMetadataPropertyInternal(const std::string& property_name,
DbusVariant&& new_value);
const std::string product_name_;
std::unique_ptr<DbusProperties> properties_;
scoped_refptr<dbus::Bus> bus_;
......
......@@ -32,6 +32,7 @@ namespace internal {
namespace {
constexpr uint32_t kFakeSerial = 123;
const char kTestProductName[] = "Foo";
} // anonymous namespace
......@@ -89,7 +90,7 @@ class SystemMediaControlsLinuxTest : public testing::Test,
private:
void StartMprisServiceAndWaitForReady() {
service_wait_loop_ = std::make_unique<base::RunLoop>();
service_ = std::make_unique<SystemMediaControlsLinux>();
service_ = std::make_unique<SystemMediaControlsLinux>(kTestProductName);
SetUpMocks();
......
......@@ -7,9 +7,12 @@
namespace system_media_controls {
// static
std::unique_ptr<SystemMediaControls> SystemMediaControls::Create() {
std::unique_ptr<SystemMediaControls> SystemMediaControls::Create(
const std::string& product_name) {
// The required APIs for interacting with the Now Playing Info Center only
// exist on 10.12.2 or later.
// TODO(https://crbug.com/942114): Use the |product_name| string in
// NowPlayingInfoCenterDelegateCocoa instead of using branding build args.
if (@available(macOS 10.12.2, *))
return std::make_unique<internal::SystemMediaControlsMac>();
return nullptr;
......
......@@ -26,7 +26,8 @@ class COMPONENT_EXPORT(SYSTEM_MEDIA_CONTROLS) SystemMediaControls {
kStopped,
};
static std::unique_ptr<SystemMediaControls> Create();
static std::unique_ptr<SystemMediaControls> Create(
const std::string& product_name);
virtual ~SystemMediaControls() = default;
......
......@@ -7,7 +7,8 @@
namespace system_media_controls {
// static
std::unique_ptr<SystemMediaControls> SystemMediaControls::Create() {
std::unique_ptr<SystemMediaControls> SystemMediaControls::Create(
const std::string& product_name) {
return nullptr;
}
......
......@@ -19,7 +19,8 @@
namespace system_media_controls {
// static
std::unique_ptr<SystemMediaControls> SystemMediaControls::Create() {
std::unique_ptr<SystemMediaControls> SystemMediaControls::Create(
const std::string& product_name) {
auto service = std::make_unique<internal::SystemMediaControlsWin>();
if (service->Initialize())
return std::move(service);
......
......@@ -12,6 +12,7 @@
#include "content/browser/browser_main_loop.h"
#include "content/browser/media/active_media_session_controller.h"
#include "content/browser/media/system_media_controls_notifier.h"
#include "media/audio/audio_manager.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/idle/idle.h"
......@@ -215,9 +216,11 @@ void MediaKeysListenerManagerImpl::StartListeningForMediaKeysIfNecessary() {
if (system_media_controls_ || media_keys_listener_)
return;
// Create an instance of SystemMediaControls to listen for media control
// events.
system_media_controls_ = system_media_controls::SystemMediaControls::Create();
#if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_MAC)
system_media_controls_ = system_media_controls::SystemMediaControls::Create(
media::AudioManager::GetGlobalAppName());
#endif
if (system_media_controls_) {
system_media_controls_->AddObserver(this);
system_media_controls_notifier_ =
......
......@@ -48,10 +48,8 @@ class AudioManagerHelper {
}
#endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
void set_app_name(const std::string& app_name) { app_name_ = app_name; }
const std::string& app_name() const { return app_name_; }
#endif
FakeAudioLogFactory fake_log_factory_;
......@@ -59,9 +57,7 @@ class AudioManagerHelper {
std::unique_ptr<base::win::ScopedCOMInitializer> com_initializer_for_testing_;
#endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
std::string app_name_;
#endif
DISALLOW_COPY_AND_ASSIGN(AudioManagerHelper);
};
......@@ -128,7 +124,6 @@ std::unique_ptr<AudioManager> AudioManager::CreateForTesting(
return Create(std::move(audio_thread), GetHelper()->fake_log_factory());
}
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
// static
void AudioManager::SetGlobalAppName(const std::string& app_name) {
GetHelper()->set_app_name(app_name);
......@@ -138,7 +133,6 @@ void AudioManager::SetGlobalAppName(const std::string& app_name) {
const std::string& AudioManager::GetGlobalAppName() {
return GetHelper()->app_name();
}
#endif
// static
AudioManager* AudioManager::Get() {
......
......@@ -60,14 +60,11 @@ class MEDIA_EXPORT AudioManager {
static std::unique_ptr<AudioManager> CreateForTesting(
std::unique_ptr<AudioThread> audio_thread);
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
// Sets the name of the audio source as seen by external apps. Only actually
// used with PulseAudio as of this writing.
// Sets the name of the audio source as seen by external apps.
static void SetGlobalAppName(const std::string& app_name);
// Returns the app name or an empty string if it is not set.
static const std::string& GetGlobalAppName();
#endif
// Returns the pointer to the last created instance, or NULL if not yet
// created. This is a utility method for the code outside of media directory,
......
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