Bug 1118163 - Restore received file for small size (1-packet) file, r=shuang
authorBen Tian <btian@mozilla.com>
Thu, 08 Jan 2015 18:11:37 +0800
changeset 222914 ccd36ead0046a565ce24326940c1a5dc99d9b89c
parent 222913 742cb34c9ba818c7808a4ea603a79c408c66e244
child 222915 0c39bc01f6345d0a1b686c787271737fad499e3e
push id10731
push usercbook@mozilla.com
push dateFri, 09 Jan 2015 14:51:37 +0000
treeherderfx-team@e6756043d930 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1118163
milestone37.0a1
Bug 1118163 - Restore received file for small size (1-packet) file, r=shuang
dom/bluetooth/bluedroid/BluetoothOppManager.cpp
dom/bluetooth/bluedroid/BluetoothOppManager.h
dom/bluetooth/bluez/BluetoothOppManager.cpp
dom/bluetooth/bluez/BluetoothOppManager.h
dom/bluetooth2/bluedroid/BluetoothOppManager.cpp
dom/bluetooth2/bluedroid/BluetoothOppManager.h
dom/bluetooth2/bluez/BluetoothOppManager.cpp
dom/bluetooth2/bluez/BluetoothOppManager.h
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
@@ -476,18 +476,18 @@ BluetoothOppManager::ConfirmReceivingFil
     StartFileTransfer();
     if (CreateFile()) {
       success = WriteToFile(mBodySegment.get(), mBodySegmentLength);
     }
   }
 
   if (success && mPutFinalFlag) {
     mSuccessFlag = true;
+    RestoreReceivedFileAndNotify();
     FileTransferComplete();
-    NotifyAboutFileChange();
   }
 
   ReplyToPut(mPutFinalFlag, success);
 
   return true;
 }
 
 void
@@ -546,65 +546,69 @@ BluetoothOppManager::AfterOppDisconnecte
     mOutputStream->Close();
     mOutputStream = nullptr;
   }
 
   if (mReadFileThread) {
     mReadFileThread->Shutdown();
     mReadFileThread = nullptr;
   }
-  // Release the Mount lock if file transfer completed
+
+  // Release the mount lock if file transfer completed
   if (mMountLock) {
     // The mount lock will be implicitly unlocked
     mMountLock = nullptr;
   }
 }
 
 void
-BluetoothOppManager::RecoverFileName()
+BluetoothOppManager::RestoreReceivedFileAndNotify()
 {
+  // Remove the empty dummy file
+  if (mDummyDsFile && mDummyDsFile->mFile) {
+    mDummyDsFile->mFile->Remove(false);
+    mDummyDsFile = nullptr;
+  }
+
   // Remove the trailing ".part" file name from mDsFile by two steps
   // 1. mDsFile->SetPath() so that the notification sent to Gaia will carry
   //    correct information of the file.
   // 2. mDsFile->mFile->RenameTo() so that the file name would actually be
   //    changed in file system.
   if (mDsFile && mDsFile->mFile) {
     nsString path;
     path.AssignLiteral(TARGET_SUBDIR);
     path.Append(mFileName);
 
     mDsFile->SetPath(path);
     mDsFile->mFile->RenameTo(nullptr, mFileName);
   }
-}
 
