Index: content/renderer/pepper/content_decryptor_delegate.cc |
diff --git a/content/renderer/pepper/content_decryptor_delegate.cc b/content/renderer/pepper/content_decryptor_delegate.cc |
index 6712f46074dbef238461e1b70729cfa93d8a090b..8513a84fdaec0ba56715502cfa6b8ab186b009a3 100644 |
--- a/content/renderer/pepper/content_decryptor_delegate.cc |
+++ b/content/renderer/pepper/content_decryptor_delegate.cc |
@@ -250,11 +250,13 @@ ContentDecryptorDelegate::ContentDecryptorDelegate( |
next_decryption_request_id_(1), |
audio_samples_per_second_(0), |
audio_channel_count_(0), |
- weak_ptr_factory_(this) { |
+ weak_ptr_factory_(this), |
+ is_valid_(true) { |
weak_this_ = weak_ptr_factory_.GetWeakPtr(); |
} |
ContentDecryptorDelegate::~ContentDecryptorDelegate() { |
+ CancelAllPendingCallbacks(); |
} |
void ContentDecryptorDelegate::Initialize(const std::string& key_system) { |
@@ -280,10 +282,18 @@ void ContentDecryptorDelegate::SetSessionEventCallbacks( |
session_error_cb_ = session_error_cb; |
} |
+void ContentDecryptorDelegate::InstanceCrashed() { |
+ CancelAllPendingCallbacks(); |
+ is_valid_ = false; |
+} |
+ |
bool ContentDecryptorDelegate::CreateSession(uint32 session_id, |
const std::string& type, |
const uint8* init_data, |
int init_data_length) { |
+ if (!is_valid_) |
+ return false; |
+ |
PP_Var init_data_array = |
PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
init_data_length, init_data); |
@@ -298,6 +308,9 @@ bool ContentDecryptorDelegate::CreateSession(uint32 session_id, |
bool ContentDecryptorDelegate::UpdateSession(uint32 session_id, |
const uint8* response, |
int response_length) { |
+ if (!is_valid_) |
+ return false; |
+ |
PP_Var response_array = |
PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
response_length, response); |
@@ -307,6 +320,9 @@ bool ContentDecryptorDelegate::UpdateSession(uint32 session_id, |
} |
bool ContentDecryptorDelegate::ReleaseSession(uint32 session_id) { |
+ if (!is_valid_) |
+ return false; |
+ |
plugin_decryption_interface_->ReleaseSession(pp_instance_, session_id); |
return true; |
} |
@@ -318,6 +334,10 @@ bool ContentDecryptorDelegate::Decrypt( |
const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
const Decryptor::DecryptCB& decrypt_cb) { |
DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
+ |
+ if (!is_valid_) |
+ return false; |
+ |
// |{audio|video}_input_resource_| is not being used by the plugin |
// now because there is only one pending audio/video decrypt request at any |
// time. This is enforced by the media pipeline. |
@@ -364,6 +384,9 @@ bool ContentDecryptorDelegate::CancelDecrypt( |
Decryptor::StreamType stream_type) { |
DVLOG(3) << "CancelDecrypt() - stream_type: " << stream_type; |
+ if (!is_valid_) |
+ return false; |
+ |
Decryptor::DecryptCB decrypt_cb; |
switch (stream_type) { |
case Decryptor::kAudio: |
@@ -394,6 +417,9 @@ bool ContentDecryptorDelegate::CancelDecrypt( |
bool ContentDecryptorDelegate::InitializeAudioDecoder( |
const media::AudioDecoderConfig& decoder_config, |
const Decryptor::DecoderInitCB& init_cb) { |
+ if (!is_valid_) |
+ return false; |
+ |
PP_AudioDecoderConfig pp_decoder_config; |
pp_decoder_config.codec = |
MediaAudioCodecToPpAudioCodec(decoder_config.codec()); |
@@ -425,6 +451,9 @@ bool ContentDecryptorDelegate::InitializeAudioDecoder( |
bool ContentDecryptorDelegate::InitializeVideoDecoder( |
const media::VideoDecoderConfig& decoder_config, |
const Decryptor::DecoderInitCB& init_cb) { |
+ if (!is_valid_) |
+ return false; |
+ |
PP_VideoDecoderConfig pp_decoder_config; |
pp_decoder_config.codec = |
MediaVideoCodecToPpVideoCodec(decoder_config.codec()); |
@@ -456,6 +485,9 @@ bool ContentDecryptorDelegate::InitializeVideoDecoder( |
bool ContentDecryptorDelegate::DeinitializeDecoder( |
Decryptor::StreamType stream_type) { |
+ if (!is_valid_) |
+ return false; |
+ |
CancelDecode(stream_type); |
natural_size_ = gfx::Size(); |
@@ -468,6 +500,9 @@ bool ContentDecryptorDelegate::DeinitializeDecoder( |
} |
bool ContentDecryptorDelegate::ResetDecoder(Decryptor::StreamType stream_type) { |
+ if (!is_valid_) |
+ return false; |
+ |
CancelDecode(stream_type); |
// TODO(tomfinegan): Add decoder reset request tracking. |
@@ -479,6 +514,9 @@ bool ContentDecryptorDelegate::ResetDecoder(Decryptor::StreamType stream_type) { |
bool ContentDecryptorDelegate::DecryptAndDecodeAudio( |
const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
const Decryptor::AudioDecodeCB& audio_decode_cb) { |
+ if (!is_valid_) |
+ return false; |
+ |
// |audio_input_resource_| is not being used by the plugin now |
// because there is only one pending audio decode request at any time. |
// This is enforced by the media pipeline. |
@@ -519,6 +557,9 @@ bool ContentDecryptorDelegate::DecryptAndDecodeAudio( |
bool ContentDecryptorDelegate::DecryptAndDecodeVideo( |
const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
const Decryptor::VideoDecodeCB& video_decode_cb) { |
+ if (!is_valid_) |
+ return false; |
+ |
// |video_input_resource_| is not being used by the plugin now |
// because there is only one pending video decode request at any time. |
// This is enforced by the media pipeline. |
@@ -1021,4 +1062,30 @@ bool ContentDecryptorDelegate::DeserializeAudioFrames( |
return true; |
} |
+void ContentDecryptorDelegate::CancelAllPendingCallbacks() { |
dmichael (off chromium)
2014/01/08 20:15:59
The meaning here is a little different from what I
xhwang
2014/01/08 23:19:14
Done.
|
+ if (!audio_decoder_init_cb_.is_null()) |
+ audio_decoder_init_cb_.ResetAndReturn().Run(false); |
+ |
+ if (!video_decoder_init_cb_.is_null()) |
+ video_decoder_init_cb_.ResetAndReturn().Run(false); |
+ |
+ audio_input_resource_ = NULL; |
+ video_input_resource_ = NULL; |
+ |
+ if (!audio_decrypt_cb_.is_null()) |
+ audio_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
+ |
+ if (!video_decrypt_cb_.is_null()) |
+ video_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
+ |
+ if (!audio_decode_cb_.is_null()) { |
+ const media::Decryptor::AudioBuffers empty_frames; |
+ audio_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, |
+ empty_frames); |
+ } |
+ |
+ if (!video_decode_cb_.is_null()) |
+ video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
+} |
+ |
} // namespace content |