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

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: 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 // A superset of media::MediaKeys::Exception for UMA reporting.
17 enum ResultCodeForUMA {
18 SUCCESS,
xhwang 2014/09/29 18:32:58 Assign numbers to these values to make sure they m
jrummell 2014/09/29 22:08:38 Done.
19 NOT_SUPPORTED_ERROR,
20 INVALID_STATE_ERROR,
21 INVALID_ACCESS_ERROR,
22 QUOTA_EXCEEDED_ERROR,
23 UNKNOWN_ERROR,
24 CLIENT_ERROR,
25 OUTPUT_ERROR,
26 NUM_RESULT_CODES
27 };
28
16 // Used to convert a WebContentDecryptionModuleResult into a CdmPromise so that 29 // Used to convert a WebContentDecryptionModuleResult into a CdmPromise so that
17 // it can be passed through Chromium. When CdmPromise::resolve(T) is called, 30 // it can be passed through Chromium. When CdmPromise::resolve(T) is called,
18 // OnResolve(T) will be called and will call the appropriate complete...() 31 // OnResolve(T) will be called and will call the appropriate complete...()
19 // method on WebContentDecryptionModuleResult. If CdmPromise::reject() is called 32 // method on WebContentDecryptionModuleResult. If CdmPromise::reject() is called
20 // instead, WebContentDecryptionModuleResult::completeWithError() is called. 33 // instead, WebContentDecryptionModuleResult::completeWithError() is called.
21 // If constructed with a |uma_name| (which must be the name of a 34 // If constructed with a |uma_name| (which must be the name of a
22 // CdmPromiseResult UMA), CdmResultPromise will report the promise result 35 // CdmPromiseResult UMA), CdmResultPromise will report the promise result
xhwang 2014/09/29 18:32:58 What is "CdmPromiseResult UMA"?
jrummell 2014/09/29 22:08:38 Removed.
23 // (success or rejection code). 36 // (success or rejection code).
xhwang 2014/09/29 18:32:58 s/CdmPromise/CdmPromiseTemplate throughout this co
jrummell 2014/09/29 22:08:38 Done.
24 template <typename T> 37 template <typename T>
25 class CdmResultPromise : public media::CdmPromiseTemplate<T> { 38 class CdmResultPromise : public media::CdmPromiseTemplate<T> {
26 public: 39 public:
27 explicit CdmResultPromise(
28 const blink::WebContentDecryptionModuleResult& result);
29 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, 40 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
30 const std::string& uma_name); 41 const std::string& uma_name);
31 virtual ~CdmResultPromise(); 42 virtual ~CdmResultPromise();
32 43
44 virtual void resolve(const T& result) OVERRIDE;
xhwang 2014/09/29 18:32:58 // CdmPromiseTemplate<T> implementation.
jrummell 2014/09/29 22:08:38 Done.
45 virtual void reject(media::MediaKeys::Exception exception_code,
46 uint32 system_code,
47 const std::string& error_message) OVERRIDE;
48
33 protected: 49 protected:
34 // OnResolve() is virtual as it may need special handling in derived classes. 50 // Called by all resolve()/reject() methods to report the UMA result if
ddorwin 2014/09/26 22:40:00 // All implementations must call this method in re
jrummell 2014/09/29 22:08:38 Removed.
35 virtual void OnResolve(const T& result); 51 // applicable, and update |is_pending_|.
36 void OnReject(media::MediaKeys::Exception exception_code, 52 void ReportResultToUMA(ResultCodeForUMA result);
37 uint32 system_code,
38 const std::string& error_message);
39 53
40 blink::WebContentDecryptionModuleResult web_cdm_result_; 54 blink::WebContentDecryptionModuleResult web_cdm_result_;
41 55
42 private: 56 private:
57 // UMA name to report result to.
58 std::string uma_name_;
59
60 // Keep track of whether the promise hasn't been resolved or rejected yet.
61 bool is_pending_;
62
43 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); 63 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
44 }; 64 };
45 65
46 // Specialization for no parameter to resolve(). 66 // Specialization for no parameter to resolve().
47 template <> 67 template <>
48 class CdmResultPromise<void> : public media::CdmPromiseTemplate<void> { 68 class CdmResultPromise<void> : public media::CdmPromiseTemplate<void> {
49 public: 69 public:
50 explicit CdmResultPromise(
51 const blink::WebContentDecryptionModuleResult& result);
52 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, 70 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
53 const std::string& uma_name); 71 const std::string& uma_name);
54 virtual ~CdmResultPromise(); 72 virtual ~CdmResultPromise();
55 73
56 protected: 74 virtual void resolve() OVERRIDE;
xhwang 2014/09/29 18:32:58 // CdmPromiseTemplate<void> implementation.
jrummell 2014/09/29 22:08:38 Done.
57 virtual void OnResolve(); 75 virtual void reject(media::MediaKeys::Exception exception_code,
58 void OnReject(media::MediaKeys::Exception exception_code, 76 uint32 system_code,
59 uint32 system_code, 77 const std::string& error_message) OVERRIDE;
60 const std::string& error_message); 78
79 private:
80 // Called by all resolve()/reject() methods to report the UMA result if
ddorwin 2014/09/26 22:40:00 ditto
jrummell 2014/09/29 22:08:38 Done.
81 // applicable, and update |is_pending_|.
82 void ReportResultToUMA(ResultCodeForUMA result);
61 83
62 blink::WebContentDecryptionModuleResult web_cdm_result_; 84 blink::WebContentDecryptionModuleResult web_cdm_result_;
63 85
64 private: 86 // UMA name to report result to.
ddorwin 2014/09/26 22:40:00 Kind of sad that we have to implement these member
jrummell 2014/09/29 22:08:38 Acknowledged.
87 std::string uma_name_;
88
89 // Keep track of whether the promise hasn't been resolved or rejected yet.
90 bool is_pending_;
91
65 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); 92 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
66 }; 93 };
67 94
68 typedef CdmResultPromise<void> SimpleCdmResultPromise; 95 typedef CdmResultPromise<void> SimpleCdmResultPromise;
69 96
70 } // namespace content 97 } // namespace content
71 98
72 #endif // CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ 99 #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