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

Side by Side Diff: content/renderer/media/crypto/proxy_decryptor.h

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more trybot issue Created 6 years, 6 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 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 CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ 6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
7 7
8 #include <map>
9 #include <set>
10 #include <string> 8 #include <string>
11 #include <vector> 9 #include <vector>
12 10
13 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
16 #include "base/synchronization/lock.h"
17 #include "media/base/decryptor.h" 15 #include "media/base/decryptor.h"
18 #include "media/base/media_keys.h" 16 #include "media/base/media_keys.h"
19 17
20 #if defined(ENABLE_PEPPER_CDMS) 18 #if defined(ENABLE_PEPPER_CDMS)
21 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" 19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h"
22 #endif 20 #endif
23 21
24 class GURL; 22 class GURL;
25 23
26 namespace content { 24 namespace content {
27 25
28 #if defined(OS_ANDROID) 26 #if defined(OS_ANDROID)
29 class RendererCdmManager; 27 class RendererCdmManager;
30 #endif // defined(OS_ANDROID) 28 #endif // defined(OS_ANDROID)
31 29
32 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. 30 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API.
33 // A decryptor proxy that creates a real decryptor object on demand and 31 // A decryptor proxy that creates a real decryptor object on demand and
34 // forwards decryptor calls to it. 32 // forwards decryptor calls to it.
35 // 33 //
36 // Now that the Pepper API calls use session ID to match responses with
37 // requests, this class maintains a mapping between session ID and web session
38 // ID. Callers of this class expect web session IDs in the responses.
39 // Session IDs are internal unique references to the session. Web session IDs
40 // are the CDM generated ID for the session, and are what are visible to users.
41 //
42 // TODO(xhwang): Currently we don't support run-time switching among decryptor 34 // TODO(xhwang): Currently we don't support run-time switching among decryptor
43 // objects. Fix this when needed. 35 // objects. Fix this when needed.
44 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! 36 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name!
45 class ProxyDecryptor { 37 class ProxyDecryptor {
46 public: 38 public:
47 // These are similar to the callbacks in media_keys.h, but pass back the 39 // These are similar to the callbacks in media_keys.h, but pass back the
48 // web session ID rather than the internal session ID. 40 // web session ID rather than the internal session ID.
49 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; 41 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB;
50 typedef base::Callback<void(const std::string& session_id, 42 typedef base::Callback<void(const std::string& session_id,
51 media::MediaKeys::KeyError error_code, 43 media::MediaKeys::KeyError error_code,
(...skipping 30 matching lines...) Expand all
82 // May only be called after InitializeCDM() succeeds. 74 // May only be called after InitializeCDM() succeeds.
83 bool GenerateKeyRequest(const std::string& type, 75 bool GenerateKeyRequest(const std::string& type,
84 const uint8* init_data, 76 const uint8* init_data,
85 int init_data_length); 77 int init_data_length);
86 void AddKey(const uint8* key, int key_length, 78 void AddKey(const uint8* key, int key_length,
87 const uint8* init_data, int init_data_length, 79 const uint8* init_data, int init_data_length,
88 const std::string& session_id); 80 const std::string& session_id);
89 void CancelKeyRequest(const std::string& session_id); 81 void CancelKeyRequest(const std::string& session_id);
90 82
91 private: 83 private:
92 // Session_id <-> web_session_id map.
93 typedef std::map<uint32, std::string> SessionIdMap;
94
95 // Helper function to create MediaKeys to handle the given |key_system|. 84 // Helper function to create MediaKeys to handle the given |key_system|.
96 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system, 85 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system,
97 const GURL& security_origin); 86 const GURL& security_origin);
98 87
99 // Callbacks for firing session events. 88 // Callbacks for firing session events.
100 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); 89 void OnSessionMessage(const std::string& web_session_id,
101 void OnSessionMessage(uint32 session_id,
102 const std::vector<uint8>& message, 90 const std::vector<uint8>& message,
103 const GURL& default_url); 91 const GURL& default_url);
104 void OnSessionReady(uint32 session_id); 92 void OnSessionReady(const std::string& web_session_id);
105 void OnSessionClosed(uint32 session_id); 93 void OnSessionClosed(const std::string& web_session_id);
106 void OnSessionError(uint32 session_id, 94 void OnSessionError(const std::string& web_session_id,
107 media::MediaKeys::KeyError error_code, 95 media::MediaKeys::Exception exception_code,
108 uint32 system_code); 96 uint32 system_code,
97 const std::string& error_message);
109 98
110 // Helper function to determine session_id for the provided |web_session_id|. 99 // Called when a session is actually created or loaded.
111 uint32 LookupSessionId(const std::string& web_session_id) const; 100 void SetSessionId(bool persistent, const std::string& web_session_id);
112
113 // Helper function to determine web_session_id for the provided |session_id|.
114 // The returned web_session_id is only valid on the main thread, and should be
115 // stored by copy.
116 const std::string& LookupWebSessionId(uint32 session_id) const;
117 101
118 #if defined(ENABLE_PEPPER_CDMS) 102 #if defined(ENABLE_PEPPER_CDMS)
119 // Callback to create the Pepper plugin. 103 // Callback to create the Pepper plugin.
120 CreatePepperCdmCB create_pepper_cdm_cb_; 104 CreatePepperCdmCB create_pepper_cdm_cb_;
121 #elif defined(OS_ANDROID) 105 #elif defined(OS_ANDROID)
122 RendererCdmManager* manager_; 106 RendererCdmManager* manager_;
123 int cdm_id_; 107 int cdm_id_;
124 #endif // defined(ENABLE_PEPPER_CDMS) 108 #endif // defined(ENABLE_PEPPER_CDMS)
125 109
126 // The real MediaKeys that manages key operations for the ProxyDecryptor. 110 // The real MediaKeys that manages key operations for the ProxyDecryptor.
127 scoped_ptr<media::MediaKeys> media_keys_; 111 scoped_ptr<media::MediaKeys> media_keys_;
128 112
129 // Callbacks for firing key events. 113 // Callbacks for firing key events.
130 KeyAddedCB key_added_cb_; 114 KeyAddedCB key_added_cb_;
131 KeyErrorCB key_error_cb_; 115 KeyErrorCB key_error_cb_;
132 KeyMessageCB key_message_cb_; 116 KeyMessageCB key_message_cb_;
133 117
134 // Session IDs are used to uniquely track sessions so that CDM callbacks 118 // Keep track of both persistent and non-persistent sessions.
135 // can get mapped to the correct session ID. Session ID should be unique 119 base::hash_map<std::string, bool> active_sessions_;
136 // per renderer process for debugging purposes.
137 static uint32 next_session_id_;
138
139 SessionIdMap sessions_;
140
141 std::set<uint32> persistent_sessions_;
142 120
143 bool is_clear_key_; 121 bool is_clear_key_;
144 122
145 // NOTE: Weak pointers must be invalidated before all other member variables. 123 // NOTE: Weak pointers must be invalidated before all other member variables.
146 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; 124 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_;
147 125
148 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); 126 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor);
149 }; 127 };
150 128
151 } // namespace content 129 } // namespace content
152 130
153 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ 131 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
OLDNEW
« no previous file with comments | « content/renderer/media/crypto/ppapi_decryptor.cc ('k') | content/renderer/media/crypto/proxy_decryptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698