| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ | |
| 6 #define CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "media/base/cdm_promise.h" | |
| 12 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | |
| 13 | |
| 14 namespace content { | |
| 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 | |
| 47 typedef base::Callback<blink::WebContentDecryptionModuleResult::SessionStatus( | |
| 48 const std::string& web_session_id)> SessionInitializedCB; | |
| 49 | |
| 50 // 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 | |
| 52 // to get passed a SessionStatus. This class converts the session id to a | |
| 53 // SessionStatus by calling |new_session_created_cb|. | |
| 54 class NewSessionCdmResultPromise | |
| 55 : public media::CdmPromiseTemplate<std::string> { | |
| 56 public: | |
| 57 NewSessionCdmResultPromise( | |
| 58 const blink::WebContentDecryptionModuleResult& result, | |
| 59 const std::string& uma_name, | |
| 60 const SessionInitializedCB& new_session_created_cb); | |
| 61 virtual ~NewSessionCdmResultPromise(); | |
| 62 | |
| 63 // CdmPromiseTemplate<T> implementation. | |
| 64 virtual void resolve(const std::string& web_session_id) override; | |
| 65 virtual void reject(media::MediaKeys::Exception exception_code, | |
| 66 uint32 system_code, | |
| 67 const std::string& error_message) override; | |
| 68 | |
| 69 private: | |
| 70 blink::WebContentDecryptionModuleResult web_cdm_result_; | |
| 71 | |
| 72 // UMA name to report result to. | |
| 73 std::string uma_name_; | |
| 74 | |
| 75 // Called on resolve() to convert the session ID into a SessionStatus to | |
| 76 // be reported to blink. | |
| 77 SessionInitializedCB new_session_created_cb_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(NewSessionCdmResultPromise); | |
| 80 }; | |
| 81 | |
| 82 } // namespace content | |
| 83 | |
| 84 #endif // CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ | |
| OLD | NEW |