| 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 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "media/base/media_keys.h" | 15 #include "media/base/media_keys.h" |
| 16 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h
" | 16 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h
" |
| 17 | 17 |
| 18 #if defined(ENABLE_PEPPER_CDMS) | 18 #if defined(ENABLE_PEPPER_CDMS) |
| 19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 class GURL; | 22 class GURL; |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 | 25 |
| 26 #if defined(OS_ANDROID) | 26 #if defined(ENABLE_BROWSER_CDMS) |
| 27 class RendererCdmManager; | 27 class RendererCdmManager; |
| 28 #endif | 28 #endif |
| 29 |
| 29 class WebContentDecryptionModuleSessionImpl; | 30 class WebContentDecryptionModuleSessionImpl; |
| 30 | 31 |
| 31 // Owns the CDM instance and makes calls from session objects to the CDM. | 32 // Owns the CDM instance and makes calls from session objects to the CDM. |
| 32 // Forwards the web session ID-based callbacks of the MediaKeys interface to the | 33 // Forwards the web session ID-based callbacks of the MediaKeys interface to the |
| 33 // appropriate session object. Callers should hold references to this class | 34 // appropriate session object. Callers should hold references to this class |
| 34 // as long as they need the CDM instance. | 35 // as long as they need the CDM instance. |
| 35 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { | 36 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { |
| 36 public: | 37 public: |
| 37 CdmSessionAdapter(); | 38 CdmSessionAdapter(); |
| 38 | 39 |
| 39 // Returns true on success. | 40 // Returns true on success. |
| 40 bool Initialize( | 41 bool Initialize( |
| 41 #if defined(ENABLE_PEPPER_CDMS) | 42 #if defined(ENABLE_PEPPER_CDMS) |
| 42 const CreatePepperCdmCB& create_pepper_cdm_cb, | 43 const CreatePepperCdmCB& create_pepper_cdm_cb, |
| 43 #elif defined(OS_ANDROID) | 44 #elif defined(ENABLE_BROWSER_CDMS) |
| 44 RendererCdmManager* manager, | 45 RendererCdmManager* manager, |
| 45 #endif | 46 #endif |
| 46 const std::string& key_system, | 47 const std::string& key_system, |
| 47 const GURL& security_origin); | 48 const GURL& security_origin); |
| 48 | 49 |
| 49 // Creates a new session and adds it to the internal map. The caller owns the | 50 // Creates a new session and adds it to the internal map. The caller owns the |
| 50 // created session. RemoveSession() must be called when destroying it, if | 51 // created session. RemoveSession() must be called when destroying it, if |
| 51 // RegisterSession() was called. | 52 // RegisterSession() was called. |
| 52 WebContentDecryptionModuleSessionImpl* CreateSession( | 53 WebContentDecryptionModuleSessionImpl* CreateSession( |
| 53 blink::WebContentDecryptionModuleSession::Client* client); | 54 blink::WebContentDecryptionModuleSession::Client* client); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 80 // Takes ownership of |promise|. | 81 // Takes ownership of |promise|. |
| 81 void ReleaseSession(const std::string& web_session_id, | 82 void ReleaseSession(const std::string& web_session_id, |
| 82 scoped_ptr<media::SimpleCdmPromise> promise); | 83 scoped_ptr<media::SimpleCdmPromise> promise); |
| 83 | 84 |
| 84 // Returns the Decryptor associated with this CDM. May be NULL if no | 85 // Returns the Decryptor associated with this CDM. May be NULL if no |
| 85 // Decryptor is associated with the MediaKeys object. | 86 // Decryptor is associated with the MediaKeys object. |
| 86 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor | 87 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor |
| 87 // after WebContentDecryptionModule is freed. http://crbug.com/330324 | 88 // after WebContentDecryptionModule is freed. http://crbug.com/330324 |
| 88 media::Decryptor* GetDecryptor(); | 89 media::Decryptor* GetDecryptor(); |
| 89 | 90 |
| 90 #if defined(OS_ANDROID) | 91 #if defined(ENABLE_BROWSER_CDMS) |
| 91 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId | 92 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId |
| 92 // if no CDM ID is associated. | 93 // if no CDM ID is associated. |
| 93 int GetCdmId() const; | 94 int GetCdmId() const; |
| 94 #endif | 95 #endif |
| 95 | 96 |
| 96 private: | 97 private: |
| 97 friend class base::RefCounted<CdmSessionAdapter>; | 98 friend class base::RefCounted<CdmSessionAdapter>; |
| 98 typedef base::hash_map<std::string, | 99 typedef base::hash_map<std::string, |
| 99 base::WeakPtr<WebContentDecryptionModuleSessionImpl> > | 100 base::WeakPtr<WebContentDecryptionModuleSessionImpl> > |
| 100 SessionMap; | 101 SessionMap; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 113 const std::string& error_message); | 114 const std::string& error_message); |
| 114 | 115 |
| 115 // Helper function of the callbacks. | 116 // Helper function of the callbacks. |
| 116 WebContentDecryptionModuleSessionImpl* GetSession( | 117 WebContentDecryptionModuleSessionImpl* GetSession( |
| 117 const std::string& web_session_id); | 118 const std::string& web_session_id); |
| 118 | 119 |
| 119 scoped_ptr<media::MediaKeys> media_keys_; | 120 scoped_ptr<media::MediaKeys> media_keys_; |
| 120 | 121 |
| 121 SessionMap sessions_; | 122 SessionMap sessions_; |
| 122 | 123 |
| 123 #if defined(OS_ANDROID) | 124 #if defined(ENABLE_BROWSER_CDMS) |
| 124 int cdm_id_; | 125 int cdm_id_; |
| 125 #endif | 126 #endif |
| 126 | 127 |
| 127 // NOTE: Weak pointers must be invalidated before all other member variables. | 128 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 128 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; | 129 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; |
| 129 | 130 |
| 130 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); | 131 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 } // namespace content | 134 } // namespace content |
| 134 | 135 |
| 135 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ | 136 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ |
| OLD | NEW |