OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ |
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "net/url_request/url_fetcher.h" | 9 #include "net/url_request/url_fetcher.h" |
10 | 10 |
11 namespace chromeos { | 11 namespace chromeos { |
12 | 12 |
13 class Network; | 13 class NetworkState; |
14 | 14 |
15 // This class handles all notifications about network changes from | 15 // This class handles all notifications about network changes from |
16 // NetworkLibrary and delegates portal detection for the active | 16 // NetworkLibrary and delegates portal detection for the active |
17 // network to CaptivePortalService. | 17 // network to CaptivePortalService. |
18 class NetworkPortalDetector { | 18 class NetworkPortalDetector { |
19 public: | 19 public: |
20 enum CaptivePortalStatus { | 20 enum CaptivePortalStatus { |
21 CAPTIVE_PORTAL_STATUS_UNKNOWN = 0, | 21 CAPTIVE_PORTAL_STATUS_UNKNOWN = 0, |
22 CAPTIVE_PORTAL_STATUS_OFFLINE = 1, | 22 CAPTIVE_PORTAL_STATUS_OFFLINE = 1, |
23 CAPTIVE_PORTAL_STATUS_ONLINE = 2, | 23 CAPTIVE_PORTAL_STATUS_ONLINE = 2, |
(...skipping 15 matching lines...) Expand all Loading... |
39 class Observer { | 39 class Observer { |
40 public: | 40 public: |
41 // Called when portal detection is completed for |network|, or | 41 // Called when portal detection is completed for |network|, or |
42 // when observers add themselves via AddAndFireObserver(). In the | 42 // when observers add themselves via AddAndFireObserver(). In the |
43 // second case, |network| is the active network and |state| is a | 43 // second case, |network| is the active network and |state| is a |
44 // current portal state for the active network, which can be | 44 // current portal state for the active network, which can be |
45 // currently in the unknown state, for instance, if portal | 45 // currently in the unknown state, for instance, if portal |
46 // detection is in process for the active network. Note, that | 46 // detection is in process for the active network. Note, that |
47 // |network| may be NULL. | 47 // |network| may be NULL. |
48 virtual void OnPortalDetectionCompleted( | 48 virtual void OnPortalDetectionCompleted( |
49 const Network* network, | 49 const NetworkState* network, |
50 const CaptivePortalState& state) = 0; | 50 const CaptivePortalState& state) = 0; |
51 | 51 |
52 protected: | 52 protected: |
53 virtual ~Observer() {} | 53 virtual ~Observer() {} |
54 }; | 54 }; |
55 | 55 |
56 virtual void Init() = 0; | 56 virtual void Init() = 0; |
57 virtual void Shutdown() = 0; | 57 virtual void Shutdown() = 0; |
58 | 58 |
59 // Adds |observer| to the observers list. | 59 // Adds |observer| to the observers list. |
60 virtual void AddObserver(Observer* observer) = 0; | 60 virtual void AddObserver(Observer* observer) = 0; |
61 | 61 |
62 // Adds |observer| to the observers list and immediately calls | 62 // Adds |observer| to the observers list and immediately calls |
63 // OnPortalDetectionCompleted() with the active network (which may | 63 // OnPortalDetectionCompleted() with the active network (which may |
64 // be NULL) and captive portal state for the active network (which | 64 // be NULL) and captive portal state for the active network (which |
65 // may be unknown, if, for instance, portal detection is in process | 65 // may be unknown, if, for instance, portal detection is in process |
66 // for the active network). | 66 // for the active network). |
67 // | 67 // |
68 // WARNING: don't call this method from the Observer's ctors or | 68 // WARNING: don't call this method from the Observer's ctors or |
69 // dtors, as it implicitly calls OnPortalDetectionCompleted(), which | 69 // dtors, as it implicitly calls OnPortalDetectionCompleted(), which |
70 // is virtual. | 70 // is virtual. |
71 // TODO (ygorshenin@): find a way to avoid this restriction. | 71 // TODO (ygorshenin@): find a way to avoid this restriction. |
72 virtual void AddAndFireObserver(Observer* observer) = 0; | 72 virtual void AddAndFireObserver(Observer* observer) = 0; |
73 | 73 |
74 // Removes |observer| from the observers list. | 74 // Removes |observer| from the observers list. |
75 virtual void RemoveObserver(Observer* observer) = 0; | 75 virtual void RemoveObserver(Observer* observer) = 0; |
76 | 76 |
77 // Returns Captive Portal state for a given |network|. | 77 // Returns Captive Portal state for a given |network|. |
78 virtual CaptivePortalState GetCaptivePortalState( | 78 virtual CaptivePortalState GetCaptivePortalState( |
79 const chromeos::Network* network) = 0; | 79 const chromeos::NetworkState* network) = 0; |
80 | 80 |
81 // Returns true if portal detection is enabled. | 81 // Returns true if portal detection is enabled. |
82 virtual bool IsEnabled() = 0; | 82 virtual bool IsEnabled() = 0; |
83 | 83 |
84 // Enable portal detection. This method is needed because we can't | 84 // Enable portal detection. This method is needed because we can't |
85 // check current network for portal state unless user accepts EULA. | 85 // check current network for portal state unless user accepts EULA. |
86 // If |start_detection| is true and NetworkPortalDetector was | 86 // If |start_detection| is true and NetworkPortalDetector was |
87 // disabled previously, portal detection for the active network is | 87 // disabled previously, portal detection for the active network is |
88 // initiated by this method. | 88 // initiated by this method. |
89 virtual void Enable(bool start_detection) = 0; | 89 virtual void Enable(bool start_detection) = 0; |
(...skipping 23 matching lines...) Expand all Loading... |
113 NetworkPortalDetector(); | 113 NetworkPortalDetector(); |
114 virtual ~NetworkPortalDetector(); | 114 virtual ~NetworkPortalDetector(); |
115 | 115 |
116 private: | 116 private: |
117 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector); | 117 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector); |
118 }; | 118 }; |
119 | 119 |
120 } // namespace chromeos | 120 } // namespace chromeos |
121 | 121 |
122 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ | 122 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ |
OLD | NEW |