diff options
author | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-09 04:23:29 +0000 |
---|---|---|
committer | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-09 04:23:29 +0000 |
commit | a27d34ab68aa875f665b043129b6315dd9e62224 (patch) | |
tree | 59c2630c3b54d0d6810b5c644b5f247cbc360a3f /content/renderer/media/crypto | |
parent | 7819ffcdd83a316cf2f010fcfd22ed89c355d5d9 (diff) | |
download | chromium_src-a27d34ab68aa875f665b043129b6315dd9e62224.zip chromium_src-a27d34ab68aa875f665b043129b6315dd9e62224.tar.gz chromium_src-a27d34ab68aa875f665b043129b6315dd9e62224.tar.bz2 |
Handle plugin instance crash in ContentDecryptorDelegate.
BUG=chrome-os-partner:17801
TEST=Kill Widevine CDM process and we get decode error.
Review URL: https://codereview.chromium.org/116443009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media/crypto')
-rw-r--r-- | content/renderer/media/crypto/ppapi_decryptor.cc | 68 | ||||
-rw-r--r-- | content/renderer/media/crypto/ppapi_decryptor.h | 8 |
2 files changed, 54 insertions, 22 deletions
diff --git a/content/renderer/media/crypto/ppapi_decryptor.cc b/content/renderer/media/crypto/ppapi_decryptor.cc index aff94a2..b60afaa 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::OnFatalPluginError, 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)) { 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_ || + !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::OnFatalPluginError() { + DCHECK(render_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_cdm_delegate_); + plugin_cdm_delegate_ = NULL; + plugin_instance_ = NULL; + base::ResetAndReturn(&destroy_plugin_cb_).Run(); +} + } // namespace content diff --git a/content/renderer/media/crypto/ppapi_decryptor.h b/content/renderer/media/crypto/ppapi_decryptor.h index 95c5f74..a51824f 100644 --- a/content/renderer/media/crypto/ppapi_decryptor.h +++ b/content/renderer/media/crypto/ppapi_decryptor.h @@ -73,7 +73,8 @@ class PpapiDecryptor : public media::MediaKeys, public media::Decryptor { virtual void DeinitializeDecoder(StreamType stream_type) OVERRIDE; private: - PpapiDecryptor(const scoped_refptr<PepperPluginInstanceImpl>& plugin_instance, + PpapiDecryptor(const std::string& key_system, + const scoped_refptr<PepperPluginInstanceImpl>& plugin_instance, ContentDecryptorDelegate* plugin_cdm_delegate, const media::SessionCreatedCB& session_created_cb, const media::SessionMessageCB& session_message_cb, @@ -97,6 +98,11 @@ class PpapiDecryptor : public media::MediaKeys, public media::Decryptor { media::MediaKeys::KeyError error_code, int system_code); + // Callback to notify that a fatal error happened in |plugin_cdm_delegate_|. + // The error is terminal and |plugin_cdm_delegate_| should not be used after + // this call. + void OnFatalPluginError(); + base::WeakPtr<PpapiDecryptor> weak_this_; // Hold a reference of the plugin instance to make sure the plugin outlives |