Bug 1804798 - Explicitly set auto page name (and corresponding debug flag) when inser...
[gecko.git] / netwerk / base / CaptivePortalService.h
blobf0a7200b4b4cb217b94b383fd144fe15ae917545
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef CaptivePortalService_h_
6 #define CaptivePortalService_h_
8 #include "nsICaptivePortalService.h"
9 #include "nsICaptivePortalDetector.h"
10 #include "nsINamed.h"
11 #include "nsIObserver.h"
12 #include "nsWeakReference.h"
13 #include "nsITimer.h"
14 #include "nsCOMArray.h"
15 #include "mozilla/TimeStamp.h"
17 namespace mozilla {
18 namespace net {
20 class CaptivePortalService : public nsICaptivePortalService,
21 public nsIObserver,
22 public nsSupportsWeakReference,
23 public nsITimerCallback,
24 public nsICaptivePortalCallback,
25 public nsINamed {
26 public:
27 NS_DECL_ISUPPORTS
28 NS_DECL_NSICAPTIVEPORTALSERVICE
29 NS_DECL_NSIOBSERVER
30 NS_DECL_NSITIMERCALLBACK
31 NS_DECL_NSICAPTIVEPORTALCALLBACK
32 NS_DECL_NSINAMED
34 nsresult Initialize();
35 nsresult Start();
36 nsresult Stop();
38 static already_AddRefed<nsICaptivePortalService> GetSingleton();
40 // This method is only called in the content process, in order to mirror
41 // the captive portal state in the parent process.
42 void SetStateInChild(int32_t aState);
44 private:
45 static const uint32_t kDefaultInterval = 60 * 1000; // check every 60 seconds
47 CaptivePortalService();
48 virtual ~CaptivePortalService();
49 nsresult PerformCheck();
50 nsresult RearmTimer();
51 void NotifyConnectivityAvailable(bool aCaptive);
53 nsCOMPtr<nsICaptivePortalDetector> mCaptivePortalDetector;
54 int32_t mState{UNKNOWN};
56 nsCOMPtr<nsITimer> mTimer;
57 bool mStarted{false};
58 bool mInitialized{false};
59 bool mRequestInProgress{false};
60 bool mEverBeenCaptive{false};
62 uint32_t mDelay{kDefaultInterval};
63 int32_t mSlackCount{0};
65 uint32_t mMinInterval{kDefaultInterval};
66 uint32_t mMaxInterval{25 * kDefaultInterval};
67 float mBackoffFactor{5.0};
69 void StateTransition(int32_t aNewState);
71 // This holds a timestamp when the last time when the captive portal check
72 // has changed state.
73 mozilla::TimeStamp mLastChecked;
76 } // namespace net
77 } // namespace mozilla
79 #endif // CaptivePortalService_h_