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