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"
11 #include "nsIObserver.h"
12 #include "nsWeakReference.h"
14 #include "nsCOMArray.h"
15 #include "mozilla/TimeStamp.h"
20 class CaptivePortalService
: public nsICaptivePortalService
,
22 public nsSupportsWeakReference
,
23 public nsITimerCallback
,
24 public nsICaptivePortalCallback
,
28 NS_DECL_NSICAPTIVEPORTALSERVICE
30 NS_DECL_NSITIMERCALLBACK
31 NS_DECL_NSICAPTIVEPORTALCALLBACK
34 nsresult
Initialize();
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
);
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
;
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
73 mozilla::TimeStamp mLastChecked
;
77 } // namespace mozilla
79 #endif // CaptivePortalService_h_