CaptivePortalService.h (2283B)
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/. */ 4 5 #ifndef CaptivePortalService_h_ 6 #define CaptivePortalService_h_ 7 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" 16 17 namespace mozilla { 18 namespace net { 19 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 33 34 nsresult Initialize(); 35 nsresult Start(); 36 nsresult Stop(); 37 38 static already_AddRefed<nsICaptivePortalService> GetSingleton(); 39 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); 43 44 private: 45 static const uint32_t kDefaultInterval = 60 * 1000; // check every 60 seconds 46 47 CaptivePortalService(); 48 virtual ~CaptivePortalService(); 49 nsresult PerformCheck(); 50 nsresult RearmTimer(); 51 void NotifyConnectivityAvailable(bool aCaptive); 52 53 nsCOMPtr<nsICaptivePortalDetector> mCaptivePortalDetector; 54 int32_t mState{UNKNOWN}; 55 56 nsCOMPtr<nsITimer> mTimer; 57 bool mStarted{false}; 58 bool mInitialized{false}; 59 bool mRequestInProgress{false}; 60 bool mEverBeenCaptive{false}; 61 62 uint32_t mDelay{kDefaultInterval}; 63 int32_t mSlackCount{0}; 64 65 uint32_t mMinInterval{kDefaultInterval}; 66 uint32_t mMaxInterval{25 * kDefaultInterval}; 67 float mBackoffFactor{5.0}; 68 69 void StateTransition(int32_t aNewState); 70 71 // This holds a timestamp when the last time when the captive portal check 72 // has changed state. 73 mozilla::TimeStamp mLastChecked; 74 }; 75 76 } // namespace net 77 } // namespace mozilla 78 79 #endif // CaptivePortalService_h_