Bug 1166176 - [cleanup] Simplify volume related code in OPP manager, r=shuang
authorBen Tian <btian@mozilla.com>
Tue, 19 May 2015 17:09:56 +0800
changeset 244676 63b96e7e7bb4a1bb13baa288dcc8ac606054cc27
parent 244675 41cd846782f36ade4e86a5a25ef41724f39c93f7
child 244677 92f0a71b6d2dea73dafe22f17b0351cd421fe5ff
push id60013
push usercbook@mozilla.com
push dateWed, 20 May 2015 14:18:01 +0000
treeherdermozilla-inbound@598680efb35f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1166176
milestone41.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 1166176 - [cleanup] Simplify volume related code in OPP manager, r=shuang
dom/bluetooth/bluedroid/BluetoothOppManager.cpp
dom/bluetooth/bluedroid/BluetoothOppManager.h
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
@@ -84,17 +84,16 @@ public:
 
 NS_IMETHODIMP
 BluetoothOppManager::Observe(nsISupports* aSubject,
                              const char* aTopic,
                              const char16_t* aData)
 {
   MOZ_ASSERT(sBluetoothOppManager);
 
-  // if state of any volume was changed
   if (!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) {
     HandleVolumeStateChanged(aSubject);
     return NS_OK;
   }
 
   if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
     HandleShutdown();
     return NS_OK;
@@ -309,41 +308,35 @@ BluetoothOppManager::HandleShutdown()
   sBluetoothOppManager = nullptr;
 }
 
 void
 BluetoothOppManager::HandleVolumeStateChanged(nsISupports* aSubject)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  // We will disconnect OPP connection no matter which volume becomes non
-  // STATE_MOUNTED, since user may select files scattered in multiple volumes
-  // in a single transfer, (e.g., user selects 2 files to transfer, one is in
-  // internal volume and the other is in external volume).
-
   if (!mConnected) {
     return;
   }
 
-  // get volume interface and state
+  /**
+   * Disconnect ongoing OPP connection when a volume becomes non-mounted, in
+   * case files of transfer are located on that volume. |OnSocketDisconnect|
+   * will handle incomplete file transfers.
+   */
+
   nsCOMPtr<nsIVolume> vol = do_QueryInterface(aSubject);
   if (!vol) {
     return;
   }
+
   int32_t state;
   vol->GetState(&state);
   if (nsIVolume::STATE_MOUNTED != state) {
-    // Here is for unexpected physical removal of any storage.
-    // By checking the volume state change, we should release the unavailable
-    // storage to prevent being killed by vold.
-    // Disconnect any connected OPP connection since volume state becomes
-    // non STATE_MOUNTED. Then |OnSocketDisconnect| would also be called to
-    // handle remaining files during send(|DiscardBlobsToSend|) or
-    // receive(|DeleteReceivedFile|).
-    BT_LOGR("Volume state is not STATE_MOUNTED. Abort any ongoing OPP connection.");
+    BT_LOGR("Volume becomes non-mounted. Abort ongoing OPP connection");
     Disconnect(nullptr);
   }
 }
 
 bool
 BluetoothOppManager::Listen()
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -1568,20 +1561,22 @@ BluetoothOppManager::Disconnect(Bluetoot
 NS_IMPL_ISUPPORTS(BluetoothOppManager, nsIObserver)
 
 bool
 BluetoothOppManager::AcquireSdcardMountLock()
 {
   nsCOMPtr<nsIVolumeService> volumeSrv =
     do_GetService(NS_VOLUMESERVICE_CONTRACTID);
   NS_ENSURE_TRUE(volumeSrv, false);
-  nsresult rv;
-  rv = volumeSrv->CreateMountLock(NS_LITERAL_STRING("sdcard"),
-                                  getter_AddRefs(mMountLock));
-  NS_ENSURE_SUCCESS(rv, false);
+
+  NS_ENSURE_SUCCESS(
+    volumeSrv->CreateMountLock(NS_LITERAL_STRING("sdcard"),
+                               getter_AddRefs(mMountLock)),
+    false);
+
   return true;
 }
 
 void
 BluetoothOppManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
                                          const nsAString& aServiceUuid,
                                          int aChannel)
 {
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.h
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.h
@@ -71,17 +71,16 @@ public:
 
 protected:
   virtual ~BluetoothOppManager();
 
 private:
   BluetoothOppManager();
   bool Init();
   void HandleShutdown();
-
   void HandleVolumeStateChanged(nsISupports* aSubject);
 
   void StartFileTransfer();
   void StartSendingNextFile();
   void FileTransferComplete();
   void UpdateProgress();
   void ReceivingFileConfirmation();
   bool CreateFile();
@@ -142,22 +141,16 @@ private:
   int mLastCommand;
 
   int mPacketLength;
   int mPutPacketReceivedLength;
   int mBodySegmentLength;
   int mUpdateProgressCounter;
 
   /**
-   * When it is true and the target service on target device couldn't be found,
-   * refreshing SDP records is necessary.
-   */
-  bool mNeedsUpdatingSdpRecords;
-
-  /**
    * Set when StopSendingFile() is called.
    */
   bool mAbortFlag;
 
   /**
    * Set when receiving the first PUT packet of a new file
    */
   bool mNewFileFlag;