Index: content/renderer/media/crypto/ppapi_decryptor.cc |
diff --git a/content/renderer/media/crypto/ppapi_decryptor.cc b/content/renderer/media/crypto/ppapi_decryptor.cc |
index aff94a240e5e9174954a38a022ca59cd0d524a35..fee25e524dd98e99d91a1bd495796d8e1ba0e1c7 100644 |
--- a/content/renderer/media/crypto/ppapi_decryptor.cc |
+++ b/content/renderer/media/crypto/ppapi_decryptor.cc |
@@ -38,9 +38,8 @@ scoped_ptr<PpapiDecryptor> PpapiDecryptor::Create( |
return scoped_ptr<PpapiDecryptor>(); |
} |
- plugin_cdm_delegate->Initialize(key_system); |
- |
- return scoped_ptr<PpapiDecryptor>(new PpapiDecryptor(plugin_instance, |
+ return scoped_ptr<PpapiDecryptor>(new PpapiDecryptor(key_system, |
+ plugin_instance, |
plugin_cdm_delegate, |
session_created_cb, |
session_message_cb, |
@@ -51,6 +50,7 @@ scoped_ptr<PpapiDecryptor> PpapiDecryptor::Create( |
} |
PpapiDecryptor::PpapiDecryptor( |
+ const std::string& key_system, |
const scoped_refptr<PepperPluginInstanceImpl>& plugin_instance, |
ContentDecryptorDelegate* plugin_cdm_delegate, |
const media::SessionCreatedCB& session_created_cb, |
@@ -79,18 +79,21 @@ PpapiDecryptor::PpapiDecryptor( |
weak_this_ = weak_ptr_factory_.GetWeakPtr(); |
- plugin_cdm_delegate_->SetSessionEventCallbacks( |
+ plugin_cdm_delegate_->Initialize( |
+ key_system, |
base::Bind(&PpapiDecryptor::OnSessionCreated, weak_this_), |
base::Bind(&PpapiDecryptor::OnSessionMessage, weak_this_), |
base::Bind(&PpapiDecryptor::OnSessionReady, weak_this_), |
base::Bind(&PpapiDecryptor::OnSessionClosed, weak_this_), |
- base::Bind(&PpapiDecryptor::OnSessionError, weak_this_)); |
+ base::Bind(&PpapiDecryptor::OnSessionError, weak_this_), |
+ base::Bind(&PpapiDecryptor::OnPluginError, weak_this_)); |
} |
PpapiDecryptor::~PpapiDecryptor() { |
plugin_cdm_delegate_ = NULL; |
plugin_instance_ = NULL; |
- destroy_plugin_cb_.Run(); |
+ if (!destroy_plugin_cb_.is_null()) |
+ base::ResetAndReturn(&destroy_plugin_cb_).Run(); |
} |
bool PpapiDecryptor::CreateSession(uint32 session_id, |
@@ -101,8 +104,9 @@ bool PpapiDecryptor::CreateSession(uint32 session_id, |
DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
DCHECK(plugin_cdm_delegate_); |
- if (!plugin_cdm_delegate_->CreateSession( |
- session_id, type, init_data, init_data_length)) { |
+ if (!plugin_cdm_delegate_ || |
+ !plugin_cdm_delegate_->CreateSession( |
+ session_id, type, init_data, init_data_length)) { |
ReportFailureToCallPlugin(session_id); |
return false; |
} |
@@ -116,9 +120,10 @@ void PpapiDecryptor::UpdateSession(uint32 session_id, |
DVLOG(2) << __FUNCTION__; |
DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
- if (!plugin_cdm_delegate_->UpdateSession( |
- session_id, response, response_length)) |
+ if (!plugin_cdm_delegate_ || !plugin_cdm_delegate_->UpdateSession( |
+ session_id, response, response_length)) { |
xhwang
2014/01/08 23:19:14
This is clang-format style:)
|
ReportFailureToCallPlugin(session_id); |
+ } |
if (!new_audio_key_cb_.is_null()) |
new_audio_key_cb_.Run(); |
@@ -131,8 +136,10 @@ void PpapiDecryptor::ReleaseSession(uint32 session_id) { |
DVLOG(2) << __FUNCTION__; |
DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
- if (!plugin_cdm_delegate_->ReleaseSession(session_id)) |
+ if (!plugin_cdm_delegate_ || |
+ !plugin_cdm_delegate_->ReleaseSession(session_id)) { |
ReportFailureToCallPlugin(session_id); |
+ } |
} |
media::Decryptor* PpapiDecryptor::GetDecryptor() { |
@@ -184,8 +191,10 @@ void PpapiDecryptor::Decrypt( |
} |
DVLOG(3) << __FUNCTION__ << " - stream_type: " << stream_type; |
- if (!plugin_cdm_delegate_->Decrypt(stream_type, encrypted, decrypt_cb)) |
+ if (!plugin_cdm_delegate_ || |
xhwang
2014/01/08 23:19:14
If I add a lock I can check this before the post (
|
+ !plugin_cdm_delegate_->Decrypt(stream_type, encrypted, decrypt_cb)) { |
decrypt_cb.Run(kError, NULL); |
+ } |
} |
void PpapiDecryptor::CancelDecrypt(StreamType stream_type) { |
@@ -196,7 +205,8 @@ void PpapiDecryptor::CancelDecrypt(StreamType stream_type) { |
} |
DVLOG(1) << __FUNCTION__ << " - stream_type: " << stream_type; |
- plugin_cdm_delegate_->CancelDecrypt(stream_type); |
+ if (plugin_cdm_delegate_) |
+ plugin_cdm_delegate_->CancelDecrypt(stream_type); |
} |
void PpapiDecryptor::InitializeAudioDecoder( |
@@ -213,8 +223,9 @@ void PpapiDecryptor::InitializeAudioDecoder( |
DCHECK(config.IsValidConfig()); |
audio_decoder_init_cb_ = init_cb; |
- if (!plugin_cdm_delegate_->InitializeAudioDecoder(config, base::Bind( |
- &PpapiDecryptor::OnDecoderInitialized, weak_this_, kAudio))) { |
+ if (!plugin_cdm_delegate_ || |
+ !plugin_cdm_delegate_->InitializeAudioDecoder(config, base::Bind( |
+ &PpapiDecryptor::OnDecoderInitialized, weak_this_, kAudio))) { |
base::ResetAndReturn(&audio_decoder_init_cb_).Run(false); |
return; |
} |
@@ -234,8 +245,9 @@ void PpapiDecryptor::InitializeVideoDecoder( |
DCHECK(config.IsValidConfig()); |
video_decoder_init_cb_ = init_cb; |
- if (!plugin_cdm_delegate_->InitializeVideoDecoder(config, base::Bind( |
- &PpapiDecryptor::OnDecoderInitialized, weak_this_, kVideo))) { |
+ if (!plugin_cdm_delegate_ || |
+ !plugin_cdm_delegate_->InitializeVideoDecoder(config, base::Bind( |
+ &PpapiDecryptor::OnDecoderInitialized, weak_this_, kVideo))) { |
base::ResetAndReturn(&video_decoder_init_cb_).Run(false); |
return; |
} |
@@ -252,8 +264,10 @@ void PpapiDecryptor::DecryptAndDecodeAudio( |
} |
DVLOG(3) << __FUNCTION__; |
- if (!plugin_cdm_delegate_->DecryptAndDecodeAudio(encrypted, audio_decode_cb)) |
+ if (!plugin_cdm_delegate_ || !plugin_cdm_delegate_->DecryptAndDecodeAudio( |
+ encrypted, audio_decode_cb)) { |
audio_decode_cb.Run(kError, AudioBuffers()); |
+ } |
} |
void PpapiDecryptor::DecryptAndDecodeVideo( |
@@ -267,8 +281,10 @@ void PpapiDecryptor::DecryptAndDecodeVideo( |
} |
DVLOG(3) << __FUNCTION__; |
- if (!plugin_cdm_delegate_->DecryptAndDecodeVideo(encrypted, video_decode_cb)) |
+ if (!plugin_cdm_delegate_ || !plugin_cdm_delegate_->DecryptAndDecodeVideo( |
+ encrypted, video_decode_cb)) { |
video_decode_cb.Run(kError, NULL); |
+ } |
} |
void PpapiDecryptor::ResetDecoder(StreamType stream_type) { |
@@ -279,7 +295,8 @@ void PpapiDecryptor::ResetDecoder(StreamType stream_type) { |
} |
DVLOG(2) << __FUNCTION__ << " - stream_type: " << stream_type; |
- plugin_cdm_delegate_->ResetDecoder(stream_type); |
+ if (plugin_cdm_delegate_) |
+ plugin_cdm_delegate_->ResetDecoder(stream_type); |
} |
void PpapiDecryptor::DeinitializeDecoder(StreamType stream_type) { |
@@ -290,7 +307,8 @@ void PpapiDecryptor::DeinitializeDecoder(StreamType stream_type) { |
} |
DVLOG(2) << __FUNCTION__ << " - stream_type: " << stream_type; |
- plugin_cdm_delegate_->DeinitializeDecoder(stream_type); |
+ if (plugin_cdm_delegate_) |
+ plugin_cdm_delegate_->DeinitializeDecoder(stream_type); |
} |
void PpapiDecryptor::ReportFailureToCallPlugin(uint32 session_id) { |
@@ -346,4 +364,12 @@ void PpapiDecryptor::OnSessionError(uint32 session_id, |
session_error_cb_.Run(session_id, error_code, system_code); |
} |
+void PpapiDecryptor::OnPluginError() { |
+ DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
+ DCHECK(plugin_cdm_delegate_); |
+ plugin_cdm_delegate_ = NULL; |
+ plugin_instance_ = NULL; |
+ base::ResetAndReturn(&destroy_plugin_cb_).Run(); |
ddorwin
2014/01/08 23:40:32
This probably exposes/tests new paths related to W
xhwang
2014/01/09 01:58:49
:) Let's see.
|
+} |
+ |
} // namespace content |