Bug 1146355: Prepare Bluetooth OPP manager, r=joliu
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 09 Apr 2015 15:57:41 +0200
changeset 238427 b934bff05755618f368fdd10113d8c6e0f17ea60
parent 238426 570a51e376eee80980b12095c675c0783cd3c0ec
child 238428 621d487759ceef5c7906762c82eb8feae937082d
push id58223
push userryanvm@gmail.com
push dateFri, 10 Apr 2015 03:00:59 +0000
treeherdermozilla-inbound@b2e2a9ff51e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoliu
bugs1146355
milestone40.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 1146355: Prepare Bluetooth OPP manager, r=joliu
dom/bluetooth/bluedroid/BluetoothOppManager.cpp
dom/bluetooth/bluedroid/BluetoothOppManager.h
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
@@ -75,21 +75,26 @@ public:
 };
 
 NS_IMETHODIMP
 BluetoothOppManager::Observe(nsISupports* aSubject,
                              const char* aTopic,
                              const char16_t* aData)
 {
   MOZ_ASSERT(sBluetoothOppManager);
+
+#ifdef MOZ_B2G_BT_API_V2
+  // Removed in bluetooth2
+#else
   // if state of any volume was changed
   if (!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) {
     HandleVolumeStateChanged(aSubject);
     return NS_OK;
   }
+#endif
 
   if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
     HandleShutdown();
     return NS_OK;
   }
 
   MOZ_ASSERT(false, "BluetoothOppManager got unexpected topic!");
   return NS_ERROR_UNEXPECTED;
@@ -208,35 +213,43 @@ BluetoothOppManager::BluetoothOppManager
 BluetoothOppManager::~BluetoothOppManager()
 {
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   NS_ENSURE_TRUE_VOID(obs);
   if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
     BT_WARNING("Failed to remove shutdown observer!");
   }
 
+#ifdef MOZ_B2G_BT_API_V2
+  // Removed in bluetooth2
+#else
   if (NS_FAILED(obs->RemoveObserver(this, NS_VOLUME_STATE_CHANGED))) {
     BT_WARNING("Failed to remove volume observer!");
   }
+#endif
 }
 
 bool
 BluetoothOppManager::Init()
 {
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   NS_ENSURE_TRUE(obs, false);
   if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
     BT_WARNING("Failed to add shutdown observer!");
     return false;
   }
 
+#ifdef MOZ_B2G_BT_API_V2
+  // Removed in bluetooth2
+#else
   if (NS_FAILED(obs->AddObserver(this, NS_VOLUME_STATE_CHANGED, false))) {
     BT_WARNING("Failed to add ns volume observer!");
     return false;
   }
+#endif
 
   /**
    * We don't start listening here as BluetoothServiceBluedroid calls Listen()
    * immediately when BT stops.
    *
    * If we start listening here, the listening fails when device boots up since
    * Listen() is called again and restarts server socket. The restart causes
    * absence of read events when device boots up.
@@ -295,16 +308,19 @@ void
 BluetoothOppManager::HandleShutdown()
 {
   MOZ_ASSERT(NS_IsMainThread());
   sInShutdown = true;
   Disconnect(nullptr);
   sBluetoothOppManager = nullptr;
 }
 
+#ifdef MOZ_B2G_BT_API_V2
+  // Removed in bluetooth2
+#else
 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
@@ -328,16 +344,17 @@ BluetoothOppManager::HandleVolumeStateCh
     // 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.");
     Disconnect(nullptr);
   }
 }
+#endif
 
 bool
 BluetoothOppManager::Listen()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mSocket) {
     BT_WARNING("mSocket exists. Failed to listen.");
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.h
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.h
@@ -78,17 +78,22 @@ public:
 
 protected:
   virtual ~BluetoothOppManager();
 
 private:
   BluetoothOppManager();
   bool Init();
   void HandleShutdown();
+
+#ifdef MOZ_B2G_BT_API_V2
+  // Removed in bluetooth2
+#else
   void HandleVolumeStateChanged(nsISupports* aSubject);
+#endif
 
   void StartFileTransfer();
   void StartSendingNextFile();
   void FileTransferComplete();
   void UpdateProgress();
   void ReceivingFileConfirmation();
   bool CreateFile();
   bool WriteToFile(const uint8_t* aData, int aDataLength);