mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 798035 - Patch 1: Change Bluetooth*Manager observers to be internal classes; r=gyeh
--HG-- extra : rebase_source : 511e9c9deec5626399fc76c0630ac4ca8285a40e
This commit is contained in:
parent
90e95550c6
commit
1aaefa52b6
@ -33,8 +33,39 @@ using namespace mozilla;
|
||||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
class mozilla::dom::bluetooth::BluetoothHfpManagerObserver : public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
BluetoothHfpManagerObserver()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
MOZ_ASSERT(obs);
|
||||
if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false))) {
|
||||
NS_WARNING("Failed to add settings change observer!");
|
||||
}
|
||||
|
||||
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
||||
NS_WARNING("Failed to add shutdown observer!");
|
||||
}
|
||||
}
|
||||
|
||||
~BluetoothHfpManagerObserver()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (obs &&
|
||||
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
|
||||
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID)))) {
|
||||
NS_WARNING("Can't unregister observers!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
StaticRefPtr<BluetoothHfpManager> gBluetoothHfpManager;
|
||||
StaticAutoPtr<BluetoothHfpManagerObserver> sHfpObserver;
|
||||
bool gInShutdown = false;
|
||||
static nsCOMPtr<nsIThread> sHfpCommandThread;
|
||||
static bool sStopSendingRingFlag = true;
|
||||
@ -42,7 +73,23 @@ namespace {
|
||||
static int kRingInterval = 3000000; //unit: us
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS1(BluetoothHfpManager, nsIObserver)
|
||||
NS_IMPL_ISUPPORTS1(BluetoothHfpManagerObserver, nsIObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothHfpManagerObserver::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
MOZ_ASSERT(gBluetoothHfpManager);
|
||||
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
|
||||
return gBluetoothHfpManager->HandleVolumeChanged(nsDependentString(aData));
|
||||
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
return gBluetoothHfpManager->HandleShutdown();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
class SendRingIndicatorTask : public nsRunnable
|
||||
{
|
||||
@ -122,17 +169,7 @@ BluetoothHfpManager::BluetoothHfpManager()
|
||||
bool
|
||||
BluetoothHfpManager::Init()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
NS_ENSURE_TRUE(obs, false);
|
||||
|
||||
if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false))) {
|
||||
NS_WARNING("Failed to add settings change observer!");
|
||||
}
|
||||
|
||||
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
||||
NS_WARNING("Failed to add shutdown observer!");
|
||||
return false;
|
||||
}
|
||||
sHfpObserver = new BluetoothHfpManagerObserver();
|
||||
|
||||
mListener = new BluetoothRilListener();
|
||||
if (!mListener->StartListening()) {
|
||||
@ -172,12 +209,7 @@ BluetoothHfpManager::Cleanup()
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (obs &&
|
||||
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
|
||||
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID)))) {
|
||||
NS_WARNING("Can't unregister observers!");
|
||||
}
|
||||
sHfpObserver = nullptr;
|
||||
}
|
||||
|
||||
//static
|
||||
@ -338,21 +370,6 @@ BluetoothHfpManager::HandleShutdown()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothHfpManager::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
|
||||
return HandleVolumeChanged(nsDependentString(aData));
|
||||
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
return HandleShutdown();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Virtual function of class SocketConsumer
|
||||
void
|
||||
BluetoothHfpManager::ReceiveSocketData(UnixSocketRawData* aMessage)
|
||||
|
@ -15,14 +15,11 @@
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothReplyRunnable;
|
||||
class BluetoothHfpManagerObserver;
|
||||
|
||||
class BluetoothHfpManager : public mozilla::ipc::UnixSocketConsumer
|
||||
, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
~BluetoothHfpManager();
|
||||
static BluetoothHfpManager* Get();
|
||||
void ReceiveSocketData(mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
@ -36,11 +33,12 @@ public:
|
||||
bool Listen();
|
||||
|
||||
private:
|
||||
friend class BluetoothHfpManagerObserver;
|
||||
BluetoothHfpManager();
|
||||
bool Init();
|
||||
void Cleanup();
|
||||
nsresult HandleVolumeChanged(const nsAString& aData);
|
||||
nsresult HandleShutdown();
|
||||
bool Init();
|
||||
void Cleanup();
|
||||
void NotifyDialer(const nsAString& aCommand);
|
||||
void NotifySettings(const bool aConnected);
|
||||
|
||||
|
@ -25,13 +25,54 @@ using namespace mozilla;
|
||||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
class mozilla::dom::bluetooth::BluetoothScoManagerObserver : public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
BluetoothScoManagerObserver()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
MOZ_ASSERT(obs);
|
||||
|
||||
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
||||
NS_WARNING("Failed to add shutdown observer!");
|
||||
}
|
||||
}
|
||||
|
||||
~BluetoothScoManagerObserver()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (obs &&
|
||||
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)))) {
|
||||
NS_WARNING("Can't unregister observers!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(BluetoothScoManagerObserver, nsIObserver)
|
||||
|
||||
namespace {
|
||||
StaticRefPtr<BluetoothScoManager> gBluetoothScoManager;
|
||||
StaticAutoPtr<BluetoothScoManagerObserver> sScoObserver;
|
||||
bool gInShutdown = false;
|
||||
static nsCOMPtr<nsIThread> sScoCommandThread;
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS1(BluetoothScoManager, nsIObserver)
|
||||
NS_IMETHODIMP
|
||||
BluetoothScoManagerObserver::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
MOZ_ASSERT(gBluetoothScoManager);
|
||||
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
return gBluetoothScoManager->HandleShutdown();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false, "BluetoothScoManager got unexpected topic!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
BluetoothScoManager::BluetoothScoManager()
|
||||
: mConnected(false)
|
||||
@ -41,19 +82,13 @@ BluetoothScoManager::BluetoothScoManager()
|
||||
bool
|
||||
BluetoothScoManager::Init()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
NS_ENSURE_TRUE(obs, false);
|
||||
|
||||
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
||||
NS_WARNING("Failed to add shutdown observer!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sScoCommandThread &&
|
||||
NS_FAILED(NS_NewThread(getter_AddRefs(sScoCommandThread)))) {
|
||||
NS_ERROR("Failed to new thread for sScoCommandThread");
|
||||
return false;
|
||||
}
|
||||
sScoObserver = new BluetoothScoManagerObserver();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -73,12 +108,7 @@ BluetoothScoManager::Cleanup()
|
||||
NS_WARNING("Failed to shut down the bluetooth hfpmanager command thread!");
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (obs &&
|
||||
NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
|
||||
NS_WARNING("Can't unregister observers!");
|
||||
}
|
||||
sScoObserver = nullptr;
|
||||
}
|
||||
|
||||
//static
|
||||
@ -115,19 +145,6 @@ BluetoothScoManager::Get()
|
||||
return gBluetoothScoManager;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothScoManager::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
return HandleShutdown();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false, "BluetoothScoManager got unexpected topic!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Virtual function of class SocketConsumer
|
||||
void
|
||||
BluetoothScoManager::ReceiveSocketData(mozilla::ipc::UnixSocketRawData* aMessage)
|
||||
|
@ -14,14 +14,11 @@
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothReplyRunnable;
|
||||
class BluetoothScoManagerObserver;
|
||||
|
||||
class BluetoothScoManager : public mozilla::ipc::UnixSocketConsumer
|
||||
, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
~BluetoothScoManager();
|
||||
|
||||
static BluetoothScoManager* Get();
|
||||
@ -33,6 +30,7 @@ public:
|
||||
bool GetConnected();
|
||||
|
||||
private:
|
||||
friend class BluetoothScoManagerObserver;
|
||||
BluetoothScoManager();
|
||||
bool Init();
|
||||
void Cleanup();
|
||||
|
Loading…
Reference in New Issue
Block a user