| 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/base/cdm_promise_adapter.h" | 5 #include "media/base/cdm_promise_adapter.h" |
| 6 | 6 |
| 7 #include "media/base/media_keys.h" | 7 #include "media/base/media_keys.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 CdmPromise::ResolveParameterType type = promise->GetResolveParameterType(); | 35 CdmPromise::ResolveParameterType type = promise->GetResolveParameterType(); |
| 36 CdmPromise::ResolveParameterType expected = CdmPromiseTraits<T...>::kType; | 36 CdmPromise::ResolveParameterType expected = CdmPromiseTraits<T...>::kType; |
| 37 if (type != expected) { | 37 if (type != expected) { |
| 38 NOTREACHED() << "Promise type mismatch: " << type << " vs " << expected; | 38 NOTREACHED() << "Promise type mismatch: " << type << " vs " << expected; |
| 39 return; | 39 return; |
| 40 } | 40 } |
| 41 | 41 |
| 42 static_cast<CdmPromiseTemplate<T...>*>(promise.get())->resolve(result...); | 42 static_cast<CdmPromiseTemplate<T...>*>(promise.get())->resolve(result...); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void CdmPromiseAdapter::RejectPromise( | 45 void CdmPromiseAdapter::RejectPromise(uint32_t promise_id, |
| 46 uint32_t promise_id, | 46 MediaKeys::Exception exception_code, |
| 47 MediaKeys::Exception exception_code, | 47 uint32 system_code, |
| 48 uint32 system_code, | 48 const std::string& error_message) { |
| 49 const std::string& error_message) { | |
| 50 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 49 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
| 51 if (!promise) { | 50 if (!promise) { |
| 52 NOTREACHED() << "No promise found for promise_id " << promise_id; | 51 NOTREACHED() << "No promise found for promise_id " << promise_id; |
| 53 return; | 52 return; |
| 54 } | 53 } |
| 55 | 54 |
| 56 promise->reject(exception_code, system_code, error_message); | 55 promise->reject(exception_code, system_code, error_message); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void CdmPromiseAdapter::Clear() { | 58 void CdmPromiseAdapter::Clear() { |
| 60 // Reject all outstanding promises. | 59 // Reject all outstanding promises. |
| 61 for (auto& promise : promises_) | 60 for (auto& promise : promises_) |
| 62 promise.second->reject(MediaKeys::UNKNOWN_ERROR, 0, "Operation aborted."); | 61 promise.second->reject(MediaKeys::UNKNOWN_ERROR, 0, "Operation aborted."); |
| 63 promises_.clear(); | 62 promises_.clear(); |
| 64 } | 63 } |
| 65 | 64 |
| 66 scoped_ptr<CdmPromise> CdmPromiseAdapter::TakePromise(uint32_t promise_id) { | 65 scoped_ptr<CdmPromise> CdmPromiseAdapter::TakePromise(uint32_t promise_id) { |
| 67 PromiseMap::iterator it = promises_.find(promise_id); | 66 PromiseMap::iterator it = promises_.find(promise_id); |
| 68 if (it == promises_.end()) | 67 if (it == promises_.end()) |
| 69 return nullptr; | 68 return nullptr; |
| 70 return promises_.take_and_erase(it); | 69 return promises_.take_and_erase(it); |
| 71 } | 70 } |
| 72 | 71 |
| 73 // Explicit instantiation of function templates. | 72 // Explicit instantiation of function templates. |
| 74 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(uint32_t); | 73 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(uint32_t); |
| 75 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise( | 74 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise( |
| 76 uint32_t, | 75 uint32_t, |
| 77 const std::string&); | 76 const std::string&); |
| 78 | 77 |
| 79 } // namespace media | 78 } // namespace media |
| OLD | NEW |