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

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 + Fix tests 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return NULL; 179 return NULL;
184 return network; 180 return network;
185 } 181 }
186 182
187 const NetworkState* NetworkStateHandler::DefaultNetwork() const { 183 const NetworkState* NetworkStateHandler::DefaultNetwork() const {
188 if (default_network_path_.empty()) 184 if (default_network_path_.empty())
189 return NULL; 185 return NULL;
190 return GetNetworkState(default_network_path_); 186 return GetNetworkState(default_network_path_);
191 } 187 }
192 188
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( 189 const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
207 const NetworkTypePattern& type) const { 190 const NetworkTypePattern& type) const {
208 for (ManagedStateList::const_iterator iter = network_list_.begin(); 191 for (ManagedStateList::const_iterator iter = network_list_.begin();
209 iter != network_list_.end(); ++iter) { 192 iter != network_list_.end(); ++iter) {
210 const NetworkState* network = (*iter)->AsNetworkState(); 193 const NetworkState* network = (*iter)->AsNetworkState();
211 DCHECK(network); 194 DCHECK(network);
212 if (!network->update_received()) 195 if (!network->update_received())
213 continue; 196 continue;
214 if (!network->IsConnectedState()) 197 if (!network->visible() || !network->IsConnectedState())
pneubeck (no reviews) 2014/06/10 10:51:37 Hm. If it's not visible but in a connected state,
stevenjb 2014/06/10 16:17:28 It's not necessarily a bug, we don't clear state w
pneubeck (no reviews) 2014/06/11 12:44:55 Ok. Got it. But considering the documentation of I
stevenjb 2014/06/11 23:31:40 I went ahead and changed connection_state() to to
215 break; // Connected networks are listed first. 198 break; // Connected networks are listed first.
216 if (network->Matches(type)) 199 if (network->Matches(type))
217 return network; 200 return network;
218 } 201 }
219 return NULL; 202 return NULL;
220 } 203 }
221 204
222 const NetworkState* NetworkStateHandler::ConnectingNetworkByType( 205 const NetworkState* NetworkStateHandler::ConnectingNetworkByType(
223 const NetworkTypePattern& type) const { 206 const NetworkTypePattern& type) const {
224 for (ManagedStateList::const_iterator iter = network_list_.begin(); 207 for (ManagedStateList::const_iterator iter = network_list_.begin();
225 iter != network_list_.end(); ++iter) { 208 iter != network_list_.end(); ++iter) {
226 const NetworkState* network = (*iter)->AsNetworkState(); 209 const NetworkState* network = (*iter)->AsNetworkState();
227 DCHECK(network); 210 DCHECK(network);
228 if (!network->update_received() || network->IsConnectedState()) 211 if (!network->update_received() || network->IsConnectedState())
229 continue; 212 continue;
230 if (!network->IsConnectingState()) 213 if (!network->visible() || !network->IsConnectingState())
pneubeck (no reviews) 2014/06/10 10:51:37 ditto
stevenjb 2014/06/10 16:17:28 ditto
231 break; // Connected and connecting networks are listed first. 214 break; // Connected and connecting networks are listed first.
232 if (network->Matches(type)) 215 if (network->Matches(type))
233 return network; 216 return network;
234 } 217 }
235 return NULL; 218 return NULL;
236 } 219 }
237 220
238 const NetworkState* NetworkStateHandler::FirstNetworkByType( 221 const NetworkState* NetworkStateHandler::FirstNetworkByType(
239 const NetworkTypePattern& type) const { 222 const NetworkTypePattern& type) const {
240 for (ManagedStateList::const_iterator iter = network_list_.begin(); 223 for (ManagedStateList::const_iterator iter = network_list_.begin();
(...skipping 14 matching lines...) Expand all
255 const NetworkState* network = ConnectedNetworkByType(type); 238 const NetworkState* network = ConnectedNetworkByType(type);
256 if (network) 239 if (network)
257 device = GetDeviceState(network->device_path()); 240 device = GetDeviceState(network->device_path());
258 else 241 else
259 device = GetDeviceStateByType(type); 242 device = GetDeviceStateByType(type);
260 if (!device) 243 if (!device)
261 return std::string(); 244 return std::string();
262 return network_util::FormattedMacAddress(device->mac_address()); 245 return network_util::FormattedMacAddress(device->mac_address());
263 } 246 }
264 247
265 void NetworkStateHandler::GetNetworkList(NetworkStateList* list) const { 248 void NetworkStateHandler::GetVisibleNetworkListByType(
266 GetNetworkListByType(NetworkTypePattern::Default(), list); 249 const NetworkTypePattern& type,
250 NetworkStateList* list) const {
251 GetNetworkListByType(type,
252 false /* configured_only */,
253 true /* visible_only */,
254 0 /* no limit */,
255 list);
256 }
257
258 void NetworkStateHandler::GetVisibleNetworkList(NetworkStateList* list) const {
259 GetVisibleNetworkListByType(NetworkTypePattern::Default(), list);
267 } 260 }
268 261
269 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, 262 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type,
263 bool configured_only,
264 bool visible_only,
265 int limit,
270 NetworkStateList* list) const { 266 NetworkStateList* list) const {
271 DCHECK(list); 267 DCHECK(list);
272 list->clear(); 268 list->clear();
269 NetworkStateList result;
pneubeck (no reviews) 2014/06/10 10:51:37 unused
stevenjb 2014/06/10 16:17:28 Done.
270 int count = 0;
273 for (ManagedStateList::const_iterator iter = network_list_.begin(); 271 for (ManagedStateList::const_iterator iter = network_list_.begin();
274 iter != network_list_.end(); ++iter) { 272 iter != network_list_.end(); ++iter) {
275 const NetworkState* network = (*iter)->AsNetworkState(); 273 const NetworkState* network = (*iter)->AsNetworkState();
276 DCHECK(network); 274 DCHECK(network);
277 if (network->update_received() && network->Matches(type)) 275 if (!network->update_received() || !network->Matches(type))
278 list->push_back(network); 276 continue;
277 if (configured_only && !network->IsInProfile())
278 continue;
279 if (visible_only && !network->visible())
280 continue;
281 list->push_back(network);
282 if (limit > 0 && ++count >= limit)
283 break;
279 } 284 }
280 } 285 }
281 286
287 const NetworkState* NetworkStateHandler::GetNetworkStateFromServicePath(
288 const std::string& service_path,
289 bool configured_only) const {
290 ManagedState* managed =
291 GetModifiableManagedState(&network_list_, service_path);
292 if (!managed)
293 return NULL;
294 const NetworkState* network = managed->AsNetworkState();
295 DCHECK(network);
296 if (!network->update_received() ||
297 (configured_only && !network->IsInProfile())) {
298 return NULL;
299 }
300 return network;
301 }
302
303 const NetworkState* NetworkStateHandler::GetNetworkStateFromGuid(
304 const std::string& guid) const {
305 DCHECK(!guid.empty());
306 for (ManagedStateList::const_iterator iter = network_list_.begin();
307 iter != network_list_.end(); ++iter) {
308 const NetworkState* network = (*iter)->AsNetworkState();
309 if (network->guid() == guid)
310 return network;
311 }
312 return NULL;
313 }
314
282 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { 315 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const {
283 GetDeviceListByType(NetworkTypePattern::Default(), list); 316 GetDeviceListByType(NetworkTypePattern::Default(), list);
284 } 317 }
285 318
286 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type, 319 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type,
287 DeviceStateList* list) const { 320 DeviceStateList* list) const {
288 DCHECK(list); 321 DCHECK(list);
289 list->clear(); 322 list->clear();
290 for (ManagedStateList::const_iterator iter = device_list_.begin(); 323 for (ManagedStateList::const_iterator iter = device_list_.begin();
291 iter != device_list_.end(); ++iter) { 324 iter != device_list_.end(); ++iter) {
292 const DeviceState* device = (*iter)->AsDeviceState(); 325 const DeviceState* device = (*iter)->AsDeviceState();
293 DCHECK(device); 326 DCHECK(device);
294 if (device->update_received() && device->Matches(type)) 327 if (device->update_received() && device->Matches(type))
295 list->push_back(device); 328 list->push_back(device);
296 } 329 }
297 } 330 }
298 331
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 { 332 void NetworkStateHandler::RequestScan() const {
369 NET_LOG_USER("RequestScan", ""); 333 NET_LOG_USER("RequestScan", "");
370 shill_property_handler_->RequestScan(); 334 shill_property_handler_->RequestScan();
371 } 335 }
372 336
373 void NetworkStateHandler::WaitForScan(const std::string& type, 337 void NetworkStateHandler::WaitForScan(const std::string& type,
374 const base::Closure& callback) { 338 const base::Closure& callback) {
375 scan_complete_callbacks_[type].push_back(callback); 339 scan_complete_callbacks_[type].push_back(callback);
376 if (!GetScanningByType(NetworkTypePattern::Primitive(type))) 340 if (!GetScanningByType(NetworkTypePattern::Primitive(type)))
377 RequestScan(); 341 RequestScan();
(...skipping 22 matching lines...) Expand all
400 if (network) 364 if (network)
401 network->clear_last_error(); 365 network->clear_last_error();
402 } 366 }
403 367
404 void NetworkStateHandler::SetCheckPortalList( 368 void NetworkStateHandler::SetCheckPortalList(
405 const std::string& check_portal_list) { 369 const std::string& check_portal_list) {
406 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); 370 NET_LOG_EVENT("SetCheckPortalList", check_portal_list);
407 shill_property_handler_->SetCheckPortalList(check_portal_list); 371 shill_property_handler_->SetCheckPortalList(check_portal_list);
408 } 372 }
409 373
410 const FavoriteState* NetworkStateHandler::GetEAPForEthernet( 374 const NetworkState* NetworkStateHandler::GetEAPForEthernet(
411 const std::string& service_path) const { 375 const std::string& service_path) const {
412 const NetworkState* network = GetNetworkState(service_path); 376 const NetworkState* network = GetNetworkState(service_path);
413 if (!network) { 377 if (!network) {
414 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path); 378 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path);
415 return NULL; 379 return NULL;
416 } 380 }
417 if (network->type() != shill::kTypeEthernet) { 381 if (network->type() != shill::kTypeEthernet) {
418 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path); 382 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path);
419 return NULL; 383 return NULL;
420 } 384 }
421 if (!network->IsConnectedState()) 385 if (!network->IsConnectedState())
422 return NULL; 386 return NULL;
423 387
424 // The same EAP service is shared for all ethernet services/devices. 388 // 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 389 // However EAP is used/enabled per device and only if the connection was
426 // successfully established. 390 // successfully established.
427 const DeviceState* device = GetDeviceState(network->device_path()); 391 const DeviceState* device = GetDeviceState(network->device_path());
428 if (!device) { 392 if (!device) {
429 NET_LOG_ERROR( 393 NET_LOG_ERROR(
430 "GetEAPForEthernet", 394 "GetEAPForEthernet",
431 base::StringPrintf("Unknown device %s of connected ethernet service %s", 395 base::StringPrintf("Unknown device %s of connected ethernet service %s",
432 network->device_path().c_str(), 396 network->device_path().c_str(),
433 service_path.c_str())); 397 service_path.c_str()));
434 return NULL; 398 return NULL;
435 } 399 }
436 if (!device->eap_authentication_completed()) 400 if (!device->eap_authentication_completed())
437 return NULL; 401 return NULL;
438 402
439 FavoriteStateList list; 403 NetworkStateList list;
440 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), 404 GetNetworkListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap),
441 true /* configured_only */, 405 true /* configured_only */,
442 false /* visible_only */, 406 false /* visible_only */,
443 1 /* limit */, 407 1 /* limit */,
444 &list); 408 &list);
445 if (list.empty()) { 409 if (list.empty()) {
446 NET_LOG_ERROR("GetEAPForEthernet", 410 NET_LOG_ERROR("GetEAPForEthernet",
447 base::StringPrintf( 411 base::StringPrintf(
448 "Ethernet service %s connected using EAP, but no " 412 "Ethernet service %s connected using EAP, but no "
449 "EAP service found.", 413 "EAP service found.",
450 service_path.c_str())); 414 service_path.c_str()));
451 return NULL; 415 return NULL;
452 } 416 }
453 return list.front(); 417 return list.front();
454 } 418 }
455 419
456 //------------------------------------------------------------------------------ 420 //------------------------------------------------------------------------------
457 // ShillPropertyHandler::Delegate overrides 421 // ShillPropertyHandler::Delegate overrides
458 422
459 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, 423 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type,
460 const base::ListValue& entries) { 424 const base::ListValue& entries) {
461 ManagedStateList* managed_list = GetManagedList(type); 425 ManagedStateList* managed_list = GetManagedList(type);
462 NET_LOG_DEBUG(base::StringPrintf("UpdateManagedList:%d", type), 426 NET_LOG_DEBUG("UpdateManagedList: " + ManagedState::TypeToString(type),
463 base::StringPrintf("%" PRIuS, entries.GetSize())); 427 base::StringPrintf("%" PRIuS, entries.GetSize()));
464 // Create a map of existing entries. Assumes all entries in |managed_list| 428 // Create a map of existing entries. Assumes all entries in |managed_list|
465 // are unique. 429 // are unique.
466 std::map<std::string, ManagedState*> managed_map; 430 typedef std::map<std::string, ManagedState*> ManagedMap;
431 ManagedMap managed_map;
467 for (ManagedStateList::iterator iter = managed_list->begin(); 432 for (ManagedStateList::iterator iter = managed_list->begin();
468 iter != managed_list->end(); ++iter) { 433 iter != managed_list->end(); ++iter) {
469 ManagedState* managed = *iter; 434 ManagedState* managed = *iter;
470 DCHECK(!ContainsKey(managed_map, managed->path())); 435 DCHECK(!ContainsKey(managed_map, managed->path()));
471 managed_map[managed->path()] = managed; 436 managed_map[managed->path()] = managed;
472 } 437 }
473 // Clear the list (pointers are temporarily owned by managed_map). 438 // Clear the list (pointers are temporarily owned by managed_map).
474 managed_list->clear(); 439 managed_list->clear();
475 // Updates managed_list and request updates for new entries. 440 // Updates managed_list and request updates for new entries.
476 std::set<std::string> list_entries; 441 std::set<std::string> list_entries;
477 for (base::ListValue::const_iterator iter = entries.begin(); 442 for (base::ListValue::const_iterator iter = entries.begin();
478 iter != entries.end(); ++iter) { 443 iter != entries.end(); ++iter) {
479 std::string path; 444 std::string path;
480 (*iter)->GetAsString(&path); 445 (*iter)->GetAsString(&path);
481 if (path.empty() || path == shill::kFlimflamServicePath) { 446 if (path.empty() || path == shill::kFlimflamServicePath) {
482 NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path); 447 NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path);
483 continue; 448 continue;
484 } 449 }
485 std::map<std::string, ManagedState*>::iterator found = 450 ManagedMap::iterator found = managed_map.find(path);
486 managed_map.find(path);
487 ManagedState* managed;
488 if (found == managed_map.end()) { 451 if (found == managed_map.end()) {
489 if (list_entries.count(path) != 0) { 452 if (list_entries.count(path) != 0) {
490 NET_LOG_ERROR("Duplicate entry in list", path); 453 NET_LOG_ERROR("Duplicate entry in list", path);
491 continue; 454 continue;
492 } 455 }
493 managed = ManagedState::Create(type, path); 456 ManagedState* managed = ManagedState::Create(type, path);
494 managed_list->push_back(managed); 457 managed_list->push_back(managed);
495 } else { 458 } else {
496 managed = found->second; 459 managed_list->push_back(found->second);
497 managed_list->push_back(managed);
498 managed_map.erase(found); 460 managed_map.erase(found);
499 } 461 }
462 NET_LOG_DEBUG("Managed Entry: " + ManagedState::TypeToString(type), path);
pneubeck (no reviews) 2014/06/10 10:51:37 optional nit: too verbose even for debug? Your cal
stevenjb 2014/06/10 16:17:28 Was debugging. Removed.
500 list_entries.insert(path); 463 list_entries.insert(path);
501 } 464 }
502 // Delete any remaining entries in managed_map. 465 // Delete any remaining entries in managed_map.
503 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); 466 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end());
504 } 467 }
505 468
506 void NetworkStateHandler::ProfileListChanged() { 469 void NetworkStateHandler::UpdateVisibleNetworks(
pneubeck (no reviews) 2014/06/10 10:51:37 if this is called because of a kServices change be
stevenjb 2014/06/10 16:17:27 Correct. Shill emits these in the order we desire,
507 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); 470 const base::ListValue& entries) {
508 for (ManagedStateList::iterator iter = favorite_list_.begin(); 471 NET_LOG_DEBUG(base::StringPrintf("UpdateVisibleNetworks"),
509 iter != favorite_list_.end(); ++iter) { 472 base::StringPrintf("%" PRIuS, entries.GetSize()));
510 shill_property_handler_->RequestProperties( 473 // Create a map of all networks and clear the visible state.
511 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path()); 474 ManagedStateList* network_list =
475 GetManagedList(ManagedState::MANAGED_TYPE_NETWORK);
476 typedef std::map<std::string, NetworkState*> NetworkMap;
477 NetworkMap network_map;
478 for (ManagedStateList::iterator iter = network_list->begin();
479 iter != network_list->end(); ++iter) {
480 NetworkState* network = (*iter)->AsNetworkState();
481 network_map[network->path()] = network;
482 network->set_visible(false);
483 }
484 // Look up each entry and set the associated network to visible.
485 for (base::ListValue::const_iterator iter = entries.begin();
486 iter != entries.end(); ++iter) {
487 std::string path;
488 (*iter)->GetAsString(&path);
489 NetworkMap::iterator found = network_map.find(path);
490 if (found != network_map.end())
491 found->second->set_visible(true);
492 else
493 NET_LOG_DEBUG("Visible network not in list", path);
512 } 494 }
513 } 495 }
514 496
497 void NetworkStateHandler::ProfileListChanged() {
498 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties");
499 for (ManagedStateList::iterator iter = network_list_.begin();
500 iter != network_list_.end(); ++iter) {
501 NetworkState* network = (*iter)->AsNetworkState();
502 DCHECK(network);
503 if (!network->IsInProfile())
pneubeck (no reviews) 2014/06/10 10:51:37 The old function updated all services from Service
stevenjb 2014/06/10 16:17:28 Yes, that was intentional, but not that you mentio
504 continue;
505 shill_property_handler_->RequestProperties(
506 ManagedState::MANAGED_TYPE_NETWORK, network->path());
507 }
508 }
509
515 void NetworkStateHandler::UpdateManagedStateProperties( 510 void NetworkStateHandler::UpdateManagedStateProperties(
516 ManagedState::ManagedType type, 511 ManagedState::ManagedType type,
517 const std::string& path, 512 const std::string& path,
518 const base::DictionaryValue& properties) { 513 const base::DictionaryValue& properties) {
519 ManagedStateList* managed_list = GetManagedList(type); 514 ManagedStateList* managed_list = GetManagedList(type);
520 ManagedState* managed = GetModifiableManagedState(managed_list, path); 515 ManagedState* managed = GetModifiableManagedState(managed_list, path);
521 if (!managed) { 516 if (!managed) {
522 if (type != ManagedState::MANAGED_TYPE_FAVORITE) { 517 // The network has been removed from the list of networks.
523 // The network has been removed from the list of visible networks. 518 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path);
524 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path); 519 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 } 520 }
533 managed->set_update_received(); 521 managed->set_update_received();
534 522
535 std::string desc = GetManagedStateLogType(managed) + " Properties Received"; 523 std::string desc = GetManagedStateLogType(managed) + " Properties Received";
536 NET_LOG_DEBUG(desc, GetManagedStateLogName(managed)); 524 NET_LOG_DEBUG(desc, GetLogName(managed));
537 525
538 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 526 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
539 UpdateNetworkStateProperties(managed->AsNetworkState(), properties); 527 UpdateNetworkStateProperties(managed->AsNetworkState(), properties);
540 } else { 528 } else {
541 // Device, Favorite 529 // Device
542 for (base::DictionaryValue::Iterator iter(properties); 530 for (base::DictionaryValue::Iterator iter(properties);
543 !iter.IsAtEnd(); iter.Advance()) { 531 !iter.IsAtEnd(); iter.Advance()) {
544 managed->PropertyChanged(iter.key(), iter.value()); 532 managed->PropertyChanged(iter.key(), iter.value());
545 } 533 }
546 managed->InitialPropertiesReceived(properties); 534 managed->InitialPropertiesReceived(properties);
547 } 535 }
548 UpdateGuid(managed);
549 managed->set_update_requested(false); 536 managed->set_update_requested(false);
550 } 537 }
551 538
552 void NetworkStateHandler::UpdateNetworkStateProperties( 539 void NetworkStateHandler::UpdateNetworkStateProperties(
553 NetworkState* network, 540 NetworkState* network,
554 const base::DictionaryValue& properties) { 541 const base::DictionaryValue& properties) {
555 DCHECK(network); 542 DCHECK(network);
556 bool network_property_updated = false; 543 bool network_property_updated = false;
557 std::string prev_connection_state = network->connection_state(); 544 std::string prev_connection_state = network->connection_state();
558 for (base::DictionaryValue::Iterator iter(properties); 545 for (base::DictionaryValue::Iterator iter(properties);
559 !iter.IsAtEnd(); iter.Advance()) { 546 !iter.IsAtEnd(); iter.Advance()) {
560 if (network->PropertyChanged(iter.key(), iter.value())) 547 if (network->PropertyChanged(iter.key(), iter.value()))
561 network_property_updated = true; 548 network_property_updated = true;
562 } 549 }
563 network_property_updated |= network->InitialPropertiesReceived(properties); 550 network_property_updated |= network->InitialPropertiesReceived(properties);
564 // Notify observers of NetworkState changes. 551 // Notify observers of NetworkState changes.
565 if (network_property_updated || network->update_requested()) { 552 if (network_property_updated || network->update_requested()) {
566 // Signal connection state changed after all properties have been updated. 553 // Signal connection state changed after all properties have been updated.
567 if (ConnectionStateChanged(network, prev_connection_state)) 554 if (ConnectionStateChanged(network, prev_connection_state))
568 OnNetworkConnectionStateChanged(network); 555 OnNetworkConnectionStateChanged(network);
569 NET_LOG_EVENT("NetworkPropertiesUpdated", GetManagedStateLogName(network)); 556 NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network));
570 NotifyNetworkPropertiesUpdated(network); 557 NotifyNetworkPropertiesUpdated(network);
571 } 558 }
559 UpdateGuid(network);
572 } 560 }
573 561
574 void NetworkStateHandler::UpdateNetworkServiceProperty( 562 void NetworkStateHandler::UpdateNetworkServiceProperty(
575 const std::string& service_path, 563 const std::string& service_path,
576 const std::string& key, 564 const std::string& key,
577 const base::Value& value) { 565 const base::Value& value) {
578 // Update any associated FavoriteState.
579 ManagedState* favorite =
580 GetModifiableManagedState(&favorite_list_, service_path);
581 bool changed = false; 566 bool changed = false;
582 if (favorite)
583 changed |= favorite->PropertyChanged(key, value);
584
585 // Update the NetworkState.
586 NetworkState* network = GetModifiableNetworkState(service_path); 567 NetworkState* network = GetModifiableNetworkState(service_path);
587 if (!network) 568 if (!network)
588 return; 569 return;
589 std::string prev_connection_state = network->connection_state(); 570 std::string prev_connection_state = network->connection_state();
590 std::string prev_profile_path = network->profile_path(); 571 std::string prev_profile_path = network->profile_path();
591 changed |= network->PropertyChanged(key, value); 572 changed |= network->PropertyChanged(key, value);
592 if (!changed) 573 if (!changed)
593 return; 574 return;
594 575
595 if (key == shill::kStateProperty) { 576 if (key == shill::kStateProperty) {
(...skipping 28 matching lines...) Expand all
624 } else { 605 } else {
625 log_level = network_event_log::LOG_LEVEL_EVENT; 606 log_level = network_event_log::LOG_LEVEL_EVENT;
626 } 607 }
627 NET_LOG_LEVEL(log_level, log_event, detail); 608 NET_LOG_LEVEL(log_level, log_event, detail);
628 } 609 }
629 } 610 }
630 611
631 // All property updates signal 'NetworkPropertiesUpdated'. 612 // All property updates signal 'NetworkPropertiesUpdated'.
632 NotifyNetworkPropertiesUpdated(network); 613 NotifyNetworkPropertiesUpdated(network);
633 614
634 // If added to a Profile, request a full update so that a FavoriteState 615 // If added to a Profile, request a full update so that a NetworkState
635 // gets created. 616 // gets created.
636 if (prev_profile_path.empty() && !network->profile_path().empty()) 617 if (prev_profile_path.empty() && !network->profile_path().empty())
637 RequestUpdateForNetwork(service_path); 618 RequestUpdateForNetwork(service_path);
638 } 619 }
639 620
640 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, 621 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path,
641 const std::string& key, 622 const std::string& key,
642 const base::Value& value) { 623 const base::Value& value) {
643 DeviceState* device = GetModifiableDeviceState(device_path); 624 DeviceState* device = GetModifiableDeviceState(device_path);
644 if (!device) 625 if (!device)
645 return; 626 return;
646 if (!device->PropertyChanged(key, value)) 627 if (!device->PropertyChanged(key, value))
647 return; 628 return;
648 629
649 std::string detail = device->name() + "." + key; 630 std::string detail = device->name() + "." + key;
650 detail += " = " + network_event_log::ValueAsString(value); 631 detail += " = " + network_event_log::ValueAsString(value);
651 NET_LOG_EVENT("DevicePropertyUpdated", detail); 632 NET_LOG_EVENT("DevicePropertyUpdated", detail);
652 633
653 NotifyDeviceListChanged(); 634 NotifyDeviceListChanged();
654 635
655 if (key == shill::kScanningProperty && device->scanning() == false) 636 if (key == shill::kScanningProperty && device->scanning() == false)
656 ScanCompleted(device->type()); 637 ScanCompleted(device->type());
657 if (key == shill::kEapAuthenticationCompletedProperty) { 638 if (key == shill::kEapAuthenticationCompletedProperty) {
658 // Notify a change for each Ethernet service using this device. 639 // Notify a change for each Ethernet service using this device.
659 NetworkStateList ethernet_services; 640 NetworkStateList ethernet_services;
660 GetNetworkListByType(NetworkTypePattern::Ethernet(), &ethernet_services); 641 GetNetworkListByType(NetworkTypePattern::Ethernet(),
642 false /* configured_only */,
643 false /* visible_only */,
644 1 /* limit */,
pneubeck (no reviews) 2014/06/10 10:51:37 the comment and the used limit are off. just don't
stevenjb 2014/06/10 16:17:28 Done.
645 &ethernet_services);
661 for (NetworkStateList::const_iterator it = ethernet_services.begin(); 646 for (NetworkStateList::const_iterator it = ethernet_services.begin();
662 it != ethernet_services.end(); ++it) { 647 it != ethernet_services.end(); ++it) {
663 const NetworkState* ethernet_service = *it; 648 const NetworkState* ethernet_service = *it;
664 if (ethernet_service->update_received() || 649 if (ethernet_service->update_received() ||
665 ethernet_service->device_path() != device->path()) { 650 ethernet_service->device_path() != device->path()) {
666 continue; 651 continue;
667 } 652 }
668 RequestUpdateForNetwork(ethernet_service->path()); 653 RequestUpdateForNetwork(ethernet_service->path());
669 } 654 }
670 } 655 }
(...skipping 21 matching lines...) Expand all
692 const std::string& check_portal_list) { 677 const std::string& check_portal_list) {
693 check_portal_list_ = check_portal_list; 678 check_portal_list_ = check_portal_list;
694 } 679 }
695 680
696 void NetworkStateHandler::TechnologyListChanged() { 681 void NetworkStateHandler::TechnologyListChanged() {
697 // Eventually we would like to replace Technology state with Device state. 682 // Eventually we would like to replace Technology state with Device state.
698 // For now, treat technology state changes as device list changes. 683 // For now, treat technology state changes as device list changes.
699 NotifyDeviceListChanged(); 684 NotifyDeviceListChanged();
700 } 685 }
701 686
702 void NetworkStateHandler::ManagedStateListChanged( 687 void NetworkStateHandler::ManagedStateListChanged(
pneubeck (no reviews) 2014/06/10 10:51:36 again, this is called on ServicesCompleteList chan
stevenjb 2014/06/10 16:17:28 It's called when all updates have been received so
pneubeck (no reviews) 2014/06/11 12:44:55 _If_ any updates were requested. If no updates wer
stevenjb 2014/06/11 23:31:40 Ugh, you're right, there is an annoying case there
703 ManagedState::ManagedType type) { 688 ManagedState::ManagedType type) {
704 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 689 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
705 // Notify observers that the list of networks has changed. 690 // Notify observers that the list of networks has changed.
706 NET_LOG_EVENT("NetworkListChanged", 691 NET_LOG_EVENT("NOTIFY:NetworkListChanged",
707 base::StringPrintf("Size:%" PRIuS, network_list_.size())); 692 base::StringPrintf("Size:%" PRIuS, network_list_.size()));
708 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 693 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
709 NetworkListChanged()); 694 NetworkListChanged());
710 // Update UMA stats. 695 // Update UMA stats.
711 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", network_list_.size()); 696 size_t shared = 0, unshared = 0, visible = 0;
712 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { 697 for (ManagedStateList::iterator iter = network_list_.begin();
713 NET_LOG_DEBUG("FavoriteListChanged", 698 iter != network_list_.end(); ++iter) {
714 base::StringPrintf("Size:%" PRIuS, favorite_list_.size())); 699 NetworkState* network = (*iter)->AsNetworkState();
715 // The FavoriteState list only changes when the NetworkState list changes, 700 if (network->visible())
716 // so no need to signal observers here again. 701 ++visible;
717 702 if (network->IsInProfile()) {
718 // Update UMA stats. 703 if (network->IsPrivate())
719 size_t shared = 0, unshared = 0; 704 ++unshared;
720 for (ManagedStateList::iterator iter = favorite_list_.begin(); 705 else
721 iter != favorite_list_.end(); ++iter) { 706 ++shared;
722 FavoriteState* favorite = (*iter)->AsFavoriteState(); 707 }
723 if (!favorite->IsInProfile())
724 continue;
725 if (favorite->IsPrivate())
726 ++unshared;
727 else
728 ++shared;
729 } 708 }
709 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", visible);
730 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); 710 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared);
731 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); 711 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared);
732 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 712 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
733 std::string devices; 713 std::string devices;
734 for (ManagedStateList::const_iterator iter = device_list_.begin(); 714 for (ManagedStateList::const_iterator iter = device_list_.begin();
735 iter != device_list_.end(); ++iter) { 715 iter != device_list_.end(); ++iter) {
736 if (iter != device_list_.begin()) 716 if (iter != device_list_.begin())
737 devices += ", "; 717 devices += ", ";
738 devices += (*iter)->name(); 718 devices += (*iter)->name();
739 } 719 }
740 NET_LOG_EVENT("DeviceList:", devices); 720 NET_LOG_EVENT("DeviceList", devices);
741 NotifyDeviceListChanged(); 721 NotifyDeviceListChanged();
742 } else { 722 } else {
743 NOTREACHED(); 723 NOTREACHED();
744 } 724 }
745 } 725 }
746 726
747 void NetworkStateHandler::DefaultNetworkServiceChanged( 727 void NetworkStateHandler::DefaultNetworkServiceChanged(
748 const std::string& service_path) { 728 const std::string& service_path) {
749 // Shill uses '/' for empty service path values; check explicitly for that. 729 // Shill uses '/' for empty service path values; check explicitly for that.
750 const char* kEmptyServicePath = "/"; 730 const char* kEmptyServicePath = "/";
751 if (service_path == kEmptyServicePath) 731 std::string new_service_path =
752 default_network_path_.clear(); 732 (service_path != kEmptyServicePath) ? service_path : "";
753 else 733 if (new_service_path == default_network_path_)
pneubeck (no reviews) 2014/06/10 10:51:36 Just noting that this is an unrelated functional c
stevenjb 2014/06/10 16:17:28 Not entirely unrelated. This CL changes some of th
pneubeck (no reviews) 2014/06/11 12:44:55 If you would want to separate it, you could commit
754 default_network_path_ = service_path; 734 return;
735
736 default_network_path_ = service_path;
755 NET_LOG_EVENT("DefaultNetworkServiceChanged:", default_network_path_); 737 NET_LOG_EVENT("DefaultNetworkServiceChanged:", default_network_path_);
756 const NetworkState* network = NULL; 738 const NetworkState* network = NULL;
757 if (!default_network_path_.empty()) { 739 if (!default_network_path_.empty()) {
758 network = GetNetworkState(default_network_path_); 740 network = GetNetworkState(default_network_path_);
759 if (!network) { 741 if (!network) {
760 // If NetworkState is not available yet, do not notify observers here, 742 // If NetworkState is not available yet, do not notify observers here,
761 // they will be notified when the state is received. 743 // they will be notified when the state is received.
762 NET_LOG_DEBUG("Default NetworkState not available", 744 NET_LOG_DEBUG("Default NetworkState not available",
763 default_network_path_); 745 default_network_path_);
764 return; 746 return;
765 } 747 }
766 } 748 }
767 if (network && !network->IsConnectedState()) { 749 if (network && !network->IsConnectedState()) {
768 NET_LOG_ERROR( 750 NET_LOG_ERROR(
769 "DefaultNetwork is not connected: " + network->connection_state(), 751 "DefaultNetwork is not connected: " + network->connection_state(),
770 network->path()); 752 network->path());
771 } 753 }
772 NotifyDefaultNetworkChanged(network); 754 NotifyDefaultNetworkChanged(network);
773 } 755 }
774 756
775 //------------------------------------------------------------------------------ 757 //------------------------------------------------------------------------------
776 // Private methods 758 // Private methods
777 759
778 void NetworkStateHandler::UpdateGuid(ManagedState* managed) { 760 void NetworkStateHandler::UpdateGuid(NetworkState* network) {
779 if (managed->managed_type() == ManagedState::MANAGED_TYPE_FAVORITE) { 761 std::string specifier = network->GetSpecifier();
pneubeck (no reviews) 2014/06/10 10:51:37 optional nit: could add a DCHECK(!specifier.empty(
stevenjb 2014/06/10 16:17:28 Done.
780 FavoriteState* favorite = managed->AsFavoriteState(); 762 if (!network->guid().empty()) {
781 std::string specifier = favorite->GetSpecifier(); 763 // If the network is saved in a profile, remove the entry from the map.
782 if (!favorite->guid().empty()) { 764 // Otherwise ensure that the entry matches the specified GUID. (e.g. in
783 // If the favorite is saved in a profile, remove the entry from the map. 765 // case a visible network with a specified guid gets configured with a
784 // Otherwise ensure that the entry matches the specified GUID. 766 // new guid).
785 if (favorite->IsInProfile()) 767 if (network->IsInProfile())
786 specifier_guid_map_.erase(specifier); 768 specifier_guid_map_.erase(specifier);
787 else 769 else
788 specifier_guid_map_[specifier] = favorite->guid(); 770 specifier_guid_map_[specifier] = network->guid();
789 return; 771 return;
790 }
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 } 772 }
773 // Ensure that the NetworkState has a valid GUID.
774 std::string guid;
775 SpecifierGuidMap::iterator iter = specifier_guid_map_.find(specifier);
776 if (iter != specifier_guid_map_.end()) {
777 guid = iter->second;
778 } else {
779 guid = base::GenerateGUID();
780 specifier_guid_map_[specifier] = guid;
781 }
782 network->SetGuid(guid);
819 } 783 }
820 784
821 void NetworkStateHandler::NotifyDeviceListChanged() { 785 void NetworkStateHandler::NotifyDeviceListChanged() {
822 NET_LOG_DEBUG("NotifyDeviceListChanged", 786 NET_LOG_DEBUG("NOTIFY:DeviceListChanged",
823 base::StringPrintf("Size:%" PRIuS, device_list_.size())); 787 base::StringPrintf("Size:%" PRIuS, device_list_.size()));
824 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 788 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
825 DeviceListChanged()); 789 DeviceListChanged());
826 } 790 }
827 791
828 DeviceState* NetworkStateHandler::GetModifiableDeviceState( 792 DeviceState* NetworkStateHandler::GetModifiableDeviceState(
829 const std::string& device_path) const { 793 const std::string& device_path) const {
830 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path); 794 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path);
831 if (!managed) 795 if (!managed)
832 return NULL; 796 return NULL;
833 return managed->AsDeviceState(); 797 return managed->AsDeviceState();
834 } 798 }
835 799
836 NetworkState* NetworkStateHandler::GetModifiableNetworkState( 800 NetworkState* NetworkStateHandler::GetModifiableNetworkState(
837 const std::string& service_path) const { 801 const std::string& service_path) const {
838 ManagedState* managed = 802 ManagedState* managed =
839 GetModifiableManagedState(&network_list_, service_path); 803 GetModifiableManagedState(&network_list_, service_path);
840 if (!managed) 804 if (!managed)
841 return NULL; 805 return NULL;
842 return managed->AsNetworkState(); 806 return managed->AsNetworkState();
843 } 807 }
844 808
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( 809 ManagedState* NetworkStateHandler::GetModifiableManagedState(
855 const ManagedStateList* managed_list, 810 const ManagedStateList* managed_list,
856 const std::string& path) const { 811 const std::string& path) const {
857 for (ManagedStateList::const_iterator iter = managed_list->begin(); 812 for (ManagedStateList::const_iterator iter = managed_list->begin();
858 iter != managed_list->end(); ++iter) { 813 iter != managed_list->end(); ++iter) {
859 ManagedState* managed = *iter; 814 ManagedState* managed = *iter;
860 if (managed->path() == path) 815 if (managed->path() == path)
861 return managed; 816 return managed;
862 } 817 }
863 return NULL; 818 return NULL;
864 } 819 }
865 820
866 NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList( 821 NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList(
867 ManagedState::ManagedType type) { 822 ManagedState::ManagedType type) {
868 switch (type) { 823 switch (type) {
869 case ManagedState::MANAGED_TYPE_NETWORK: 824 case ManagedState::MANAGED_TYPE_NETWORK:
870 return &network_list_; 825 return &network_list_;
871 case ManagedState::MANAGED_TYPE_FAVORITE:
872 return &favorite_list_;
873 case ManagedState::MANAGED_TYPE_DEVICE: 826 case ManagedState::MANAGED_TYPE_DEVICE:
874 return &device_list_; 827 return &device_list_;
875 } 828 }
876 NOTREACHED(); 829 NOTREACHED();
877 return NULL; 830 return NULL;
878 } 831 }
879 832
880 void NetworkStateHandler::OnNetworkConnectionStateChanged( 833 void NetworkStateHandler::OnNetworkConnectionStateChanged(
881 NetworkState* network) { 834 NetworkState* network) {
882 DCHECK(network); 835 DCHECK(network);
883 std::string event = "NetworkConnectionStateChanged"; 836 std::string event = "NetworkConnectionStateChanged";
884 if (network->path() == default_network_path_) { 837 if (network->path() == default_network_path_) {
885 event = "Default" + event; 838 event = "Default" + event;
886 if (!network->IsConnectedState()) { 839 if (!network->IsConnectedState()) {
887 NET_LOG_ERROR( 840 NET_LOG_ERROR(
888 "DefaultNetwork is not connected: " + network->connection_state(), 841 "DefaultNetwork is not connected: " + network->connection_state(),
889 network->path()); 842 network->path());
890 } 843 }
891 } 844 }
892 NET_LOG_EVENT(event + ": " + network->connection_state(), 845 NET_LOG_EVENT("NOTIFY:" + event + ": " + network->connection_state(),
893 GetManagedStateLogName(network)); 846 GetLogName(network));
894 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 847 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
895 NetworkConnectionStateChanged(network)); 848 NetworkConnectionStateChanged(network));
896 if (network->path() == default_network_path_) 849 if (network->path() == default_network_path_)
897 NotifyDefaultNetworkChanged(network); 850 NotifyDefaultNetworkChanged(network);
898 } 851 }
899 852
900 void NetworkStateHandler::NotifyDefaultNetworkChanged( 853 void NetworkStateHandler::NotifyDefaultNetworkChanged(
901 const NetworkState* default_network) { 854 const NetworkState* default_network) {
855 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network));
902 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 856 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
903 DefaultNetworkChanged(default_network)); 857 DefaultNetworkChanged(default_network));
904 } 858 }
905 859
906 void NetworkStateHandler::NotifyNetworkPropertiesUpdated( 860 void NetworkStateHandler::NotifyNetworkPropertiesUpdated(
907 const NetworkState* network) { 861 const NetworkState* network) {
862 NET_LOG_DEBUG("NOTIFY:NetworkPropertiesUpdated", GetLogName(network));
908 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 863 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
909 NetworkPropertiesUpdated(network)); 864 NetworkPropertiesUpdated(network));
910 } 865 }
911 866
912 void NetworkStateHandler::ScanCompleted(const std::string& type) { 867 void NetworkStateHandler::ScanCompleted(const std::string& type) {
913 size_t num_callbacks = scan_complete_callbacks_.count(type); 868 size_t num_callbacks = scan_complete_callbacks_.count(type);
914 NET_LOG_EVENT("ScanCompleted", 869 NET_LOG_EVENT("ScanCompleted",
915 base::StringPrintf("%s:%" PRIuS, type.c_str(), num_callbacks)); 870 base::StringPrintf("%s:%" PRIuS, type.c_str(), num_callbacks));
916 if (num_callbacks == 0) 871 if (num_callbacks == 0)
917 return; 872 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 if (type.MatchesType(shill::kTypeBluetooth)) 916 if (type.MatchesType(shill::kTypeBluetooth))
962 technologies.push_back(new std::string(shill::kTypeBluetooth)); 917 technologies.push_back(new std::string(shill::kTypeBluetooth));
963 if (type.MatchesType(shill::kTypeVPN)) 918 if (type.MatchesType(shill::kTypeVPN))
964 technologies.push_back(new std::string(shill::kTypeVPN)); 919 technologies.push_back(new std::string(shill::kTypeVPN));
965 920
966 CHECK_GT(technologies.size(), 0ul); 921 CHECK_GT(technologies.size(), 0ul);
967 return technologies.Pass(); 922 return technologies.Pass();
968 } 923 }
969 924
970 } // namespace chromeos 925 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698