Bug 1770126 - Make WindowsLocationProvider::Startup() deal correctly with already-initialized instances. r=gcp
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 19 May 2022 09:28:59 +0000
changeset 618217 16856951218b2c0148382d12645cc690ceb19039
parent 618216 f4df29fbfa9597d4482d5bc66ff3bc04fd0928c2
child 618218 f4e4de791d7fdc9cd6707fe28798a1c6d2d1ce58
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, 1766770
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::Startup() deal correctly with already-initialized instances. r=gcp We can call Startup() on an already-running instance, and that would cause us to not unregister notifications from a pre-existing ILocation instance, which seems likely to cause things like bug 1766770. Other location providers deal correctly with this. Differential Revision: https://phabricator.services.mozilla.com/D146783
dom/system/windows/WindowsLocationProvider.cpp
--- a/dom/system/windows/WindowsLocationProvider.cpp
+++ b/dom/system/windows/WindowsLocationProvider.cpp
@@ -5,22 +5,27 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WindowsLocationProvider.h"
 #include "GeolocationPosition.h"
 #include "nsComponentManagerUtils.h"
 #include "prtime.h"
 #include "MLSFallback.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/Logging.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/dom/GeolocationPositionErrorBinding.h"
 
 namespace mozilla::dom {
 
+LazyLogModule gWindowsLocationProviderLog("WindowsLocationProvider");
+#define LOG(...) \
+  MOZ_LOG(gWindowsLocationProviderLog, LogLevel::Debug, (__VA_ARGS__))
+
 NS_IMPL_ISUPPORTS(WindowsLocationProvider::MLSUpdate, nsIGeolocationUpdate);
 
 WindowsLocationProvider::MLSUpdate::MLSUpdate(nsIGeolocationUpdate* aCallback)
     : mCallback(aCallback) {}
 
 NS_IMETHODIMP
 WindowsLocationProvider::MLSUpdate::Update(nsIDOMGeoPosition* aPosition) {
   if (!mCallback) {
@@ -173,22 +178,32 @@ LocationEvent::OnLocationChanged(REFIID 
 
   Telemetry::Accumulate(Telemetry::GEOLOCATION_WIN8_SOURCE_IS_MLS, false);
 
   return S_OK;
 }
 
 NS_IMPL_ISUPPORTS(WindowsLocationProvider, nsIGeolocationProvider)
 
-WindowsLocationProvider::WindowsLocationProvider() {}
+WindowsLocationProvider::WindowsLocationProvider() {
+  LOG("WindowsLocationProvider::WindowsLocationProvider(%p)\n", this);
+}
 
-WindowsLocationProvider::~WindowsLocationProvider() {}
+WindowsLocationProvider::~WindowsLocationProvider() {
+  LOG("WindowsLocationProvider::~WindowsLocationProvider(%p, %p)\n", this,
+      mLocation.get());
+}
 
 NS_IMETHODIMP
 WindowsLocationProvider::Startup() {
+  LOG("WindowsLocationProvider::Startup(%p, %p)\n", this, mLocation.get());
+  if (mLocation) {
+    return NS_OK;
+  }
+
   RefPtr<ILocation> location;
   if (FAILED(::CoCreateInstance(CLSID_Location, nullptr, CLSCTX_INPROC_SERVER,
                                 IID_ILocation, getter_AddRefs(location)))) {
     // We will use MLS provider
     return NS_OK;
   }
 
   IID reportTypes[] = {IID_ILatLongReport};
@@ -198,31 +213,34 @@ WindowsLocationProvider::Startup() {
   }
 
   mLocation = location;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WindowsLocationProvider::Watch(nsIGeolocationUpdate* aCallback) {
+  LOG("WindowsLocationProvider::Watch(%p, %p)\n", this, mLocation.get());
   if (mLocation) {
     RefPtr<LocationEvent> event = new LocationEvent(aCallback, this);
     if (SUCCEEDED(mLocation->RegisterForReport(event, IID_ILatLongReport, 0))) {
       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);
     mLocation = nullptr;
   }
 
   CancelMLSProvider();
 
   return NS_OK;
@@ -262,9 +280,11 @@ void WindowsLocationProvider::CancelMLSP
   if (!mMLSProvider) {
     return;
   }
 
   mMLSProvider->Shutdown();
   mMLSProvider = nullptr;
 }
 
+#undef LOG
+
 }  // namespace mozilla::dom