OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/system/chromeos/network/network_state_notifier.h" | 5 #include "ash/system/chromeos/network/network_state_notifier.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/chromeos/network/network_observer.h" | 8 #include "ash/system/chromeos/network/network_observer.h" |
9 #include "ash/system/tray/system_tray_notifier.h" | 9 #include "ash/system/tray/system_tray_notifier.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chromeos/network/network_event_log.h" | 13 #include "chromeos/network/network_event_log.h" |
14 #include "chromeos/network/network_state.h" | 14 #include "chromeos/network/network_state.h" |
15 #include "chromeos/network/network_state_handler.h" | 15 #include "chromeos/network/network_state_handler.h" |
16 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 | 19 |
| 20 using chromeos::NetworkHandler; |
20 using chromeos::NetworkState; | 21 using chromeos::NetworkState; |
21 using chromeos::NetworkStateHandler; | 22 using chromeos::NetworkStateHandler; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 const int kMinTimeBetweenOutOfCreditsNotifySeconds = 10 * 60; | 26 const int kMinTimeBetweenOutOfCreditsNotifySeconds = 10 * 60; |
26 | 27 |
27 ash::NetworkObserver::NetworkType GetAshNetworkType( | 28 ash::NetworkObserver::NetworkType GetAshNetworkType( |
28 const NetworkState* network) { | 29 const NetworkState* network) { |
29 const std::string& type = network->type(); | 30 const std::string& type = network->type(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 UTF8ToUTF16(error)); | 101 UTF8ToUTF16(error)); |
101 } | 102 } |
102 | 103 |
103 } // namespace | 104 } // namespace |
104 | 105 |
105 namespace ash { | 106 namespace ash { |
106 namespace internal { | 107 namespace internal { |
107 | 108 |
108 NetworkStateNotifier::NetworkStateNotifier() | 109 NetworkStateNotifier::NetworkStateNotifier() |
109 : cellular_out_of_credits_(false) { | 110 : cellular_out_of_credits_(false) { |
110 if (!NetworkStateHandler::Get()) | 111 NetworkHandler::Get()->network_state_handler()->AddObserver(this); |
111 return; | |
112 NetworkStateHandler::Get()->AddObserver(this); | |
113 InitializeNetworks(); | 112 InitializeNetworks(); |
114 } | 113 } |
115 | 114 |
116 NetworkStateNotifier::~NetworkStateNotifier() { | 115 NetworkStateNotifier::~NetworkStateNotifier() { |
117 if (NetworkStateHandler::Get()) | 116 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this); |
118 NetworkStateHandler::Get()->RemoveObserver(this); | |
119 } | 117 } |
120 | 118 |
121 void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) { | 119 void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) { |
122 if (!network || !network->IsConnectedState()) | 120 if (!network || !network->IsConnectedState()) |
123 return; | 121 return; |
124 if (network->path() != last_active_network_) { | 122 if (network->path() != last_active_network_) { |
125 last_active_network_ = network->path(); | 123 last_active_network_ = network->path(); |
126 // Reset state for new connected network | 124 // Reset state for new connected network |
127 cellular_out_of_credits_ = false; | 125 cellular_out_of_credits_ = false; |
128 } | 126 } |
129 } | 127 } |
130 | 128 |
131 void NetworkStateNotifier::NetworkConnectionStateChanged( | 129 void NetworkStateNotifier::NetworkConnectionStateChanged( |
132 const NetworkState* network) { | 130 const NetworkState* network) { |
133 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 131 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
134 std::string prev_state; | 132 std::string prev_state; |
135 std::string new_state = network->connection_state(); | 133 std::string new_state = network->connection_state(); |
136 CachedStateMap::iterator iter = cached_state_.find(network->path()); | 134 CachedStateMap::iterator iter = cached_state_.find(network->path()); |
137 if (iter != cached_state_.end()) { | 135 if (iter != cached_state_.end()) { |
138 prev_state = iter->second; | 136 prev_state = iter->second; |
139 if (prev_state == new_state) | 137 if (prev_state == new_state) |
140 return; // No state change | 138 return; // No state change |
141 VLOG(1) << "NetworkStateNotifier: State: " << prev_state | 139 VLOG(1) << "NetworkStateNotifier: State: " << prev_state |
142 << " ->: " << new_state; | 140 << " ->: " << new_state; |
143 iter->second = new_state; | 141 iter->second = new_state; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( | 206 Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( |
209 cellular_network_); | 207 cellular_network_); |
210 } | 208 } |
211 ash::Shell::GetInstance()->system_tray_notifier()-> | 209 ash::Shell::GetInstance()->system_tray_notifier()-> |
212 NotifyClearNetworkMessage(message_type); | 210 NotifyClearNetworkMessage(message_type); |
213 } | 211 } |
214 } | 212 } |
215 | 213 |
216 void NetworkStateNotifier::InitializeNetworks() { | 214 void NetworkStateNotifier::InitializeNetworks() { |
217 NetworkStateList network_list; | 215 NetworkStateList network_list; |
218 NetworkStateHandler::Get()->GetNetworkList(&network_list); | 216 NetworkHandler::Get()->network_state_handler()->GetNetworkList(&network_list); |
219 VLOG(1) << "NetworkStateNotifier:InitializeNetworks: " | 217 VLOG(1) << "NetworkStateNotifier:InitializeNetworks: " |
220 << network_list.size(); | 218 << network_list.size(); |
221 for (NetworkStateList::iterator iter = network_list.begin(); | 219 for (NetworkStateList::iterator iter = network_list.begin(); |
222 iter != network_list.end(); ++iter) { | 220 iter != network_list.end(); ++iter) { |
223 const NetworkState* network = *iter; | 221 const NetworkState* network = *iter; |
224 VLOG(2) << " Network: " << network->path(); | 222 VLOG(2) << " Network: " << network->path(); |
225 cached_state_[network->path()] = network->connection_state(); | 223 cached_state_[network->path()] = network->connection_state(); |
226 } | 224 } |
227 const NetworkState* default_network = | 225 const NetworkState* default_network = |
228 NetworkStateHandler::Get()->DefaultNetwork(); | 226 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
229 if (default_network && default_network->IsConnectedState()) | 227 if (default_network && default_network->IsConnectedState()) |
230 last_active_network_ = default_network->path(); | 228 last_active_network_ = default_network->path(); |
231 } | 229 } |
232 | 230 |
233 } // namespace internal | 231 } // namespace internal |
234 } // namespace ash | 232 } // namespace ash |
OLD | NEW |