-void
-BluetoothOppManager::DeleteDummyFile()
-{
-  // Remove the empty temp file
-  if (mDummyDsFile && mDummyDsFile->mFile) {
-    mDummyDsFile->mFile->Remove(false);
-    mDummyDsFile = nullptr;
-  }
+  // Notify about change of received file
+  NotifyAboutFileChange();
 }
 
 void
 BluetoothOppManager::DeleteReceivedFile()
 {
   if (mOutputStream) {
     mOutputStream->Close();
     mOutputStream = nullptr;
   }
 
   if (mDsFile && mDsFile->mFile) {
     mDsFile->mFile->Remove(false);
     mDsFile = nullptr;
   }
 
-  DeleteDummyFile();
+  // Remove the empty dummy file
+  if (mDummyDsFile && mDummyDsFile->mFile) {
+    mDummyDsFile->mFile->Remove(false);
+    mDummyDsFile = nullptr;
+  }
 }
 
 bool
 BluetoothOppManager::CreateFile()
 {
   MOZ_ASSERT(mPutPacketReceivedLength == mPacketLength);
 
   // Create one dummy file to be a placeholder for the target file name, and
@@ -951,22 +955,18 @@ BluetoothOppManager::ServerDataHandler(U
     if (mSentFileLength > kUpdateProgressBase * mUpdateProgressCounter) {
       UpdateProgress();
       mUpdateProgressCounter = mSentFileLength / kUpdateProgressBase + 1;
     }
 
     // Success to receive a file and notify completion
     if (mPutFinalFlag) {
       mSuccessFlag = true;
-
-      DeleteDummyFile();
-      RecoverFileName();
-
+      RestoreReceivedFileAndNotify();
       FileTransferComplete();
-      NotifyAboutFileChange();
     }
   } else if (opCode == ObexRequestCode::Get ||
              opCode == ObexRequestCode::GetFinal ||
              opCode == ObexRequestCode::SetPath) {
     ReplyError(ObexResponseCode::BadRequest);
     BT_WARNING("Unsupported ObexRequestCode");
   } else {
     ReplyError(ObexResponseCode::NotImplemented);
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.h
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.h
@@ -80,18 +80,17 @@ private:
 
   void StartFileTransfer();
   void StartSendingNextFile();
   void FileTransferComplete();
   void UpdateProgress();
   void ReceivingFileConfirmation();
   bool CreateFile();
   bool WriteToFile(const uint8_t* aData, int aDataLength);
-  void RecoverFileName();
-  void DeleteDummyFile();
+  void RestoreReceivedFileAndNotify();
   void DeleteReceivedFile();
   void ReplyToConnect();
   void ReplyToDisconnectOrAbort();
   void ReplyToPut(bool aFinal, bool aContinue);
   void ReplyError(uint8_t aError);
   void AfterOppConnected();
   void AfterFirstPut();
   void AfterOppDisconnected();
--- a/dom/bluetooth/bluez/BluetoothOppManager.cpp
+++ b/dom/bluetooth/bluez/BluetoothOppManager.cpp
@@ -498,18 +498,18 @@ BluetoothOppManager::ConfirmReceivingFil
     StartFileTransfer();
     if (CreateFile()) {
       success = WriteToFile(mBodySegment.get(), mBodySegmentLength);
     }
   }
 
   if (success && mPutFinalFlag) {
     mSuccessFlag = true;
+    RestoreReceivedFileAndNotify();
     FileTransferComplete();
-    NotifyAboutFileChange();
   }
 
   ReplyToPut(mPutFinalFlag, success);
 
   return true;
 }
 
 void
@@ -568,65 +568,69 @@ BluetoothOppManager::AfterOppDisconnecte
     mOutputStream->Close();
     mOutputStream = nullptr;
   }
 
   if (mReadFileThread) {
     mReadFileThread->Shutdown();
     mReadFileThread = nullptr;
   }
-  // Release the Mount lock if file transfer completed
+
+  // Release the mount lock if file transfer completed
   if (mMountLock) {
     // The mount lock will be implicitly unlocked
     mMountLock = nullptr;
   }
 }
 
 void
-BluetoothOppManager::RecoverFileName()
+BluetoothOppManager::RestoreReceivedFileAndNotify()
 {
+  // Remove the empty dummy file
+  if (mDummyDsFile && mDummyDsFile->mFile) {
+    mDummyDsFile->mFile->Remove(false);
+    mDummyDsFile = nullptr;
+  }
+
   // Remove the trailing ".part" file name from mDsFile by two steps
   // 1. mDsFile->SetPath() so that the notification sent to Gaia will carry
   //    correct information of the file.
   // 2. mDsFile->mFile->RenameTo() so that the file name would actually be
   //    changed in file system.
   if (mDsFile && mDsFile->mFile) {
     nsString path;
     path.AssignLiteral(TARGET_SUBDIR);
     path.Append(mFileName);
 
     mDsFile->SetPath(path);
     mDsFile->mFile->RenameTo(nullptr, mFileName);
   }
-}
 
