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

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

Issue 1407933010: media: Make MediaKeys ref-counted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 years, 1 month 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 | « media/base/cdm_initialized_promise.cc ('k') | media/base/media_keys.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_MEDIA_KEYS_H_ 5 #ifndef MEDIA_BASE_MEDIA_KEYS_H_
6 #define MEDIA_BASE_MEDIA_KEYS_H_ 6 #define MEDIA_BASE_MEDIA_KEYS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
15 #include "media/base/eme_constants.h" 16 #include "media/base/eme_constants.h"
16 #include "media/base/media_export.h" 17 #include "media/base/media_export.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace base { 20 namespace base {
20 class Time; 21 class Time;
21 } 22 }
22 23
23 namespace media { 24 namespace media {
24 25
25 class CdmContext; 26 class CdmContext;
26 struct CdmKeyInformation; 27 struct CdmKeyInformation;
28 struct MediaKeysTraits;
27 29
28 template <typename... T> 30 template <typename... T>
29 class CdmPromiseTemplate; 31 class CdmPromiseTemplate;
30 32
31 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise; 33 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise;
32 typedef CdmPromiseTemplate<> SimpleCdmPromise; 34 typedef CdmPromiseTemplate<> SimpleCdmPromise;
33 typedef ScopedVector<CdmKeyInformation> CdmKeysInfo; 35 typedef ScopedVector<CdmKeyInformation> CdmKeysInfo;
34 36
35 // Performs media key operations. 37 // An interface for the Content Decryption Module (CDM) in the Encrypted Media
ddorwin 2015/11/03 00:28:50 This makes it sound like _this_ represents the CDM
xhwang 2015/11/03 00:50:29 Added the "in chromium" part, since "WebCDM" is a
38 // Extensions (EME) spec. See http://w3c.github.io/encrypted-media/#definitions
ddorwin 2015/11/03 00:28:50 http://w3c.github.io/encrypted-media/#cdm
xhwang 2015/11/03 00:50:29 Done.
36 // 39 //
37 // All key operations are called on the renderer thread. Therefore, these calls 40 // * Ownership
38 // should be fast and nonblocking; key events should be fired asynchronously. 41 //
39 class MEDIA_EXPORT MediaKeys{ 42 // This class is ref-counted. However, a ref-count should only be held by:
43 // - The owner of the CDM. This is usually some class in the EME stack, e.g.
44 // CdmSessionAdapter in the render process, or MojoCdmService in a non-render
45 // process.
46 // - The media player that uses the CDM, to prevent the CDM from being
47 // destructed while still being used by the media player.
48 //
49 // When binding class methods into callbacks, prefer WeakPtr to using |this|
50 // directly to avoid having a ref-count held by the callback.
51 //
52 // * Thread Safety
53 //
54 // Most CDM operations happen on one thread. However, it is not uncommon that
55 // the media player lives on a different thread and may call into the CDM from
56 // that thread. For example, if the CDM supports a Decryptor interface, the
57 // Decryptor methods could be called on a different thread. The CDM
58 // implementation should make sure it's thread safe for these situations.
59 //
60 // TODO(xhwang): Rename MediaKeys to ContentDecryptionModule. See
61 // http://crbug.com/309237
62
63 class MEDIA_EXPORT MediaKeys
64 : public base::RefCountedThreadSafe<MediaKeys, MediaKeysTraits> {
40 public: 65 public:
41 // Reported to UMA, so never reuse a value! 66 // Reported to UMA, so never reuse a value!
42 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode 67 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode
43 // (enforced in webmediaplayer_impl.cc). 68 // (enforced in webmediaplayer_impl.cc).
44 // TODO(jrummell): Can this be moved to proxy_decryptor as it should only be 69 // TODO(jrummell): Can this be moved to proxy_decryptor as it should only be
45 // used by the prefixed EME code? 70 // used by the prefixed EME code?
46 enum KeyError { 71 enum KeyError {
47 kUnknownError = 1, 72 kUnknownError = 1,
48 kClientError, 73 kClientError,
49 // The commented v0.1b values below have never been used. 74 // The commented v0.1b values below have never been used.
(...skipping 29 matching lines...) Expand all
79 // Type of message being sent to the application. 104 // Type of message being sent to the application.
80 // Must be consistent with the values specified in the spec: 105 // Must be consistent with the values specified in the spec:
81 // https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType 106 // https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType
82 enum MessageType { 107 enum MessageType {
83 LICENSE_REQUEST, 108 LICENSE_REQUEST,
84 LICENSE_RENEWAL, 109 LICENSE_RENEWAL,
85 LICENSE_RELEASE, 110 LICENSE_RELEASE,
86 MESSAGE_TYPE_MAX = LICENSE_RELEASE 111 MESSAGE_TYPE_MAX = LICENSE_RELEASE
87 }; 112 };
88 113
89 virtual ~MediaKeys();
90
91 // Provides a server certificate to be used to encrypt messages to the 114 // Provides a server certificate to be used to encrypt messages to the
92 // license server. 115 // license server.
93 virtual void SetServerCertificate(const std::vector<uint8_t>& certificate, 116 virtual void SetServerCertificate(const std::vector<uint8_t>& certificate,
94 scoped_ptr<SimpleCdmPromise> promise) = 0; 117 scoped_ptr<SimpleCdmPromise> promise) = 0;
95 118
96 // Creates a session with |session_type|. Then generates a request with the 119 // Creates a session with |session_type|. Then generates a request with the
97 // |init_data_type| and |init_data|. 120 // |init_data_type| and |init_data|.
98 // Note: 121 // Note:
99 // 1. The session ID will be provided when the |promise| is resolved. 122 // 1. The session ID will be provided when the |promise| is resolved.
100 // 2. The generated request should be returned through a SessionMessageCB, 123 // 2. The generated request should be returned through a SessionMessageCB,
(...skipping 29 matching lines...) Expand all
130 // Removes stored session data associated with the session specified by 153 // Removes stored session data associated with the session specified by
131 // |session_id|. 154 // |session_id|.
132 virtual void RemoveSession(const std::string& session_id, 155 virtual void RemoveSession(const std::string& session_id,
133 scoped_ptr<SimpleCdmPromise> promise) = 0; 156 scoped_ptr<SimpleCdmPromise> promise) = 0;
134 157
135 // Returns the CdmContext associated with |this|, which must NOT be null. 158 // Returns the CdmContext associated with |this|, which must NOT be null.
136 // Usually the CdmContext is owned by |this|. Caller needs to make sure it is 159 // Usually the CdmContext is owned by |this|. Caller needs to make sure it is
137 // not used after |this| is destructed. 160 // not used after |this| is destructed.
138 virtual CdmContext* GetCdmContext() = 0; 161 virtual CdmContext* GetCdmContext() = 0;
139 162
163 // Deletes |this| on the correct thread. By default |this| is deleted
164 // immediately. Override this method if |this| needs to be deleted on a
165 // specific thread.
166 virtual void DeleteOnCorrectThread() const;
167
140 protected: 168 protected:
169 friend class base::RefCountedThreadSafe<MediaKeys, MediaKeysTraits>;
170
141 MediaKeys(); 171 MediaKeys();
172 virtual ~MediaKeys();
142 173
143 private: 174 private:
144 DISALLOW_COPY_AND_ASSIGN(MediaKeys); 175 DISALLOW_COPY_AND_ASSIGN(MediaKeys);
145 }; 176 };
146 177
147 // Key event callbacks. See the spec for details: 178 struct MEDIA_EXPORT MediaKeysTraits {
148 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted- media.html#event-summary 179 // Destroys |media_keys| on the correct thread.
180 static void Destruct(const MediaKeys* media_keys);
181 };
149 182
183 // CDM session event callbacks.
184 // See the spec for details: http://w3c.github.io/encrypted-media/
ddorwin 2015/11/03 00:28:50 https://w3c.github.io/encrypted-media/#mediakeyses
xhwang 2015/11/03 00:50:29 Removed.
185
186 // Called when the CDM needs to queue a message event to the session object.
187 // See http://w3c.github.io/encrypted-media/#dom-evt-message
150 typedef base::Callback<void(const std::string& session_id, 188 typedef base::Callback<void(const std::string& session_id,
151 MediaKeys::MessageType message_type, 189 MediaKeys::MessageType message_type,
152 const std::vector<uint8_t>& message, 190 const std::vector<uint8_t>& message,
153 const GURL& legacy_destination_url)> 191 const GURL& legacy_destination_url)>
154 SessionMessageCB; 192 SessionMessageCB;
155 193
156 // Called when the session specified by |session_id| is closed. Note that the 194 // Called when the session specified by |session_id| is closed. Note that the
157 // CDM may close a session at any point, such as in response to a CloseSession() 195 // CDM may close a session at any point, such as in response to a CloseSession()
158 // call, when the session is no longer needed, or when system resources are 196 // call, when the session is no longer needed, or when system resources are
159 // lost. See for details: http://w3c.github.io/encrypted-media/#session-close 197 // lost. See http://w3c.github.io/encrypted-media/#session-close
160 typedef base::Callback<void(const std::string& session_id)> SessionClosedCB; 198 typedef base::Callback<void(const std::string& session_id)> SessionClosedCB;
161 199
200 // TODO(xhwang): Remove after prefixed EME support is removed. See
201 // http://crbug.com/249976
162 typedef base::Callback<void(const std::string& session_id, 202 typedef base::Callback<void(const std::string& session_id,
163 MediaKeys::Exception exception, 203 MediaKeys::Exception exception,
164 uint32_t system_code, 204 uint32_t system_code,
165 const std::string& error_message)> 205 const std::string& error_message)>
166 LegacySessionErrorCB; 206 LegacySessionErrorCB;
167 207
208 // Called when there has been a change in the keys in the session or their
209 // status. See http://w3c.github.io/encrypted-media/#dom-evt-keystatuseschange
168 typedef base::Callback<void(const std::string& session_id, 210 typedef base::Callback<void(const std::string& session_id,
169 bool has_additional_usable_key, 211 bool has_additional_usable_key,
170 CdmKeysInfo keys_info)> SessionKeysChangeCB; 212 CdmKeysInfo keys_info)> SessionKeysChangeCB;
171 213
214 // Called when the CDM changes the expiration time of a session.
215 // See http://w3c.github.io/encrypted-media/#update-expiration
172 typedef base::Callback<void(const std::string& session_id, 216 typedef base::Callback<void(const std::string& session_id,
173 const base::Time& new_expiry_time)> 217 const base::Time& new_expiry_time)>
174 SessionExpirationUpdateCB; 218 SessionExpirationUpdateCB;
175 219
176 } // namespace media 220 } // namespace media
177 221
178 #endif // MEDIA_BASE_MEDIA_KEYS_H_ 222 #endif // MEDIA_BASE_MEDIA_KEYS_H_
OLDNEW
« no previous file with comments | « media/base/cdm_initialized_promise.cc ('k') | media/base/media_keys.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698