#ifndef CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_
#define CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_
#include <map>
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "media/base/media_keys.h"
#include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h"
#if defined(ENABLE_PEPPER_CDMS)
#include "content/renderer/media/crypto/pepper_cdm_wrapper.h"
#endif
class GURL;
namespace content {
class WebContentDecryptionModuleSessionImpl;
class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> {
public:
CdmSessionAdapter();
bool Initialize(
#if defined(ENABLE_PEPPER_CDMS)
const CreatePepperCdmCB& create_pepper_cdm_cb,
#endif
const std::string& key_system,
const GURL& security_origin);
WebContentDecryptionModuleSessionImpl* CreateSession(
blink::WebContentDecryptionModuleSession::Client* client);
void RemoveSession(uint32 session_id);
void InitializeNewSession(uint32 session_id,
const std::string& content_type,
const uint8* init_data,
int init_data_length);
void UpdateSession(uint32 session_id,
const uint8* response,
int response_length);
void ReleaseSession(uint32 session_id);
media::Decryptor* GetDecryptor();
#if defined(OS_ANDROID)
int GetCdmId() const;
#endif
private:
friend class base::RefCounted<CdmSessionAdapter>;
typedef std::map<uint32, WebContentDecryptionModuleSessionImpl*> SessionMap;
~CdmSessionAdapter();
void OnSessionCreated(uint32 session_id, const std::string& web_session_id);
void OnSessionMessage(uint32 session_id,
const std::vector<uint8>& message,
const std::string& destination_url);
void OnSessionReady(uint32 session_id);
void OnSessionClosed(uint32 session_id);
void OnSessionError(uint32 session_id,
media::MediaKeys::KeyError error_code,
uint32 system_code);
WebContentDecryptionModuleSessionImpl* GetSession(uint32 session_id);
static uint32 next_session_id_;
scoped_ptr<media::MediaKeys> media_keys_;
SessionMap sessions_;
#if defined(OS_ANDROID)
int cdm_id_;
#endif
base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter);
};
}
#endif