-void
-BluetoothOppManager::DeleteDummyFile()
-{
-  // Remove the empty temp file
-  if (mDummyDsFile && mDummyDsFile->mFile) {
-    mDummyDsFile->mFile->Remove(false);
-    mDummyDsFile = nullptr;
-  }
+  // Notify about change of received file
+  NotifyAboutFileChange();
 }
 
 void
 BluetoothOppManager::DeleteReceivedFile()
 {
   if (mOutputStream) {
     mOutputStream->Close();
     mOutputStream = nullptr;
   }
 
   if (mDsFile && mDsFile->mFile) {
     mDsFile->mFile->Remove(false);
     mDsFile = nullptr;
   }
 
-  DeleteDummyFile();
+  // Remove the empty dummy file
+  if (mDummyDsFile && mDummyDsFile->mFile) {
+    mDummyDsFile->mFile->Remove(false);
+    mDummyDsFile = nullptr;
+  }
 }
 
 bool
 BluetoothOppManager::CreateFile()
 {
   MOZ_ASSERT(mPutPacketReceivedLength == mPacketLength);
 
   // Create one dummy file to be a placeholder for the target file name, and
@@ -972,22 +976,18 @@ BluetoothOppManager::ServerDataHandler(U
     if (mSentFileLength > kUpdateProgressBase * mUpdateProgressCounter) {
       UpdateProgress();
       mUpdateProgressCounter = mSentFileLength / kUpdateProgressBase + 1;
     }
 
     // Success to receive a file and notify completion
     if (mPutFinalFlag) {
       mSuccessFlag = true;
-
-      DeleteDummyFile();
-      RecoverFileName();
-
+      RestoreReceivedFileAndNotify();
       FileTransferComplete();
-      NotifyAboutFileChange();
     }
   } else if (opCode == ObexRequestCode::Get ||
              opCode == ObexRequestCode::GetFinal ||
              opCode == ObexRequestCode::SetPath) {
     ReplyError(ObexResponseCode::BadRequest);
     BT_WARNING("Unsupported ObexRequestCode");
   } else {
     ReplyError(ObexResponseCode::NotImplemented);
--- a/dom/bluetooth/bluez/BluetoothOppManager.h
+++ b/dom/bluetooth/bluez/BluetoothOppManager.h
@@ -80,18 +80,17 @@ private:
 
   void StartFileTransfer();
   void StartSendingNextFile();
   void FileTransferComplete();
   void UpdateProgress();
   void ReceivingFileConfirmation();
   bool CreateFile();
   bool WriteToFile(const uint8_t* aData, int aDataLength);
-  void RecoverFileName();
-  void DeleteDummyFile();
+  void RestoreReceivedFileAndNotify();
   void DeleteReceivedFile();
   void ReplyToConnect();
   void ReplyToDisconnectOrAbort();
   void ReplyToPut(bool aFinal, bool aContinue);
   void ReplyError(uint8_t aError);
   void AfterOppConnected();
   void AfterFirstPut();
   void AfterOppDisconnected();
--- a/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp
+++ b/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp
@@ -476,18 +476,18 @@ BluetoothOppManager::ConfirmReceivingFil
     StartFileTransfer();
     if (CreateFile()) {
       success = WriteToFile(mBodySegment.get(), mBodySegmentLength);
     }
   }
 
   if (success && mPutFinalFlag) {
     mSuccessFlag = true;
+    RestoreReceivedFileAndNotify();
     FileTransferComplete();
-    NotifyAboutFileChange();
   }
 
   ReplyToPut(mPutFinalFlag, success);
 
   return true;
 }
 
 void
@@ -546,65 +546,69 @@ BluetoothOppManager::AfterOppDisconnecte
     mOutputStream->Close();
     mOutputStream = nullptr;
   }
 
   if (mReadFileThread) {
     mReadFileThread->Shutdown();
     mReadFileThread = nullptr;
   }
-  // Release the Mount lock if file transfer completed
+
+  // Release the mount lock if file transfer completed
   if (mMountLock) {
     // The mount lock will be implicitly unlocked
     mMountLock = nullptr;
   }
 }
 
 void
-BluetoothOppManager::RecoverFileName()
+BluetoothOppManager::RestoreReceivedFileAndNotify()
 {
+  // Remove the empty dummy file
+  if (mDummyDsFile && mDummyDsFile->mFile) {
+    mDummyDsFile->mFile->Remove(false);
+    mDummyDsFile = nullptr;
+  }
+
   // Remove the trailing ".part" file name from mDsFile by two steps
   // 1. mDsFile->SetPath() so that the notification sent to Gaia will carry
   //    correct information of the file.
   // 2. mDsFile->mFile->RenameTo() so that the file name would actually be
   //    changed in file system.
   if (mDsFile && mDsFile->mFile) {
     nsString path;
     path.AssignLiteral(TARGET_SUBDIR);
     path.Append(mFileName);
 
     mDsFile->SetPath(path);
     mDsFile->mFile->RenameTo(nullptr, mFileName);
   }
-}
 
