#include "content/public/renderer/key_system_support.h"
#include "base/logging.h"
#include "content/public/renderer/render_thread.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace content {
namespace {
class KeySystemSupportObserverImpl
: public media::mojom::KeySystemSupportObserver {
public:
explicit KeySystemSupportObserverImpl(KeySystemSupportCB cb)
: key_system_support_cb_(std::move(cb)) {}
KeySystemSupportObserverImpl(const KeySystemSupportObserverImpl&) = delete;
KeySystemSupportObserverImpl& operator=(const KeySystemSupportObserverImpl&) =
delete;
~KeySystemSupportObserverImpl() override = default;
void OnKeySystemSupportUpdated(
KeySystemCapabilityPtrMap key_system_capabilities) final {
key_system_support_cb_.Run(std::move(key_system_capabilities));
}
private:
KeySystemSupportCB key_system_support_cb_;
};
}
void ObserveKeySystemSupportUpdate(KeySystemSupportCB cb) {
DVLOG(1) << __func__;
mojo::Remote<media::mojom::KeySystemSupport> key_system_support;
content::RenderThread::Get()->BindHostReceiver(
key_system_support.BindNewPipeAndPassReceiver());
mojo::PendingRemote<media::mojom::KeySystemSupportObserver> observer_remote;
mojo::MakeSelfOwnedReceiver(
std::make_unique<KeySystemSupportObserverImpl>(std::move(cb)),
observer_remote.InitWithNewPipeAndPassReceiver());
key_system_support->AddObserver(std::move(observer_remote));
}
}