1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_BASE_CDM_PROMISE_H_
#define MEDIA_BASE_CDM_PROMISE_H_
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "media/base/media_export.h"
#include "media/base/media_keys.h"
namespace media {
// Interface for promises being resolved/rejected in response to various
// session actions. These may be called synchronously or asynchronously.
// The promise must be resolved or rejected exactly once. It is expected that
// the caller free the promise once it is resolved/rejected.
//
// This is only the base class, as parameter to resolve() varies.
class MEDIA_EXPORT CdmPromise {
public:
// A superset of media::MediaKeys::Exception for UMA reporting.
enum ResultCodeForUMA {
SUCCESS,
NOT_SUPPORTED_ERROR,
INVALID_STATE_ERROR,
INVALID_ACCESS_ERROR,
QUOTA_EXCEEDED_ERROR,
UNKNOWN_ERROR,
CLIENT_ERROR,
OUTPUT_ERROR,
NUM_RESULT_CODES
};
enum ResolveParameterType {
VOID_TYPE,
STRING_TYPE,
KEY_IDS_VECTOR_TYPE
};
typedef base::Callback<void(MediaKeys::Exception exception_code,
uint32 system_code,
const std::string& error_message)>
PromiseRejectedCB;
virtual ~CdmPromise();
// Used to indicate that the operation failed. |exception_code| must be
// specified. |system_code| is a Key System-specific value for the error
// that occurred, or 0 if there is no associated status code or such status
// codes are not supported by the Key System. |error_message| is optional.
virtual void reject(MediaKeys::Exception exception_code,
uint32 system_code,
const std::string& error_message);
ResolveParameterType GetResolveParameterType() const {
return parameter_type_;
}
protected:
explicit CdmPromise(ResolveParameterType parameter_type);
CdmPromise(ResolveParameterType parameter_type, PromiseRejectedCB reject_cb);
// If constructed with a |uma_name| (which must be the name of a
// CdmPromiseResult UMA), CdmPromise will report the promise result (success
// or rejection code).
CdmPromise(ResolveParameterType parameter_type,
PromiseRejectedCB reject_cb,
const std::string& uma_name);
// Called by all resolve()/reject() methods to report the UMA result if
// applicable, and update |is_pending_|.
void ReportResultToUMA(ResultCodeForUMA result);
const ResolveParameterType parameter_type_;
PromiseRejectedCB reject_cb_;
// Keep track of whether the promise hasn't been resolved or rejected yet.
bool is_pending_;
// UMA name to report result to.
std::string uma_name_;
DISALLOW_COPY_AND_ASSIGN(CdmPromise);
};
template <typename T>
class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise {
public:
CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb,
PromiseRejectedCB rejected_cb);
CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb,
PromiseRejectedCB rejected_cb,
const std::string& uma_name);
virtual void resolve(const T& result);
protected:
// Allow subclasses to completely override the implementation.
CdmPromiseTemplate();
private:
base::Callback<void(const T&)> resolve_cb_;
DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate);
};
// Specialization for no parameter to resolve().
template <>
class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise {
public:
CdmPromiseTemplate(base::Callback<void(void)> resolve_cb,
PromiseRejectedCB rejected_cb);
CdmPromiseTemplate(base::Callback<void(void)> resolve_cb,
PromiseRejectedCB rejected_cb,
const std::string& uma_name);
virtual void resolve();
protected:
// Allow subclasses to completely override the implementation.
CdmPromiseTemplate();
private:
base::Callback<void(void)> resolve_cb_;
DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate);
};
} // namespace media
#endif // MEDIA_BASE_CDM_PROMISE_H_
|