Bug 830551 - Send file-transfer-complete message after receiving unexpected response code from remote, r=echou
authorGina Yeh <gyeh@mozilla.com>
Mon, 25 Feb 2013 12:40:31 +0800
changeset 122875 924c07c3cb32d4120380fafec06c1873322e1a63
parent 122874 3c11909c216acc5b02052b43027e45cfb9dfabc3
child 122876 e9438169e05035db0c537f6a64872d8f6276e48b
push id1387
push userphilringnalda@gmail.com
push dateTue, 26 Feb 2013 22:32:56 +0000
treeherderfx-team@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs830551
milestone22.0a1
Bug 830551 - Send file-transfer-complete message after receiving unexpected response code from remote, r=echou
dom/bluetooth/BluetoothOppManager.cpp
--- a/dom/bluetooth/BluetoothOppManager.cpp
+++ b/dom/bluetooth/BluetoothOppManager.cpp
@@ -356,16 +356,17 @@ BluetoothOppManager::SendFile(BlobParent
         sFileName.AppendLiteral(".");
         AppendUTF8toUTF16(extension, sFileName);
       }
     }
   }
 
   SendConnectRequest();
   mTransferMode = false;
+  StartFileTransfer();
 
   return true;
 }
 
 bool
 BluetoothOppManager::StopSendingFile()
 {
   mAbortFlag = true;
@@ -792,34 +793,36 @@ BluetoothOppManager::ClientDataHandler(U
   if (mPacketLeftLength > 0) {
     opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put;
     packetLength = mPacketLeftLength;
   } else {
     opCode = aMessage->mData[0];
     packetLength = (((int)aMessage->mData[1]) << 8) | aMessage->mData[2];
   }
 
-  // Check response code
-  if (mLastCommand == ObexRequestCode::Put &&
-      opCode != ObexResponseCode::Continue) {
-    NS_WARNING("[OPP] Put(0x02) failed");
-    SendDisconnectRequest();
+  // Check response code and send out system message as finished if the reponse
+  // code is somehow incorrect.
+  uint8_t expectedOpCode = ObexResponseCode::Success;
+  if (mLastCommand == ObexRequestCode::Put) {
+    expectedOpCode = ObexResponseCode::Continue;
+  }
+
+  if (opCode != expectedOpCode) {
+    if (mLastCommand == ObexRequestCode::Put ||
+        mLastCommand == ObexRequestCode::Abort ||
+        mLastCommand == ObexRequestCode::PutFinal) {
+      SendDisconnectRequest();
+    }
+    nsAutoCString str;
+    str += "[OPP] 0x";
+    str.AppendInt(mLastCommand, 16);
+    str += " failed";
+    NS_WARNING(str.get());
+    FileTransferComplete();
     return;
-  } else if (mLastCommand == ObexRequestCode::Abort ||
-             mLastCommand == ObexRequestCode::Connect ||
-             mLastCommand == ObexRequestCode::Disconnect ||
-             mLastCommand == ObexRequestCode::PutFinal){
-    if (opCode != ObexResponseCode::Success) {
-      nsAutoCString str;
-      str += "[OPP] 0x";
-      str += mLastCommand;
-      str += " failed";
-      NS_WARNING(str.get());
-      return;
-    }
   }
 
   if (mLastCommand == ObexRequestCode::PutFinal) {
     mSuccessFlag = true;
     FileTransferComplete();
     SendDisconnectRequest();
   } else if (mLastCommand == ObexRequestCode::Abort) {
     SendDisconnectRequest();
@@ -844,17 +847,16 @@ BluetoothOppManager::ClientDataHandler(U
       (((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]);
 
     /*
      * Before sending content, we have to send a header including
      * information such as file name, file length and content type.
      */
     if (ExtractBlobHeaders()) {
       sInstance->SendPutHeaderRequest(sFileName, sFileLength);
-      StartFileTransfer();
     }
   } else if (mLastCommand == ObexRequestCode::Put) {
 
     // Send PutFinal packet when we get response
     if (sWaitingToSendPutFinal) {
       SendPutFinalRequest();
       return;
     }