MLSFallback.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsCOMPtr.h"
  6. #include "nsITimer.h"
  7. class nsIGeolocationUpdate;
  8. class nsIGeolocationProvider;
  9. /*
  10. This class wraps the NetworkGeolocationProvider in a delayed startup.
  11. It is for providing a fallback to MLS when:
  12. 1) using another provider as the primary provider, and
  13. 2) that primary provider may fail to return a result (i.e. the error returned
  14. is indeterminate, or no error callback occurs)
  15. The intent is that the primary provider is started, then MLSFallback
  16. is started with sufficient delay that the primary provider will respond first
  17. if successful (in the majority of cases).
  18. MLS has an average response of 3s, so with the 2s default delay, a response can
  19. be expected in 5s.
  20. Telemetry is recommended to monitor that the primary provider is responding
  21. first when expected to do so.
  22. */
  23. class MLSFallback : public nsITimerCallback
  24. {
  25. public:
  26. NS_DECL_ISUPPORTS
  27. NS_DECL_NSITIMERCALLBACK
  28. explicit MLSFallback(uint32_t delayMs = 2000);
  29. nsresult Startup(nsIGeolocationUpdate* aWatcher);
  30. nsresult Shutdown();
  31. private:
  32. nsresult CreateMLSFallbackProvider();
  33. virtual ~MLSFallback();
  34. nsCOMPtr<nsITimer> mHandoffTimer;
  35. nsCOMPtr<nsIGeolocationProvider> mMLSFallbackProvider;
  36. nsCOMPtr<nsIGeolocationUpdate> mUpdateWatcher;
  37. const uint32_t mDelayMs;
  38. };