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

Side by Side Diff: media/base/cdm_promise.h

Issue 567123002: Cleanup template in CdmPromise (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | media/base/cdm_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 MEDIA_BASE_CDM_PROMISE_H_ 5 #ifndef MEDIA_BASE_CDM_PROMISE_H_
6 #define MEDIA_BASE_CDM_PROMISE_H_ 6 #define MEDIA_BASE_CDM_PROMISE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
13 #include "media/base/media_keys.h" 13 #include "media/base/media_keys.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 typedef std::vector<std::vector<uint8> > KeyIdsVector;
18
17 // Interface for promises being resolved/rejected in response to various 19 // Interface for promises being resolved/rejected in response to various
18 // session actions. These may be called synchronously or asynchronously. 20 // session actions. These may be called synchronously or asynchronously.
19 // The promise must be resolved or rejected exactly once. It is expected that 21 // The promise must be resolved or rejected exactly once. It is expected that
20 // the caller free the promise once it is resolved/rejected. 22 // the caller free the promise once it is resolved/rejected.
21 // 23 //
22 // This is only the base class, as parameter to resolve() varies. 24 // This is only the base class, as parameter to resolve() varies.
23 class MEDIA_EXPORT CdmPromise { 25 class MEDIA_EXPORT CdmPromise {
24 public: 26 public:
25 // A superset of media::MediaKeys::Exception for UMA reporting. 27 // A superset of media::MediaKeys::Exception for UMA reporting.
26 enum ResultCodeForUMA { 28 enum ResultCodeForUMA {
(...skipping 27 matching lines...) Expand all
54 // codes are not supported by the Key System. |error_message| is optional. 56 // codes are not supported by the Key System. |error_message| is optional.
55 virtual void reject(MediaKeys::Exception exception_code, 57 virtual void reject(MediaKeys::Exception exception_code,
56 uint32 system_code, 58 uint32 system_code,
57 const std::string& error_message); 59 const std::string& error_message);
58 60
59 virtual ResolveParameterType GetResolveParameterType() const = 0; 61 virtual ResolveParameterType GetResolveParameterType() const = 0;
60 62
61 protected: 63 protected:
62 CdmPromise(); 64 CdmPromise();
63 CdmPromise(PromiseRejectedCB reject_cb); 65 CdmPromise(PromiseRejectedCB reject_cb);
66 CdmPromise(const std::string& uma_name);
64 67
65 // If constructed with a |uma_name| (which must be the name of a 68 // If constructed with a |uma_name| (which must be the name of a
66 // CdmPromiseResult UMA), CdmPromise will report the promise result (success 69 // CdmPromiseResult UMA), CdmPromise will report the promise result (success
67 // or rejection code). 70 // or rejection code).
68 CdmPromise(PromiseRejectedCB reject_cb, const std::string& uma_name); 71 CdmPromise(PromiseRejectedCB reject_cb, const std::string& uma_name);
69 72
73 // Called by all resolve() methods to do the check on |is_pending_|
74 // and call the UMA success if required.
75 void ResolveBase();
sandersd (OOO until July 31) 2014/09/16 00:42:54 As discussed, rename as ReportResolution().
76
77 // Called by all reject() methods to do the check on |is_pending_|
78 // and call the UMA with |exception_code| if required.
79 void RejectBase(MediaKeys::Exception exception_code);
80
70 PromiseRejectedCB reject_cb_; 81 PromiseRejectedCB reject_cb_;
71 82
72 // Keep track of whether the promise hasn't been resolved or rejected yet. 83 // Keep track of whether the promise hasn't been resolved or rejected yet.
73 bool is_pending_; 84 bool is_pending_;
74 85
75 // UMA to report result to. 86 // UMA to report result to.
76 std::string uma_name_; 87 std::string uma_name_;
77 88
78 DISALLOW_COPY_AND_ASSIGN(CdmPromise); 89 DISALLOW_COPY_AND_ASSIGN(CdmPromise);
79 }; 90 };
80 91
81 // Specialization for no parameter to resolve(). 92 // Used when there is no parameter to resolve().
82 template <> 93 class MEDIA_EXPORT SimpleCdmPromise : public CdmPromise {
83 class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise {
84 public: 94 public:
85 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, 95 SimpleCdmPromise(base::Callback<void(void)> resolve_cb,
86 PromiseRejectedCB rejected_cb); 96 PromiseRejectedCB rejected_cb);
87 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, 97 SimpleCdmPromise(base::Callback<void(void)> resolve_cb,
88 PromiseRejectedCB rejected_cb, 98 PromiseRejectedCB rejected_cb,
89 const std::string& uma_name); 99 const std::string& uma_name);
90 virtual ~CdmPromiseTemplate(); 100 virtual ~SimpleCdmPromise();
91 virtual void resolve(); 101 virtual void resolve();
92 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; 102 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE;
93 103
94 protected: 104 protected:
95 // Allow subclasses to completely override the implementation. 105 SimpleCdmPromise();
96 CdmPromiseTemplate(); 106 SimpleCdmPromise(const std::string& uma_name);
97 107
98 private: 108 private:
99 base::Callback<void(void)> resolve_cb_; 109 base::Callback<void(void)> resolve_cb_;
100 110
101 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); 111 DISALLOW_COPY_AND_ASSIGN(SimpleCdmPromise);
102 }; 112 };
103 113
104 template <> 114 class MEDIA_EXPORT NewSessionCdmPromise : public CdmPromise {
105 class MEDIA_EXPORT CdmPromiseTemplate<std::string> : public CdmPromise {
106 public: 115 public:
107 CdmPromiseTemplate(base::Callback<void(const std::string&)> resolve_cb, 116 NewSessionCdmPromise(base::Callback<void(const std::string&)> resolve_cb,
108 PromiseRejectedCB rejected_cb); 117 PromiseRejectedCB rejected_cb);
109 CdmPromiseTemplate(base::Callback<void(const std::string&)> resolve_cb, 118 NewSessionCdmPromise(base::Callback<void(const std::string&)> resolve_cb,
110 PromiseRejectedCB rejected_cb, 119 PromiseRejectedCB rejected_cb,
111 const std::string& uma_name); 120 const std::string& uma_name);
112 virtual ~CdmPromiseTemplate(); 121 virtual ~NewSessionCdmPromise();
113 virtual void resolve(const std::string& result); 122 virtual void resolve(const std::string& result);
114 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; 123 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE;
115 124
116 protected: 125 protected:
117 // Allow subclasses to completely override the implementation. 126 NewSessionCdmPromise();
118 // TODO(jrummell): Remove when derived class SessionLoadedPromise 127 NewSessionCdmPromise(const std::string& uma_name);
119 // (in ppapi_decryptor.cc) is no longer needed.
120 CdmPromiseTemplate();
121 128
122 private: 129 private:
123 base::Callback<void(const std::string&)> resolve_cb_; 130 base::Callback<void(const std::string&)> resolve_cb_;
124 131
125 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); 132 DISALLOW_COPY_AND_ASSIGN(NewSessionCdmPromise);
126 }; 133 };
127 134
128 template <> 135 class MEDIA_EXPORT KeyIdsPromise : public CdmPromise {
129 class MEDIA_EXPORT CdmPromiseTemplate<KeyIdsVector> : public CdmPromise {
130 public: 136 public:
131 CdmPromiseTemplate(base::Callback<void(const KeyIdsVector&)> resolve_cb, 137 KeyIdsPromise(base::Callback<void(const KeyIdsVector&)> resolve_cb,
132 PromiseRejectedCB rejected_cb); 138 PromiseRejectedCB rejected_cb);
133 CdmPromiseTemplate(base::Callback<void(const KeyIdsVector&)> resolve_cb, 139 KeyIdsPromise(base::Callback<void(const KeyIdsVector&)> resolve_cb,
134 PromiseRejectedCB rejected_cb, 140 PromiseRejectedCB rejected_cb,
135 const std::string& uma_name); 141 const std::string& uma_name);
136 virtual ~CdmPromiseTemplate(); 142 virtual ~KeyIdsPromise();
137 virtual void resolve(const KeyIdsVector& result); 143 virtual void resolve(const KeyIdsVector& result);
138 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; 144 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE;
139 145
146 protected:
147 KeyIdsPromise();
148 KeyIdsPromise(const std::string& uma_name);
149
140 private: 150 private:
141 base::Callback<void(const KeyIdsVector&)> resolve_cb_; 151 base::Callback<void(const KeyIdsVector&)> resolve_cb_;
142 152
143 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); 153 DISALLOW_COPY_AND_ASSIGN(KeyIdsPromise);
144 }; 154 };
145 155
146 } // namespace media 156 } // namespace media
147 157
148 #endif // MEDIA_BASE_CDM_PROMISE_H_ 158 #endif // MEDIA_BASE_CDM_PROMISE_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/cdm_promise.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698