Bug 882551 - Patch 3: Remove BluetoothOppManagerObserver, r=qdot, r=mrbkap, r=echou

This commit is contained in:
Gina Yeh 2013-06-20 09:19:46 +08:00
parent e1a7a2500d
commit ed2a4cfcfe
2 changed files with 30 additions and 47 deletions

View File

@ -36,46 +36,6 @@ USING_BLUETOOTH_NAMESPACE
using namespace mozilla;
using namespace mozilla::ipc;
class BluetoothOppManagerObserver : public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
BluetoothOppManagerObserver()
{
}
bool Init()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
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()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs ||
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)))) {
NS_WARNING("Can't unregister observers, or already unregistered!");
return false;
}
return true;
}
~BluetoothOppManagerObserver()
{
Shutdown();
}
};
namespace {
// Sending system message "bluetooth-opp-update-progress" every 50kb
static const uint32_t kUpdateProgressBase = 50 * 1024;
@ -106,14 +66,14 @@ static bool sWaitingToSendPutFinal = false;
}
NS_IMETHODIMP
BluetoothOppManagerObserver::Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aData)
BluetoothOppManager::Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aData)
{
MOZ_ASSERT(sInstance);
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
return sInstance->HandleShutdown();
return HandleShutdown();
}
MOZ_ASSERT(false, "BluetoothOppManager got unexpected topic!");
@ -231,11 +191,31 @@ BluetoothOppManager::BluetoothOppManager() : mConnected(false)
, mCurrentBlobIndex(-1)
{
mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
Listen();
Init();
}
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!");
}
}
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;
}
Listen();
return true;
}
//static
@ -1516,7 +1496,7 @@ BluetoothOppManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
}
}
NS_IMPL_ISUPPORTS0(BluetoothOppManager)
NS_IMPL_ISUPPORTS1(BluetoothOppManager, nsIObserver)
bool
BluetoothOppManager::AcquireSdcardMountLock()

View File

@ -30,6 +30,7 @@ class BluetoothOppManager : public BluetoothSocketObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
/*
* Channel of reserved services are fixed values, please check
@ -73,7 +74,6 @@ public:
void ExtractPacketHeaders(const ObexHeaderSet& aHeader);
bool ExtractBlobHeaders();
nsresult HandleShutdown();
// Return true if there is an ongoing file-transfer session, please see
// Bug 827267 for more information.
@ -95,6 +95,9 @@ public:
private:
BluetoothOppManager();
bool Init();
nsresult HandleShutdown();
void StartFileTransfer();
void StartSendingNextFile();
void FileTransferComplete();