mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 864575 - Notify all observers of file-changing at the right time, r=gyeh
When we receive multiple files in a row, we need to notify observers of file-changing whenever a file is completely received. Currently we only send one notification at the end of the entire session.
This commit is contained in:
parent
084a1b39cc
commit
e3926e8f4d
@ -376,7 +376,7 @@ BluetoothOppManager::StartSendingNextFile()
|
||||
AfterFirstPut();
|
||||
}
|
||||
|
||||
mTransferMode = false;
|
||||
mIsServer = false;
|
||||
}
|
||||
|
||||
bool
|
||||
@ -510,6 +510,38 @@ BluetoothOppManager::DeleteReceivedFile()
|
||||
f->Remove(false);
|
||||
}
|
||||
|
||||
DeviceStorageFile*
|
||||
BluetoothOppManager::CreateDeviceStorageFile(nsIFile* aFile)
|
||||
{
|
||||
nsString fullFilePath;
|
||||
aFile->GetPath(fullFilePath);
|
||||
|
||||
MOZ_ASSERT(StringBeginsWith(fullFilePath, NS_LITERAL_STRING(TARGET_ROOT)));
|
||||
|
||||
nsDependentSubstring storagePath =
|
||||
Substring(fullFilePath, strlen(TARGET_ROOT));
|
||||
|
||||
nsCOMPtr<nsIMIMEService> mimeSvc = do_GetService(NS_MIMESERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(mimeSvc, nullptr);
|
||||
|
||||
nsCString mimeType;
|
||||
nsresult rv = mimeSvc->GetTypeFromFile(aFile, mimeType);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (StringBeginsWith(mimeType, NS_LITERAL_CSTRING("image/"))) {
|
||||
return new DeviceStorageFile(NS_LITERAL_STRING("pictures"), storagePath);
|
||||
} else if (StringBeginsWith(mimeType, NS_LITERAL_CSTRING("video/"))) {
|
||||
return new DeviceStorageFile(NS_LITERAL_STRING("movies"), storagePath);
|
||||
} else if (StringBeginsWith(mimeType, NS_LITERAL_CSTRING("audio/"))) {
|
||||
return new DeviceStorageFile(NS_LITERAL_STRING("music"), storagePath);
|
||||
} else {
|
||||
NS_WARNING("Couldn't recognize the mimetype of received file.");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothOppManager::CreateFile()
|
||||
{
|
||||
@ -539,36 +571,10 @@ BluetoothOppManager::CreateFile()
|
||||
*/
|
||||
f->GetLeafName(sFileName);
|
||||
|
||||
nsString fullFileName;
|
||||
f->GetPath(fullFileName);
|
||||
MOZ_ASSERT(StringBeginsWith(fullFileName, NS_LITERAL_STRING(TARGET_ROOT)));
|
||||
nsDependentSubstring storagePath = Substring(fullFileName, strlen(TARGET_ROOT));
|
||||
|
||||
mDsFile = nullptr;
|
||||
|
||||
nsCOMPtr<nsIMIMEService> mimeSvc = do_GetService(NS_MIMESERVICE_CONTRACTID);
|
||||
if (mimeSvc) {
|
||||
nsCString mimeType;
|
||||
nsresult rv = mimeSvc->GetTypeFromFile(f, mimeType);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (StringBeginsWith(mimeType, NS_LITERAL_CSTRING("image/"))) {
|
||||
mDsFile = new DeviceStorageFile(NS_LITERAL_STRING("pictures"), storagePath);
|
||||
} else if (StringBeginsWith(mimeType, NS_LITERAL_CSTRING("video/"))) {
|
||||
mDsFile = new DeviceStorageFile(NS_LITERAL_STRING("movies"), storagePath);
|
||||
} else if (StringBeginsWith(mimeType, NS_LITERAL_CSTRING("audio/"))) {
|
||||
mDsFile = new DeviceStorageFile(NS_LITERAL_STRING("music"), storagePath);
|
||||
} else {
|
||||
NS_WARNING("Couldn't recognize the mimetype of received file.");
|
||||
}
|
||||
}
|
||||
}
|
||||
mDsFile = CreateDeviceStorageFile(f);
|
||||
|
||||
NS_NewLocalFileOutputStream(getter_AddRefs(mOutputStream), f);
|
||||
if (!mOutputStream) {
|
||||
NS_WARNING("Couldn't new an output stream");
|
||||
return false;
|
||||
}
|
||||
NS_ENSURE_TRUE(mOutputStream, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -755,7 +761,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
|
||||
&pktHeaders);
|
||||
ReplyToConnect();
|
||||
AfterOppConnected();
|
||||
mTransferMode = true;
|
||||
mIsServer = true;
|
||||
} else if (opCode == ObexRequestCode::Disconnect ||
|
||||
opCode == ObexRequestCode::Abort) {
|
||||
// Section 3.3.2 "Disconnect", IrOBEX 1.2
|
||||
@ -857,6 +863,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
|
||||
if (mPutFinalFlag) {
|
||||
mSuccessFlag = true;
|
||||
FileTransferComplete();
|
||||
NotifyAboutFileChange();
|
||||
}
|
||||
} else {
|
||||
NS_WARNING("Unhandled ObexRequestCode");
|
||||
@ -1250,7 +1257,7 @@ BluetoothOppManager::FileTransferComplete()
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("received");
|
||||
v = mTransferMode;
|
||||
v = mIsServer;
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("fileName");
|
||||
@ -1286,7 +1293,7 @@ BluetoothOppManager::StartFileTransfer()
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("received");
|
||||
v = mTransferMode;
|
||||
v = mIsServer;
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("fileName");
|
||||
@ -1320,7 +1327,7 @@ BluetoothOppManager::UpdateProgress()
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("received");
|
||||
v = mTransferMode;
|
||||
v = mIsServer;
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("processedLength");
|
||||
@ -1367,6 +1374,18 @@ BluetoothOppManager::ReceivingFileConfirmation()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::NotifyAboutFileChange()
|
||||
{
|
||||
NS_NAMED_LITERAL_STRING(data, "modified");
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs =
|
||||
mozilla::services::GetObserverService();
|
||||
NS_ENSURE_TRUE_VOID(obs);
|
||||
|
||||
obs->NotifyObservers(mDsFile, "file-watcher-notify", data.get());
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::OnConnectSuccess(BluetoothSocket* aSocket)
|
||||
{
|
||||
@ -1445,22 +1464,11 @@ BluetoothOppManager::OnDisconnect(BluetoothSocket* aSocket)
|
||||
* and notify the transfer has been completed (but failed). We also call
|
||||
* AfterOppDisconnected here to ensure all variables will be cleaned.
|
||||
*/
|
||||
|
||||
if (!mSuccessFlag) {
|
||||
if (mTransferMode) {
|
||||
if (mIsServer) {
|
||||
DeleteReceivedFile();
|
||||
}
|
||||
FileTransferComplete();
|
||||
} else if (mTransferMode && mDsFile) {
|
||||
NS_NAMED_LITERAL_STRING(data, "modified");
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs =
|
||||
mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->NotifyObservers(mDsFile, "file-watcher-notify", data.get());
|
||||
} else {
|
||||
NS_WARNING("Couldn't get ObserverService");
|
||||
}
|
||||
}
|
||||
|
||||
AfterOppDisconnected();
|
||||
|
@ -106,6 +106,8 @@ private:
|
||||
bool IsReservedChar(PRUnichar c);
|
||||
void ClearQueue();
|
||||
void RetrieveSentFileName();
|
||||
DeviceStorageFile* CreateDeviceStorageFile(nsIFile* aFile);
|
||||
void NotifyAboutFileChange();
|
||||
|
||||
/**
|
||||
* OBEX session status.
|
||||
@ -163,7 +165,7 @@ private:
|
||||
* True: Receive file (Server)
|
||||
* False: Send file (Client)
|
||||
*/
|
||||
bool mTransferMode;
|
||||
bool mIsServer;
|
||||
|
||||
/**
|
||||
* Set when receiving the first PUT packet and wait for
|
||||
|
Loading…
Reference in New Issue
Block a user