summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorachuith <achuith@chromium.org>2015-09-28 14:11:26 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-28 21:13:06 +0000
commit95786022884fbc4f6515956d9b832f455ede019d (patch)
tree46c422c6a4c9f5b6e763afac0e13621de2362bff /chromeos
parent38d41d3774fb9f74588dc7f23d27613eaf28c864 (diff)
downloadchromium_src-95786022884fbc4f6515956d9b832f455ede019d.zip
chromium_src-95786022884fbc4f6515956d9b832f455ede019d.tar.gz
chromium_src-95786022884fbc4f6515956d9b832f455ede019d.tar.bz2
Introduce namespace network_portal_detector.
* This houses previously static methods of NetworkPortalDetector, such as Get (now GetInstance), IsInitialized, InitializeForTesting, etc. * InitializeNetworkPortalDetector moved to cbmc * Number of renames of NetworkPortalDetector:: to network_portal_detector:: Files with non-trivial changes: network_portal_detector_impl.{cc|h} network_portal_detector.{cc|h} chrome_browser_main_chromeos.cc Everything else is a mechanical search/replace BUG=530485 TEST=unit tests and browser tests. TBR=kalman@chromium.org Review URL: https://codereview.chromium.org/1358343003 Cr-Commit-Position: refs/heads/master@{#351153}
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/network/portal_detector/network_portal_detector.cc79
-rw-r--r--chromeos/network/portal_detector/network_portal_detector.h75
2 files changed, 79 insertions, 75 deletions
diff --git a/chromeos/network/portal_detector/network_portal_detector.cc b/chromeos/network/portal_detector/network_portal_detector.cc
index a9af6ac..6fcbb3b 100644
--- a/chromeos/network/portal_detector/network_portal_detector.cc
+++ b/chromeos/network/portal_detector/network_portal_detector.cc
@@ -5,11 +5,15 @@
#include "chromeos/network/portal_detector/network_portal_detector.h"
#include "base/logging.h"
+#include "components/device_event_log/device_event_log.h"
namespace chromeos {
namespace {
+bool set_for_testing_ = false;
+NetworkPortalDetector* network_portal_detector_ = nullptr;
+
const char kCaptivePortalStatusUnknown[] = "Unknown";
const char kCaptivePortalStatusOffline[] = "Offline";
const char kCaptivePortalStatusOnline[] = "Online";
@@ -20,16 +24,30 @@ const char kCaptivePortalStatusUnrecognized[] = "Unrecognized";
} // namespace
// static
-bool NetworkPortalDetector::set_for_testing_ = false;
-NetworkPortalDetector* NetworkPortalDetector::network_portal_detector_ =
- nullptr;
+std::string NetworkPortalDetector::CaptivePortalStatusString(
+ CaptivePortalStatus status) {
+ switch (status) {
+ case CAPTIVE_PORTAL_STATUS_UNKNOWN:
+ return kCaptivePortalStatusUnknown;
+ case CAPTIVE_PORTAL_STATUS_OFFLINE:
+ return kCaptivePortalStatusOffline;
+ case CAPTIVE_PORTAL_STATUS_ONLINE:
+ return kCaptivePortalStatusOnline;
+ case CAPTIVE_PORTAL_STATUS_PORTAL:
+ return kCaptivePortalStatusPortal;
+ case CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED:
+ return kCaptivePortalStatusProxyAuthRequired;
+ case CAPTIVE_PORTAL_STATUS_COUNT:
+ NOTREACHED();
+ }
+ return kCaptivePortalStatusUnrecognized;
+}
-// static
-void NetworkPortalDetector::InitializeForTesting(
- NetworkPortalDetector* network_portal_detector) {
+namespace network_portal_detector {
+
+void InitializeForTesting(NetworkPortalDetector* network_portal_detector) {
if (network_portal_detector) {
- CHECK(!set_for_testing_)
- << "NetworkPortalDetector::InitializeForTesting is called twice";
+ CHECK(!set_for_testing_) << "InitializeForTesting is called twice";
delete network_portal_detector_;
network_portal_detector_ = network_portal_detector;
set_for_testing_ = true;
@@ -39,44 +57,33 @@ void NetworkPortalDetector::InitializeForTesting(
}
}
-// static
-bool NetworkPortalDetector::IsInitialized() {
- return NetworkPortalDetector::network_portal_detector_;
+bool IsInitialized() {
+ return network_portal_detector_;
}
-// static
-void NetworkPortalDetector::Shutdown() {
+bool SetForTesting() {
+ return set_for_testing_;
+}
+
+void Shutdown() {
CHECK(network_portal_detector_ || set_for_testing_)
- << "NetworkPortalDetector::Shutdown() called without Initialize()";
+ << "Shutdown() called without Initialize()";
delete network_portal_detector_;
network_portal_detector_ = nullptr;
}
-// static
-NetworkPortalDetector* NetworkPortalDetector::Get() {
- CHECK(network_portal_detector_)
- << "NetworkPortalDetector::Get() called before Initialize()";
+NetworkPortalDetector* GetInstance() {
+ CHECK(network_portal_detector_) << "GetInstance() called before Initialize()";
return network_portal_detector_;
}
-// static
-std::string NetworkPortalDetector::CaptivePortalStatusString(
- CaptivePortalStatus status) {
- switch (status) {
- case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN:
- return kCaptivePortalStatusUnknown;
- case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE:
- return kCaptivePortalStatusOffline;
- case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE:
- return kCaptivePortalStatusOnline;
- case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL:
- return kCaptivePortalStatusPortal;
- case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED:
- return kCaptivePortalStatusProxyAuthRequired;
- case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT:
- NOTREACHED();
- }
- return kCaptivePortalStatusUnrecognized;
+void SetNetworkPortalDetector(NetworkPortalDetector* network_portal_detector) {
+ CHECK(!network_portal_detector_)
+ << "NetworkPortalDetector was initialized twice.";
+ NET_LOG(EVENT) << "SetNetworkPortalDetector";
+ network_portal_detector_ = network_portal_detector;
}
+} // namespace network_portal_detector
+
} // namespace chromeos
diff --git a/chromeos/network/portal_detector/network_portal_detector.h b/chromeos/network/portal_detector/network_portal_detector.h
index 38843fe..611cb64 100644
--- a/chromeos/network/portal_detector/network_portal_detector.h
+++ b/chromeos/network/portal_detector/network_portal_detector.h
@@ -14,16 +14,16 @@ namespace chromeos {
class NetworkState;
-// This class handles all notifications about network changes from
-// NetworkStateHandler and delegates portal detection for the active
-// network to CaptivePortalService.
+// This is an interface for a chromeos portal detector that allows for
+// observation of captive portal state. It supports retries based on a portal
+// detector strategy.
class CHROMEOS_EXPORT NetworkPortalDetector {
public:
enum CaptivePortalStatus {
- CAPTIVE_PORTAL_STATUS_UNKNOWN = 0,
- CAPTIVE_PORTAL_STATUS_OFFLINE = 1,
- CAPTIVE_PORTAL_STATUS_ONLINE = 2,
- CAPTIVE_PORTAL_STATUS_PORTAL = 3,
+ CAPTIVE_PORTAL_STATUS_UNKNOWN = 0,
+ CAPTIVE_PORTAL_STATUS_OFFLINE = 1,
+ CAPTIVE_PORTAL_STATUS_ONLINE = 2,
+ CAPTIVE_PORTAL_STATUS_PORTAL = 3,
CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED = 4,
CAPTIVE_PORTAL_STATUS_COUNT
};
@@ -31,8 +31,7 @@ class CHROMEOS_EXPORT NetworkPortalDetector {
struct CaptivePortalState {
CaptivePortalState()
: status(CAPTIVE_PORTAL_STATUS_UNKNOWN),
- response_code(net::URLFetcher::RESPONSE_CODE_INVALID) {
- }
+ response_code(net::URLFetcher::RESPONSE_CODE_INVALID) {}
bool operator==(const CaptivePortalState& o) const {
return status == o.status && response_code == o.response_code;
@@ -60,6 +59,8 @@ class CHROMEOS_EXPORT NetworkPortalDetector {
virtual ~Observer() {}
};
+ virtual ~NetworkPortalDetector() {}
+
// Adds |observer| to the observers list.
virtual void AddObserver(Observer* observer) = 0;
@@ -107,43 +108,39 @@ class CHROMEOS_EXPORT NetworkPortalDetector {
// Returns non-localized string representation of |status|.
static std::string CaptivePortalStatusString(CaptivePortalStatus status);
- // Initializes network portal detector for testing. The
- // |network_portal_detector| will be owned by the internal pointer
- // and deleted by Shutdown().
- static void InitializeForTesting(
- NetworkPortalDetector* network_portal_detector);
+ protected:
+ NetworkPortalDetector() {}
- // Returns |true| if NetworkPortalDetector was Initialized and it is safe to
- // call Get.
- static bool IsInitialized();
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector);
+};
- // Deletes the instance of the NetworkPortalDetector.
- static void Shutdown();
+// Manages a global NetworkPortalDetector instance that can be accessed across
+// all ChromeOS components.
+namespace network_portal_detector {
+// Gets the instance of the NetworkPortalDetector. Return value should
+// be used carefully in tests, because it can be changed "on the fly"
+// by calls to InitializeForTesting().
+CHROMEOS_EXPORT NetworkPortalDetector* GetInstance();
- // Gets the instance of the NetworkPortalDetector. Return value should
- // be used carefully in tests, because it can be changed "on the fly"
- // by calls to InitializeForTesting().
- static NetworkPortalDetector* Get();
+// Returns |true| if NetworkPortalDetector was Initialized and it is safe to
+// call GetInstance.
+CHROMEOS_EXPORT bool IsInitialized();
- protected:
- NetworkPortalDetector() {}
- virtual ~NetworkPortalDetector() {}
+// Deletes the instance of the NetworkPortalDetector.
+CHROMEOS_EXPORT void Shutdown();
- static bool set_for_testing() { return set_for_testing_; }
- static NetworkPortalDetector* network_portal_detector() {
- return network_portal_detector_;
- }
- static void set_network_portal_detector(
- NetworkPortalDetector* network_portal_detector) {
- network_portal_detector_ = network_portal_detector;
- }
+CHROMEOS_EXPORT void SetNetworkPortalDetector(
+ NetworkPortalDetector* network_portal_detector);
- private:
- static bool set_for_testing_;
- static NetworkPortalDetector* network_portal_detector_;
+// Initializes network portal detector for testing. The
+// |network_portal_detector| will be owned by the internal pointer
+// and deleted by Shutdown().
+CHROMEOS_EXPORT void InitializeForTesting(
+ NetworkPortalDetector* network_portal_detector);
+CHROMEOS_EXPORT bool SetForTesting();
- DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector);
-};
+} // namespace network_portal_detector
} // namespace chromeos