| 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_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 // NetworkPortalDetector implementation: | 67 // NetworkPortalDetector implementation: |
| 68 virtual void AddObserver(Observer* observer) OVERRIDE; | 68 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 69 virtual void AddAndFireObserver(Observer* observer) OVERRIDE; | 69 virtual void AddAndFireObserver(Observer* observer) OVERRIDE; |
| 70 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 70 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 71 virtual CaptivePortalState GetCaptivePortalState( | 71 virtual CaptivePortalState GetCaptivePortalState( |
| 72 const std::string& service_path) OVERRIDE; | 72 const std::string& service_path) OVERRIDE; |
| 73 virtual bool IsEnabled() OVERRIDE; | 73 virtual bool IsEnabled() OVERRIDE; |
| 74 virtual void Enable(bool start_detection) OVERRIDE; | 74 virtual void Enable(bool start_detection) OVERRIDE; |
| 75 virtual bool StartDetectionIfIdle() OVERRIDE; | 75 virtual bool StartDetectionIfIdle() OVERRIDE; |
| 76 virtual void SetStrategy(PortalDetectorStrategy::StrategyId id) OVERRIDE; |
| 76 | 77 |
| 77 // NetworkStateHandlerObserver implementation: | 78 // NetworkStateHandlerObserver implementation: |
| 78 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; | 79 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; |
| 79 | 80 |
| 80 // PortalDetectorStrategy::Delegate implementation: | 81 // PortalDetectorStrategy::Delegate implementation: |
| 81 virtual int AttemptCount() OVERRIDE; | 82 virtual int AttemptCount() OVERRIDE; |
| 82 virtual base::TimeTicks AttemptStartTime() OVERRIDE; | 83 virtual base::TimeTicks AttemptStartTime() OVERRIDE; |
| 83 virtual base::TimeTicks GetCurrentTimeTicks() OVERRIDE; | 84 virtual base::TimeTicks GetCurrentTimeTicks() OVERRIDE; |
| 84 | 85 |
| 85 // ErrorScreen::Observer implementation: | |
| 86 virtual void OnErrorScreenShow() OVERRIDE; | |
| 87 virtual void OnErrorScreenHide() OVERRIDE; | |
| 88 | |
| 89 private: | 86 private: |
| 90 friend class NetworkPortalDetectorImplTest; | 87 friend class NetworkPortalDetectorImplTest; |
| 91 friend class NetworkPortalDetectorImplBrowserTest; | 88 friend class NetworkPortalDetectorImplBrowserTest; |
| 92 | 89 |
| 93 typedef std::string NetworkId; | 90 typedef std::string NetworkId; |
| 94 typedef base::hash_map<NetworkId, CaptivePortalState> CaptivePortalStateMap; | 91 typedef base::hash_map<NetworkId, CaptivePortalState> CaptivePortalStateMap; |
| 95 | 92 |
| 96 enum State { | 93 enum State { |
| 97 // No portal check is running. | 94 // No portal check is running. |
| 98 STATE_IDLE = 0, | 95 STATE_IDLE = 0, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const content::NotificationDetails& details) OVERRIDE; | 130 const content::NotificationDetails& details) OVERRIDE; |
| 134 | 131 |
| 135 // Stores captive portal state for a |network| and notifies observers. | 132 // Stores captive portal state for a |network| and notifies observers. |
| 136 void OnDetectionCompleted(const NetworkState* network, | 133 void OnDetectionCompleted(const NetworkState* network, |
| 137 const CaptivePortalState& results); | 134 const CaptivePortalState& results); |
| 138 | 135 |
| 139 // Notifies observers that portal detection is completed for a |network|. | 136 // Notifies observers that portal detection is completed for a |network|. |
| 140 void NotifyDetectionCompleted(const NetworkState* network, | 137 void NotifyDetectionCompleted(const NetworkState* network, |
| 141 const CaptivePortalState& state); | 138 const CaptivePortalState& state); |
| 142 | 139 |
| 143 // Updates current detection strategy according to the curren state: | |
| 144 // error screen, login screen or user session. | |
| 145 void UpdateCurrentStrategy(); | |
| 146 | |
| 147 // Sets current strategy according to |id|. If current detection id | |
| 148 // doesn't equal to |id|, detection is restarted. | |
| 149 void SetStrategy(PortalDetectorStrategy::StrategyId id); | |
| 150 | |
| 151 State state() const { return state_; } | 140 State state() const { return state_; } |
| 152 | 141 |
| 153 bool is_idle() const { | 142 bool is_idle() const { |
| 154 return state_ == STATE_IDLE; | 143 return state_ == STATE_IDLE; |
| 155 } | 144 } |
| 156 bool is_portal_check_pending() const { | 145 bool is_portal_check_pending() const { |
| 157 return state_ == STATE_PORTAL_CHECK_PENDING; | 146 return state_ == STATE_PORTAL_CHECK_PENDING; |
| 158 } | 147 } |
| 159 bool is_checking_for_portal() const { | 148 bool is_checking_for_portal() const { |
| 160 return state_ == STATE_CHECKING_FOR_PORTAL; | 149 return state_ == STATE_CHECKING_FOR_PORTAL; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 219 |
| 231 // Number of already performed detection attempts. | 220 // Number of already performed detection attempts. |
| 232 int attempt_count_; | 221 int attempt_count_; |
| 233 | 222 |
| 234 // Delay before next portal detection. | 223 // Delay before next portal detection. |
| 235 base::TimeDelta next_attempt_delay_; | 224 base::TimeDelta next_attempt_delay_; |
| 236 | 225 |
| 237 // Current detection strategy. | 226 // Current detection strategy. |
| 238 scoped_ptr<PortalDetectorStrategy> strategy_; | 227 scoped_ptr<PortalDetectorStrategy> strategy_; |
| 239 | 228 |
| 240 // True when error screen is displayed. | |
| 241 bool error_screen_displayed_; | |
| 242 | |
| 243 // UI notification controller about captive portal state. | 229 // UI notification controller about captive portal state. |
| 244 NetworkPortalNotificationController notification_controller_; | 230 NetworkPortalNotificationController notification_controller_; |
| 245 | 231 |
| 246 content::NotificationRegistrar registrar_; | 232 content::NotificationRegistrar registrar_; |
| 247 | 233 |
| 248 // Test time ticks used by unit tests. | 234 // Test time ticks used by unit tests. |
| 249 base::TimeTicks time_ticks_for_testing_; | 235 base::TimeTicks time_ticks_for_testing_; |
| 250 | 236 |
| 251 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl); | 237 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl); |
| 252 }; | 238 }; |
| 253 | 239 |
| 254 } // namespace chromeos | 240 } // namespace chromeos |
| 255 | 241 |
| 256 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ | 242 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ |
| OLD | NEW |