Add ability for NetLogLogger to gather data from more than just NetLog
[chromium-blink-merge.git] / chromecast / media / cdm / browser_cdm_cast.cc
blob8db9563d31692f5e819a2291f29916da45a0e8e5
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/media/cdm/browser_cdm_cast.h"
7 #include "media/base/cdm_key_information.h"
9 namespace chromecast {
10 namespace media {
12 BrowserCdmCast::BrowserCdmCast()
13 : next_registration_id_(0) {
16 BrowserCdmCast::~BrowserCdmCast() {
17 base::AutoLock auto_lock(callback_lock_);
18 for (std::map<uint32_t, base::Closure>::const_iterator it =
19 cdm_unset_callbacks_.begin(); it != cdm_unset_callbacks_.end(); ++it) {
20 it->second.Run();
24 void BrowserCdmCast::SetCallbacks(
25 const ::media::SessionMessageCB& session_message_cb,
26 const ::media::SessionClosedCB& session_closed_cb,
27 const ::media::SessionErrorCB& session_error_cb,
28 const ::media::SessionKeysChangeCB& session_keys_change_cb,
29 const ::media::SessionExpirationUpdateCB& session_expiration_update_cb) {
30 session_message_cb_ = session_message_cb;
31 session_closed_cb_ = session_closed_cb;
32 session_error_cb_ = session_error_cb;
33 session_keys_change_cb_ = session_keys_change_cb;
34 session_expiration_update_cb_ = session_expiration_update_cb;
37 int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb,
38 const base::Closure& cdm_unset_cb) {
39 int registration_id = next_registration_id_++;
40 DCHECK(!new_key_cb.is_null());
41 DCHECK(!cdm_unset_cb.is_null());
43 base::AutoLock auto_lock(callback_lock_);
44 DCHECK(!ContainsKey(new_key_callbacks_, registration_id));
45 DCHECK(!ContainsKey(cdm_unset_callbacks_, registration_id));
46 new_key_callbacks_[registration_id] = new_key_cb;
47 cdm_unset_callbacks_[registration_id] = cdm_unset_cb;
49 return registration_id;
52 void BrowserCdmCast::UnregisterPlayer(int registration_id) {
53 base::AutoLock auto_lock(callback_lock_);
54 DCHECK(ContainsKey(new_key_callbacks_, registration_id));
55 DCHECK(ContainsKey(cdm_unset_callbacks_, registration_id));
56 new_key_callbacks_.erase(registration_id);
57 cdm_unset_callbacks_.erase(registration_id);
60 void BrowserCdmCast::LoadSession(
61 ::media::MediaKeys::SessionType session_type,
62 const std::string& session_id,
63 scoped_ptr<::media::NewSessionCdmPromise> promise) {
64 NOTREACHED() << "LoadSession not supported";
65 session_error_cb_.Run(session_id,
66 ::media::MediaKeys::Exception::NOT_SUPPORTED_ERROR,
68 std::string());
71 ::media::CdmContext* BrowserCdmCast::GetCdmContext() {
72 NOTREACHED();
73 return nullptr;
76 void BrowserCdmCast::OnSessionMessage(const std::string& session_id,
77 const std::vector<uint8>& message,
78 const GURL& destination_url) {
79 // Note: Message type is not supported in Chromecast. Do our best guess here.
80 ::media::MediaKeys::MessageType message_type =
81 destination_url.is_empty() ? ::media::MediaKeys::LICENSE_REQUEST
82 : ::media::MediaKeys::LICENSE_RENEWAL;
83 session_message_cb_.Run(session_id,
84 message_type,
85 message,
86 destination_url);
89 void BrowserCdmCast::OnSessionClosed(const std::string& session_id) {
90 session_closed_cb_.Run(session_id);
93 void BrowserCdmCast::OnSessionKeysChange(
94 const std::string& session_id,
95 const ::media::KeyIdAndKeyPairs& keys) {
96 ::media::CdmKeysInfo cdm_keys_info;
97 for (const std::pair<std::string, std::string>& key : keys) {
98 scoped_ptr< ::media::CdmKeyInformation> cdm_key_information(
99 new ::media::CdmKeyInformation());
100 cdm_key_information->key_id.assign(key.first.begin(), key.first.end());
101 cdm_keys_info.push_back(cdm_key_information.release());
103 session_keys_change_cb_.Run(session_id, true, cdm_keys_info.Pass());
105 // Notify listeners of a new key.
107 base::AutoLock auto_lock(callback_lock_);
108 for (std::map<uint32_t, base::Closure>::const_iterator it =
109 new_key_callbacks_.begin(); it != new_key_callbacks_.end(); ++it) {
110 it->second.Run();
115 } // namespace media
116 } // namespace chromecast