1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chromeos/network/portal_detector/network_portal_detector.h" 6 7 #include "base/logging.h" 8 9 namespace chromeos { 10 11 namespace { 12 13 const char kCaptivePortalStatusUnknown[] = "Unknown"; 14 const char kCaptivePortalStatusOffline[] = "Offline"; 15 const char kCaptivePortalStatusOnline[] = "Online"; 16 const char kCaptivePortalStatusPortal[] = "Portal"; 17 const char kCaptivePortalStatusProxyAuthRequired[] = "ProxyAuthRequired"; 18 const char kCaptivePortalStatusUnrecognized[] = "Unrecognized"; 19 20 } // namespace 21 22 // static 23 bool NetworkPortalDetector::set_for_testing_ = false; 24 NetworkPortalDetector* NetworkPortalDetector::network_portal_detector_ = NULL; 25 26 // static 27 void NetworkPortalDetector::InitializeForTesting( 28 NetworkPortalDetector* network_portal_detector) { 29 if (network_portal_detector) { 30 CHECK(!set_for_testing_) 31 << "NetworkPortalDetector::InitializeForTesting is called twice"; 32 CHECK(network_portal_detector); 33 delete network_portal_detector_; 34 network_portal_detector_ = network_portal_detector; 35 set_for_testing_ = true; 36 } else { 37 network_portal_detector_ = NULL; 38 set_for_testing_ = false; 39 } 40 } 41 42 // static 43 bool NetworkPortalDetector::IsInitialized() { 44 return NetworkPortalDetector::network_portal_detector_; 45 } 46 47 // static 48 void NetworkPortalDetector::Shutdown() { 49 CHECK(network_portal_detector_ || set_for_testing_) 50 << "NetworkPortalDetector::Shutdown() called without Initialize()"; 51 delete network_portal_detector_; 52 network_portal_detector_ = NULL; 53 } 54 55 // static 56 NetworkPortalDetector* NetworkPortalDetector::Get() { 57 CHECK(network_portal_detector_) 58 << "NetworkPortalDetector::Get() called before Initialize()"; 59 return network_portal_detector_; 60 } 61 62 // static 63 std::string NetworkPortalDetector::CaptivePortalStatusString( 64 CaptivePortalStatus status) { 65 switch (status) { 66 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: 67 return kCaptivePortalStatusUnknown; 68 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: 69 return kCaptivePortalStatusOffline; 70 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: 71 return kCaptivePortalStatusOnline; 72 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: 73 return kCaptivePortalStatusPortal; 74 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: 75 return kCaptivePortalStatusProxyAuthRequired; 76 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: 77 NOTREACHED(); 78 } 79 return kCaptivePortalStatusUnrecognized; 80 } 81 82 // NetworkPortalDetectorStubImpl 83 84 NetworkPortalDetectorStubImpl::NetworkPortalDetectorStubImpl() { 85 } 86 87 NetworkPortalDetectorStubImpl::~NetworkPortalDetectorStubImpl() { 88 } 89 90 void NetworkPortalDetectorStubImpl::AddObserver(Observer* /* observer */) { 91 } 92 93 void NetworkPortalDetectorStubImpl::AddAndFireObserver(Observer* observer) { 94 if (observer) 95 observer->OnPortalDetectionCompleted(NULL, CaptivePortalState()); 96 } 97 98 void NetworkPortalDetectorStubImpl::RemoveObserver(Observer* /* observer */) { 99 } 100 101 NetworkPortalDetector::CaptivePortalState 102 NetworkPortalDetectorStubImpl::GetCaptivePortalState( 103 const std::string& /* service_path */) { 104 return CaptivePortalState(); 105 } 106 107 bool NetworkPortalDetectorStubImpl::IsEnabled() { 108 return false; 109 } 110 111 void NetworkPortalDetectorStubImpl::Enable(bool /* start_detection */) { 112 } 113 114 bool NetworkPortalDetectorStubImpl::StartDetectionIfIdle() { 115 return false; 116 } 117 118 void NetworkPortalDetectorStubImpl::SetStrategy( 119 PortalDetectorStrategy::StrategyId /* id */) { 120 } 121 122 } // namespace chromeos 123