Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / net / network_portal_detector.cc
blob3a4c4658cac5e10b69cbdd233d78373be1a06695
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/net/network_portal_detector.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h"
11 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chromeos/chromeos_switches.h"
15 namespace chromeos {
17 namespace {
19 const char kCaptivePortalStatusUnknown[] = "Unknown";
20 const char kCaptivePortalStatusOffline[] = "Offline";
21 const char kCaptivePortalStatusOnline[] = "Online";
22 const char kCaptivePortalStatusPortal[] = "Portal";
23 const char kCaptivePortalStatusProxyAuthRequired[] = "ProxyAuthRequired";
24 const char kCaptivePortalStatusUnrecognized[] = "Unrecognized";
26 NetworkPortalDetector* g_network_portal_detector = NULL;
27 bool g_network_portal_detector_set_for_testing = false;
29 bool IsTestMode() {
30 return CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType);
33 // Stub implementation of NetworkPortalDetector.
34 class NetworkPortalDetectorStubImpl : public NetworkPortalDetector {
35 protected:
36 // NetworkPortalDetector implementation:
37 virtual void AddObserver(Observer* /* observer */) OVERRIDE {}
38 virtual void AddAndFireObserver(Observer* observer) OVERRIDE {
39 if (observer)
40 observer->OnPortalDetectionCompleted(NULL, CaptivePortalState());
42 virtual void RemoveObserver(Observer* /* observer */) OVERRIDE {}
43 virtual CaptivePortalState GetCaptivePortalState(
44 const std::string& /* service_path */) OVERRIDE {
45 return CaptivePortalState();
47 virtual bool IsEnabled() OVERRIDE { return false; }
48 virtual void Enable(bool /* start_detection */) OVERRIDE {}
49 virtual bool StartDetectionIfIdle() OVERRIDE { return false; }
52 } // namespace
54 void NetworkPortalDetector::InitializeForTesting(
55 NetworkPortalDetector* network_portal_detector) {
56 if (network_portal_detector) {
57 CHECK(!g_network_portal_detector_set_for_testing)
58 << "NetworkPortalDetector::InitializeForTesting is called twice";
59 CHECK(network_portal_detector);
60 delete g_network_portal_detector;
61 g_network_portal_detector = network_portal_detector;
62 g_network_portal_detector_set_for_testing = true;
63 } else {
64 g_network_portal_detector = NULL;
65 g_network_portal_detector_set_for_testing = false;
69 // static
70 void NetworkPortalDetector::Initialize() {
71 if (g_network_portal_detector_set_for_testing)
72 return;
73 CHECK(!g_network_portal_detector)
74 << "NetworkPortalDetector::Initialize() is called twice";
75 if (IsTestMode()) {
76 g_network_portal_detector = new NetworkPortalDetectorStubImpl();
77 } else {
78 CHECK(g_browser_process);
79 CHECK(g_browser_process->system_request_context());
80 g_network_portal_detector = new NetworkPortalDetectorImpl(
81 g_browser_process->system_request_context());
85 // static
86 void NetworkPortalDetector::Shutdown() {
87 CHECK(g_network_portal_detector || g_network_portal_detector_set_for_testing)
88 << "NetworkPortalDetectorImpl::Shutdown() is called "
89 << "without previous call to Initialize()";
90 delete g_network_portal_detector;
91 g_network_portal_detector = NULL;
94 // static
95 NetworkPortalDetector* NetworkPortalDetector::Get() {
96 CHECK(g_network_portal_detector)
97 << "NetworkPortalDetector::Get() called before Initialize()";
98 return g_network_portal_detector;
101 // static
102 std::string NetworkPortalDetector::CaptivePortalStatusString(
103 CaptivePortalStatus status) {
104 switch (status) {
105 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_UNKNOWN:
106 return kCaptivePortalStatusUnknown;
107 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_OFFLINE:
108 return kCaptivePortalStatusOffline;
109 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_ONLINE:
110 return kCaptivePortalStatusOnline;
111 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_PORTAL:
112 return kCaptivePortalStatusPortal;
113 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED:
114 return kCaptivePortalStatusProxyAuthRequired;
115 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_COUNT:
116 NOTREACHED();
118 return kCaptivePortalStatusUnrecognized;
121 // static
122 bool NetworkPortalDetector::IsInitialized() {
123 return g_network_portal_detector;
126 } // namespace chromeos