-void
-BluetoothOppManager::DeleteDummyFile()
-{
-  // Remove the empty temp file
-  if (mDummyDsFile && mDummyDsFile->mFile) {
-    mDummyDsFile->mFile->Remove(false);
-    mDummyDsFile = nullptr;
-  }
+  // Notify about change of received file
+  NotifyAboutFileChange();
 }
 
 void
 BluetoothOppManager::DeleteReceivedFile()
 {
   if (mOutputStream) {
     mOutputStream->Close();
     mOutputStream = nullptr;
   }
 
   if (mDsFile && mDsFile->mFile) {
     mDsFile->mFile->Remove(false);
     mDsFile = nullptr;
   }
 
-  DeleteDummyFile();
+  // Remove the empty dummy file
+  if (mDummyDsFile && mDummyDsFile->mFile) {
+    mDummyDsFile->mFile->Remove(false);
+    mDummyDsFile = nullptr;
+  }
 }
 
 bool
 BluetoothOppManager::CreateFile()
 {
   MOZ_ASSERT(mPutPacketReceivedLength == mPacketLength);
 
   // Create one dummy file to be a placeholder for the target file name, and
@@ -951,22 +955,18 @@ BluetoothOppManager::ServerDataHandler(U
     if (mSentFileLength > kUpdateProgressBase * mUpdateProgressCounter) {
       UpdateProgress();
       mUpdateProgressCounter = mSentFileLength / kUpdateProgressBase + 1;
     }
 
     // Success to receive a file and notify completion
     if (mPutFinalFlag) {
       mSuccessFlag = true;
-
-      DeleteDummyFile();
-      RecoverFileName();
-
+      RestoreReceivedFileAndNotify();
       FileTransferComplete();
-      NotifyAboutFileChange();
     }
   } else if (opCode == ObexRequestCode::Get ||
              opCode == ObexRequestCode::GetFinal ||
              opCode == ObexRequestCode::SetPath) {
     ReplyError(ObexResponseCode::BadRequest);
     BT_WARNING("Unsupported ObexRequestCode");
   } else {
     ReplyError(ObexResponseCode::NotImplemented);
--- a/dom/bluetooth2/bluedroid/BluetoothOppManager.h
+++ b/dom/bluetooth2/bluedroid/BluetoothOppManager.h
@@ -80,18 +80,17 @@ private:
 
   void StartFileTransfer();
   void StartSendingNextFile();
   void FileTransferComplete();
   void UpdateProgress();
   void ReceivingFileConfirmation();
   bool CreateFile();
   bool WriteToFile(const uint8_t* aData, int aDataLength);
-  void RecoverFileName();
-  void DeleteDummyFile();
+  void RestoreReceivedFileAndNotify();
   void DeleteReceivedFile();
   void ReplyToConnect();
   void ReplyToDisconnectOrAbort();
   void ReplyToPut(bool aFinal, bool aContinue);
   void ReplyError(uint8_t aError);
   void AfterOppConnected();
   void AfterFirstPut();
   void AfterOppDisconnected();
--- a/dom/bluetooth2/bluez/BluetoothOppManager.cpp
+++ b/dom/bluetooth2/bluez/BluetoothOppManager.cpp
@@ -498,18 +498,18 @@ BluetoothOppManager::ConfirmReceivingFil
     StartFileTransfer();
     if (CreateFile()) {
       success = WriteToFile(mBodySegment.get(), mBodySegmentLength);
     }
   }
 
   if (success && mPutFinalFlag) {
     mSuccessFlag = true;
+    RestoreReceivedFileAndNotify();
     FileTransferComplete();
-    NotifyAboutFileChange();
   }
 
   ReplyToPut(mPutFinalFlag, success);
 
   return true;
 }
 
 void
@@ -568,65 +568,69 @@ BluetoothOppManager::AfterOppDisconnecte
     mOutputStream->Close();
     mOutputStream = nullptr;
   }
 
   if (mReadFileThread) {
     mReadFileThread->Shutdown();
     mReadFileThread = nullptr;
   }
