OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/blink/cdm_session_adapter.h" | 5 #include "media/blink/cdm_session_adapter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // |this| instead of |weak_this| to prevent |this| from being destructed. | 49 // |this| instead of |weak_this| to prevent |this| from being destructed. |
50 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); | 50 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); |
51 | 51 |
52 DCHECK(!cdm_created_result_); | 52 DCHECK(!cdm_created_result_); |
53 cdm_created_result_ = std::move(result); | 53 cdm_created_result_ = std::move(result); |
54 | 54 |
55 cdm_factory->Create( | 55 cdm_factory->Create( |
56 key_system, security_origin, cdm_config, | 56 key_system, security_origin, cdm_config, |
57 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | 57 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), |
58 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | 58 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), |
59 base::Bind(&CdmSessionAdapter::OnLegacySessionError, weak_this), | |
60 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), | 59 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), |
61 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this), | 60 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this), |
62 base::Bind(&CdmSessionAdapter::OnCdmCreated, this, key_system, | 61 base::Bind(&CdmSessionAdapter::OnCdmCreated, this, key_system, |
63 start_time)); | 62 start_time)); |
64 } | 63 } |
65 | 64 |
66 void CdmSessionAdapter::SetServerCertificate( | 65 void CdmSessionAdapter::SetServerCertificate( |
67 const std::vector<uint8_t>& certificate, | 66 const std::vector<uint8_t>& certificate, |
68 std::unique_ptr<SimpleCdmPromise> promise) { | 67 std::unique_ptr<SimpleCdmPromise> promise) { |
69 cdm_->SetServerCertificate(certificate, std::move(promise)); | 68 cdm_->SetServerCertificate(certificate, std::move(promise)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // Only report time for successful CDM creation. | 163 // Only report time for successful CDM creation. |
165 ReportTimeToCreateCdmUMA(base::TimeTicks::Now() - start_time); | 164 ReportTimeToCreateCdmUMA(base::TimeTicks::Now() - start_time); |
166 | 165 |
167 cdm_ = cdm; | 166 cdm_ = cdm; |
168 | 167 |
169 cdm_created_result_->completeWithContentDecryptionModule( | 168 cdm_created_result_->completeWithContentDecryptionModule( |
170 new WebContentDecryptionModuleImpl(this)); | 169 new WebContentDecryptionModuleImpl(this)); |
171 cdm_created_result_.reset(); | 170 cdm_created_result_.reset(); |
172 } | 171 } |
173 | 172 |
174 void CdmSessionAdapter::OnSessionMessage( | 173 void CdmSessionAdapter::OnSessionMessage(const std::string& session_id, |
175 const std::string& session_id, | 174 MediaKeys::MessageType message_type, |
176 MediaKeys::MessageType message_type, | 175 const std::vector<uint8_t>& message) { |
177 const std::vector<uint8_t>& message, | |
178 const GURL& /* legacy_destination_url */) { | |
179 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | 176 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); |
180 DLOG_IF(WARNING, !session) << __func__ << " for unknown session " | 177 DLOG_IF(WARNING, !session) << __func__ << " for unknown session " |
181 << session_id; | 178 << session_id; |
182 if (session) | 179 if (session) |
183 session->OnSessionMessage(message_type, message); | 180 session->OnSessionMessage(message_type, message); |
184 } | 181 } |
185 | 182 |
186 void CdmSessionAdapter::OnSessionKeysChange(const std::string& session_id, | 183 void CdmSessionAdapter::OnSessionKeysChange(const std::string& session_id, |
187 bool has_additional_usable_key, | 184 bool has_additional_usable_key, |
188 CdmKeysInfo keys_info) { | 185 CdmKeysInfo keys_info) { |
(...skipping 16 matching lines...) Expand all Loading... |
205 } | 202 } |
206 | 203 |
207 void CdmSessionAdapter::OnSessionClosed(const std::string& session_id) { | 204 void CdmSessionAdapter::OnSessionClosed(const std::string& session_id) { |
208 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | 205 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); |
209 DLOG_IF(WARNING, !session) << __func__ << " for unknown session " | 206 DLOG_IF(WARNING, !session) << __func__ << " for unknown session " |
210 << session_id; | 207 << session_id; |
211 if (session) | 208 if (session) |
212 session->OnSessionClosed(); | 209 session->OnSessionClosed(); |
213 } | 210 } |
214 | 211 |
215 void CdmSessionAdapter::OnLegacySessionError( | |
216 const std::string& session_id, | |
217 MediaKeys::Exception exception_code, | |
218 uint32_t system_code, | |
219 const std::string& error_message) { | |
220 // Error events not used by unprefixed EME. | |
221 // TODO(jrummell): Remove when prefixed EME removed. https://crbug.com/249976 | |
222 } | |
223 | |
224 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | 212 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( |
225 const std::string& session_id) { | 213 const std::string& session_id) { |
226 // Since session objects may get garbage collected, it is possible that there | 214 // Since session objects may get garbage collected, it is possible that there |
227 // are events coming back from the CDM and the session has been unregistered. | 215 // are events coming back from the CDM and the session has been unregistered. |
228 // We can not tell if the CDM is firing events at sessions that never existed. | 216 // We can not tell if the CDM is firing events at sessions that never existed. |
229 SessionMap::iterator session = sessions_.find(session_id); | 217 SessionMap::iterator session = sessions_.find(session_id); |
230 return (session != sessions_.end()) ? session->second.get() : NULL; | 218 return (session != sessions_.end()) ? session->second.get() : NULL; |
231 } | 219 } |
232 | 220 |
233 void CdmSessionAdapter::ReportTimeToCreateCdmUMA(base::TimeDelta time) const { | 221 void CdmSessionAdapter::ReportTimeToCreateCdmUMA(base::TimeDelta time) const { |
234 // Note: This leaks memory, which is expected behavior. | 222 // Note: This leaks memory, which is expected behavior. |
235 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( | 223 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( |
236 GetKeySystemUMAPrefix() + kTimeToCreateCdmUMAName, | 224 GetKeySystemUMAPrefix() + kTimeToCreateCdmUMAName, |
237 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), | 225 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), |
238 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 226 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
239 | 227 |
240 histogram->AddTime(time); | 228 histogram->AddTime(time); |
241 } | 229 } |
242 | 230 |
243 } // namespace media | 231 } // namespace media |
OLD | NEW |