| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 remote_cdm_->SetClient(binding_.CreateInterfacePtrAndBind()); | 77 remote_cdm_->SetClient(binding_.CreateInterfacePtrAndBind()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 MojoCdm::~MojoCdm() { | 80 MojoCdm::~MojoCdm() { |
| 81 DVLOG(1) << __FUNCTION__; | 81 DVLOG(1) << __FUNCTION__; |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
| 83 | 83 |
| 84 base::AutoLock auto_lock(lock_); | 84 base::AutoLock auto_lock(lock_); |
| 85 | 85 |
| 86 // Release |decryptor_| on the correct thread. If GetDecryptor() is never | 86 // Release |decryptor_| on the correct thread. If GetDecryptor() is never |
| 87 // called but |decryptor_ptr_| is not null, it is not bound to any thread and | 87 // called but |decryptor_ptr_info_| is not null, it is not bound to any thread |
| 88 // is safe to be released on the current thread. | 88 // and is safe to be released on the current thread. |
| 89 if (decryptor_task_runner_ && | 89 if (decryptor_task_runner_ && |
| 90 !decryptor_task_runner_->BelongsToCurrentThread() && decryptor_) { | 90 !decryptor_task_runner_->BelongsToCurrentThread() && decryptor_) { |
| 91 decryptor_task_runner_->DeleteSoon(FROM_HERE, decryptor_.release()); | 91 decryptor_task_runner_->DeleteSoon(FROM_HERE, decryptor_.release()); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Using base::Unretained(this) below is safe because |this| owns |remote_cdm_|, | 95 // Using base::Unretained(this) below is safe because |this| owns |remote_cdm_|, |
| 96 // and if |this| is destroyed, |remote_cdm_| will be destroyed as well. Then the | 96 // and if |this| is destroyed, |remote_cdm_| will be destroyed as well. Then the |
| 97 // error handler can't be invoked and callbacks won't be dispatched. | 97 // error handler can't be invoked and callbacks won't be dispatched. |
| 98 | 98 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 media::Decryptor* MojoCdm::GetDecryptor() { | 213 media::Decryptor* MojoCdm::GetDecryptor() { |
| 214 base::AutoLock auto_lock(lock_); | 214 base::AutoLock auto_lock(lock_); |
| 215 | 215 |
| 216 if (!decryptor_task_runner_) | 216 if (!decryptor_task_runner_) |
| 217 decryptor_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 217 decryptor_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 218 | 218 |
| 219 DCHECK(decryptor_task_runner_->BelongsToCurrentThread()); | 219 DCHECK(decryptor_task_runner_->BelongsToCurrentThread()); |
| 220 | 220 |
| 221 // Can be called on a different thread. | 221 // Can be called on a different thread. |
| 222 if (decryptor_ptr_) { | 222 if (decryptor_ptr_info_.is_valid()) { |
| 223 DCHECK(!decryptor_); | 223 DCHECK(!decryptor_); |
| 224 decryptor_.reset(new MojoDecryptor(std::move(decryptor_ptr_))); | 224 mojom::DecryptorPtr decryptor_ptr; |
| 225 decryptor_ptr.Bind(std::move(decryptor_ptr_info_)); |
| 226 decryptor_.reset(new MojoDecryptor(std::move(decryptor_ptr))); |
| 225 } | 227 } |
| 226 | 228 |
| 227 return decryptor_.get(); | 229 return decryptor_.get(); |
| 228 } | 230 } |
| 229 | 231 |
| 230 int MojoCdm::GetCdmId() const { | 232 int MojoCdm::GetCdmId() const { |
| 231 base::AutoLock auto_lock(lock_); | 233 base::AutoLock auto_lock(lock_); |
| 232 // Can be called on a different thread. | 234 // Can be called on a different thread. |
| 233 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id_); | 235 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id_); |
| 234 return cdm_id_; | 236 return cdm_id_; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 301 |
| 300 if (!result->success) { | 302 if (!result->success) { |
| 301 RejectPromise(std::move(pending_init_promise_), std::move(result)); | 303 RejectPromise(std::move(pending_init_promise_), std::move(result)); |
| 302 return; | 304 return; |
| 303 } | 305 } |
| 304 | 306 |
| 305 { | 307 { |
| 306 base::AutoLock auto_lock(lock_); | 308 base::AutoLock auto_lock(lock_); |
| 307 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id); | 309 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id); |
| 308 cdm_id_ = cdm_id; | 310 cdm_id_ = cdm_id; |
| 309 decryptor_ptr_ = std::move(decryptor); | 311 decryptor_ptr_info_ = decryptor.PassInterface(); |
| 310 } | 312 } |
| 311 | 313 |
| 312 pending_init_promise_->resolve(); | 314 pending_init_promise_->resolve(); |
| 313 pending_init_promise_.reset(); | 315 pending_init_promise_.reset(); |
| 314 } | 316 } |
| 315 | 317 |
| 316 void MojoCdm::OnKeyAdded() { | 318 void MojoCdm::OnKeyAdded() { |
| 317 base::AutoLock auto_lock(lock_); | 319 base::AutoLock auto_lock(lock_); |
| 318 | 320 |
| 319 DCHECK(decryptor_task_runner_); | 321 DCHECK(decryptor_task_runner_); |
| 320 DCHECK(decryptor_task_runner_->BelongsToCurrentThread()); | 322 DCHECK(decryptor_task_runner_->BelongsToCurrentThread()); |
| 321 DCHECK(decryptor_); | 323 DCHECK(decryptor_); |
| 322 | 324 |
| 323 decryptor_->OnKeyAdded(); | 325 decryptor_->OnKeyAdded(); |
| 324 } | 326 } |
| 325 | 327 |
| 326 } // namespace media | 328 } // namespace media |
| OLD | NEW |