summaryrefslogtreecommitdiffstats
path: root/netwerk/base/CaptivePortalService.h
blob: 9edd0752df6e45da5dc8016259af57254ac41d47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CaptivePortalService_h_
#define CaptivePortalService_h_

#include "nsICaptivePortalService.h"
#include "nsICaptivePortalDetector.h"
#include "nsINamed.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsITimer.h"
#include "nsCOMArray.h"
#include "mozilla/TimeStamp.h"

namespace mozilla {
namespace net {

class CaptivePortalService : public nsICaptivePortalService,
                             public nsIObserver,
                             public nsSupportsWeakReference,
                             public nsITimerCallback,
                             public nsICaptivePortalCallback,
                             public nsINamed {
 public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSICAPTIVEPORTALSERVICE
  NS_DECL_NSIOBSERVER
  NS_DECL_NSITIMERCALLBACK
  NS_DECL_NSICAPTIVEPORTALCALLBACK
  NS_DECL_NSINAMED

  nsresult Initialize();
  nsresult Start();
  nsresult Stop();

  static already_AddRefed<nsICaptivePortalService> GetSingleton();

  // This method is only called in the content process, in order to mirror
  // the captive portal state in the parent process.
  void SetStateInChild(int32_t aState);

 private:
  CaptivePortalService();
  virtual ~CaptivePortalService();
  nsresult PerformCheck();
  nsresult RearmTimer();
  void NotifyConnectivityAvailable(bool aCaptive);

  nsCOMPtr<nsICaptivePortalDetector> mCaptivePortalDetector;
  int32_t mState;

  nsCOMPtr<nsITimer> mTimer;
  bool mStarted;
  bool mInitialized;
  bool mRequestInProgress;
  bool mEverBeenCaptive;

  uint32_t mDelay;
  int32_t mSlackCount;

  uint32_t mMinInterval;
  uint32_t mMaxInterval;
  float mBackoffFactor;

  // This holds a timestamp when the last time when the captive portal check
  // has changed state.
  mozilla::TimeStamp mLastChecked;
};

}  // namespace net
}  // namespace mozilla

#endif  // CaptivePortalService_h_