Bug 1770126 - Make WindowsLocationProvider::Watch() not try to watch for events if already watching. r=gcp
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 19 May 2022 09:28:59 +0000
changeset 618218 f4e4de791d7fdc9cd6707fe28798a1c6d2d1ce58
parent 618217 16856951218b2c0148382d12645cc690ceb19039
child 618219 12b36415ea9261876f1325eb236fdd6b16b35fdc
push id39719
push usersmolnar@mozilla.com
push dateThu, 19 May 2022 16:03:14 +0000
treeherdermozilla-central@cc776278c4ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
bugs1770126
milestone102.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 1770126 - Make WindowsLocationProvider::Watch() not try to watch for events if already watching. r=gcp The second call would fail and thus fall back to MLS, but only null out mLocation (not unregister the existing listener), so Windows would think we're still using the location permission forever. Differential Revision: https://phabricator.services.mozilla.com/D146785
dom/system/windows/WindowsLocationProvider.cpp
dom/system/windows/WindowsLocationProvider.h
--- a/dom/system/windows/WindowsLocationProvider.cpp
+++ b/dom/system/windows/WindowsLocationProvider.cpp
@@ -213,41 +213,48 @@ WindowsLocationProvider::Startup() {
   }
 
   mLocation = location;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WindowsLocationProvider::Watch(nsIGeolocationUpdate* aCallback) {
-  LOG("WindowsLocationProvider::Watch(%p, %p)\n", this, mLocation.get());
+  LOG("WindowsLocationProvider::Watch(%p, %p, %d)\n", this, mLocation.get(),
+      mWatching);
   if (mLocation) {
+    if (mWatching) {
+      return NS_OK;
+    }
     RefPtr<LocationEvent> event = new LocationEvent(aCallback, this);
     if (SUCCEEDED(mLocation->RegisterForReport(event, IID_ILatLongReport, 0))) {
+      mWatching = true;
       return NS_OK;
     }
   }
 
   // Cannot use Location API.  We will use MLS instead.
   LOG(" > MLS fallback\n");
   mLocation = nullptr;
 
   return CreateAndWatchMLSProvider(aCallback);
 }
 
 NS_IMETHODIMP
 WindowsLocationProvider::Shutdown() {
   LOG("WindowsLocationProvider::Shutdown(%p, %p)\n", this, mLocation.get());
   if (mLocation) {
-    mLocation->UnregisterForReport(IID_ILatLongReport);
+    if (mWatching) {
+      mLocation->UnregisterForReport(IID_ILatLongReport);
+    }
     mLocation = nullptr;
+    mWatching = false;
   }
 
   CancelMLSProvider();
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WindowsLocationProvider::SetHighAccuracy(bool enable) {
   if (!mLocation) {
     // MLS provider doesn't support HighAccuracy
     return NS_OK;
--- a/dom/system/windows/WindowsLocationProvider.h
+++ b/dom/system/windows/WindowsLocationProvider.h
@@ -37,13 +37,14 @@ class WindowsLocationProvider final : pu
     virtual ~MLSUpdate() {}
   };
 
  private:
   ~WindowsLocationProvider();
 
   RefPtr<ILocation> mLocation;
   RefPtr<MLSFallback> mMLSProvider;
+  bool mWatching = false;
 };
 
 }  // namespace mozilla::dom
 
 #endif  // mozilla_dom_WindowsLocationProvider_h__