-  // Release the Mount lock if file transfer completed
+
+  // Release the mount lock if file transfer completed
   if (mMountLock) {
     // The mount lock will be implicitly unlocked
     mMountLock = nullptr;
   }
 }
 
 void
-BluetoothOppManager::RecoverFileName()
+BluetoothOppManager::RestoreReceivedFileAndNotify()
 {
+  // Remove the empty dummy file
+  if (mDummyDsFile && mDummyDsFile->mFile) {
+    mDummyDsFile->mFile->Remove(false);
+    mDummyDsFile = nullptr;
+  }
+
   // Remove the trailing ".part" file name from mDsFile by two steps
   // 1. mDsFile->SetPath() so that the notification sent to Gaia will carry
   //    correct information of the file.
   // 2. mDsFile->mFile->RenameTo() so that the file name would actually be
   //    changed in file system.
   if (mDsFile && mDsFile->mFile) {
     nsString path;
     path.AssignLiteral(TARGET_SUBDIR);
     path.Append(mFileName);
 
     mDsFile->SetPath(path);
     mDsFile->mFile->RenameTo(nullptr, mFileName);
   }
-}
 
-void
-BluetoothOppManager::DeleteDummyFile()
-{
-  // Remove the empty temp file
-  if (mDummyDsFile && mDummyDsFile->mFile) {
-    mDummyDsFile->mFile->Remove(false);
-    mDummyDsFile = nullptr;
-  }
+  // Notify about change of received file
+  NotifyAboutFileChange();
 }
 
 void
 BluetoothOppManager::DeleteReceivedFile()
 {
   if (mOutputStream) {
     mOutputStream->Close();
     mOutputStream = nullptr;
   }
 
   if (mDsFile && mDsFile->mFile) {
     mDsFile->mFile->Remove(false);
     mDsFile = nullptr;
   }
 
-  DeleteDummyFile();
+  // Remove the empty dummy file
+  if (mDummyDsFile && mDummyDsFile->mFile) {
+    mDummyDsFile->mFile->Remove(false);
+    mDummyDsFile = nullptr;
+  }
 }
 
 bool
 BluetoothOppManager::CreateFile()
 {
   MOZ_ASSERT(mPutPacketReceivedLength == mPacketLength);
 
   // Create one dummy file to be a placeholder for the target file name, and
@@ -972,22 +976,18 @@ BluetoothOppManager::ServerDataHandler(U
     if (mSentFileLength > kUpdateProgressBase * mUpdateProgressCounter) {
       UpdateProgress();
       mUpdateProgressCounter = mSentFileLength / kUpdateProgressBase + 1;
     }
 
     // Success to receive a file and notify completion
     if (mPutFinalFlag) {
       mSuccessFlag = true;
-
-      DeleteDummyFile();
-      RecoverFileName();
-
+      RestoreReceivedFileAndNotify();
       FileTransferComplete();
-      NotifyAboutFileChange();
     }
   } else if (opCode == ObexRequestCode::Get ||
              opCode == ObexRequestCode::GetFinal ||
              opCode == ObexRequestCode::SetPath) {
     ReplyError(ObexResponseCode::BadRequest);
     BT_WARNING("Unsupported ObexRequestCode");
   } else {
     ReplyError(ObexResponseCode::NotImplemented);
--- a/dom/bluetooth2/bluez/BluetoothOppManager.h
+++ b/dom/bluetooth2/bluez/BluetoothOppManager.h
@@ -80,18 +80,17 @@ private:
 
   void StartFileTransfer();
   void StartSendingNextFile();
   void FileTransferComplete();
   void UpdateProgress();
   void ReceivingFileConfirmation();
   bool CreateFile();
   bool WriteToFile(const uint8_t* aData, int aDataLength);
-  void RecoverFileName();
-  void DeleteDummyFile();
+  void RestoreReceivedFileAndNotify();
   void DeleteReceivedFile();
   void ReplyToConnect();
   void ReplyToDisconnectOrAbort();
   void ReplyToPut(bool aFinal, bool aContinue);
   void ReplyError(uint8_t aError);
   void AfterOppConnected();
   void AfterFirstPut();
   void AfterOppDisconnected();