tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MLSFallback.h (1924B)


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