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

Side by Side Diff: chromeos/network/network_state_handler.cc

Issue 289383004: Merge FavoriteState into NetworkState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 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 "chromeos/network/network_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chromeos/network/device_state.h" 17 #include "chromeos/network/device_state.h"
18 #include "chromeos/network/favorite_state.h"
19 #include "chromeos/network/managed_state.h" 18 #include "chromeos/network/managed_state.h"
20 #include "chromeos/network/network_event_log.h" 19 #include "chromeos/network/network_event_log.h"
21 #include "chromeos/network/network_state.h" 20 #include "chromeos/network/network_state.h"
22 #include "chromeos/network/network_state_handler_observer.h" 21 #include "chromeos/network/network_state_handler_observer.h"
23 #include "chromeos/network/shill_property_handler.h" 22 #include "chromeos/network/shill_property_handler.h"
24 #include "third_party/cros_system_api/dbus/service_constants.h" 23 #include "third_party/cros_system_api/dbus/service_constants.h"
25 24
26 namespace chromeos { 25 namespace chromeos {
27 26
28 namespace { 27 namespace {
29 28
30 bool ConnectionStateChanged(NetworkState* network, 29 bool ConnectionStateChanged(NetworkState* network,
31 const std::string& prev_connection_state) { 30 const std::string& prev_connection_state) {
32 return (network->connection_state() != prev_connection_state) && 31 return (network->connection_state() != prev_connection_state) &&
33 (network->connection_state() != shill::kStateIdle || 32 (network->connection_state() != shill::kStateIdle ||
34 !prev_connection_state.empty()); 33 !prev_connection_state.empty());
35 } 34 }
36 35
37 std::string GetManagedStateLogType(const ManagedState* state) { 36 std::string GetManagedStateLogType(const ManagedState* state) {
38 switch (state->managed_type()) { 37 switch (state->managed_type()) {
39 case ManagedState::MANAGED_TYPE_NETWORK: 38 case ManagedState::MANAGED_TYPE_NETWORK:
40 return "Network"; 39 return "Network";
41 case ManagedState::MANAGED_TYPE_FAVORITE:
42 return "Favorite";
43 case ManagedState::MANAGED_TYPE_DEVICE: 40 case ManagedState::MANAGED_TYPE_DEVICE:
44 return "Device"; 41 return "Device";
45 } 42 }
46 NOTREACHED(); 43 NOTREACHED();
47 return ""; 44 return "";
48 } 45 }
49 46
50 std::string GetManagedStateLogName(const ManagedState* state) { 47 std::string GetLogName(const ManagedState* state) {
51 if (!state) 48 if (!state)
52 return "None"; 49 return "None";
53 return base::StringPrintf("%s (%s)", state->name().c_str(), 50 return base::StringPrintf("%s (%s)", state->name().c_str(),
54 state->path().c_str()); 51 state->path().c_str());
55 } 52 }
56 53
57 } // namespace 54 } // namespace
58 55
59 const char NetworkStateHandler::kDefaultCheckPortalList[] = 56 const char NetworkStateHandler::kDefaultCheckPortalList[] =
60 "ethernet,wifi,cellular"; 57 "ethernet,wifi,cellular";
61 58
62 NetworkStateHandler::NetworkStateHandler() { 59 NetworkStateHandler::NetworkStateHandler() {
63 } 60 }
64 61
65 NetworkStateHandler::~NetworkStateHandler() { 62 NetworkStateHandler::~NetworkStateHandler() {
66 STLDeleteContainerPointers(network_list_.begin(), network_list_.end()); 63 STLDeleteContainerPointers(network_list_.begin(), network_list_.end());
67 STLDeleteContainerPointers(favorite_list_.begin(), favorite_list_.end());
68 STLDeleteContainerPointers(device_list_.begin(), device_list_.end()); 64 STLDeleteContainerPointers(device_list_.begin(), device_list_.end());
69 } 65 }
70 66
71 void NetworkStateHandler::InitShillPropertyHandler() { 67 void NetworkStateHandler::InitShillPropertyHandler() {
72 shill_property_handler_.reset(new internal::ShillPropertyHandler(this)); 68 shill_property_handler_.reset(new internal::ShillPropertyHandler(this));
73 shill_property_handler_->Init(); 69 shill_property_handler_->Init();
74 } 70 }
75 71
76 // static 72 // static
77 NetworkStateHandler* NetworkStateHandler::InitializeForTest() { 73 NetworkStateHandler* NetworkStateHandler::InitializeForTest() {
(...skipping 15 matching lines...) Expand all
93 void NetworkStateHandler::RemoveObserver( 89 void NetworkStateHandler::RemoveObserver(
94 NetworkStateHandlerObserver* observer, 90 NetworkStateHandlerObserver* observer,
95 const tracked_objects::Location& from_here) { 91 const tracked_objects::Location& from_here) {
96 observers_.RemoveObserver(observer); 92 observers_.RemoveObserver(observer);
97 network_event_log::internal::AddEntry( 93 network_event_log::internal::AddEntry(
98 from_here.file_name(), from_here.line_number(), 94 from_here.file_name(), from_here.line_number(),
99 network_event_log::LOG_LEVEL_DEBUG, 95 network_event_log::LOG_LEVEL_DEBUG,
100 "NetworkStateHandler::RemoveObserver", ""); 96 "NetworkStateHandler::RemoveObserver", "");
101 } 97 }
102 98
103 void NetworkStateHandler::UpdateManagerProperties() {
104 NET_LOG_USER("UpdateManagerProperties", "");
105 shill_property_handler_->UpdateManagerProperties();
106 }
107
108 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( 99 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState(
109 const NetworkTypePattern& type) const { 100 const NetworkTypePattern& type) const {
110 std::string technology = GetTechnologyForType(type); 101 std::string technology = GetTechnologyForType(type);
111 TechnologyState state; 102 TechnologyState state;
112 if (shill_property_handler_->IsTechnologyEnabled(technology)) 103 if (shill_property_handler_->IsTechnologyEnabled(technology))
113 state = TECHNOLOGY_ENABLED; 104 state = TECHNOLOGY_ENABLED;
114 else if (shill_property_handler_->IsTechnologyEnabling(technology)) 105 else if (shill_property_handler_->IsTechnologyEnabling(technology))
115 state = TECHNOLOGY_ENABLING; 106 state = TECHNOLOGY_ENABLING;
116 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) 107 else if (shill_property_handler_->IsTechnologyUninitialized(technology))
117 state = TECHNOLOGY_UNINITIALIZED; 108 state = TECHNOLOGY_UNINITIALIZED;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return NULL; 174 return NULL;
184 return network; 175 return network;
185 } 176 }
186 177
187 const NetworkState* NetworkStateHandler::DefaultNetwork() const { 178 const NetworkState* NetworkStateHandler::DefaultNetwork() const {
188 if (default_network_path_.empty()) 179 if (default_network_path_.empty())
189 return NULL; 180 return NULL;
190 return GetNetworkState(default_network_path_); 181 return GetNetworkState(default_network_path_);
191 } 182 }
192 183
193 const FavoriteState* NetworkStateHandler::DefaultFavoriteNetwork() const {
194 const NetworkState* default_network = DefaultNetwork();
195 if (!default_network)
196 return NULL;
197 const FavoriteState* default_favorite = GetFavoriteStateFromServicePath(
198 default_network->path(), true /* configured_only */);
199 DCHECK(default_network->type() != shill::kTypeWifi || default_favorite)
200 << "No favorite for: " << default_network->path();
201 DCHECK(!default_favorite || default_favorite->update_received())
202 << "No update received for: " << default_network->path();
203 return default_favorite;
204 }
205
206 const NetworkState* NetworkStateHandler::ConnectedNetworkByType( 184 const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
207 const NetworkTypePattern& type) const { 185 const NetworkTypePattern& type) const {
208 for (ManagedStateList::const_iterator iter = network_list_.begin(); 186 for (ManagedStateList::const_iterator iter = network_list_.begin();
209 iter != network_list_.end(); ++iter) { 187 iter != network_list_.end(); ++iter) {
210 const NetworkState* network = (*iter)->AsNetworkState(); 188 const NetworkState* network = (*iter)->AsNetworkState();
211 DCHECK(network); 189 DCHECK(network);
212 if (!network->update_received()) 190 if (!network->update_received())
213 continue; 191 continue;
214 if (!network->IsConnectedState()) 192 if (!network->IsConnectedState())
215 break; // Connected networks are listed first. 193 break; // Connected networks are listed first.
(...skipping 20 matching lines...) Expand all
236 } 214 }
237 215
238 const NetworkState* NetworkStateHandler::FirstNetworkByType( 216 const NetworkState* NetworkStateHandler::FirstNetworkByType(
239 const NetworkTypePattern& type) const { 217 const NetworkTypePattern& type) const {
240 for (ManagedStateList::const_iterator iter = network_list_.begin(); 218 for (ManagedStateList::const_iterator iter = network_list_.begin();
241 iter != network_list_.end(); ++iter) { 219 iter != network_list_.end(); ++iter) {
242 const NetworkState* network = (*iter)->AsNetworkState(); 220 const NetworkState* network = (*iter)->AsNetworkState();
243 DCHECK(network); 221 DCHECK(network);
244 if (!network->update_received()) 222 if (!network->update_received())
245 continue; 223 continue;
224 if (!network->visible())
225 break;
246 if (network->Matches(type)) 226 if (network->Matches(type))
247 return network; 227 return network;
248 } 228 }
249 return NULL; 229 return NULL;
250 } 230 }
251 231
252 std::string NetworkStateHandler::FormattedHardwareAddressForType( 232 std::string NetworkStateHandler::FormattedHardwareAddressForType(
253 const NetworkTypePattern& type) const { 233 const NetworkTypePattern& type) const {
254 const DeviceState* device = NULL; 234 const DeviceState* device = NULL;
255 const NetworkState* network = ConnectedNetworkByType(type); 235 const NetworkState* network = ConnectedNetworkByType(type);
256 if (network) 236 if (network)
257 device = GetDeviceState(network->device_path()); 237 device = GetDeviceState(network->device_path());
258 else 238 else
259 device = GetDeviceStateByType(type); 239 device = GetDeviceStateByType(type);
260 if (!device) 240 if (!device)
261 return std::string(); 241 return std::string();
262 return network_util::FormattedMacAddress(device->mac_address()); 242 return network_util::FormattedMacAddress(device->mac_address());
263 } 243 }
264 244
265 void NetworkStateHandler::GetNetworkList(NetworkStateList* list) const { 245 void NetworkStateHandler::GetVisibleNetworkListByType(
266 GetNetworkListByType(NetworkTypePattern::Default(), list); 246 const NetworkTypePattern& type,
247 NetworkStateList* list) const {
248 GetNetworkListByType(type,
249 false /* configured_only */,
250 true /* visible_only */,
251 0 /* no limit */,
252 list);
253 }
254
255 void NetworkStateHandler::GetVisibleNetworkList(NetworkStateList* list) const {
256 GetVisibleNetworkListByType(NetworkTypePattern::Default(), list);
267 } 257 }
268 258
269 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, 259 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type,
260 bool configured_only,
261 bool visible_only,
262 int limit,
270 NetworkStateList* list) const { 263 NetworkStateList* list) const {
271 DCHECK(list); 264 DCHECK(list);
272 list->clear(); 265 list->clear();
266 int count = 0;
273 for (ManagedStateList::const_iterator iter = network_list_.begin(); 267 for (ManagedStateList::const_iterator iter = network_list_.begin();
274 iter != network_list_.end(); ++iter) { 268 iter != network_list_.end(); ++iter) {
275 const NetworkState* network = (*iter)->AsNetworkState(); 269 const NetworkState* network = (*iter)->AsNetworkState();
276 DCHECK(network); 270 DCHECK(network);
277 if (network->update_received() && network->Matches(type)) 271 if (!network->update_received() || !network->Matches(type))
278 list->push_back(network); 272 continue;
273 if (configured_only && !network->IsInProfile())
274 continue;
275 if (visible_only && !network->visible())
276 continue;
277 list->push_back(network);
278 if (limit > 0 && ++count >= limit)
279 break;
279 } 280 }
280 } 281 }
281 282
283 const NetworkState* NetworkStateHandler::GetNetworkStateFromServicePath(
284 const std::string& service_path,
285 bool configured_only) const {
286 ManagedState* managed =
287 GetModifiableManagedState(&network_list_, service_path);
288 if (!managed)
289 return NULL;
290 const NetworkState* network = managed->AsNetworkState();
291 DCHECK(network);
292 if (!network->update_received() ||
293 (configured_only && !network->IsInProfile())) {
294 return NULL;
295 }
296 return network;
297 }
298
299 const NetworkState* NetworkStateHandler::GetNetworkStateFromGuid(
300 const std::string& guid) const {
301 DCHECK(!guid.empty());
302 for (ManagedStateList::const_iterator iter = network_list_.begin();
303 iter != network_list_.end(); ++iter) {
304 const NetworkState* network = (*iter)->AsNetworkState();
305 if (network->guid() == guid)
306 return network;
307 }
308 return NULL;
309 }
310
282 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { 311 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const {
283 GetDeviceListByType(NetworkTypePattern::Default(), list); 312 GetDeviceListByType(NetworkTypePattern::Default(), list);
284 } 313 }
285 314
286 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type, 315 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type,
287 DeviceStateList* list) const { 316 DeviceStateList* list) const {
288 DCHECK(list); 317 DCHECK(list);
289 list->clear(); 318 list->clear();
290 for (ManagedStateList::const_iterator iter = device_list_.begin(); 319 for (ManagedStateList::const_iterator iter = device_list_.begin();
291 iter != device_list_.end(); ++iter) { 320 iter != device_list_.end(); ++iter) {
292 const DeviceState* device = (*iter)->AsDeviceState(); 321 const DeviceState* device = (*iter)->AsDeviceState();
293 DCHECK(device); 322 DCHECK(device);
294 if (device->update_received() && device->Matches(type)) 323 if (device->update_received() && device->Matches(type))
295 list->push_back(device); 324 list->push_back(device);
296 } 325 }
297 } 326 }
298 327
299 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const {
300 GetFavoriteListByType(NetworkTypePattern::Default(),
301 true /* configured_only */,
302 false /* visible_only */,
303 0 /* no limit */,
304 list);
305 }
306
307 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type,
308 bool configured_only,
309 bool visible_only,
310 int limit,
311 FavoriteStateList* list) const {
312 DCHECK(list);
313 std::set<std::string> visible_networks;
314 if (visible_only) {
315 // Prepare a set of visible network service paths for fast lookup.
316 for (ManagedStateList::const_iterator iter = network_list_.begin();
317 iter != network_list_.end(); ++iter) {
318 visible_networks.insert((*iter)->path());
319 }
320 }
321 FavoriteStateList result;
322 list->clear();
323 int count = 0;
324 for (ManagedStateList::const_iterator iter = favorite_list_.begin();
325 iter != favorite_list_.end(); ++iter) {
326 const FavoriteState* favorite = (*iter)->AsFavoriteState();
327 DCHECK(favorite);
328 if (!favorite->update_received() || !favorite->Matches(type))
329 continue;
330 if (configured_only && !favorite->IsInProfile())
331 continue;
332 if (visible_only && !ContainsKey(visible_networks, favorite->path()))
333 continue;
334 list->push_back(favorite);
335 if (limit > 0 && ++count >= limit)
336 break;
337 }
338 }
339
340 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromServicePath(
341 const std::string& service_path,
342 bool configured_only) const {
343 ManagedState* managed =
344 GetModifiableManagedState(&favorite_list_, service_path);
345 if (!managed)
346 return NULL;
347 const FavoriteState* favorite = managed->AsFavoriteState();
348 DCHECK(favorite);
349 if (!favorite->update_received() ||
350 (configured_only && !favorite->IsInProfile())) {
351 return NULL;
352 }
353 return favorite;
354 }
355
356 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromGuid(
357 const std::string& guid) const {
358 DCHECK(!guid.empty());
359 for (ManagedStateList::const_iterator iter = favorite_list_.begin();
360 iter != favorite_list_.end(); ++iter) {
361 const FavoriteState* favorite = (*iter)->AsFavoriteState();
362 if (favorite->guid() == guid)
363 return favorite;
364 }
365 return NULL;
366 }
367
368 void NetworkStateHandler::RequestScan() const { 328 void NetworkStateHandler::RequestScan() const {
369 NET_LOG_USER("RequestScan", ""); 329 NET_LOG_USER("RequestScan", "");
370 shill_property_handler_->RequestScan(); 330 shill_property_handler_->RequestScan();
371 } 331 }
372 332
373 void NetworkStateHandler::WaitForScan(const std::string& type, 333 void NetworkStateHandler::WaitForScan(const std::string& type,
374 const base::Closure& callback) { 334 const base::Closure& callback) {
375 scan_complete_callbacks_[type].push_back(callback); 335 scan_complete_callbacks_[type].push_back(callback);
376 if (!GetScanningByType(NetworkTypePattern::Primitive(type))) 336 if (!GetScanningByType(NetworkTypePattern::Primitive(type)))
377 RequestScan(); 337 RequestScan();
(...skipping 22 matching lines...) Expand all
400 if (network) 360 if (network)
401 network->clear_last_error(); 361 network->clear_last_error();
402 } 362 }
403 363
404 void NetworkStateHandler::SetCheckPortalList( 364 void NetworkStateHandler::SetCheckPortalList(
405 const std::string& check_portal_list) { 365 const std::string& check_portal_list) {
406 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); 366 NET_LOG_EVENT("SetCheckPortalList", check_portal_list);
407 shill_property_handler_->SetCheckPortalList(check_portal_list); 367 shill_property_handler_->SetCheckPortalList(check_portal_list);
408 } 368 }
409 369
410 const FavoriteState* NetworkStateHandler::GetEAPForEthernet( 370 const NetworkState* NetworkStateHandler::GetEAPForEthernet(
411 const std::string& service_path) const { 371 const std::string& service_path) const {
412 const NetworkState* network = GetNetworkState(service_path); 372 const NetworkState* network = GetNetworkState(service_path);
413 if (!network) { 373 if (!network) {
414 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path); 374 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path);
415 return NULL; 375 return NULL;
416 } 376 }
417 if (network->type() != shill::kTypeEthernet) { 377 if (network->type() != shill::kTypeEthernet) {
418 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path); 378 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path);
419 return NULL; 379 return NULL;
420 } 380 }
421 if (!network->IsConnectedState()) 381 if (!network->IsConnectedState())
422 return NULL; 382 return NULL;
423 383
424 // The same EAP service is shared for all ethernet services/devices. 384 // The same EAP service is shared for all ethernet services/devices.
425 // However EAP is used/enabled per device and only if the connection was 385 // However EAP is used/enabled per device and only if the connection was
426 // successfully established. 386 // successfully established.
427 const DeviceState* device = GetDeviceState(network->device_path()); 387 const DeviceState* device = GetDeviceState(network->device_path());
428 if (!device) { 388 if (!device) {
429 NET_LOG_ERROR( 389 NET_LOG_ERROR(
430 "GetEAPForEthernet", 390 "GetEAPForEthernet",
431 base::StringPrintf("Unknown device %s of connected ethernet service %s", 391 base::StringPrintf("Unknown device %s of connected ethernet service %s",
432 network->device_path().c_str(), 392 network->device_path().c_str(),
433 service_path.c_str())); 393 service_path.c_str()));
434 return NULL; 394 return NULL;
435 } 395 }
436 if (!device->eap_authentication_completed()) 396 if (!device->eap_authentication_completed())
437 return NULL; 397 return NULL;
438 398
439 FavoriteStateList list; 399 NetworkStateList list;
440 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), 400 GetNetworkListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap),
441 true /* configured_only */, 401 true /* configured_only */,
442 false /* visible_only */, 402 false /* visible_only */,
443 1 /* limit */, 403 1 /* limit */,
444 &list); 404 &list);
445 if (list.empty()) { 405 if (list.empty()) {
446 NET_LOG_ERROR("GetEAPForEthernet", 406 NET_LOG_ERROR("GetEAPForEthernet",
447 base::StringPrintf( 407 base::StringPrintf(
448 "Ethernet service %s connected using EAP, but no " 408 "Ethernet service %s connected using EAP, but no "
449 "EAP service found.", 409 "EAP service found.",
450 service_path.c_str())); 410 service_path.c_str()));
451 return NULL; 411 return NULL;
452 } 412 }
453 return list.front(); 413 return list.front();
454 } 414 }
455 415
456 //------------------------------------------------------------------------------ 416 //------------------------------------------------------------------------------
457 // ShillPropertyHandler::Delegate overrides 417 // ShillPropertyHandler::Delegate overrides
458 418
459 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, 419 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type,
460 const base::ListValue& entries) { 420 const base::ListValue& entries) {
461 ManagedStateList* managed_list = GetManagedList(type); 421 ManagedStateList* managed_list = GetManagedList(type);
462 NET_LOG_DEBUG(base::StringPrintf("UpdateManagedList:%d", type), 422 NET_LOG_DEBUG("UpdateManagedList: " + ManagedState::TypeToString(type),
463 base::StringPrintf("%" PRIuS, entries.GetSize())); 423 base::StringPrintf("%" PRIuS, entries.GetSize()));
464 // Create a map of existing entries. Assumes all entries in |managed_list| 424 // Create a map of existing entries. Assumes all entries in |managed_list|
465 // are unique. 425 // are unique.
466 std::map<std::string, ManagedState*> managed_map; 426 typedef std::map<std::string, ManagedState*> ManagedMap;
427 ManagedMap managed_map;
467 for (ManagedStateList::iterator iter = managed_list->begin(); 428 for (ManagedStateList::iterator iter = managed_list->begin();
468 iter != managed_list->end(); ++iter) { 429 iter != managed_list->end(); ++iter) {
469 ManagedState* managed = *iter; 430 ManagedState* managed = *iter;
470 DCHECK(!ContainsKey(managed_map, managed->path())); 431 DCHECK(!ContainsKey(managed_map, managed->path()));
471 managed_map[managed->path()] = managed; 432 managed_map[managed->path()] = managed;
472 } 433 }
473 // Clear the list (pointers are temporarily owned by managed_map). 434 // Clear the list (pointers are temporarily owned by managed_map).
474 managed_list->clear(); 435 managed_list->clear();
475 // Updates managed_list and request updates for new entries. 436 // Updates managed_list and request updates for new entries.
476 std::set<std::string> list_entries; 437 std::set<std::string> list_entries;
477 for (base::ListValue::const_iterator iter = entries.begin(); 438 for (base::ListValue::const_iterator iter = entries.begin();
478 iter != entries.end(); ++iter) { 439 iter != entries.end(); ++iter) {
479 std::string path; 440 std::string path;
480 (*iter)->GetAsString(&path); 441 (*iter)->GetAsString(&path);
481 if (path.empty() || path == shill::kFlimflamServicePath) { 442 if (path.empty() || path == shill::kFlimflamServicePath) {
482 NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path); 443 NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path);
483 continue; 444 continue;
484 } 445 }
485 std::map<std::string, ManagedState*>::iterator found = 446 ManagedMap::iterator found = managed_map.find(path);
486 managed_map.find(path);
487 ManagedState* managed;
488 if (found == managed_map.end()) { 447 if (found == managed_map.end()) {
489 if (list_entries.count(path) != 0) { 448 if (list_entries.count(path) != 0) {
490 NET_LOG_ERROR("Duplicate entry in list", path); 449 NET_LOG_ERROR("Duplicate entry in list", path);
491 continue; 450 continue;
492 } 451 }
493 managed = ManagedState::Create(type, path); 452 ManagedState* managed = ManagedState::Create(type, path);
494 managed_list->push_back(managed); 453 managed_list->push_back(managed);
495 } else { 454 } else {
496 managed = found->second; 455 managed_list->push_back(found->second);
497 managed_list->push_back(managed);
498 managed_map.erase(found); 456 managed_map.erase(found);
499 } 457 }
500 list_entries.insert(path); 458 list_entries.insert(path);
501 } 459 }
502 // Delete any remaining entries in managed_map. 460 // Delete any remaining entries in managed_map.
503 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); 461 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end());
504 } 462 }
505 463
464 void NetworkStateHandler::UpdateVisibleNetworks(
465 const base::ListValue& entries) {
466 NET_LOG_DEBUG(base::StringPrintf("UpdateVisibleNetworks"),
467 base::StringPrintf("%" PRIuS, entries.GetSize()));
468 // Create a map of all networks and clear the visible state.
469 ManagedStateList* network_list =
470 GetManagedList(ManagedState::MANAGED_TYPE_NETWORK);
471 typedef std::map<std::string, NetworkState*> NetworkMap;
472 NetworkMap network_map;
473 for (ManagedStateList::iterator iter = network_list->begin();
474 iter != network_list->end(); ++iter) {
475 NetworkState* network = (*iter)->AsNetworkState();
476 network_map[network->path()] = network;
477 network->set_visible(false);
478 }
479 // Look up each entry and set the associated network to visible.
480 for (base::ListValue::const_iterator iter = entries.begin();
481 iter != entries.end(); ++iter) {
482 std::string path;
483 (*iter)->GetAsString(&path);
484 NetworkMap::iterator found = network_map.find(path);
485 if (found != network_map.end())
486 found->second->set_visible(true);
487 else
488 NET_LOG_DEBUG("Visible network not in list", path);
489 }
490 }
491
506 void NetworkStateHandler::ProfileListChanged() { 492 void NetworkStateHandler::ProfileListChanged() {
507 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); 493 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties");
508 for (ManagedStateList::iterator iter = favorite_list_.begin(); 494 for (ManagedStateList::iterator iter = network_list_.begin();
509 iter != favorite_list_.end(); ++iter) { 495 iter != network_list_.end(); ++iter) {
496 NetworkState* network = (*iter)->AsNetworkState();
497 DCHECK(network);
510 shill_property_handler_->RequestProperties( 498 shill_property_handler_->RequestProperties(
511 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path()); 499 ManagedState::MANAGED_TYPE_NETWORK, network->path());
512 } 500 }
513 } 501 }
514 502
515 void NetworkStateHandler::UpdateManagedStateProperties( 503 void NetworkStateHandler::UpdateManagedStateProperties(
516 ManagedState::ManagedType type, 504 ManagedState::ManagedType type,
517 const std::string& path, 505 const std::string& path,
518 const base::DictionaryValue& properties) { 506 const base::DictionaryValue& properties) {
519 ManagedStateList* managed_list = GetManagedList(type); 507 ManagedStateList* managed_list = GetManagedList(type);
520 ManagedState* managed = GetModifiableManagedState(managed_list, path); 508 ManagedState* managed = GetModifiableManagedState(managed_list, path);
521 if (!managed) { 509 if (!managed) {
522 if (type != ManagedState::MANAGED_TYPE_FAVORITE) { 510 // The network has been removed from the list of networks.
523 // The network has been removed from the list of visible networks. 511 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path);
524 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path); 512 return;
525 return;
526 }
527 // A Favorite may not have been created yet if it was added later (e.g.
528 // through ConfigureService) since ServiceCompleteList updates are not
529 // emitted. Add and update the state here.
530 managed = ManagedState::Create(type, path);
531 managed_list->push_back(managed);
532 } 513 }
533 managed->set_update_received(); 514 managed->set_update_received();
534 515
535 std::string desc = GetManagedStateLogType(managed) + " Properties Received"; 516 std::string desc = GetManagedStateLogType(managed) + " Properties Received";
536 NET_LOG_DEBUG(desc, GetManagedStateLogName(managed)); 517 NET_LOG_DEBUG(desc, GetLogName(managed));
537 518
538 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 519 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
539 UpdateNetworkStateProperties(managed->AsNetworkState(), properties); 520 UpdateNetworkStateProperties(managed->AsNetworkState(), properties);
540 } else { 521 } else {
541 // Device, Favorite 522 // Device
542 for (base::DictionaryValue::Iterator iter(properties); 523 for (base::DictionaryValue::Iterator iter(properties);
543 !iter.IsAtEnd(); iter.Advance()) { 524 !iter.IsAtEnd(); iter.Advance()) {
544 managed->PropertyChanged(iter.key(), iter.value()); 525 managed->PropertyChanged(iter.key(), iter.value());
545 } 526 }
546 managed->InitialPropertiesReceived(properties); 527 managed->InitialPropertiesReceived(properties);
547 } 528 }
548 UpdateGuid(managed);
549 managed->set_update_requested(false); 529 managed->set_update_requested(false);
550 } 530 }
551 531
552 void NetworkStateHandler::UpdateNetworkStateProperties( 532 void NetworkStateHandler::UpdateNetworkStateProperties(
553 NetworkState* network, 533 NetworkState* network,
554 const base::DictionaryValue& properties) { 534 const base::DictionaryValue& properties) {
555 DCHECK(network); 535 DCHECK(network);
556 bool network_property_updated = false; 536 bool network_property_updated = false;
557 std::string prev_connection_state = network->connection_state(); 537 std::string prev_connection_state = network->connection_state();
558 for (base::DictionaryValue::Iterator iter(properties); 538 for (base::DictionaryValue::Iterator iter(properties);
559 !iter.IsAtEnd(); iter.Advance()) { 539 !iter.IsAtEnd(); iter.Advance()) {
560 if (network->PropertyChanged(iter.key(), iter.value())) 540 if (network->PropertyChanged(iter.key(), iter.value()))
561 network_property_updated = true; 541 network_property_updated = true;
562 } 542 }
563 network_property_updated |= network->InitialPropertiesReceived(properties); 543 network_property_updated |= network->InitialPropertiesReceived(properties);
564 // Notify observers of NetworkState changes. 544 // Notify observers of NetworkState changes.
565 if (network_property_updated || network->update_requested()) { 545 if (network_property_updated || network->update_requested()) {
566 // Signal connection state changed after all properties have been updated. 546 // Signal connection state changed after all properties have been updated.
567 if (ConnectionStateChanged(network, prev_connection_state)) 547 if (ConnectionStateChanged(network, prev_connection_state))
568 OnNetworkConnectionStateChanged(network); 548 OnNetworkConnectionStateChanged(network);
569 NET_LOG_EVENT("NetworkPropertiesUpdated", GetManagedStateLogName(network)); 549 NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network));
570 NotifyNetworkPropertiesUpdated(network); 550 NotifyNetworkPropertiesUpdated(network);
571 } 551 }
552 UpdateGuid(network);
572 } 553 }
573 554
574 void NetworkStateHandler::UpdateNetworkServiceProperty( 555 void NetworkStateHandler::UpdateNetworkServiceProperty(
575 const std::string& service_path, 556 const std::string& service_path,
576 const std::string& key, 557 const std::string& key,
577 const base::Value& value) { 558 const base::Value& value) {
578 // Update any associated FavoriteState.
579 ManagedState* favorite =
580 GetModifiableManagedState(&favorite_list_, service_path);
581 bool changed = false; 559 bool changed = false;
582 if (favorite)
583 changed |= favorite->PropertyChanged(key, value);
584
585 // Update the NetworkState.
586 NetworkState* network = GetModifiableNetworkState(service_path); 560 NetworkState* network = GetModifiableNetworkState(service_path);
587 if (!network) 561 if (!network)
588 return; 562 return;
589 std::string prev_connection_state = network->connection_state(); 563 std::string prev_connection_state = network->connection_state();
590 std::string prev_profile_path = network->profile_path(); 564 std::string prev_profile_path = network->profile_path();
591 changed |= network->PropertyChanged(key, value); 565 changed |= network->PropertyChanged(key, value);
592 if (!changed) 566 if (!changed)
593 return; 567 return;
594 568
595 if (key == shill::kStateProperty) { 569 if (key == shill::kStateProperty) {
(...skipping 28 matching lines...) Expand all
624 } else { 598 } else {
625 log_level = network_event_log::LOG_LEVEL_EVENT; 599 log_level = network_event_log::LOG_LEVEL_EVENT;
626 } 600 }
627 NET_LOG_LEVEL(log_level, log_event, detail); 601 NET_LOG_LEVEL(log_level, log_event, detail);
628 } 602 }
629 } 603 }
630 604
631 // All property updates signal 'NetworkPropertiesUpdated'. 605 // All property updates signal 'NetworkPropertiesUpdated'.
632 NotifyNetworkPropertiesUpdated(network); 606 NotifyNetworkPropertiesUpdated(network);
633 607
634 // If added to a Profile, request a full update so that a FavoriteState 608 // If added to a Profile, request a full update so that a NetworkState
635 // gets created. 609 // gets created.
636 if (prev_profile_path.empty() && !network->profile_path().empty()) 610 if (prev_profile_path.empty() && !network->profile_path().empty())
637 RequestUpdateForNetwork(service_path); 611 RequestUpdateForNetwork(service_path);
638 } 612 }
639 613
640 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, 614 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path,
641 const std::string& key, 615 const std::string& key,
642 const base::Value& value) { 616 const base::Value& value) {
643 DeviceState* device = GetModifiableDeviceState(device_path); 617 DeviceState* device = GetModifiableDeviceState(device_path);
644 if (!device) 618 if (!device)
645 return; 619 return;
646 if (!device->PropertyChanged(key, value)) 620 if (!device->PropertyChanged(key, value))
647 return; 621 return;
648 622
649 std::string detail = device->name() + "." + key; 623 std::string detail = device->name() + "." + key;
650 detail += " = " + network_event_log::ValueAsString(value); 624 detail += " = " + network_event_log::ValueAsString(value);
651 NET_LOG_EVENT("DevicePropertyUpdated", detail); 625 NET_LOG_EVENT("DevicePropertyUpdated", detail);
652 626
653 NotifyDeviceListChanged(); 627 NotifyDeviceListChanged();
654 628
655 if (key == shill::kScanningProperty && device->scanning() == false) 629 if (key == shill::kScanningProperty && device->scanning() == false)
656 ScanCompleted(device->type()); 630 ScanCompleted(device->type());
657 if (key == shill::kEapAuthenticationCompletedProperty) { 631 if (key == shill::kEapAuthenticationCompletedProperty) {
658 // Notify a change for each Ethernet service using this device. 632 // Notify a change for each Ethernet service using this device.
659 NetworkStateList ethernet_services; 633 NetworkStateList ethernet_services;
660 GetNetworkListByType(NetworkTypePattern::Ethernet(), &ethernet_services); 634 GetNetworkListByType(NetworkTypePattern::Ethernet(),
635 false /* configured_only */,
636 false /* visible_only */,
637 0 /* no limit */,
638 &ethernet_services);
661 for (NetworkStateList::const_iterator it = ethernet_services.begin(); 639 for (NetworkStateList::const_iterator it = ethernet_services.begin();
662 it != ethernet_services.end(); ++it) { 640 it != ethernet_services.end(); ++it) {
663 const NetworkState* ethernet_service = *it; 641 const NetworkState* ethernet_service = *it;
664 if (ethernet_service->update_received() || 642 if (ethernet_service->update_received() ||
665 ethernet_service->device_path() != device->path()) { 643 ethernet_service->device_path() != device->path()) {
666 continue; 644 continue;
667 } 645 }
668 RequestUpdateForNetwork(ethernet_service->path()); 646 RequestUpdateForNetwork(ethernet_service->path());
669 } 647 }
670 } 648 }
(...skipping 25 matching lines...) Expand all
696 void NetworkStateHandler::TechnologyListChanged() { 674 void NetworkStateHandler::TechnologyListChanged() {
697 // Eventually we would like to replace Technology state with Device state. 675 // Eventually we would like to replace Technology state with Device state.
698 // For now, treat technology state changes as device list changes. 676 // For now, treat technology state changes as device list changes.
699 NotifyDeviceListChanged(); 677 NotifyDeviceListChanged();
700 } 678 }
701 679
702 void NetworkStateHandler::ManagedStateListChanged( 680 void NetworkStateHandler::ManagedStateListChanged(
703 ManagedState::ManagedType type) { 681 ManagedState::ManagedType type) {
704 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 682 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
705 // Notify observers that the list of networks has changed. 683 // Notify observers that the list of networks has changed.
706 NET_LOG_EVENT("NetworkListChanged", 684 NET_LOG_EVENT("NOTIFY:NetworkListChanged",
707 base::StringPrintf("Size:%" PRIuS, network_list_.size())); 685 base::StringPrintf("Size:%" PRIuS, network_list_.size()));
708 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 686 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
709 NetworkListChanged()); 687 NetworkListChanged());
710 // Update UMA stats. 688 // Update UMA stats.
711 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", network_list_.size()); 689 size_t shared = 0, unshared = 0, visible = 0;
712 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { 690 for (ManagedStateList::iterator iter = network_list_.begin();
713 NET_LOG_DEBUG("FavoriteListChanged", 691 iter != network_list_.end(); ++iter) {
714 base::StringPrintf("Size:%" PRIuS, favorite_list_.size())); 692 NetworkState* network = (*iter)->AsNetworkState();
715 // The FavoriteState list only changes when the NetworkState list changes, 693 if (network->visible())
716 // so no need to signal observers here again. 694 ++visible;
717 695 if (network->IsInProfile()) {
718 // Update UMA stats. 696 if (network->IsPrivate())
719 size_t shared = 0, unshared = 0; 697 ++unshared;
720 for (ManagedStateList::iterator iter = favorite_list_.begin(); 698 else
721 iter != favorite_list_.end(); ++iter) { 699 ++shared;
722 FavoriteState* favorite = (*iter)->AsFavoriteState(); 700 }
723 if (!favorite->IsInProfile())
724 continue;
725 if (favorite->IsPrivate())
726 ++unshared;
727 else
728 ++shared;
729 } 701 }
702 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", visible);
730 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); 703 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared);
731 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); 704 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared);
732 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 705 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
733 std::string devices; 706 std::string devices;
734 for (ManagedStateList::const_iterator iter = device_list_.begin(); 707 for (ManagedStateList::const_iterator iter = device_list_.begin();
735 iter != device_list_.end(); ++iter) { 708 iter != device_list_.end(); ++iter) {
736 if (iter != device_list_.begin()) 709 if (iter != device_list_.begin())
737 devices += ", "; 710 devices += ", ";
738 devices += (*iter)->name(); 711 devices += (*iter)->name();
739 } 712 }
740 NET_LOG_EVENT("DeviceList:", devices); 713 NET_LOG_EVENT("DeviceList", devices);
741 NotifyDeviceListChanged(); 714 NotifyDeviceListChanged();
742 } else { 715 } else {
743 NOTREACHED(); 716 NOTREACHED();
744 } 717 }
745 } 718 }
746 719
747 void NetworkStateHandler::DefaultNetworkServiceChanged( 720 void NetworkStateHandler::DefaultNetworkServiceChanged(
748 const std::string& service_path) { 721 const std::string& service_path) {
749 // Shill uses '/' for empty service path values; check explicitly for that. 722 // Shill uses '/' for empty service path values; check explicitly for that.
750 const char* kEmptyServicePath = "/"; 723 const char* kEmptyServicePath = "/";
751 if (service_path == kEmptyServicePath) 724 std::string new_service_path =
752 default_network_path_.clear(); 725 (service_path != kEmptyServicePath) ? service_path : "";
753 else 726 if (new_service_path == default_network_path_)
754 default_network_path_ = service_path; 727 return;
728
729 default_network_path_ = service_path;
755 NET_LOG_EVENT("DefaultNetworkServiceChanged:", default_network_path_); 730 NET_LOG_EVENT("DefaultNetworkServiceChanged:", default_network_path_);
756 const NetworkState* network = NULL; 731 const NetworkState* network = NULL;
757 if (!default_network_path_.empty()) { 732 if (!default_network_path_.empty()) {
758 network = GetNetworkState(default_network_path_); 733 network = GetNetworkState(default_network_path_);
759 if (!network) { 734 if (!network) {
760 // If NetworkState is not available yet, do not notify observers here, 735 // If NetworkState is not available yet, do not notify observers here,
761 // they will be notified when the state is received. 736 // they will be notified when the state is received.
762 NET_LOG_DEBUG("Default NetworkState not available", 737 NET_LOG_DEBUG("Default NetworkState not available",
763 default_network_path_); 738 default_network_path_);
764 return; 739 return;
765 } 740 }
766 } 741 }
767 if (network && !network->IsConnectedState()) { 742 if (network && !network->IsConnectedState()) {
768 NET_LOG_ERROR( 743 NET_LOG_ERROR(
769 "DefaultNetwork is not connected: " + network->connection_state(), 744 "DefaultNetwork is not connected: " + network->connection_state(),
770 network->path()); 745 network->path());
771 } 746 }
772 NotifyDefaultNetworkChanged(network); 747 NotifyDefaultNetworkChanged(network);
773 } 748 }
774 749
775 //------------------------------------------------------------------------------ 750 //------------------------------------------------------------------------------
776 // Private methods 751 // Private methods
777 752
778 void NetworkStateHandler::UpdateGuid(ManagedState* managed) { 753 void NetworkStateHandler::UpdateGuid(NetworkState* network) {
779 if (managed->managed_type() == ManagedState::MANAGED_TYPE_FAVORITE) { 754 std::string specifier = network->GetSpecifier();
780 FavoriteState* favorite = managed->AsFavoriteState(); 755 DCHECK(!specifier.empty());
781 std::string specifier = favorite->GetSpecifier(); 756 if (!network->guid().empty()) {
782 if (!favorite->guid().empty()) { 757 // If the network is saved in a profile, remove the entry from the map.
783 // If the favorite is saved in a profile, remove the entry from the map. 758 // Otherwise ensure that the entry matches the specified GUID. (e.g. in
784 // Otherwise ensure that the entry matches the specified GUID. 759 // case a visible network with a specified guid gets configured with a
785 if (favorite->IsInProfile()) 760 // new guid).
786 specifier_guid_map_.erase(specifier); 761 if (network->IsInProfile())
787 else 762 specifier_guid_map_.erase(specifier);
788 specifier_guid_map_[specifier] = favorite->guid(); 763 else
789 return; 764 specifier_guid_map_[specifier] = network->guid();
790 } 765 return;
791 // Ensure that the FavoriteState has a valid GUID.
792 std::string guid;
793 SpecifierGuidMap::iterator iter = specifier_guid_map_.find(specifier);
794 if (iter != specifier_guid_map_.end()) {
795 guid = iter->second;
796 } else {
797 guid = base::GenerateGUID();
798 specifier_guid_map_[specifier] = guid;
799 }
800 favorite->SetGuid(guid);
801 NetworkState* network = GetModifiableNetworkState(favorite->path());
802 if (network)
803 network->SetGuid(guid);
804 } else if (managed->managed_type() == ManagedState::MANAGED_TYPE_NETWORK) {
805 // If the GUID is not set and a corresponding FavoriteState exists, get the
806 // GUID from the FavoriteState. Otherwise it will get set when the Favorite
807 // is created.
808 NetworkState* network = managed->AsNetworkState();
809 if (!network->guid().empty())
810 return;
811 // ShillPropertyHandler will always call UpdateManagedStateProperties with
812 // type FAVORITE before type NETWORK, so there should always be a
813 // corresponding FavoriteState here.
814 FavoriteState* favorite = GetModifiableFavoriteState(network->path());
815 DCHECK(favorite);
816 if (favorite && !favorite->guid().empty())
817 network->SetGuid(favorite->guid());
818 } 766 }
767 // Ensure that the NetworkState has a valid GUID.
768 std::string guid;
769 SpecifierGuidMap::iterator iter = specifier_guid_map_.find(specifier);
770 if (iter != specifier_guid_map_.end()) {
771 guid = iter->second;
772 } else {
773 guid = base::GenerateGUID();
774 specifier_guid_map_[specifier] = guid;
775 }
776 network->SetGuid(guid);
819 } 777 }
820 778
821 void NetworkStateHandler::NotifyDeviceListChanged() { 779 void NetworkStateHandler::NotifyDeviceListChanged() {
822 NET_LOG_DEBUG("NotifyDeviceListChanged", 780 NET_LOG_DEBUG("NOTIFY:DeviceListChanged",
823 base::StringPrintf("Size:%" PRIuS, device_list_.size())); 781 base::StringPrintf("Size:%" PRIuS, device_list_.size()));
824 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 782 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
825 DeviceListChanged()); 783 DeviceListChanged());
826 } 784 }
827 785
828 DeviceState* NetworkStateHandler::GetModifiableDeviceState( 786 DeviceState* NetworkStateHandler::GetModifiableDeviceState(
829 const std::string& device_path) const { 787 const std::string& device_path) const {
830 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path); 788 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path);
831 if (!managed) 789 if (!managed)
832 return NULL; 790 return NULL;
833 return managed->AsDeviceState(); 791 return managed->AsDeviceState();
834 } 792 }
835 793
836 NetworkState* NetworkStateHandler::GetModifiableNetworkState( 794 NetworkState* NetworkStateHandler::GetModifiableNetworkState(
837 const std::string& service_path) const { 795 const std::string& service_path) const {
838 ManagedState* managed = 796 ManagedState* managed =
839 GetModifiableManagedState(&network_list_, service_path); 797 GetModifiableManagedState(&network_list_, service_path);
840 if (!managed) 798 if (!managed)
841 return NULL; 799 return NULL;
842 return managed->AsNetworkState(); 800 return managed->AsNetworkState();
843 } 801 }
844 802
845 FavoriteState* NetworkStateHandler::GetModifiableFavoriteState(
846 const std::string& service_path) const {
847 ManagedState* managed =
848 GetModifiableManagedState(&favorite_list_, service_path);
849 if (!managed)
850 return NULL;
851 return managed->AsFavoriteState();
852 }
853
854 ManagedState* NetworkStateHandler::GetModifiableManagedState( 803 ManagedState* NetworkStateHandler::GetModifiableManagedState(
855 const ManagedStateList* managed_list, 804 const ManagedStateList* managed_list,
856 const std::string& path) const { 805 const std::string& path) const {
857 for (ManagedStateList::const_iterator iter = managed_list->begin(); 806 for (ManagedStateList::const_iterator iter = managed_list->begin();
858 iter != managed_list->end(); ++iter) { 807 iter != managed_list->end(); ++iter) {
859 ManagedState* managed = *iter; 808 ManagedState* managed = *iter;
860 if (managed->path() == path) 809 if (managed->path() == path)
861 return managed; 810 return managed;
862 } 811 }
863 return NULL; 812 return NULL;
864 } 813 }
865 814
866 NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList( 815 NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList(
867 ManagedState::ManagedType type) { 816 ManagedState::ManagedType type) {
868 switch (type) { 817 switch (type) {
869 case ManagedState::MANAGED_TYPE_NETWORK: 818 case ManagedState::MANAGED_TYPE_NETWORK:
870 return &network_list_; 819 return &network_list_;
871 case ManagedState::MANAGED_TYPE_FAVORITE:
872 return &favorite_list_;
873 case ManagedState::MANAGED_TYPE_DEVICE: 820 case ManagedState::MANAGED_TYPE_DEVICE:
874 return &device_list_; 821 return &device_list_;
875 } 822 }
876 NOTREACHED(); 823 NOTREACHED();
877 return NULL; 824 return NULL;
878 } 825 }
879 826
880 void NetworkStateHandler::OnNetworkConnectionStateChanged( 827 void NetworkStateHandler::OnNetworkConnectionStateChanged(
881 NetworkState* network) { 828 NetworkState* network) {
882 DCHECK(network); 829 DCHECK(network);
883 std::string event = "NetworkConnectionStateChanged"; 830 std::string event = "NetworkConnectionStateChanged";
884 if (network->path() == default_network_path_) { 831 if (network->path() == default_network_path_) {
885 event = "Default" + event; 832 event = "Default" + event;
886 if (!network->IsConnectedState()) { 833 if (!network->IsConnectedState()) {
887 NET_LOG_ERROR( 834 NET_LOG_ERROR(
888 "DefaultNetwork is not connected: " + network->connection_state(), 835 "DefaultNetwork is not connected: " + network->connection_state(),
889 network->path()); 836 network->path());
890 } 837 }
891 } 838 }
892 NET_LOG_EVENT(event + ": " + network->connection_state(), 839 NET_LOG_EVENT("NOTIFY:" + event + ": " + network->connection_state(),
893 GetManagedStateLogName(network)); 840 GetLogName(network));
894 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 841 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
895 NetworkConnectionStateChanged(network)); 842 NetworkConnectionStateChanged(network));
896 if (network->path() == default_network_path_) 843 if (network->path() == default_network_path_)
897 NotifyDefaultNetworkChanged(network); 844 NotifyDefaultNetworkChanged(network);
898 } 845 }
899 846
900 void NetworkStateHandler::NotifyDefaultNetworkChanged( 847 void NetworkStateHandler::NotifyDefaultNetworkChanged(
901 const NetworkState* default_network) { 848 const NetworkState* default_network) {
849 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network));
902 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 850 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
903 DefaultNetworkChanged(default_network)); 851 DefaultNetworkChanged(default_network));
904 } 852 }
905 853
906 void NetworkStateHandler::NotifyNetworkPropertiesUpdated( 854 void NetworkStateHandler::NotifyNetworkPropertiesUpdated(
907 const NetworkState* network) { 855 const NetworkState* network) {
856 NET_LOG_DEBUG("NOTIFY:NetworkPropertiesUpdated", GetLogName(network));
908 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 857 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
909 NetworkPropertiesUpdated(network)); 858 NetworkPropertiesUpdated(network));
910 } 859 }
911 860
912 void NetworkStateHandler::ScanCompleted(const std::string& type) { 861 void NetworkStateHandler::ScanCompleted(const std::string& type) {
913 size_t num_callbacks = scan_complete_callbacks_.count(type); 862 size_t num_callbacks = scan_complete_callbacks_.count(type);
914 NET_LOG_EVENT("ScanCompleted", 863 NET_LOG_EVENT("ScanCompleted",
915 base::StringPrintf("%s:%" PRIuS, type.c_str(), num_callbacks)); 864 base::StringPrintf("%s:%" PRIuS, type.c_str(), num_callbacks));
916 if (num_callbacks == 0) 865 if (num_callbacks == 0)
917 return; 866 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 if (type.MatchesType(shill::kTypeBluetooth)) 910 if (type.MatchesType(shill::kTypeBluetooth))
962 technologies.push_back(new std::string(shill::kTypeBluetooth)); 911 technologies.push_back(new std::string(shill::kTypeBluetooth));
963 if (type.MatchesType(shill::kTypeVPN)) 912 if (type.MatchesType(shill::kTypeVPN))
964 technologies.push_back(new std::string(shill::kTypeVPN)); 913 technologies.push_back(new std::string(shill::kTypeVPN));
965 914
966 CHECK_GT(technologies.size(), 0ul); 915 CHECK_GT(technologies.size(), 0ul);
967 return technologies.Pass(); 916 return technologies.Pass();
968 } 917 }
969 918
970 } // namespace chromeos 919 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | chromeos/network/network_state_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698