| 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 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" | 5 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/chromeos/cros/cros_library.h" | 8 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 9 #include "chrome/browser/chromeos/cros/network_library.h" | 9 #include "chrome/browser/chromeos/cros/network_library.h" |
| 10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
| 11 #include "chromeos/network/network_state.h" | 11 #include "chromeos/network/network_state.h" |
| 12 #include "chromeos/network/network_state_handler.h" | 12 #include "chromeos/network/network_state_handler.h" |
| 13 #include "chromeos/network/network_state_handler_observer.h" | 13 #include "chromeos/network/network_state_handler_observer.h" |
| 14 #include "third_party/cros_system_api/dbus/service_constants.h" | 14 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 | 17 |
| 18 static ConnectivityStateHelper* g_connectivity_state_helper = NULL; | 18 static ConnectivityStateHelper* g_connectivity_state_helper = NULL; |
| 19 static ConnectivityStateHelper* g_test_connectivity_state_helper = NULL; |
| 19 | 20 |
| 20 // Implementation of the connectivity state helper that uses the network | 21 // Implementation of the connectivity state helper that uses the network |
| 21 // state handler for fetching connectivity state. | 22 // state handler for fetching connectivity state. |
| 22 class ConnectivityStateHelperImpl | 23 class ConnectivityStateHelperImpl |
| 23 : public ConnectivityStateHelper, | 24 : public ConnectivityStateHelper, |
| 24 public NetworkStateHandlerObserver { | 25 public NetworkStateHandlerObserver { |
| 25 public: | 26 public: |
| 26 ConnectivityStateHelperImpl(); | 27 ConnectivityStateHelperImpl(); |
| 27 virtual ~ConnectivityStateHelperImpl(); | 28 virtual ~ConnectivityStateHelperImpl(); |
| 28 | 29 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 if (CommandLine::ForCurrentProcess()->HasSwitch( | 80 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 80 chromeos::switches::kEnableNewNetworkChangeNotifier)) { | 81 chromeos::switches::kEnableNewNetworkChangeNotifier)) { |
| 81 g_connectivity_state_helper = new ConnectivityStateHelperImpl(); | 82 g_connectivity_state_helper = new ConnectivityStateHelperImpl(); |
| 82 } else { | 83 } else { |
| 83 g_connectivity_state_helper = | 84 g_connectivity_state_helper = |
| 84 new ConnectivityStateHelperNetworkLibrary(); | 85 new ConnectivityStateHelperNetworkLibrary(); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 // static | 89 // static |
| 89 void ConnectivityStateHelper::InitializeForTesting( | |
| 90 ConnectivityStateHelper* connectivity_state_helper) { | |
| 91 CHECK(!g_connectivity_state_helper); | |
| 92 CHECK(connectivity_state_helper); | |
| 93 g_connectivity_state_helper = connectivity_state_helper; | |
| 94 } | |
| 95 | |
| 96 // static | |
| 97 bool ConnectivityStateHelper::IsInitialized() { | 90 bool ConnectivityStateHelper::IsInitialized() { |
| 98 return g_connectivity_state_helper != NULL; | 91 return g_connectivity_state_helper != NULL; |
| 99 } | 92 } |
| 100 | 93 |
| 101 // static | 94 // static |
| 102 void ConnectivityStateHelper::Shutdown() { | 95 void ConnectivityStateHelper::Shutdown() { |
| 103 CHECK(g_connectivity_state_helper); | 96 CHECK(g_connectivity_state_helper); |
| 104 delete g_connectivity_state_helper; | 97 delete g_connectivity_state_helper; |
| 105 g_connectivity_state_helper = NULL; | 98 g_connectivity_state_helper = NULL; |
| 106 } | 99 } |
| 107 | 100 |
| 108 // static | 101 // static |
| 109 ConnectivityStateHelper* ConnectivityStateHelper::Get() { | 102 ConnectivityStateHelper* ConnectivityStateHelper::Get() { |
| 110 CHECK(g_connectivity_state_helper) | 103 CHECK(g_connectivity_state_helper || g_test_connectivity_state_helper) |
| 111 << "ConnectivityStateHelper: Get() called before Initialize()"; | 104 << "ConnectivityStateHelper: Get() called before Initialize()"; |
| 105 if (g_test_connectivity_state_helper) |
| 106 return g_test_connectivity_state_helper; |
| 112 return g_connectivity_state_helper; | 107 return g_connectivity_state_helper; |
| 113 } | 108 } |
| 114 | 109 |
| 110 // static |
| 111 void ConnectivityStateHelper::SetForTest(ConnectivityStateHelper* impl) { |
| 112 CHECK(!g_test_connectivity_state_helper || !impl); |
| 113 g_test_connectivity_state_helper = impl; |
| 114 } |
| 115 |
| 115 void ConnectivityStateHelper::AddNetworkManagerObserver( | 116 void ConnectivityStateHelper::AddNetworkManagerObserver( |
| 116 ConnectivityStateHelperObserver* observer) { | 117 ConnectivityStateHelperObserver* observer) { |
| 117 network_manager_observers_.AddObserver(observer); | 118 network_manager_observers_.AddObserver(observer); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void ConnectivityStateHelper::RemoveNetworkManagerObserver( | 121 void ConnectivityStateHelper::RemoveNetworkManagerObserver( |
| 121 ConnectivityStateHelperObserver* observer) { | 122 ConnectivityStateHelperObserver* observer) { |
| 122 network_manager_observers_.RemoveObserver(observer); | 123 network_manager_observers_.RemoveObserver(observer); |
| 123 } | 124 } |
| 124 | 125 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 network_library_->RequestNetworkScan(); | 260 network_library_->RequestNetworkScan(); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void ConnectivityStateHelperNetworkLibrary::OnNetworkManagerChanged( | 263 void ConnectivityStateHelperNetworkLibrary::OnNetworkManagerChanged( |
| 263 NetworkLibrary* network_library) { | 264 NetworkLibrary* network_library) { |
| 264 FOR_EACH_OBSERVER(ConnectivityStateHelperObserver, network_manager_observers_, | 265 FOR_EACH_OBSERVER(ConnectivityStateHelperObserver, network_manager_observers_, |
| 265 NetworkManagerChanged()); | 266 NetworkManagerChanged()); |
| 266 } | 267 } |
| 267 | 268 |
| 268 } // namespace chromeos | 269 } // namespace chromeos |
| OLD | NEW |