| 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 "chromecast/media/cdm/browser_cdm_cast.h" | 5 #include "chromecast/media/cdm/browser_cdm_cast.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // media::CdmPromiseTemplate implementation that wraps a promise so as to | 22 // media::CdmPromiseTemplate implementation that wraps a promise so as to |
| 23 // allow passing to other threads. | 23 // allow passing to other threads. |
| 24 template <typename... T> | 24 template <typename... T> |
| 25 class CdmPromiseInternal : public ::media::CdmPromiseTemplate<T...> { | 25 class CdmPromiseInternal : public ::media::CdmPromiseTemplate<T...> { |
| 26 public: | 26 public: |
| 27 CdmPromiseInternal(scoped_ptr<::media::CdmPromiseTemplate<T...>> promise) | 27 CdmPromiseInternal(scoped_ptr<::media::CdmPromiseTemplate<T...>> promise) |
| 28 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 28 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 29 promise_(std::move(promise)) {} | 29 promise_(std::move(promise)) {} |
| 30 | 30 |
| 31 ~CdmPromiseInternal() final { | 31 ~CdmPromiseInternal() final { |
| 32 // Promise must be resolved or rejected before destruction. | 32 if (IsPromiseSettled()) |
| 33 DCHECK(!promise_); | 33 return; |
| 34 |
| 35 DCHECK(promise_); |
| 36 RejectPromiseOnDestruction(); |
| 34 } | 37 } |
| 35 | 38 |
| 36 // CdmPromiseTemplate<> implementation. | 39 // CdmPromiseTemplate<> implementation. |
| 37 void resolve(const T&... result) final; | 40 void resolve(const T&... result) final; |
| 38 | 41 |
| 39 void reject(::media::MediaKeys::Exception exception, | 42 void reject(::media::MediaKeys::Exception exception, |
| 40 uint32_t system_code, | 43 uint32_t system_code, |
| 41 const std::string& error_message) final { | 44 const std::string& error_message) final { |
| 42 MarkPromiseSettled(); | 45 MarkPromiseSettled(); |
| 43 task_runner_->PostTask( | 46 task_runner_->PostTask( |
| 44 FROM_HERE, | 47 FROM_HERE, |
| 45 base::Bind(&::media::CdmPromiseTemplate<T...>::reject, | 48 base::Bind(&::media::CdmPromiseTemplate<T...>::reject, |
| 46 base::Owned(promise_.release()), | 49 base::Owned(promise_.release()), |
| 47 exception, system_code, error_message)); | 50 exception, system_code, error_message)); |
| 48 } | 51 } |
| 49 | 52 |
| 50 private: | 53 private: |
| 54 using ::media::CdmPromiseTemplate<T...>::IsPromiseSettled; |
| 51 using ::media::CdmPromiseTemplate<T...>::MarkPromiseSettled; | 55 using ::media::CdmPromiseTemplate<T...>::MarkPromiseSettled; |
| 56 using ::media::CdmPromiseTemplate<T...>::RejectPromiseOnDestruction; |
| 52 | 57 |
| 53 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 54 scoped_ptr<::media::CdmPromiseTemplate<T...>> promise_; | 59 scoped_ptr<::media::CdmPromiseTemplate<T...>> promise_; |
| 55 }; | 60 }; |
| 56 | 61 |
| 57 template <typename... T> | 62 template <typename... T> |
| 58 void CdmPromiseInternal<T...>::resolve(const T&... result) { | 63 void CdmPromiseInternal<T...>::resolve(const T&... result) { |
| 59 MarkPromiseSettled(); | 64 MarkPromiseSettled(); |
| 60 task_runner_->PostTask( | 65 task_runner_->PostTask( |
| 61 FROM_HERE, | 66 FROM_HERE, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 base::Passed(BindPromiseToCurrentLoop(std::move(promise)))); | 237 base::Passed(BindPromiseToCurrentLoop(std::move(promise)))); |
| 233 } | 238 } |
| 234 | 239 |
| 235 // A default empty implementation for subclasses that don't need to provide | 240 // A default empty implementation for subclasses that don't need to provide |
| 236 // any key system specific initialization. | 241 // any key system specific initialization. |
| 237 void BrowserCdmCast::InitializeInternal() { | 242 void BrowserCdmCast::InitializeInternal() { |
| 238 } | 243 } |
| 239 | 244 |
| 240 } // namespace media | 245 } // namespace media |
| 241 } // namespace chromecast | 246 } // namespace chromecast |
| OLD | NEW |