Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: content/renderer/media/cdm_result_promise.h

Issue 604283003: Refactor CdmPromise and related classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + override Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/media/cdm_result_promise.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_
6 #define CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ 6 #define CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_
7 7
8 #include <map> 8 #include <map>
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 "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" 12 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 // Used to convert a WebContentDecryptionModuleResult into a CdmPromise so that 16 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate
17 // it can be passed through Chromium. When CdmPromise::resolve(T) is called, 17 // so that it can be passed through Chromium. When resolve(T) is called, the
18 // OnResolve(T) will be called and will call the appropriate complete...() 18 // appropriate complete...() method on WebContentDecryptionModuleResult will be
19 // method on WebContentDecryptionModuleResult. If CdmPromise::reject() is called 19 // invoked. If reject() is called instead,
20 // instead, WebContentDecryptionModuleResult::completeWithError() is called. 20 // WebContentDecryptionModuleResult::completeWithError() is called.
21 // If constructed with a |uma_name| (which must be the name of a 21 // If constructed with a |uma_name|, CdmResultPromise will report the promise
22 // CdmPromiseResult UMA), CdmResultPromise will report the promise result 22 // result (success or rejection code) to UMA.
23 // (success or rejection code). 23 template <typename... T>
24 template <typename T> 24 class CdmResultPromise : public media::CdmPromiseTemplate<T...> {
25 class CdmResultPromise : public media::CdmPromiseTemplate<T> {
26 public: 25 public:
27 explicit CdmResultPromise(
28 const blink::WebContentDecryptionModuleResult& result);
29 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, 26 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
30 const std::string& uma_name); 27 const std::string& uma_name);
31 virtual ~CdmResultPromise(); 28 virtual ~CdmResultPromise();
32 29
33 protected: 30 // CdmPromiseTemplate<T> implementation.
34 // OnResolve() is virtual as it may need special handling in derived classes. 31 virtual void resolve(const T&... result) override;
35 virtual void OnResolve(const T& result); 32 virtual void reject(media::MediaKeys::Exception exception_code,
36 void OnReject(media::MediaKeys::Exception exception_code, 33 uint32 system_code,
37 uint32 system_code, 34 const std::string& error_message) override;
38 const std::string& error_message); 35
36 private:
37 using media::CdmPromiseTemplate<T...>::MarkPromiseSettled;
39 38
40 blink::WebContentDecryptionModuleResult web_cdm_result_; 39 blink::WebContentDecryptionModuleResult web_cdm_result_;
41 40
42 private: 41 // UMA name to report result to.
42 std::string uma_name_;
43
43 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); 44 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
44 }; 45 };
45 46
46 // Specialization for no parameter to resolve(). 47 typedef base::Callback<blink::WebContentDecryptionModuleResult::SessionStatus(
47 template <> 48 const std::string& web_session_id)> SessionInitializedCB;
48 class CdmResultPromise<void> : public media::CdmPromiseTemplate<void> { 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> {
49 public: 56 public:
50 explicit CdmResultPromise( 57 NewSessionCdmResultPromise(
51 const blink::WebContentDecryptionModuleResult& result); 58 const blink::WebContentDecryptionModuleResult& result,
52 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, 59 const std::string& uma_name,
53 const std::string& uma_name); 60 const SessionInitializedCB& new_session_created_cb);
54 virtual ~CdmResultPromise(); 61 virtual ~NewSessionCdmResultPromise();
55 62
56 protected: 63 // CdmPromiseTemplate<T> implementation.
57 virtual void OnResolve(); 64 virtual void resolve(const std::string& web_session_id) override;
58 void OnReject(media::MediaKeys::Exception exception_code, 65 virtual void reject(media::MediaKeys::Exception exception_code,
59 uint32 system_code, 66 uint32 system_code,
60 const std::string& error_message); 67 const std::string& error_message) override;
61 68
69 private:
62 blink::WebContentDecryptionModuleResult web_cdm_result_; 70 blink::WebContentDecryptionModuleResult web_cdm_result_;
63 71
64 private: 72 // UMA name to report result to.
65 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); 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);
66 }; 80 };
67 81
68 typedef CdmResultPromise<void> SimpleCdmResultPromise;
69
70 } // namespace content 82 } // namespace content
71 83
72 #endif // CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ 84 #endif // CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/cdm_result_promise.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698