am 8b6bacd0: Properly handle the case where a pending connection process is disconnected

* commit '8b6bacd02a0478ed51b3b15a9e997624c95a7564':
  Properly handle the case where a pending connection process is disconnected
diff --git a/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp b/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
index 76f7946..3f0b2c2 100644
--- a/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
+++ b/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
@@ -100,7 +100,7 @@
 
     mDelegate->initiateConnection(mURI.c_str(), &mHeaders, offset);
 
-    while (mState == CONNECTING) {
+    while (mState == CONNECTING || mState == DISCONNECTING) {
         mCondition.wait(mLock);
     }
 
@@ -110,6 +110,13 @@
 void ChromiumHTTPDataSource::onConnectionEstablished(
         int64_t contentSize, const char *contentType) {
     Mutex::Autolock autoLock(mLock);
+
+    if (mState != CONNECTING) {
+        // We may have initiated disconnection.
+        CHECK_EQ(mState, DISCONNECTING);
+        return;
+    }
+
     mState = CONNECTED;
     mContentSize = (contentSize < 0) ? -1 : contentSize + mCurrentOffset;
     mContentType = String8(contentType);
@@ -255,6 +262,7 @@
 
     mState = DISCONNECTED;
     // mURI.clear();
+    mIOResult = -ENOTCONN;
 
     mCondition.broadcast();
 }
diff --git a/media/libstagefright/chromium_http/support.cpp b/media/libstagefright/chromium_http/support.cpp
index f15014e..13ae3df 100644
--- a/media/libstagefright/chromium_http/support.cpp
+++ b/media/libstagefright/chromium_http/support.cpp
@@ -490,6 +490,10 @@
 }
 
 void SfDelegate::onInitiateDisconnect() {
+    if (mURLRequest == NULL) {
+        return;
+    }
+
     mURLRequest->Cancel();
 
     delete mURLRequest;