| 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/mojo/clients/mojo_cdm.h" | 5 #include "media/mojo/clients/mojo_cdm.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 remote_cdm_.set_connection_error_with_reason_handler( | 115 remote_cdm_.set_connection_error_with_reason_handler( |
| 116 base::Bind(&MojoCdm::OnConnectionError, base::Unretained(this))); | 116 base::Bind(&MojoCdm::OnConnectionError, base::Unretained(this))); |
| 117 | 117 |
| 118 pending_init_promise_ = std::move(promise); | 118 pending_init_promise_ = std::move(promise); |
| 119 | 119 |
| 120 remote_cdm_->Initialize( | 120 remote_cdm_->Initialize( |
| 121 key_system, security_origin.spec(), mojom::CdmConfig::From(cdm_config), | 121 key_system, security_origin.spec(), mojom::CdmConfig::From(cdm_config), |
| 122 base::Bind(&MojoCdm::OnCdmInitialized, base::Unretained(this))); | 122 base::Bind(&MojoCdm::OnCdmInitialized, base::Unretained(this))); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // TODO(xhwang): Properly handle CDM calls after connection error. | |
| 126 // See http://crbug.com/671362 | |
| 127 void MojoCdm::OnConnectionError(uint32_t custom_reason, | 125 void MojoCdm::OnConnectionError(uint32_t custom_reason, |
| 128 const std::string& description) { | 126 const std::string& description) { |
| 129 LOG(ERROR) << "Remote CDM connection error: custom_reason=" << custom_reason | 127 LOG(ERROR) << "Remote CDM connection error: custom_reason=" << custom_reason |
| 130 << ", description=\"" << description << "\""; | 128 << ", description=\"" << description << "\""; |
| 131 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
| 132 | 130 |
| 131 remote_cdm_.reset(); |
| 132 |
| 133 // Handle initial connection error. | 133 // Handle initial connection error. |
| 134 if (pending_init_promise_) { | 134 if (pending_init_promise_) { |
| 135 DCHECK(!cdm_session_tracker_.HasRemainingSessions()); | 135 DCHECK(!cdm_session_tracker_.HasRemainingSessions()); |
| 136 pending_init_promise_->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, | 136 pending_init_promise_->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, |
| 137 "Mojo CDM creation failed."); | 137 "Mojo CDM creation failed."); |
| 138 // Dropping the promise could cause |this| to be destructed. | 138 // Dropping the promise could cause |this| to be destructed. |
| 139 pending_init_promise_.reset(); | 139 pending_init_promise_.reset(); |
| 140 return; | 140 return; |
| 141 } | 141 } |
| 142 | 142 |
| 143 cdm_session_tracker_.CloseRemainingSessions(session_closed_cb_); | 143 cdm_session_tracker_.CloseRemainingSessions(session_closed_cb_); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void MojoCdm::SetServerCertificate(const std::vector<uint8_t>& certificate, | 146 void MojoCdm::SetServerCertificate(const std::vector<uint8_t>& certificate, |
| 147 std::unique_ptr<SimpleCdmPromise> promise) { | 147 std::unique_ptr<SimpleCdmPromise> promise) { |
| 148 DVLOG(2) << __func__; | 148 DVLOG(2) << __func__; |
| 149 DCHECK(thread_checker_.CalledOnValidThread()); | 149 DCHECK(thread_checker_.CalledOnValidThread()); |
| 150 | 150 |
| 151 if (!remote_cdm_) { |
| 152 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0, |
| 153 "CDM connection lost."); |
| 154 return; |
| 155 } |
| 156 |
| 151 remote_cdm_->SetServerCertificate( | 157 remote_cdm_->SetServerCertificate( |
| 152 certificate, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, | 158 certificate, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, |
| 153 base::Unretained(this), base::Passed(&promise))); | 159 base::Unretained(this), base::Passed(&promise))); |
| 154 } | 160 } |
| 155 | 161 |
| 156 void MojoCdm::CreateSessionAndGenerateRequest( | 162 void MojoCdm::CreateSessionAndGenerateRequest( |
| 157 SessionType session_type, | 163 SessionType session_type, |
| 158 EmeInitDataType init_data_type, | 164 EmeInitDataType init_data_type, |
| 159 const std::vector<uint8_t>& init_data, | 165 const std::vector<uint8_t>& init_data, |
| 160 std::unique_ptr<NewSessionCdmPromise> promise) { | 166 std::unique_ptr<NewSessionCdmPromise> promise) { |
| 161 DVLOG(2) << __func__; | 167 DVLOG(2) << __func__; |
| 162 DCHECK(thread_checker_.CalledOnValidThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
| 163 | 169 |
| 170 if (!remote_cdm_) { |
| 171 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0, |
| 172 "CDM connection lost."); |
| 173 return; |
| 174 } |
| 175 |
| 164 remote_cdm_->CreateSessionAndGenerateRequest( | 176 remote_cdm_->CreateSessionAndGenerateRequest( |
| 165 session_type, init_data_type, init_data, | 177 session_type, init_data_type, init_data, |
| 166 base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult, base::Unretained(this), | 178 base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult, base::Unretained(this), |
| 167 base::Passed(&promise))); | 179 base::Passed(&promise))); |
| 168 } | 180 } |
| 169 | 181 |
| 170 void MojoCdm::LoadSession(SessionType session_type, | 182 void MojoCdm::LoadSession(SessionType session_type, |
| 171 const std::string& session_id, | 183 const std::string& session_id, |
| 172 std::unique_ptr<NewSessionCdmPromise> promise) { | 184 std::unique_ptr<NewSessionCdmPromise> promise) { |
| 173 DVLOG(2) << __func__; | 185 DVLOG(2) << __func__; |
| 174 DCHECK(thread_checker_.CalledOnValidThread()); | 186 DCHECK(thread_checker_.CalledOnValidThread()); |
| 175 | 187 |
| 188 if (!remote_cdm_) { |
| 189 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0, |
| 190 "CDM connection lost."); |
| 191 return; |
| 192 } |
| 193 |
| 176 remote_cdm_->LoadSession( | 194 remote_cdm_->LoadSession( |
| 177 session_type, session_id, | 195 session_type, session_id, |
| 178 base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult, base::Unretained(this), | 196 base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult, base::Unretained(this), |
| 179 base::Passed(&promise))); | 197 base::Passed(&promise))); |
| 180 } | 198 } |
| 181 | 199 |
| 182 void MojoCdm::UpdateSession(const std::string& session_id, | 200 void MojoCdm::UpdateSession(const std::string& session_id, |
| 183 const std::vector<uint8_t>& response, | 201 const std::vector<uint8_t>& response, |
| 184 std::unique_ptr<SimpleCdmPromise> promise) { | 202 std::unique_ptr<SimpleCdmPromise> promise) { |
| 185 DVLOG(2) << __func__; | 203 DVLOG(2) << __func__; |
| 186 DCHECK(thread_checker_.CalledOnValidThread()); | 204 DCHECK(thread_checker_.CalledOnValidThread()); |
| 187 | 205 |
| 206 if (!remote_cdm_) { |
| 207 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0, |
| 208 "CDM connection lost."); |
| 209 return; |
| 210 } |
| 211 |
| 188 remote_cdm_->UpdateSession( | 212 remote_cdm_->UpdateSession( |
| 189 session_id, response, | 213 session_id, response, |
| 190 base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, base::Unretained(this), | 214 base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, base::Unretained(this), |
| 191 base::Passed(&promise))); | 215 base::Passed(&promise))); |
| 192 } | 216 } |
| 193 | 217 |
| 194 void MojoCdm::CloseSession(const std::string& session_id, | 218 void MojoCdm::CloseSession(const std::string& session_id, |
| 195 std::unique_ptr<SimpleCdmPromise> promise) { | 219 std::unique_ptr<SimpleCdmPromise> promise) { |
| 196 DVLOG(2) << __func__; | 220 DVLOG(2) << __func__; |
| 197 DCHECK(thread_checker_.CalledOnValidThread()); | 221 DCHECK(thread_checker_.CalledOnValidThread()); |
| 198 | 222 |
| 223 if (!remote_cdm_) { |
| 224 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0, |
| 225 "CDM connection lost."); |
| 226 return; |
| 227 } |
| 228 |
| 199 remote_cdm_->CloseSession( | 229 remote_cdm_->CloseSession( |
| 200 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, | 230 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, |
| 201 base::Unretained(this), base::Passed(&promise))); | 231 base::Unretained(this), base::Passed(&promise))); |
| 202 } | 232 } |
| 203 | 233 |
| 204 void MojoCdm::RemoveSession(const std::string& session_id, | 234 void MojoCdm::RemoveSession(const std::string& session_id, |
| 205 std::unique_ptr<SimpleCdmPromise> promise) { | 235 std::unique_ptr<SimpleCdmPromise> promise) { |
| 206 DVLOG(2) << __func__; | 236 DVLOG(2) << __func__; |
| 207 DCHECK(thread_checker_.CalledOnValidThread()); | 237 DCHECK(thread_checker_.CalledOnValidThread()); |
| 208 | 238 |
| 239 if (!remote_cdm_) { |
| 240 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0, |
| 241 "CDM connection lost."); |
| 242 return; |
| 243 } |
| 244 |
| 209 remote_cdm_->RemoveSession( | 245 remote_cdm_->RemoveSession( |
| 210 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, | 246 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, |
| 211 base::Unretained(this), base::Passed(&promise))); | 247 base::Unretained(this), base::Passed(&promise))); |
| 212 } | 248 } |
| 213 | 249 |
| 214 CdmContext* MojoCdm::GetCdmContext() { | 250 CdmContext* MojoCdm::GetCdmContext() { |
| 215 DVLOG(2) << __func__; | 251 DVLOG(2) << __func__; |
| 216 return this; | 252 return this; |
| 217 } | 253 } |
| 218 | 254 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 mojom::CdmPromiseResultPtr result, | 380 mojom::CdmPromiseResultPtr result, |
| 345 const std::string& session_id) { | 381 const std::string& session_id) { |
| 346 if (result->success) { | 382 if (result->success) { |
| 347 cdm_session_tracker_.AddSession(session_id); | 383 cdm_session_tracker_.AddSession(session_id); |
| 348 promise->resolve(session_id); | 384 promise->resolve(session_id); |
| 349 } else | 385 } else |
| 350 RejectPromise(std::move(promise), std::move(result)); | 386 RejectPromise(std::move(promise), std::move(result)); |
| 351 } | 387 } |
| 352 | 388 |
| 353 } // namespace media | 389 } // namespace media |
| OLD | NEW |