mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 13:25:37 +00:00
Bug 895325 - [Bluetooth][Cleanup] Revise BluetoothOppManager constructor and BluetoothOppManager::Get(), r=echou
This commit is contained in:
parent
4028e3305f
commit
66990b2788
@ -24,8 +24,8 @@ using namespace mozilla;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
namespace {
|
||||
StaticRefPtr<BluetoothA2dpManager> gBluetoothA2dpManager;
|
||||
bool gInShutdown = false;
|
||||
StaticRefPtr<BluetoothA2dpManager> sBluetoothA2dpManager;
|
||||
bool sInShutdown = false;
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -33,7 +33,7 @@ BluetoothA2dpManager::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
MOZ_ASSERT(gBluetoothA2dpManager);
|
||||
MOZ_ASSERT(sBluetoothA2dpManager);
|
||||
|
||||
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
HandleShutdown();
|
||||
@ -101,32 +101,32 @@ BluetoothA2dpManager::Get()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// If we already exist, exit early
|
||||
if (gBluetoothA2dpManager) {
|
||||
return gBluetoothA2dpManager;
|
||||
// If sBluetoothA2dpManager already exists, exit early
|
||||
if (sBluetoothA2dpManager) {
|
||||
return sBluetoothA2dpManager;
|
||||
}
|
||||
|
||||
// If we're in shutdown, don't create a new instance
|
||||
if (gInShutdown) {
|
||||
if (sInShutdown) {
|
||||
NS_WARNING("BluetoothA2dpManager can't be created during shutdown");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create new instance, register, return
|
||||
// Create a new instance, register, and return
|
||||
BluetoothA2dpManager* manager = new BluetoothA2dpManager();
|
||||
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
||||
|
||||
gBluetoothA2dpManager = manager;
|
||||
return gBluetoothA2dpManager;
|
||||
sBluetoothA2dpManager = manager;
|
||||
return sBluetoothA2dpManager;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::HandleShutdown()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
gInShutdown = true;
|
||||
sInShutdown = true;
|
||||
Disconnect();
|
||||
gBluetoothA2dpManager = nullptr;
|
||||
sBluetoothA2dpManager = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
@ -135,7 +135,7 @@ BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress)
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
|
||||
|
||||
if (gInShutdown) {
|
||||
if (sInShutdown) {
|
||||
NS_WARNING("Connect called while in shutdown!");
|
||||
return false;
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
namespace {
|
||||
StaticRefPtr<BluetoothHfpManager> gBluetoothHfpManager;
|
||||
bool gInShutdown = false;
|
||||
StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
|
||||
bool sInShutdown = false;
|
||||
static const char kHfpCrlf[] = "\xd\xa";
|
||||
|
||||
// Sending ringtone related
|
||||
@ -232,11 +232,11 @@ class BluetoothHfpManager::RespondToBLDNTask : public Task
|
||||
private:
|
||||
void Run() MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_ASSERT(gBluetoothHfpManager);
|
||||
MOZ_ASSERT(sBluetoothHfpManager);
|
||||
|
||||
if (!gBluetoothHfpManager->mDialingRequestProcessed) {
|
||||
gBluetoothHfpManager->mDialingRequestProcessed = true;
|
||||
gBluetoothHfpManager->SendLine("ERROR");
|
||||
if (!sBluetoothHfpManager->mDialingRequestProcessed) {
|
||||
sBluetoothHfpManager->mDialingRequestProcessed = true;
|
||||
sBluetoothHfpManager->SendLine("ERROR");
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -260,20 +260,20 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gBluetoothHfpManager) {
|
||||
if (!sBluetoothHfpManager) {
|
||||
NS_WARNING("BluetoothHfpManager no longer exists, cannot send ring!");
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString ringMsg("RING");
|
||||
gBluetoothHfpManager->SendLine(ringMsg.get());
|
||||
sBluetoothHfpManager->SendLine(ringMsg.get());
|
||||
|
||||
if (!mNumber.IsEmpty()) {
|
||||
nsAutoCString clipMsg("+CLIP: \"");
|
||||
clipMsg.Append(NS_ConvertUTF16toUTF8(mNumber).get());
|
||||
clipMsg.AppendLiteral("\",");
|
||||
clipMsg.AppendInt(mType);
|
||||
gBluetoothHfpManager->SendLine(clipMsg.get());
|
||||
sBluetoothHfpManager->SendLine(clipMsg.get());
|
||||
}
|
||||
|
||||
MessageLoop::current()->
|
||||
@ -292,9 +292,9 @@ class BluetoothHfpManager::CloseScoTask : public Task
|
||||
private:
|
||||
void Run() MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_ASSERT(gBluetoothHfpManager);
|
||||
MOZ_ASSERT(sBluetoothHfpManager);
|
||||
|
||||
gBluetoothHfpManager->DisconnectSco();
|
||||
sBluetoothHfpManager->DisconnectSco();
|
||||
}
|
||||
};
|
||||
|
||||
@ -434,23 +434,23 @@ BluetoothHfpManager::Get()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// If we already exist, exit early
|
||||
if (gBluetoothHfpManager) {
|
||||
return gBluetoothHfpManager;
|
||||
// If sBluetoothHfpManager already exists, exit early
|
||||
if (sBluetoothHfpManager) {
|
||||
return sBluetoothHfpManager;
|
||||
}
|
||||
|
||||
// If we're in shutdown, don't create a new instance
|
||||
if (gInShutdown) {
|
||||
if (sInShutdown) {
|
||||
NS_WARNING("BluetoothHfpManager can't be created during shutdown");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create new instance, register, return
|
||||
// Create a new instance, register, and return
|
||||
BluetoothHfpManager* manager = new BluetoothHfpManager();
|
||||
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
||||
|
||||
gBluetoothHfpManager = manager;
|
||||
return gBluetoothHfpManager;
|
||||
sBluetoothHfpManager = manager;
|
||||
return sBluetoothHfpManager;
|
||||
}
|
||||
|
||||
void
|
||||
@ -650,10 +650,10 @@ void
|
||||
BluetoothHfpManager::HandleShutdown()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
gInShutdown = true;
|
||||
sInShutdown = true;
|
||||
Disconnect();
|
||||
DisconnectSco();
|
||||
gBluetoothHfpManager = nullptr;
|
||||
sBluetoothHfpManager = nullptr;
|
||||
}
|
||||
|
||||
// Virtual function of class SocketConsumer
|
||||
@ -1000,7 +1000,7 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs || gInShutdown) {
|
||||
if (!bs || sInShutdown) {
|
||||
DispatchBluetoothReply(aRunnable, BluetoothValue(),
|
||||
NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
@ -1057,7 +1057,7 @@ BluetoothHfpManager::Listen()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (gInShutdown) {
|
||||
if (sInShutdown) {
|
||||
NS_WARNING("Listen called while in shutdown!");
|
||||
return false;
|
||||
}
|
||||
@ -1679,7 +1679,7 @@ BluetoothHfpManager::ConnectSco(BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (gInShutdown) {
|
||||
if (sInShutdown) {
|
||||
NS_WARNING("ConnecteSco called while in shutdown!");
|
||||
return false;
|
||||
}
|
||||
@ -1732,7 +1732,7 @@ BluetoothHfpManager::ListenSco()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (gInShutdown) {
|
||||
if (sInShutdown) {
|
||||
NS_WARNING("ListenSco called while in shutdown!");
|
||||
return false;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ static const uint32_t kUpdateProgressBase = 50 * 1024;
|
||||
*/
|
||||
static const uint32_t kPutRequestHeaderSize = 6;
|
||||
|
||||
StaticRefPtr<BluetoothOppManager> sInstance;
|
||||
StaticRefPtr<BluetoothOppManager> sBluetoothOppManager;
|
||||
static bool sInShutdown = false;
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ BluetoothOppManager::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
MOZ_ASSERT(sInstance);
|
||||
MOZ_ASSERT(sBluetoothOppManager);
|
||||
|
||||
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
HandleShutdown();
|
||||
@ -80,7 +80,7 @@ public:
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
sInstance->SendPutRequest(mStream, mSize);
|
||||
sBluetoothOppManager->SendPutRequest(mStream, mSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -117,7 +117,7 @@ public:
|
||||
}
|
||||
|
||||
if (numRead > 0) {
|
||||
sInstance->CheckPutFinal(numRead);
|
||||
sBluetoothOppManager->CheckPutFinal(numRead);
|
||||
|
||||
nsRefPtr<SendSocketDataTask> task =
|
||||
new SendSocketDataTask((uint8_t*)buf.forget(), numRead);
|
||||
@ -178,7 +178,6 @@ BluetoothOppManager::BluetoothOppManager() : mConnected(false)
|
||||
, mCurrentBlobIndex(-1)
|
||||
{
|
||||
mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||
Init();
|
||||
}
|
||||
|
||||
BluetoothOppManager::~BluetoothOppManager()
|
||||
@ -211,12 +210,23 @@ BluetoothOppManager::Get()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!sInstance) {
|
||||
sInstance = new BluetoothOppManager();
|
||||
NS_ENSURE_TRUE(sInstance->Init(), nullptr);
|
||||
// If sBluetoothOppManager already exists, exit early
|
||||
if (sBluetoothOppManager) {
|
||||
return sBluetoothOppManager;
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
// If we're in shutdown, don't create a new instance
|
||||
if (sInShutdown) {
|
||||
NS_WARNING("BluetoothOppManager can't be created during shutdown");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create a new instance, register, and return
|
||||
BluetoothOppManager *manager = new BluetoothOppManager();
|
||||
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
||||
|
||||
sBluetoothOppManager = manager;
|
||||
return sBluetoothOppManager;
|
||||
}
|
||||
|
||||
void
|
||||
@ -287,7 +297,7 @@ BluetoothOppManager::HandleShutdown()
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
sInShutdown = true;
|
||||
Disconnect();
|
||||
sInstance = nullptr;
|
||||
sBluetoothOppManager = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
@ -911,7 +921,7 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
|
||||
mRemoteMaxPacketLength =
|
||||
(((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]);
|
||||
|
||||
sInstance->SendPutHeaderRequest(mFileName, mFileLength);
|
||||
sBluetoothOppManager->SendPutHeaderRequest(mFileName, mFileLength);
|
||||
} else if (mLastCommand == ObexRequestCode::Put) {
|
||||
if (mWaitingToSendPutFinal) {
|
||||
SendPutFinalRequest();
|
||||
|
Loading…
Reference in New Issue
Block a user