| 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 MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ | 5 #ifndef MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ |
| 6 #define MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ | 6 #define MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Owns the CDM instance and makes calls from session objects to the CDM. | 30 // Owns the CDM instance and makes calls from session objects to the CDM. |
| 31 // Forwards the session ID-based callbacks of the MediaKeys interface to the | 31 // Forwards the session ID-based callbacks of the MediaKeys interface to the |
| 32 // appropriate session object. Callers should hold references to this class | 32 // appropriate session object. Callers should hold references to this class |
| 33 // as long as they need the CDM instance. | 33 // as long as they need the CDM instance. |
| 34 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { | 34 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { |
| 35 public: | 35 public: |
| 36 CdmSessionAdapter(); | 36 CdmSessionAdapter(); |
| 37 | 37 |
| 38 // Creates the CDM for |key_system| using |cdm_factory| and returns the result | 38 // Creates the CDM for |key_system| using |cdm_factory| and returns the result |
| 39 // via |result|. | 39 // via |result|. |
| 40 void CreateCdm(CdmFactory* cdm_factory, | 40 void CreateCdm( |
| 41 const std::string& key_system, | 41 CdmFactory* cdm_factory, |
| 42 const GURL& security_origin, | 42 const std::string& key_system, |
| 43 const CdmConfig& cdm_config, | 43 const GURL& security_origin, |
| 44 scoped_ptr<blink::WebContentDecryptionModuleResult> result); | 44 const CdmConfig& cdm_config, |
| 45 std::unique_ptr<blink::WebContentDecryptionModuleResult> result); |
| 45 | 46 |
| 46 // Provides a server certificate to be used to encrypt messages to the | 47 // Provides a server certificate to be used to encrypt messages to the |
| 47 // license server. | 48 // license server. |
| 48 void SetServerCertificate(const std::vector<uint8_t>& certificate, | 49 void SetServerCertificate(const std::vector<uint8_t>& certificate, |
| 49 scoped_ptr<SimpleCdmPromise> promise); | 50 std::unique_ptr<SimpleCdmPromise> promise); |
| 50 | 51 |
| 51 // Creates a new session and adds it to the internal map. The caller owns the | 52 // Creates a new session and adds it to the internal map. The caller owns the |
| 52 // created session. RemoveSession() must be called when destroying it, if | 53 // created session. RemoveSession() must be called when destroying it, if |
| 53 // RegisterSession() was called. | 54 // RegisterSession() was called. |
| 54 WebContentDecryptionModuleSessionImpl* CreateSession(); | 55 WebContentDecryptionModuleSessionImpl* CreateSession(); |
| 55 | 56 |
| 56 // Adds a session to the internal map. Called once the session is successfully | 57 // Adds a session to the internal map. Called once the session is successfully |
| 57 // initialized. Returns true if the session was registered, false if there is | 58 // initialized. Returns true if the session was registered, false if there is |
| 58 // already an existing session with the same |session_id|. | 59 // already an existing session with the same |session_id|. |
| 59 bool RegisterSession( | 60 bool RegisterSession( |
| 60 const std::string& session_id, | 61 const std::string& session_id, |
| 61 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session); | 62 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session); |
| 62 | 63 |
| 63 // Removes a session from the internal map. | 64 // Removes a session from the internal map. |
| 64 void UnregisterSession(const std::string& session_id); | 65 void UnregisterSession(const std::string& session_id); |
| 65 | 66 |
| 66 // Initializes a session with the |init_data_type|, |init_data| and | 67 // Initializes a session with the |init_data_type|, |init_data| and |
| 67 // |session_type| provided. | 68 // |session_type| provided. |
| 68 void InitializeNewSession(EmeInitDataType init_data_type, | 69 void InitializeNewSession(EmeInitDataType init_data_type, |
| 69 const std::vector<uint8_t>& init_data, | 70 const std::vector<uint8_t>& init_data, |
| 70 MediaKeys::SessionType session_type, | 71 MediaKeys::SessionType session_type, |
| 71 scoped_ptr<NewSessionCdmPromise> promise); | 72 std::unique_ptr<NewSessionCdmPromise> promise); |
| 72 | 73 |
| 73 // Loads the session specified by |session_id|. | 74 // Loads the session specified by |session_id|. |
| 74 void LoadSession(MediaKeys::SessionType session_type, | 75 void LoadSession(MediaKeys::SessionType session_type, |
| 75 const std::string& session_id, | 76 const std::string& session_id, |
| 76 scoped_ptr<NewSessionCdmPromise> promise); | 77 std::unique_ptr<NewSessionCdmPromise> promise); |
| 77 | 78 |
| 78 // Updates the session specified by |session_id| with |response|. | 79 // Updates the session specified by |session_id| with |response|. |
| 79 void UpdateSession(const std::string& session_id, | 80 void UpdateSession(const std::string& session_id, |
| 80 const std::vector<uint8_t>& response, | 81 const std::vector<uint8_t>& response, |
| 81 scoped_ptr<SimpleCdmPromise> promise); | 82 std::unique_ptr<SimpleCdmPromise> promise); |
| 82 | 83 |
| 83 // Closes the session specified by |session_id|. | 84 // Closes the session specified by |session_id|. |
| 84 void CloseSession(const std::string& session_id, | 85 void CloseSession(const std::string& session_id, |
| 85 scoped_ptr<SimpleCdmPromise> promise); | 86 std::unique_ptr<SimpleCdmPromise> promise); |
| 86 | 87 |
| 87 // Removes stored session data associated with the session specified by | 88 // Removes stored session data associated with the session specified by |
| 88 // |session_id|. | 89 // |session_id|. |
| 89 void RemoveSession(const std::string& session_id, | 90 void RemoveSession(const std::string& session_id, |
| 90 scoped_ptr<SimpleCdmPromise> promise); | 91 std::unique_ptr<SimpleCdmPromise> promise); |
| 91 | 92 |
| 92 // Returns the CdmContext associated with |media_keys_|. | 93 // Returns the CdmContext associated with |media_keys_|. |
| 93 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor | 94 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor |
| 94 // after WebContentDecryptionModule is freed. http://crbug.com/330324 | 95 // after WebContentDecryptionModule is freed. http://crbug.com/330324 |
| 95 CdmContext* GetCdmContext(); | 96 CdmContext* GetCdmContext(); |
| 96 | 97 |
| 97 // Returns the key system name. | 98 // Returns the key system name. |
| 98 const std::string& GetKeySystem() const; | 99 const std::string& GetKeySystem() const; |
| 99 | 100 |
| 100 // Returns a prefix to use for UMAs. | 101 // Returns a prefix to use for UMAs. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 143 |
| 143 SessionMap sessions_; | 144 SessionMap sessions_; |
| 144 | 145 |
| 145 std::string key_system_; | 146 std::string key_system_; |
| 146 std::string key_system_uma_prefix_; | 147 std::string key_system_uma_prefix_; |
| 147 | 148 |
| 148 // A unique ID to trace CdmSessionAdapter::CreateCdm() call and the matching | 149 // A unique ID to trace CdmSessionAdapter::CreateCdm() call and the matching |
| 149 // OnCdmCreated() call. | 150 // OnCdmCreated() call. |
| 150 uint32_t trace_id_; | 151 uint32_t trace_id_; |
| 151 | 152 |
| 152 scoped_ptr<blink::WebContentDecryptionModuleResult> cdm_created_result_; | 153 std::unique_ptr<blink::WebContentDecryptionModuleResult> cdm_created_result_; |
| 153 | 154 |
| 154 // NOTE: Weak pointers must be invalidated before all other member variables. | 155 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 155 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; | 156 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; |
| 156 | 157 |
| 157 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); | 158 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); |
| 158 }; | 159 }; |
| 159 | 160 |
| 160 } // namespace media | 161 } // namespace media |
| 161 | 162 |
| 162 #endif // MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ | 163 #endif // MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ |
| OLD | NEW |