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