| 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 #ifndef MEDIA_BASE_CDM_PROMISE_ADAPTER_H_ | 5 #ifndef MEDIA_BASE_CDM_PROMISE_ADAPTER_H_ |
| 6 #define MEDIA_BASE_CDM_PROMISE_ADAPTER_H_ | 6 #define MEDIA_BASE_CDM_PROMISE_ADAPTER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 10 #include "base/macros.h" | 9 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 13 #include "media/base/cdm_promise.h" | 12 #include "media/base/cdm_promise.h" |
| 14 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
| 15 | 14 |
| 16 namespace media { | 15 namespace media { |
| 17 | 16 |
| 18 // Helps convert CdmPromises to an integer identifier and vice versa. The | 17 // Helps convert CdmPromises to an integer identifier and vice versa. The |
| 19 // integer identifier is needed where we cannot pass CdmPromises through, such | 18 // integer identifier is needed where we cannot pass CdmPromises through, such |
| 20 // as PPAPI, IPC and JNI. | 19 // as PPAPI, IPC and JNI. |
| 21 class MEDIA_EXPORT CdmPromiseAdapter { | 20 class MEDIA_EXPORT CdmPromiseAdapter { |
| 22 public: | 21 public: |
| 23 CdmPromiseAdapter(); | 22 CdmPromiseAdapter(); |
| 24 ~CdmPromiseAdapter(); | 23 ~CdmPromiseAdapter(); |
| 25 | 24 |
| 26 // Takes ownership of |promise| and returns an integer promise ID. | 25 // Takes ownership of |promise| and returns an integer promise ID. |
| 27 uint32_t SavePromise(scoped_ptr<media::CdmPromise> promise); | 26 uint32_t SavePromise(scoped_ptr<media::CdmPromise> promise); |
| 28 | 27 |
| 29 // Takes the promise for |promise_id|, sanity checks its |type|, and resolves | 28 // Takes the promise for |promise_id|, sanity checks its |type|, and resolves |
| 30 // it with |result|. | 29 // it with |result|. |
| 31 template <typename... T> | 30 template <typename... T> |
| 32 void ResolvePromise(uint32_t promise_id, const T&... result); | 31 void ResolvePromise(uint32_t promise_id, const T&... result); |
| 33 | 32 |
| 34 // Takes the promise for |promise_id| and rejects it with |exception_code|, | 33 // Takes the promise for |promise_id| and rejects it with |exception_code|, |
| 35 // |system_code| and |error_message|. | 34 // |system_code| and |error_message|. |
| 36 void RejectPromise(uint32_t promise_id, | 35 void RejectPromise(uint32_t promise_id, |
| 37 MediaKeys::Exception exception_code, | 36 MediaKeys::Exception exception_code, |
| 38 uint32 system_code, | 37 uint32_t system_code, |
| 39 const std::string& error_message); | 38 const std::string& error_message); |
| 40 | 39 |
| 41 // Rejects and clears all |promises_|. | 40 // Rejects and clears all |promises_|. |
| 42 void Clear(); | 41 void Clear(); |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 // A map between promise IDs and CdmPromises. It owns the CdmPromises. | 44 // A map between promise IDs and CdmPromises. It owns the CdmPromises. |
| 46 typedef base::ScopedPtrHashMap<uint32_t, scoped_ptr<CdmPromise>> PromiseMap; | 45 typedef base::ScopedPtrHashMap<uint32_t, scoped_ptr<CdmPromise>> PromiseMap; |
| 47 | 46 |
| 48 // Finds, takes the ownership of and returns the promise for |promise_id|. | 47 // Finds, takes the ownership of and returns the promise for |promise_id|. |
| 49 // Returns null if no promise can be found. | 48 // Returns null if no promise can be found. |
| 50 scoped_ptr<CdmPromise> TakePromise(uint32_t promise_id); | 49 scoped_ptr<CdmPromise> TakePromise(uint32_t promise_id); |
| 51 | 50 |
| 52 uint32_t next_promise_id_; | 51 uint32_t next_promise_id_; |
| 53 PromiseMap promises_; | 52 PromiseMap promises_; |
| 54 | 53 |
| 55 base::ThreadChecker thread_checker_; | 54 base::ThreadChecker thread_checker_; |
| 56 DISALLOW_COPY_AND_ASSIGN(CdmPromiseAdapter); | 55 DISALLOW_COPY_AND_ASSIGN(CdmPromiseAdapter); |
| 57 }; | 56 }; |
| 58 | 57 |
| 59 } // namespace media | 58 } // namespace media |
| 60 | 59 |
| 61 #endif // MEDIA_BASE_CDM_PROMISE_ADAPTER_H_ | 60 #endif // MEDIA_BASE_CDM_PROMISE_ADAPTER_H_ |
| OLD | NEW |