Bug 816859 - Patch 1: Failed to receive a file, r=echou
authorGina Yeh <gyeh@mozilla.com>
Fri, 30 Nov 2012 17:49:08 +0800
changeset 114587 b774fae6ddc62f788368c35305425448d19f38e5
parent 114586 daa8b967628b4882c68020af7d6aa2e8e6a82286
child 114588 76c4e4fbd8bdd0e54ea1c7b08825a5738785ad50
push id23926
push userryanvm@gmail.com
push dateSat, 01 Dec 2012 15:27:30 +0000
treeherdermozilla-central@ecdf0e332f17 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs816859
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816859 - Patch 1: Failed to receive a file, r=echou
dom/bluetooth/BluetoothOppManager.cpp
--- a/dom/bluetooth/BluetoothOppManager.cpp
+++ b/dom/bluetooth/BluetoothOppManager.cpp
@@ -328,16 +328,17 @@ BluetoothOppManager::SendFile(BlobParent
       if (NS_SUCCEEDED(rv)) {
         sFileName.AppendLiteral(".");
         AppendUTF8toUTF16(extension, sFileName);
       }
     }
   }
 
   SendConnectRequest();
+  mTransferMode = false;
 
   return true;
 }
 
 bool
 BluetoothOppManager::StopSendingFile()
 {
   mAbortFlag = true;
@@ -374,28 +375,33 @@ BluetoothOppManager::AfterOppConnected()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   mConnected = true;
   mUpdateProgressCounter = 1;
   sSentFileLength = 0;
   mReceivedDataBufferOffset = 0;
   mAbortFlag = false;
+  mSuccessFlag = false;
   mWaitingForConfirmationFlag = true;
 }
 
 void
 BluetoothOppManager::AfterOppDisconnected()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   mConnected = false;
   mLastCommand = 0;
   mBlob = nullptr;
 
+  // We can't reset mSuccessFlag here since this function may be called
+  // before we send system message of transfer complete
+  // mSuccessFlag = false;
+
   if (mInputStream) {
     mInputStream->Close();
     mInputStream = nullptr;
   }
 
   if (mOutputStream) {
     mOutputStream->Close();
     mOutputStream = nullptr;
@@ -603,29 +609,28 @@ BluetoothOppManager::ReceiveSocketData(U
     SendDisconnectRequest();
   } else if (mLastCommand == ObexRequestCode::Abort) {
     if (opCode != ObexResponseCode::Success) {
       NS_WARNING("[OPP] Abort failed");
     }
     SendDisconnectRequest();
   } else {
     // Remote request or unknown mLastCommand
-    mTransferMode = true;
-    mSuccessFlag = false;
     ObexHeaderSet pktHeaders(opCode);
 
     if (opCode == ObexRequestCode::Connect) {
       // Section 3.3.1 "Connect", IrOBEX 1.2
       // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
       // [Headers:var]
       ParseHeaders(&aMessage->mData[7],
                    receivedLength - 7,
                    &pktHeaders);
       ReplyToConnect();
       AfterOppConnected();
+      mTransferMode = true;
     } else if (opCode == ObexRequestCode::Disconnect) {
       // Section 3.3.2 "Disconnect", IrOBEX 1.2
       // [opcode:1][length:2][Headers:var]
       ParseHeaders(&aMessage->mData[3],
                   receivedLength - 3,
                   &pktHeaders);
       ReplyToDisconnect();
       AfterOppDisconnected();
@@ -734,18 +739,16 @@ BluetoothOppManager::SendConnectRequest(
   req[3] = 0x10; // version=1.0
   req[4] = 0x00; // flag=0x00
   req[5] = BluetoothOppManager::MAX_PACKET_LENGTH >> 8;
   req[6] = (uint8_t)BluetoothOppManager::MAX_PACKET_LENGTH;
 
   index += AppendHeaderConnectionId(&req[index], mConnectionId);
   SetObexPacketInfo(req, ObexRequestCode::Connect, index);
   mLastCommand = ObexRequestCode::Connect;
-  mTransferMode = false;
-  mSuccessFlag = false;
 
   UnixSocketRawData* s = new UnixSocketRawData(index);
   memcpy(s->mData, req, s->mSize);
   SendSocketData(s);
 }
 
 void
 BluetoothOppManager::SendPutHeaderRequest(const nsAString& aFileName,
@@ -1104,9 +1107,10 @@ BluetoothOppManager::OnDisconnect()
     NS_WARNING("BluetoothOppManager got unexpected socket status!");
   }
 
   // It is valid for a bluetooth device which is transfering file via OPP
   // closing socket without sending OBEX disconnect request first. So we
   // call AfterOppDisconnected here to ensure all variables will be cleaned.
   AfterOppDisconnected();
   mConnectedDeviceAddress.AssignLiteral("00:00:00:00:00:00");
+  mSuccessFlag = false;
 }