author | Eric Chou <echou@mozilla.com> |
Wed, 12 Dec 2012 16:54:54 +0800 | |
changeset 115770 | f0951ef3bc4d86b761b3725e7219c2f2752337af |
parent 115769 | cbb29aa0964913917f09cc94680ec207ac2c24a9 |
child 115771 | febf7b3ad73179d24167b7413d67b4d4a5420e89 |
push id | 19530 |
push user | echou@mozilla.com |
push date | Wed, 12 Dec 2012 08:55:24 +0000 |
treeherder | mozilla-inbound@f0951ef3bc4d [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | dougt |
bugs | 815079 |
milestone | 20.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
|
dom/bluetooth/BluetoothOppManager.cpp | file | annotate | diff | comparison | revisions | |
dom/bluetooth/BluetoothOppManager.h | file | annotate | diff | comparison | revisions |
--- a/dom/bluetooth/BluetoothOppManager.cpp +++ b/dom/bluetooth/BluetoothOppManager.cpp @@ -41,19 +41,19 @@ public: BluetoothOppManagerObserver() { } bool Init() { nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); - if (NS_FAILED(obs->AddObserver(this, - NS_XPCOM_SHUTDOWN_OBSERVER_ID, - false))) { + if (!obs || NS_FAILED(obs->AddObserver(this, + NS_XPCOM_SHUTDOWN_OBSERVER_ID, + false))) { NS_WARNING("Failed to add shutdown observer!"); return false; } return true; } bool Shutdown() @@ -477,16 +477,36 @@ BluetoothOppManager::CreateFile() /* * The function CreateUnique() may create a file with a different file * name from the original sFileName. Therefore we have to retrieve * the file name again. */ f->GetLeafName(sFileName); + 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"), f); + } else if (StringBeginsWith(mimeType, NS_LITERAL_CSTRING("video/"))) { + mDsFile = new DeviceStorageFile(NS_LITERAL_STRING("movies"), f); + } else if (StringBeginsWith(mimeType, NS_LITERAL_CSTRING("audio/"))) { + mDsFile = new DeviceStorageFile(NS_LITERAL_STRING("music"), f); + } else { + NS_WARNING("Couldn't recognize the mimetype of received file."); + } + } + } + NS_NewLocalFileOutputStream(getter_AddRefs(mOutputStream), f); if (!mOutputStream) { NS_WARNING("Couldn't new an output stream"); return false; } return true; } @@ -1235,22 +1255,34 @@ BluetoothOppManager::OnDisconnect() /** * It is valid for a bluetooth device which is transfering file via OPP * closing socket without sending OBEX disconnect request first. So we * delete the broken file when we failed to receive a file from the remote, * and notify the transfer has been completed (but failed). We also call * AfterOppDisconnected here to ensure all variables will be cleaned. */ if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) { + if (mTransferMode) { + if (!mSuccessFlag) { + DeleteReceivedFile(); + } else if (mDsFile) { + nsString data; + CopyASCIItoUTF16("modified", data); + + nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService(); + if (obs) { + obs->NotifyObservers(mDsFile, "file-watcher-update", data.get()); + } + } + } + if (!mSuccessFlag) { - if (mTransferMode) { - DeleteReceivedFile(); - } FileTransferComplete(); } + Listen(); } else if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTING) { NS_WARNING("BluetoothOppManager got unexpected socket status!"); } AfterOppDisconnected(); mConnectedDeviceAddress.AssignLiteral("00:00:00:00:00:00"); mSuccessFlag = false;
--- a/dom/bluetooth/BluetoothOppManager.h +++ b/dom/bluetooth/BluetoothOppManager.h @@ -5,16 +5,17 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_dom_bluetooth_bluetoothoppmanager_h__ #define mozilla_dom_bluetooth_bluetoothoppmanager_h__ #include "BluetoothCommon.h" #include "mozilla/dom/ipc/Blob.h" #include "mozilla/ipc/UnixSocket.h" +#include "DeviceStorage.h" class nsIOutputStream; class nsIInputStream; BEGIN_BLUETOOTH_NAMESPACE class BluetoothReplyRunnable; class ObexHeaderSet; @@ -160,13 +161,14 @@ private: nsAutoPtr<uint8_t> mReceivedDataBuffer; nsCOMPtr<nsIDOMBlob> mBlob; nsCOMPtr<nsIThread> mReadFileThread; nsCOMPtr<nsIOutputStream> mOutputStream; nsCOMPtr<nsIInputStream> mInputStream; nsRefPtr<BluetoothReplyRunnable> mRunnable; + nsRefPtr<DeviceStorageFile> mDsFile; }; END_BLUETOOTH_NAMESPACE #endif