OLD | NEW |
---|---|
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_SESSION_ADAPTER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ |
6 #define CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ | 6 #define CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/containers/hash_tables.h" | |
11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
13 #include "media/base/media_keys.h" | 15 #include "media/base/media_keys.h" |
14 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h " | 16 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h " |
15 | 17 |
16 #if defined(ENABLE_PEPPER_CDMS) | 18 #if defined(ENABLE_PEPPER_CDMS) |
17 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
18 #endif | 20 #endif |
19 | 21 |
20 class GURL; | 22 class GURL; |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 class WebContentDecryptionModuleSessionImpl; | 26 class WebContentDecryptionModuleSessionImpl; |
25 | 27 |
26 // Owns the CDM instance and makes calls from session objects to the CDM. | 28 // Owns the CDM instance and makes calls from session objects to the CDM. |
27 // Forwards the session ID-based callbacks of the MediaKeys interface to the | 29 // Forwards the wwb session ID-based callbacks of the MediaKeys interface to the |
jrummell
2014/05/08 23:37:46
spelling.
jrummell
2014/05/09 00:55:23
Done.
| |
28 // appropriate session object. Callers should hold references to this class | 30 // appropriate session object. Callers should hold references to this class |
29 // as long as they need the CDM instance. | 31 // as long as they need the CDM instance. |
30 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { | 32 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { |
31 public: | 33 public: |
32 CdmSessionAdapter(); | 34 CdmSessionAdapter(); |
33 | 35 |
34 // Returns true on success. | 36 // Returns true on success. |
35 bool Initialize( | 37 bool Initialize( |
36 #if defined(ENABLE_PEPPER_CDMS) | 38 #if defined(ENABLE_PEPPER_CDMS) |
37 const CreatePepperCdmCB& create_pepper_cdm_cb, | 39 const CreatePepperCdmCB& create_pepper_cdm_cb, |
38 #endif | 40 #endif |
39 const std::string& key_system, | 41 const std::string& key_system, |
40 const GURL& security_origin); | 42 const GURL& security_origin); |
41 | 43 |
42 // Creates a new session and adds it to the internal map. The caller owns the | 44 // Creates a new session and adds it to the internal map. The caller owns the |
43 // created session. RemoveSession() must be called when destroying it. | 45 // created session. RemoveSession() must be called when destroying it, if |
46 // RegisterSession() was called. | |
44 WebContentDecryptionModuleSessionImpl* CreateSession( | 47 WebContentDecryptionModuleSessionImpl* CreateSession( |
45 blink::WebContentDecryptionModuleSession::Client* client); | 48 blink::WebContentDecryptionModuleSession::Client* client); |
46 | 49 |
50 // Adds a session to the internal map. Called once the session is successfully | |
51 // initialized. | |
52 void RegisterSession( | |
53 const std::string& web_session_id, | |
54 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session); | |
55 | |
47 // Removes a session from the internal map. | 56 // Removes a session from the internal map. |
48 void RemoveSession(uint32 session_id); | 57 void RemoveSession(const std::string& web_session_id); |
49 | 58 |
50 // Initializes the session specified by |session_id| with the |content_type| | 59 // Initializes a session with the |init_data_type|, |init_data| and |
51 // and |init_data| provided. | 60 // |session_type| provided. Takes ownership of |promise|. |
52 void InitializeNewSession(uint32 session_id, | 61 void InitializeNewSession( |
53 const std::string& content_type, | 62 const std::string& init_data_type, |
54 const uint8* init_data, | 63 const uint8* init_data, |
55 int init_data_length); | 64 int init_data_length, |
65 media::MediaKeys::SessionType session_type, | |
66 scoped_ptr<media::CdmPromise<std::string> > promise); | |
56 | 67 |
57 // Updates the session specified by |session_id| with |response|. | 68 // Updates the session specified by |web_session_id| with |response|. |
58 void UpdateSession(uint32 session_id, | 69 // Takes ownership of |promise|. |
70 void UpdateSession(const std::string& web_session_id, | |
59 const uint8* response, | 71 const uint8* response, |
60 int response_length); | 72 int response_length, |
73 scoped_ptr<media::CdmPromise<void> > promise); | |
61 | 74 |
62 // Releases the session specified by |session_id|. | 75 // Releases the session specified by |web_session_id|. |
63 void ReleaseSession(uint32 session_id); | 76 // Takes ownership of |promise|. |
77 void ReleaseSession(const std::string& web_session_id, | |
78 scoped_ptr<media::CdmPromise<void> > promise); | |
64 | 79 |
65 // Returns the Decryptor associated with this CDM. May be NULL if no | 80 // Returns the Decryptor associated with this CDM. May be NULL if no |
66 // Decryptor is associated with the MediaKeys object. | 81 // Decryptor is associated with the MediaKeys object. |
67 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor | 82 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor |
68 // after WebContentDecryptionModule is freed. http://crbug.com/330324 | 83 // after WebContentDecryptionModule is freed. http://crbug.com/330324 |
69 media::Decryptor* GetDecryptor(); | 84 media::Decryptor* GetDecryptor(); |
70 | 85 |
71 #if defined(OS_ANDROID) | 86 #if defined(OS_ANDROID) |
72 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId | 87 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId |
73 // if no CDM ID is associated. | 88 // if no CDM ID is associated. |
74 int GetCdmId() const; | 89 int GetCdmId() const; |
75 #endif | 90 #endif |
76 | 91 |
77 private: | 92 private: |
78 friend class base::RefCounted<CdmSessionAdapter>; | 93 friend class base::RefCounted<CdmSessionAdapter>; |
79 typedef std::map<uint32, WebContentDecryptionModuleSessionImpl*> SessionMap; | 94 typedef base::hash_map<std::string, |
95 base::WeakPtr<WebContentDecryptionModuleSessionImpl> > | |
96 SessionMap; | |
80 | 97 |
81 ~CdmSessionAdapter(); | 98 ~CdmSessionAdapter(); |
82 | 99 |
83 // Callbacks for firing session events. | 100 // Callbacks for firing session events. |
84 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 101 void OnSessionMessage(const std::string& web_session_id, |
85 void OnSessionMessage(uint32 session_id, | |
86 const std::vector<uint8>& message, | 102 const std::vector<uint8>& message, |
87 const std::string& destination_url); | 103 const std::string& destination_url); |
88 void OnSessionReady(uint32 session_id); | 104 void OnSessionReady(const std::string& web_session_id); |
89 void OnSessionClosed(uint32 session_id); | 105 void OnSessionClosed(const std::string& web_session_id); |
90 void OnSessionError(uint32 session_id, | 106 void OnSessionError(const std::string& web_session_id, |
91 media::MediaKeys::KeyError error_code, | 107 media::MediaKeys::MediaKeysException exception_code, |
92 uint32 system_code); | 108 uint32 system_code, |
109 const std::string& error_message); | |
93 | 110 |
94 // Helper function of the callbacks. | 111 // Helper function of the callbacks. |
95 WebContentDecryptionModuleSessionImpl* GetSession(uint32 session_id); | 112 WebContentDecryptionModuleSessionImpl* GetSession( |
96 | 113 const std::string& web_session_id); |
97 // Session ID should be unique per renderer process for debugging purposes. | |
98 static uint32 next_session_id_; | |
99 | 114 |
100 scoped_ptr<media::MediaKeys> media_keys_; | 115 scoped_ptr<media::MediaKeys> media_keys_; |
101 | 116 |
102 SessionMap sessions_; | 117 SessionMap sessions_; |
103 | 118 |
104 #if defined(OS_ANDROID) | 119 #if defined(OS_ANDROID) |
105 int cdm_id_; | 120 int cdm_id_; |
106 #endif | 121 #endif |
107 | 122 |
108 // NOTE: Weak pointers must be invalidated before all other member variables. | 123 // NOTE: Weak pointers must be invalidated before all other member variables. |
109 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; | 124 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; |
110 | 125 |
111 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); | 126 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); |
112 }; | 127 }; |
113 | 128 |
114 } // namespace content | 129 } // namespace content |
115 | 130 |
116 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ | 131 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ |
OLD | NEW |