From 3fcb4bc5005b61c3b1de9d2e05feadfd192755f7 Mon Sep 17 00:00:00 2001 From: Ben Tian Date: Thu, 8 Jan 2015 18:11:37 +0800 Subject: [PATCH] Bug 1118163 - Restore received file for small size (1-packet) file, r=shuang --- .../bluedroid/BluetoothOppManager.cpp | 36 +++++++++---------- dom/bluetooth/bluedroid/BluetoothOppManager.h | 3 +- dom/bluetooth/bluez/BluetoothOppManager.cpp | 36 +++++++++---------- dom/bluetooth/bluez/BluetoothOppManager.h | 3 +- .../bluedroid/BluetoothOppManager.cpp | 36 +++++++++---------- .../bluedroid/BluetoothOppManager.h | 3 +- dom/bluetooth2/bluez/BluetoothOppManager.cpp | 36 +++++++++---------- dom/bluetooth2/bluez/BluetoothOppManager.h | 3 +- 8 files changed, 76 insertions(+), 80 deletions(-) diff --git a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp index 0a4d8fbc54b..31966028636 100644 --- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp @@ -481,8 +481,8 @@ BluetoothOppManager::ConfirmReceivingFile(bool aConfirm) if (success && mPutFinalFlag) { mSuccessFlag = true; + RestoreReceivedFileAndNotify(); FileTransferComplete(); - NotifyAboutFileChange(); } ReplyToPut(mPutFinalFlag, success); @@ -551,7 +551,8 @@ BluetoothOppManager::AfterOppDisconnected() 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; @@ -559,8 +560,14 @@ BluetoothOppManager::AfterOppDisconnected() } 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. @@ -574,16 +581,9 @@ BluetoothOppManager::RecoverFileName() 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 @@ -599,7 +599,11 @@ BluetoothOppManager::DeleteReceivedFile() mDsFile = nullptr; } - DeleteDummyFile(); + // Remove the empty dummy file + if (mDummyDsFile && mDummyDsFile->mFile) { + mDummyDsFile->mFile->Remove(false); + mDummyDsFile = nullptr; + } } bool @@ -956,12 +960,8 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) // 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 || diff --git a/dom/bluetooth/bluedroid/BluetoothOppManager.h b/dom/bluetooth/bluedroid/BluetoothOppManager.h index c751a17af5c..e26fb759cd9 100644 --- a/dom/bluetooth/bluedroid/BluetoothOppManager.h +++ b/dom/bluetooth/bluedroid/BluetoothOppManager.h @@ -85,8 +85,7 @@ private: void ReceivingFileConfirmation(); bool CreateFile(); bool WriteToFile(const uint8_t* aData, int aDataLength); - void RecoverFileName(); - void DeleteDummyFile(); + void RestoreReceivedFileAndNotify(); void DeleteReceivedFile(); void ReplyToConnect(); void ReplyToDisconnectOrAbort(); diff --git a/dom/bluetooth/bluez/BluetoothOppManager.cpp b/dom/bluetooth/bluez/BluetoothOppManager.cpp index 904d6c70442..8586ad92ec4 100644 --- a/dom/bluetooth/bluez/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluez/BluetoothOppManager.cpp @@ -503,8 +503,8 @@ BluetoothOppManager::ConfirmReceivingFile(bool aConfirm) if (success && mPutFinalFlag) { mSuccessFlag = true; + RestoreReceivedFileAndNotify(); FileTransferComplete(); - NotifyAboutFileChange(); } ReplyToPut(mPutFinalFlag, success); @@ -573,7 +573,8 @@ BluetoothOppManager::AfterOppDisconnected() 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; @@ -581,8 +582,14 @@ BluetoothOppManager::AfterOppDisconnected() } 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. @@ -596,16 +603,9 @@ BluetoothOppManager::RecoverFileName() 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 @@ -621,7 +621,11 @@ BluetoothOppManager::DeleteReceivedFile() mDsFile = nullptr; } - DeleteDummyFile(); + // Remove the empty dummy file + if (mDummyDsFile && mDummyDsFile->mFile) { + mDummyDsFile->mFile->Remove(false); + mDummyDsFile = nullptr; + } } bool @@ -977,12 +981,8 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) // 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 || diff --git a/dom/bluetooth/bluez/BluetoothOppManager.h b/dom/bluetooth/bluez/BluetoothOppManager.h index 6d21d144eca..8b0a29cf2ba 100644 --- a/dom/bluetooth/bluez/BluetoothOppManager.h +++ b/dom/bluetooth/bluez/BluetoothOppManager.h @@ -85,8 +85,7 @@ private: void ReceivingFileConfirmation(); bool CreateFile(); bool WriteToFile(const uint8_t* aData, int aDataLength); - void RecoverFileName(); - void DeleteDummyFile(); + void RestoreReceivedFileAndNotify(); void DeleteReceivedFile(); void ReplyToConnect(); void ReplyToDisconnectOrAbort(); diff --git a/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp b/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp index 0a4d8fbc54b..31966028636 100644 --- a/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp @@ -481,8 +481,8 @@ BluetoothOppManager::ConfirmReceivingFile(bool aConfirm) if (success && mPutFinalFlag) { mSuccessFlag = true; + RestoreReceivedFileAndNotify(); FileTransferComplete(); - NotifyAboutFileChange(); } ReplyToPut(mPutFinalFlag, success); @@ -551,7 +551,8 @@ BluetoothOppManager::AfterOppDisconnected() 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; @@ -559,8 +560,14 @@ BluetoothOppManager::AfterOppDisconnected() } 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. @@ -574,16 +581,9 @@ BluetoothOppManager::RecoverFileName() 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 @@ -599,7 +599,11 @@ BluetoothOppManager::DeleteReceivedFile() mDsFile = nullptr; } - DeleteDummyFile(); + // Remove the empty dummy file + if (mDummyDsFile && mDummyDsFile->mFile) { + mDummyDsFile->mFile->Remove(false); + mDummyDsFile = nullptr; + } } bool @@ -956,12 +960,8 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) // 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 || diff --git a/dom/bluetooth2/bluedroid/BluetoothOppManager.h b/dom/bluetooth2/bluedroid/BluetoothOppManager.h index c751a17af5c..e26fb759cd9 100644 --- a/dom/bluetooth2/bluedroid/BluetoothOppManager.h +++ b/dom/bluetooth2/bluedroid/BluetoothOppManager.h @@ -85,8 +85,7 @@ private: void ReceivingFileConfirmation(); bool CreateFile(); bool WriteToFile(const uint8_t* aData, int aDataLength); - void RecoverFileName(); - void DeleteDummyFile(); + void RestoreReceivedFileAndNotify(); void DeleteReceivedFile(); void ReplyToConnect(); void ReplyToDisconnectOrAbort(); diff --git a/dom/bluetooth2/bluez/BluetoothOppManager.cpp b/dom/bluetooth2/bluez/BluetoothOppManager.cpp index 8b42d5c02b5..628f1707bc6 100644 --- a/dom/bluetooth2/bluez/BluetoothOppManager.cpp +++ b/dom/bluetooth2/bluez/BluetoothOppManager.cpp @@ -503,8 +503,8 @@ BluetoothOppManager::ConfirmReceivingFile(bool aConfirm) if (success && mPutFinalFlag) { mSuccessFlag = true; + RestoreReceivedFileAndNotify(); FileTransferComplete(); - NotifyAboutFileChange(); } ReplyToPut(mPutFinalFlag, success); @@ -573,7 +573,8 @@ BluetoothOppManager::AfterOppDisconnected() 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; @@ -581,8 +582,14 @@ BluetoothOppManager::AfterOppDisconnected() } 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. @@ -596,16 +603,9 @@ BluetoothOppManager::RecoverFileName() 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 @@ -621,7 +621,11 @@ BluetoothOppManager::DeleteReceivedFile() mDsFile = nullptr; } - DeleteDummyFile(); + // Remove the empty dummy file + if (mDummyDsFile && mDummyDsFile->mFile) { + mDummyDsFile->mFile->Remove(false); + mDummyDsFile = nullptr; + } } bool @@ -977,12 +981,8 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) // 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 || diff --git a/dom/bluetooth2/bluez/BluetoothOppManager.h b/dom/bluetooth2/bluez/BluetoothOppManager.h index 6d21d144eca..8b0a29cf2ba 100644 --- a/dom/bluetooth2/bluez/BluetoothOppManager.h +++ b/dom/bluetooth2/bluez/BluetoothOppManager.h @@ -85,8 +85,7 @@ private: void ReceivingFileConfirmation(); bool CreateFile(); bool WriteToFile(const uint8_t* aData, int aDataLength); - void RecoverFileName(); - void DeleteDummyFile(); + void RestoreReceivedFileAndNotify(); void DeleteReceivedFile(); void ReplyToConnect(); void ReplyToDisconnectOrAbort();