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

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: Variadic Templates 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
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 // A superset of media::MediaKeys::Exception for UMA reporting. These values
17 // it can be passed through Chromium. When CdmPromise::resolve(T) is called, 17 // should never be changed as it will affect existing reporting, and must match
18 // OnResolve(T) will be called and will call the appropriate complete...() 18 // the values for CdmPromiseResult in tools/metrics/histograms/histograms.xml.
19 // method on WebContentDecryptionModuleResult. If CdmPromise::reject() is called 19 enum ResultCodeForUMA {
20 // instead, WebContentDecryptionModuleResult::completeWithError() is called. 20 SUCCESS = 0,
21 // If constructed with a |uma_name| (which must be the name of a 21 NOT_SUPPORTED_ERROR = 1,
22 // CdmPromiseResult UMA), CdmResultPromise will report the promise result 22 INVALID_STATE_ERROR = 2,
23 // (success or rejection code). 23 INVALID_ACCESS_ERROR = 3,
24 template <typename T> 24 QUOTA_EXCEEDED_ERROR = 4,
25 class CdmResultPromise : public media::CdmPromiseTemplate<T> { 25 UNKNOWN_ERROR = 5,
26 CLIENT_ERROR = 6,
27 OUTPUT_ERROR = 7,
28 NUM_RESULT_CODES
29 };
30
31 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate
32 // so that it can be passed through Chromium. When resolve(T) is called, the
33 // appropriate complete...() method on WebContentDecryptionModuleResult will be
34 // invoked. If reject() is called instead,
35 // WebContentDecryptionModuleResult::completeWithError() is called.
36 // If constructed with a |uma_name|, CdmResultPromise will report the promise
37 // result (success or rejection code) to UMA.
38 template <typename... T>
39 class CdmResultPromise : public media::CdmPromiseTemplate<T...> {
xhwang 2014/10/03 07:34:21 Cool!
jrummell 2014/10/03 18:58:30 Acknowledged. I like it too.
26 public: 40 public:
27 explicit CdmResultPromise(
28 const blink::WebContentDecryptionModuleResult& result);
29 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, 41 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
30 const std::string& uma_name); 42 const std::string& uma_name);
31 virtual ~CdmResultPromise(); 43 virtual ~CdmResultPromise();
32 44
45 // CdmPromiseTemplate<T> implementation.
46 virtual void resolve(const T&... result) OVERRIDE;
47 virtual void reject(media::MediaKeys::Exception exception_code,
48 uint32 system_code,
49 const std::string& error_message) OVERRIDE;
50
33 protected: 51 protected:
34 // OnResolve() is virtual as it may need special handling in derived classes.
35 virtual void OnResolve(const T& result);
36 void OnReject(media::MediaKeys::Exception exception_code,
37 uint32 system_code,
38 const std::string& error_message);
39
40 blink::WebContentDecryptionModuleResult web_cdm_result_; 52 blink::WebContentDecryptionModuleResult web_cdm_result_;
41 53
42 private: 54 private:
xhwang 2014/10/03 07:34:21 You can have this here: using media::CdmPromiseTe
jrummell 2014/10/03 18:58:30 Done.
55 // UMA name to report result to.
56 std::string uma_name_;
57
43 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); 58 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
44 }; 59 };
45 60
46 // Specialization for no parameter to resolve(). 61 typedef CdmResultPromise<> SimpleCdmResultPromise;
47 template <>
48 class CdmResultPromise<void> : public media::CdmPromiseTemplate<void> {
49 public:
50 explicit CdmResultPromise(
51 const blink::WebContentDecryptionModuleResult& result);
52 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
53 const std::string& uma_name);
54 virtual ~CdmResultPromise();
55
56 protected:
57 virtual void OnResolve();
58 void OnReject(media::MediaKeys::Exception exception_code,
59 uint32 system_code,
60 const std::string& error_message);
61
62 blink::WebContentDecryptionModuleResult web_cdm_result_;
63
64 private:
65 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
66 };
67
68 typedef CdmResultPromise<void> SimpleCdmResultPromise;
69 62
70 } // namespace content 63 } // namespace content
71 64
72 #endif // CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ 65 #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') | content/renderer/media/cdm_result_promise.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698