Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / media / filters / decrypting_audio_decoder.cc
index 136e171..ee50e2e 100644 (file)
@@ -144,13 +144,12 @@ void DecryptingAudioDecoder::Reset(const base::Closure& closure) {
   DoReset();
 }
 
-void DecryptingAudioDecoder::Stop() {
-  DVLOG(2) << "Stop() - state: " << state_;
+DecryptingAudioDecoder::~DecryptingAudioDecoder() {
+  DVLOG(2) << __FUNCTION__;
   DCHECK(task_runner_->BelongsToCurrentThread());
 
-  // Invalidate all weak pointers so that pending callbacks won't be fired into
-  // this object.
-  weak_factory_.InvalidateWeakPtrs();
+  if (state_ == kUninitialized)
+    return;
 
   if (decryptor_) {
     decryptor_->DeinitializeDecoder(Decryptor::kAudio);
@@ -165,15 +164,11 @@ void DecryptingAudioDecoder::Stop() {
     base::ResetAndReturn(&decode_cb_).Run(kAborted);
   if (!reset_cb_.is_null())
     base::ResetAndReturn(&reset_cb_).Run();
-
-  state_ = kStopped;
 }
 
-DecryptingAudioDecoder::~DecryptingAudioDecoder() {
-  DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
-}
-
-void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
+void DecryptingAudioDecoder::SetDecryptor(
+    Decryptor* decryptor,
+    const DecryptorAttachedCB& decryptor_attached_cb) {
   DVLOG(2) << "SetDecryptor()";
   DCHECK(task_runner_->BelongsToCurrentThread());
   DCHECK_EQ(state_, kDecryptorRequested) << state_;
@@ -184,14 +179,15 @@ void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
 
   if (!decryptor) {
     base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
-    // TODO(xhwang): Add kError state. See http://crbug.com/251503
-    state_ = kStopped;
+    state_ = kError;
+    decryptor_attached_cb.Run(false);
     return;
   }
 
   decryptor_ = decryptor;
 
   InitializeDecoder();
+  decryptor_attached_cb.Run(true);
 }
 
 void DecryptingAudioDecoder::InitializeDecoder() {
@@ -212,7 +208,8 @@ void DecryptingAudioDecoder::FinishInitialization(bool success) {
 
   if (!success) {
     base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
-    state_ = kStopped;
+    decryptor_ = NULL;
+    state_ = kError;
     return;
   }