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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "media/base/media_keys.h" | 13 #include "media/base/media_keys.h" |
14 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h " | 14 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h " |
15 | 15 |
16 #if defined(ENABLE_PEPPER_CDMS) | 16 #if defined(ENABLE_PEPPER_CDMS) |
17 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 17 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
18 #endif | 18 #endif |
19 | 19 |
20 class GURL; | 20 class GURL; |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 #if defined(OS_ANDROID) | 24 #if defined(ENABLE_BROWSER_CDMS) |
25 class RendererCdmManager; | 25 class RendererCdmManager; |
26 #endif | 26 #endif |
27 class WebContentDecryptionModuleSessionImpl; | 27 class WebContentDecryptionModuleSessionImpl; |
28 | 28 |
29 // Owns the CDM instance and makes calls from session objects to the CDM. | 29 // Owns the CDM instance and makes calls from session objects to the CDM. |
30 // Forwards the session ID-based callbacks of the MediaKeys interface to the | 30 // Forwards the session ID-based callbacks of the MediaKeys interface to the |
31 // appropriate session object. Callers should hold references to this class | 31 // appropriate session object. Callers should hold references to this class |
32 // as long as they need the CDM instance. | 32 // as long as they need the CDM instance. |
33 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { | 33 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { |
34 public: | 34 public: |
35 CdmSessionAdapter(); | 35 CdmSessionAdapter(); |
36 | 36 |
37 // Returns true on success. | 37 // Returns true on success. |
38 bool Initialize( | 38 bool Initialize( |
39 #if defined(ENABLE_PEPPER_CDMS) | 39 #if defined(ENABLE_PEPPER_CDMS) |
40 const CreatePepperCdmCB& create_pepper_cdm_cb, | 40 const CreatePepperCdmCB& create_pepper_cdm_cb, |
41 #elif defined(OS_ANDROID) | 41 #elif defined(ENABLE_BROWSER_CDMS) |
42 RendererCdmManager* manager, | 42 RendererCdmManager* manager, |
43 #endif | 43 #endif |
44 const std::string& key_system, | 44 const std::string& key_system, |
45 const GURL& security_origin); | 45 const GURL& security_origin); |
46 | 46 |
47 // Creates a new session and adds it to the internal map. The caller owns the | 47 // Creates a new session and adds it to the internal map. The caller owns the |
48 // created session. RemoveSession() must be called when destroying it. | 48 // created session. RemoveSession() must be called when destroying it. |
49 WebContentDecryptionModuleSessionImpl* CreateSession( | 49 WebContentDecryptionModuleSessionImpl* CreateSession( |
50 blink::WebContentDecryptionModuleSession::Client* client); | 50 blink::WebContentDecryptionModuleSession::Client* client); |
51 | 51 |
(...skipping 14 matching lines...) Expand all Loading... | |
66 | 66 |
67 // Releases the session specified by |session_id|. | 67 // Releases the session specified by |session_id|. |
68 void ReleaseSession(uint32 session_id); | 68 void ReleaseSession(uint32 session_id); |
69 | 69 |
70 // Returns the Decryptor associated with this CDM. May be NULL if no | 70 // Returns the Decryptor associated with this CDM. May be NULL if no |
71 // Decryptor is associated with the MediaKeys object. | 71 // Decryptor is associated with the MediaKeys object. |
72 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor | 72 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor |
73 // after WebContentDecryptionModule is freed. http://crbug.com/330324 | 73 // after WebContentDecryptionModule is freed. http://crbug.com/330324 |
74 media::Decryptor* GetDecryptor(); | 74 media::Decryptor* GetDecryptor(); |
75 | 75 |
76 #if defined(OS_ANDROID) | 76 #if defined(ENABLE_BROWSER_CDMS) |
77 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId | 77 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId |
78 // if no CDM ID is associated. | 78 // if no CDM ID is associated. |
79 int GetCdmId() const; | 79 int GetCdmId() const; |
ddorwin
2014/06/05 17:59:48
Since this has a clear purpose now, should we name
xhwang
2014/06/09 20:57:19
I tried. Actually it looks weird when you have cod
| |
80 #endif | 80 #endif |
81 | 81 |
82 private: | 82 private: |
83 friend class base::RefCounted<CdmSessionAdapter>; | 83 friend class base::RefCounted<CdmSessionAdapter>; |
84 typedef std::map<uint32, WebContentDecryptionModuleSessionImpl*> SessionMap; | 84 typedef std::map<uint32, WebContentDecryptionModuleSessionImpl*> SessionMap; |
85 | 85 |
86 ~CdmSessionAdapter(); | 86 ~CdmSessionAdapter(); |
87 | 87 |
88 // Callbacks for firing session events. | 88 // Callbacks for firing session events. |
89 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 89 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); |
90 void OnSessionMessage(uint32 session_id, | 90 void OnSessionMessage(uint32 session_id, |
91 const std::vector<uint8>& message, | 91 const std::vector<uint8>& message, |
92 const GURL& destination_url); | 92 const GURL& destination_url); |
93 void OnSessionReady(uint32 session_id); | 93 void OnSessionReady(uint32 session_id); |
94 void OnSessionClosed(uint32 session_id); | 94 void OnSessionClosed(uint32 session_id); |
95 void OnSessionError(uint32 session_id, | 95 void OnSessionError(uint32 session_id, |
96 media::MediaKeys::KeyError error_code, | 96 media::MediaKeys::KeyError error_code, |
97 uint32 system_code); | 97 uint32 system_code); |
98 | 98 |
99 // Helper function of the callbacks. | 99 // Helper function of the callbacks. |
100 WebContentDecryptionModuleSessionImpl* GetSession(uint32 session_id); | 100 WebContentDecryptionModuleSessionImpl* GetSession(uint32 session_id); |
101 | 101 |
102 // Session ID should be unique per renderer process for debugging purposes. | 102 // Session ID should be unique per renderer process for debugging purposes. |
103 static uint32 next_session_id_; | 103 static uint32 next_session_id_; |
104 | 104 |
105 scoped_ptr<media::MediaKeys> media_keys_; | 105 scoped_ptr<media::MediaKeys> media_keys_; |
106 | 106 |
107 SessionMap sessions_; | 107 SessionMap sessions_; |
108 | 108 |
109 #if defined(OS_ANDROID) | 109 #if defined(ENABLE_BROWSER_CDMS) |
110 int cdm_id_; | 110 int cdm_id_; |
111 #endif | 111 #endif |
112 | 112 |
113 // NOTE: Weak pointers must be invalidated before all other member variables. | 113 // NOTE: Weak pointers must be invalidated before all other member variables. |
114 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; | 114 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); | 116 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); |
117 }; | 117 }; |
118 | 118 |
119 } // namespace content | 119 } // namespace content |
120 | 120 |
121 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ | 121 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ |
OLD | NEW |