blob: f6d92c6f20a831c620782ad66f1e0d040c49c65e [file] [log] [blame]
// Copyright 2019 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 <memory>
#include <vector>
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/media_session/public/mojom/media_controller.mojom.h"
namespace mpris {
class MprisService;
} // namespace mpris
namespace service_manager {
class Connector;
} // namespace service_manager
namespace content {
// The MprisNotifier connects to our MPRIS service and keeps it informed of the
// current media playstate and metadata. It observes changes to the active Media
// Session and updates MPRIS accordingly.
// TODO( combine this with the
// NowPlayingInfoCenterNotifier (Mac) and SystemMediaControlsNotifier (Win) into
// something platform-independent.
class CONTENT_EXPORT MprisNotifier
: public media_session::mojom::MediaControllerObserver {
explicit MprisNotifier(service_manager::Connector* connector);
~MprisNotifier() override;
void Initialize();
// media_session::mojom::MediaControllerObserver implementation.
void MediaSessionInfoChanged(
media_session::mojom::MediaSessionInfoPtr session_info) override;
void MediaSessionMetadataChanged(
const base::Optional<media_session::MediaMetadata>& metadata) override;
void MediaSessionActionsChanged(
const std::vector<media_session::mojom::MediaSessionAction>& actions)
override {}
void MediaSessionChanged(
const base::Optional<base::UnguessableToken>& request_id) override {}
void SetMprisServiceForTesting(mpris::MprisService* service) {
service_ = service;
// Our connection to MPRIS.
mpris::MprisService* service_ = nullptr;
// Used to connect to the Media Session service.
service_manager::Connector* connector_;
// Tracks current media session state/metadata.
media_session::mojom::MediaControllerPtr media_controller_ptr_;
media_session::mojom::MediaSessionInfoPtr session_info_;
// Used to receive updates to the active media controller.
} // namespace content