Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: ash/system/chromeos/network/network_state_notifier.cc

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Add NetworkConnectionHandler to NetworkHandler Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/system/chromeos/network/network_observer.h" 9 #include "ash/system/chromeos/network/network_observer.h"
10 #include "ash/system/tray/system_tray_notifier.h" 10 #include "ash/system/tray/system_tray_notifier.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/string16.h" 12 #include "base/string16.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chromeos/network/network_event_log.h" 15 #include "chromeos/network/network_event_log.h"
16 #include "chromeos/network/network_state.h" 16 #include "chromeos/network/network_state.h"
17 #include "chromeos/network/network_state_handler.h" 17 #include "chromeos/network/network_state_handler.h"
18 #include "grit/ash_strings.h" 18 #include "grit/ash_strings.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h" 19 #include "third_party/cros_system_api/dbus/service_constants.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 21
22 using chromeos::NetworkHandler;
22 using chromeos::NetworkState; 23 using chromeos::NetworkState;
23 using chromeos::NetworkStateHandler; 24 using chromeos::NetworkStateHandler;
24 25
25 namespace { 26 namespace {
26 27
27 const char kLogModule[] = "NetworkStateNotifier"; 28 const char kLogModule[] = "NetworkStateNotifier";
28 29
29 const int kMinTimeBetweenOutOfCreditsNotifySeconds = 10 * 60; 30 const int kMinTimeBetweenOutOfCreditsNotifySeconds = 10 * 60;
30 31
31 ash::NetworkObserver::NetworkType GetAshNetworkType( 32 ash::NetworkObserver::NetworkType GetAshNetworkType(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 UTF8ToUTF16(error)); 105 UTF8ToUTF16(error));
105 } 106 }
106 107
107 } // namespace 108 } // namespace
108 109
109 namespace ash { 110 namespace ash {
110 namespace internal { 111 namespace internal {
111 112
112 NetworkStateNotifier::NetworkStateNotifier() 113 NetworkStateNotifier::NetworkStateNotifier()
113 : cellular_out_of_credits_(false) { 114 : cellular_out_of_credits_(false) {
114 if (!NetworkStateHandler::Get()) 115 NetworkHandler::Get()->network_state_handler()->AddObserver(this);
115 return;
116 NetworkStateHandler::Get()->AddObserver(this);
117 InitializeNetworks(); 116 InitializeNetworks();
118 } 117 }
119 118
120 NetworkStateNotifier::~NetworkStateNotifier() { 119 NetworkStateNotifier::~NetworkStateNotifier() {
121 if (NetworkStateHandler::Get()) 120 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this);
122 NetworkStateHandler::Get()->RemoveObserver(this);
123 } 121 }
124 122
125 void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) { 123 void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) {
126 if (!network || !network->IsConnectedState()) 124 if (!network || !network->IsConnectedState())
127 return; 125 return;
128 if (network->path() != last_active_network_) { 126 if (network->path() != last_active_network_) {
129 last_active_network_ = network->path(); 127 last_active_network_ = network->path();
130 // Reset state for new connected network 128 // Reset state for new connected network
131 cellular_out_of_credits_ = false; 129 cellular_out_of_credits_ = false;
132 } 130 }
133 } 131 }
134 132
135 void NetworkStateNotifier::NetworkConnectionStateChanged( 133 void NetworkStateNotifier::NetworkConnectionStateChanged(
136 const NetworkState* network) { 134 const NetworkState* network) {
137 NetworkStateHandler* handler = NetworkStateHandler::Get(); 135 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
138 std::string prev_state; 136 std::string prev_state;
139 std::string new_state = network->connection_state(); 137 std::string new_state = network->connection_state();
140 CachedStateMap::iterator iter = cached_state_.find(network->path()); 138 CachedStateMap::iterator iter = cached_state_.find(network->path());
141 if (iter != cached_state_.end()) { 139 if (iter != cached_state_.end()) {
142 prev_state = iter->second; 140 prev_state = iter->second;
143 if (prev_state == new_state) 141 if (prev_state == new_state)
144 return; // No state change 142 return; // No state change
145 VLOG(1) << "NetworkStateNotifier: State: " << prev_state 143 VLOG(1) << "NetworkStateNotifier: State: " << prev_state
146 << " ->: " << new_state; 144 << " ->: " << new_state;
147 iter->second = new_state; 145 iter->second = new_state;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 Shell::GetInstance()->system_tray_delegate()->ConnectToNetwork( 215 Shell::GetInstance()->system_tray_delegate()->ConnectToNetwork(
218 cellular_network_); 216 cellular_network_);
219 } 217 }
220 ash::Shell::GetInstance()->system_tray_notifier()-> 218 ash::Shell::GetInstance()->system_tray_notifier()->
221 NotifyClearNetworkMessage(message_type); 219 NotifyClearNetworkMessage(message_type);
222 } 220 }
223 } 221 }
224 222
225 void NetworkStateNotifier::InitializeNetworks() { 223 void NetworkStateNotifier::InitializeNetworks() {
226 NetworkStateList network_list; 224 NetworkStateList network_list;
227 NetworkStateHandler::Get()->GetNetworkList(&network_list); 225 NetworkHandler::Get()->network_state_handler()->GetNetworkList(&network_list);
228 VLOG(1) << "NetworkStateNotifier:InitializeNetworks: " 226 VLOG(1) << "NetworkStateNotifier:InitializeNetworks: "
229 << network_list.size(); 227 << network_list.size();
230 for (NetworkStateList::iterator iter = network_list.begin(); 228 for (NetworkStateList::iterator iter = network_list.begin();
231 iter != network_list.end(); ++iter) { 229 iter != network_list.end(); ++iter) {
232 const NetworkState* network = *iter; 230 const NetworkState* network = *iter;
233 VLOG(2) << " Network: " << network->path(); 231 VLOG(2) << " Network: " << network->path();
234 cached_state_[network->path()] = network->connection_state(); 232 cached_state_[network->path()] = network->connection_state();
235 } 233 }
236 const NetworkState* default_network = 234 const NetworkState* default_network =
237 NetworkStateHandler::Get()->DefaultNetwork(); 235 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
238 if (default_network && default_network->IsConnectedState()) 236 if (default_network && default_network->IsConnectedState())
239 last_active_network_ = default_network->path(); 237 last_active_network_ = default_network->path();
240 } 238 }
241 239
242 } // namespace internal 240 } // namespace internal
243 } // namespace ash 241 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698