| 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 "chrome/browser/chromeos/login/screens/error_screen.h" | 9 #include "chrome/browser/chromeos/login/screens/error_screen.h" |
| 10 #include "components/captive_portal/captive_portal_types.h" |
| 10 #include "net/url_request/url_fetcher.h" | 11 #include "net/url_request/url_fetcher.h" |
| 11 | 12 |
| 12 namespace chromeos { | 13 namespace chromeos { |
| 13 | 14 |
| 14 class NetworkState; | 15 class NetworkState; |
| 15 | 16 |
| 16 // This class handles all notifications about network changes from | 17 // This class handles all notifications about network changes from |
| 17 // NetworkStateHandler and delegates portal detection for the active | 18 // NetworkStateHandler and delegates portal detection for the active |
| 18 // network to CaptivePortalService. | 19 // network to CaptivePortalService. |
| 19 class NetworkPortalDetector : public ErrorScreen::Observer { | 20 class NetworkPortalDetector : public ErrorScreen::Observer { |
| 20 public: | 21 public: |
| 21 enum CaptivePortalStatus { | |
| 22 CAPTIVE_PORTAL_STATUS_UNKNOWN = 0, | |
| 23 CAPTIVE_PORTAL_STATUS_OFFLINE = 1, | |
| 24 CAPTIVE_PORTAL_STATUS_ONLINE = 2, | |
| 25 CAPTIVE_PORTAL_STATUS_PORTAL = 3, | |
| 26 CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED = 4, | |
| 27 CAPTIVE_PORTAL_STATUS_COUNT | |
| 28 }; | |
| 29 | |
| 30 struct CaptivePortalState { | 22 struct CaptivePortalState { |
| 31 CaptivePortalState() | 23 CaptivePortalState() |
| 32 : status(CAPTIVE_PORTAL_STATUS_UNKNOWN), | 24 : status(captive_portal::CAPTIVE_PORTAL_STATUS_UNKNOWN), |
| 33 response_code(net::URLFetcher::RESPONSE_CODE_INVALID) { | 25 response_code(net::URLFetcher::RESPONSE_CODE_INVALID) { |
| 34 } | 26 } |
| 35 | 27 |
| 36 bool operator==(const CaptivePortalState& o) const { | 28 bool operator==(const CaptivePortalState& o) const { |
| 37 return status == o.status && response_code == o.response_code; | 29 return status == o.status && response_code == o.response_code; |
| 38 } | 30 } |
| 39 | 31 |
| 40 CaptivePortalStatus status; | 32 captive_portal::CaptivePortalStatus status; |
| 41 int response_code; | 33 int response_code; |
| 42 base::TimeTicks time; | 34 base::TimeTicks time; |
| 43 }; | 35 }; |
| 44 | 36 |
| 45 class Observer { | 37 class Observer { |
| 46 public: | 38 public: |
| 47 // Called when portal detection is completed for |network|, or | 39 // Called when portal detection is completed for |network|, or |
| 48 // when observers add themselves via AddAndFireObserver(). In the | 40 // when observers add themselves via AddAndFireObserver(). In the |
| 49 // second case, |network| is the active network and |state| is a | 41 // second case, |network| is the active network and |state| is a |
| 50 // current portal state for the active network, which can be | 42 // current portal state for the active network, which can be |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 102 |
| 111 // Deletes the instance of the NetworkPortalDetector. | 103 // Deletes the instance of the NetworkPortalDetector. |
| 112 static void Shutdown(); | 104 static void Shutdown(); |
| 113 | 105 |
| 114 // Gets the instance of the NetworkPortalDetector. Return value should | 106 // Gets the instance of the NetworkPortalDetector. Return value should |
| 115 // be used carefully in tests, because it can be changed "on the fly" | 107 // be used carefully in tests, because it can be changed "on the fly" |
| 116 // by calls to InitializeForTesting(). | 108 // by calls to InitializeForTesting(). |
| 117 static NetworkPortalDetector* Get(); | 109 static NetworkPortalDetector* Get(); |
| 118 | 110 |
| 119 // Returns non-localized string representation of |status|. | 111 // Returns non-localized string representation of |status|. |
| 120 static std::string CaptivePortalStatusString(CaptivePortalStatus status); | 112 static std::string CaptivePortalStatusString( |
| 113 captive_portal::CaptivePortalStatus status); |
| 121 | 114 |
| 122 // Returns |true| if NetworkPortalDetector was Initialized and it is safe to | 115 // Returns |true| if NetworkPortalDetector was Initialized and it is safe to |
| 123 // call Get. | 116 // call Get. |
| 124 static bool IsInitialized(); | 117 static bool IsInitialized(); |
| 125 | 118 |
| 126 protected: | 119 protected: |
| 127 NetworkPortalDetector() {} | 120 NetworkPortalDetector() {} |
| 128 virtual ~NetworkPortalDetector() {} | 121 virtual ~NetworkPortalDetector() {} |
| 129 | 122 |
| 130 private: | 123 private: |
| 131 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector); | 124 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector); |
| 132 }; | 125 }; |
| 133 | 126 |
| 134 } // namespace chromeos | 127 } // namespace chromeos |
| 135 | 128 |
| 136 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ | 129 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ |
| OLD | NEW |