зеркало из https://github.com/mozilla/gecko-dev.git
Bug 978709 - 2.b/6: don't use nsIRILDataCallback in GonkGPSGeolocationProvider. r=kanru
nsIRILDataCallback has been abused in RadioInterfaceLayer.js and is becoming an RIL internal utility. Besides, nsIRILDataCallback has also racing problem as described in bug 976897. We should really use NetworkManager observer events to replace the notification mechanism here.
This commit is contained in:
Родитель
d3ffb856e3
Коммит
5ef7d49855
|
@ -19,9 +19,11 @@
|
||||||
|
|
||||||
#include "GonkGPSGeolocationProvider.h"
|
#include "GonkGPSGeolocationProvider.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
|
#include "mozilla/Services.h"
|
||||||
#include "nsGeoPosition.h"
|
#include "nsGeoPosition.h"
|
||||||
#include "nsIInterfaceRequestorUtils.h"
|
#include "nsIInterfaceRequestorUtils.h"
|
||||||
#include "nsINetworkManager.h"
|
#include "nsINetworkManager.h"
|
||||||
|
#include "nsIObserverService.h"
|
||||||
#include "nsJSUtils.h"
|
#include "nsJSUtils.h"
|
||||||
#include "nsServiceManagerUtils.h"
|
#include "nsServiceManagerUtils.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
@ -44,17 +46,20 @@ using namespace mozilla;
|
||||||
|
|
||||||
static const int kDefaultPeriod = 1000; // ms
|
static const int kDefaultPeriod = 1000; // ms
|
||||||
|
|
||||||
|
static const char* kNetworkConnStateChangedTopic = "network-connection-state-changed";
|
||||||
|
|
||||||
// While most methods of GonkGPSGeolocationProvider should only be
|
// While most methods of GonkGPSGeolocationProvider should only be
|
||||||
// called from main thread, we deliberately put the Init and ShutdownGPS
|
// called from main thread, we deliberately put the Init and ShutdownGPS
|
||||||
// methods off main thread to avoid blocking.
|
// methods off main thread to avoid blocking.
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
NS_IMPL_ISUPPORTS3(GonkGPSGeolocationProvider,
|
NS_IMPL_ISUPPORTS3(GonkGPSGeolocationProvider,
|
||||||
nsIGeolocationProvider,
|
nsIGeolocationProvider,
|
||||||
nsIRILDataCallback,
|
nsIObserver,
|
||||||
nsISettingsServiceCallback)
|
nsISettingsServiceCallback)
|
||||||
#else
|
#else
|
||||||
NS_IMPL_ISUPPORTS1(GonkGPSGeolocationProvider,
|
NS_IMPL_ISUPPORTS2(GonkGPSGeolocationProvider,
|
||||||
nsIGeolocationProvider)
|
nsIGeolocationProvider,
|
||||||
|
nsIObserver)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* static */ GonkGPSGeolocationProvider* GonkGPSGeolocationProvider::sSingleton = nullptr;
|
/* static */ GonkGPSGeolocationProvider* GonkGPSGeolocationProvider::sSingleton = nullptr;
|
||||||
|
@ -636,15 +641,16 @@ GonkGPSGeolocationProvider::SetupAGPS()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup network state listener
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||||
|
if (obs) {
|
||||||
|
obs->AddObserver(this, kNetworkConnStateChangedTopic, false);
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIRadioInterfaceLayer> ril = do_GetService("@mozilla.org/ril;1");
|
nsCOMPtr<nsIRadioInterfaceLayer> ril = do_GetService("@mozilla.org/ril;1");
|
||||||
if (ril) {
|
if (ril) {
|
||||||
// TODO: Bug 878748 - B2G GPS: acquire correct RadioInterface instance in
|
// TODO: Bug 878748 - B2G GPS: acquire correct RadioInterface instance in
|
||||||
// MultiSIM configuration
|
// MultiSIM configuration
|
||||||
ril->GetRadioInterface(0 /* clientId */, getter_AddRefs(mRadioInterface));
|
ril->GetRadioInterface(0 /* clientId */, getter_AddRefs(mRadioInterface));
|
||||||
if (mRadioInterface) {
|
|
||||||
mRadioInterface->RegisterDataCallCallback(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // MOZ_B2G_RIL
|
#endif // MOZ_B2G_RIL
|
||||||
|
@ -746,8 +752,9 @@ GonkGPSGeolocationProvider::Shutdown()
|
||||||
mNetworkLocationProvider = nullptr;
|
mNetworkLocationProvider = nullptr;
|
||||||
}
|
}
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
if (mRadioInterface) {
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||||
mRadioInterface->UnregisterDataCallCallback(this);
|
if (obs) {
|
||||||
|
obs->RemoveObserver(this, kNetworkConnStateChangedTopic);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -774,23 +781,27 @@ GonkGPSGeolocationProvider::SetHighAccuracy(bool)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MOZ_B2G_RIL
|
|
||||||
/** nsIRILDataCallback interface **/
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
GonkGPSGeolocationProvider::DataCallStateChanged(nsIRILDataCallInfo* aDataCall)
|
GonkGPSGeolocationProvider::Observe(nsISupports* aSubject,
|
||||||
|
const char* aTopic,
|
||||||
|
const char16_t* aData)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
MOZ_ASSERT(aDataCall);
|
|
||||||
|
|
||||||
// We call Setting Service before we get the state of supl data connection
|
if (strcmp(aTopic, kNetworkConnStateChangedTopic)) {
|
||||||
// since it is possible that state of supl data connection haven't been
|
return NS_OK;
|
||||||
// updated and will be updated after we finished this function (code that
|
}
|
||||||
// updates the state is in another dataCallStateChanged callback).
|
|
||||||
|
nsCOMPtr<nsIRilNetworkInterface> iface = do_QueryInterface(aSubject);
|
||||||
|
if (!iface) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
RequestSettingValue("ril.supl.apn");
|
RequestSettingValue("ril.supl.apn");
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MOZ_B2G_RIL
|
||||||
/** nsISettingsServiceCallback **/
|
/** nsISettingsServiceCallback **/
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <hardware/gps.h> // for GpsInterface
|
#include <hardware/gps.h> // for GpsInterface
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIGeolocationProvider.h"
|
#include "nsIGeolocationProvider.h"
|
||||||
|
#include "nsIObserver.h"
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
#include "nsIRadioInterfaceLayer.h"
|
#include "nsIRadioInterfaceLayer.h"
|
||||||
#include "nsISettingsService.h"
|
#include "nsISettingsService.h"
|
||||||
|
@ -34,16 +35,16 @@ class nsIThread;
|
||||||
"@mozilla.org/gonk-gps-geolocation-provider;1"
|
"@mozilla.org/gonk-gps-geolocation-provider;1"
|
||||||
|
|
||||||
class GonkGPSGeolocationProvider : public nsIGeolocationProvider
|
class GonkGPSGeolocationProvider : public nsIGeolocationProvider
|
||||||
|
, public nsIObserver
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
, public nsIRILDataCallback
|
|
||||||
, public nsISettingsServiceCallback
|
, public nsISettingsServiceCallback
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
NS_DECL_NSIGEOLOCATIONPROVIDER
|
NS_DECL_NSIGEOLOCATIONPROVIDER
|
||||||
|
NS_DECL_NSIOBSERVER
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
NS_DECL_NSIRILDATACALLBACK
|
|
||||||
NS_DECL_NSISETTINGSSERVICECALLBACK
|
NS_DECL_NSISETTINGSSERVICECALLBACK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче