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 CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ | 5 #ifndef MEDIA_BLINK_NEW_SESSION_CDM_RESULT_PROMISE_H_ |
6 #define CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ | 6 #define MEDIA_BLINK_NEW_SESSION_CDM_RESULT_PROMISE_H_ |
7 | 7 |
8 #include <map> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "media/base/cdm_promise.h" | 11 #include "media/base/cdm_promise.h" |
12 #include "media/base/media_export.h" | |
13 #include "media/base/media_keys.h" | |
12 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 14 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
13 | 15 |
14 namespace content { | 16 namespace media { |
15 | |
16 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate | |
17 // so that it can be passed through Chromium. When resolve(T) is called, the | |
18 // appropriate complete...() method on WebContentDecryptionModuleResult will be | |
19 // invoked. If reject() is called instead, | |
20 // WebContentDecryptionModuleResult::completeWithError() is called. | |
21 // If constructed with a |uma_name|, CdmResultPromise will report the promise | |
22 // result (success or rejection code) to UMA. | |
23 template <typename... T> | |
24 class CdmResultPromise : public media::CdmPromiseTemplate<T...> { | |
25 public: | |
26 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, | |
27 const std::string& uma_name); | |
28 virtual ~CdmResultPromise(); | |
29 | |
30 // CdmPromiseTemplate<T> implementation. | |
31 virtual void resolve(const T&... result) override; | |
32 virtual void reject(media::MediaKeys::Exception exception_code, | |
33 uint32 system_code, | |
34 const std::string& error_message) override; | |
35 | |
36 private: | |
37 using media::CdmPromiseTemplate<T...>::MarkPromiseSettled; | |
38 | |
39 blink::WebContentDecryptionModuleResult web_cdm_result_; | |
40 | |
41 // UMA name to report result to. | |
42 std::string uma_name_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); | |
45 }; | |
46 | 17 |
47 typedef base::Callback<blink::WebContentDecryptionModuleResult::SessionStatus( | 18 typedef base::Callback<blink::WebContentDecryptionModuleResult::SessionStatus( |
48 const std::string& web_session_id)> SessionInitializedCB; | 19 const std::string& web_session_id)> SessionInitializedCB; |
49 | 20 |
50 // Special class for resolving a new session promise. Resolving a new session | 21 // Special class for resolving a new session promise. Resolving a new session |
51 // promise returns the session ID (as a string), but the blink promise needs | 22 // promise returns the session ID (as a string), but the blink promise needs |
52 // to get passed a SessionStatus. This class converts the session id to a | 23 // to get passed a SessionStatus. This class converts the session id to a |
53 // SessionStatus by calling |new_session_created_cb|. | 24 // SessionStatus by calling |new_session_created_cb|. |
54 class NewSessionCdmResultPromise | 25 class MEDIA_EXPORT NewSessionCdmResultPromise |
55 : public media::CdmPromiseTemplate<std::string> { | 26 : public media::CdmPromiseTemplate<std::string> { |
jrummell
2014/10/16 00:20:16
ditto on media::
xhwang
2014/10/16 04:25:44
Done.
| |
56 public: | 27 public: |
57 NewSessionCdmResultPromise( | 28 NewSessionCdmResultPromise( |
58 const blink::WebContentDecryptionModuleResult& result, | 29 const blink::WebContentDecryptionModuleResult& result, |
59 const std::string& uma_name, | 30 const std::string& uma_name, |
60 const SessionInitializedCB& new_session_created_cb); | 31 const SessionInitializedCB& new_session_created_cb); |
61 virtual ~NewSessionCdmResultPromise(); | 32 virtual ~NewSessionCdmResultPromise(); |
62 | 33 |
63 // CdmPromiseTemplate<T> implementation. | 34 // CdmPromiseTemplate<T> implementation. |
64 virtual void resolve(const std::string& web_session_id) override; | 35 virtual void resolve(const std::string& web_session_id) override; |
65 virtual void reject(media::MediaKeys::Exception exception_code, | 36 virtual void reject(media::MediaKeys::Exception exception_code, |
66 uint32 system_code, | 37 uint32 system_code, |
67 const std::string& error_message) override; | 38 const std::string& error_message) override; |
68 | 39 |
69 private: | 40 private: |
70 blink::WebContentDecryptionModuleResult web_cdm_result_; | 41 blink::WebContentDecryptionModuleResult web_cdm_result_; |
71 | 42 |
72 // UMA name to report result to. | 43 // UMA name to report result to. |
73 std::string uma_name_; | 44 std::string uma_name_; |
74 | 45 |
75 // Called on resolve() to convert the session ID into a SessionStatus to | 46 // Called on resolve() to convert the session ID into a SessionStatus to |
76 // be reported to blink. | 47 // be reported to blink. |
77 SessionInitializedCB new_session_created_cb_; | 48 SessionInitializedCB new_session_created_cb_; |
78 | 49 |
79 DISALLOW_COPY_AND_ASSIGN(NewSessionCdmResultPromise); | 50 DISALLOW_COPY_AND_ASSIGN(NewSessionCdmResultPromise); |
80 }; | 51 }; |
81 | 52 |
82 } // namespace content | 53 } // namespace media |
83 | 54 |
84 #endif // CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ | 55 #endif // MEDIA_BLINK_NEW_SESSION_CDM_RESULT_PROMISE_H_ |
OLD | NEW |