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

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

Issue 14876021: Re-factor network_event_log (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + update comment Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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/json/json_writer.h"
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
11 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chromeos/network/device_state.h" 14 #include "chromeos/network/device_state.h"
14 #include "chromeos/network/managed_state.h" 15 #include "chromeos/network/managed_state.h"
15 #include "chromeos/network/network_event_log.h" 16 #include "chromeos/network/network_event_log.h"
16 #include "chromeos/network/network_state.h" 17 #include "chromeos/network/network_state.h"
17 #include "chromeos/network/network_state_handler_observer.h" 18 #include "chromeos/network/network_state_handler_observer.h"
18 #include "chromeos/network/shill_property_handler.h" 19 #include "chromeos/network/shill_property_handler.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h" 20 #include "third_party/cros_system_api/dbus/service_constants.h"
20 21
21 namespace { 22 namespace {
22 23
23 const char kLogModule[] = "NetworkStateHandler";
24
25 // Returns true if |network->type()| == |match_type|, or it matches one of the 24 // Returns true if |network->type()| == |match_type|, or it matches one of the
26 // following special match types: 25 // following special match types:
27 // * kMatchTypeDefault matches any network (i.e. the first instance) 26 // * kMatchTypeDefault matches any network (i.e. the first instance)
28 // * kMatchTypeNonVirtual matches non virtual networks 27 // * kMatchTypeNonVirtual matches non virtual networks
29 // * kMatchTypeWireless matches wireless networks 28 // * kMatchTypeWireless matches wireless networks
30 // * kMatchTypeMobile matches cellular or wimax networks 29 // * kMatchTypeMobile matches cellular or wimax networks
31 bool ManagedStateMatchesType(const chromeos::ManagedState* managed, 30 bool ManagedStateMatchesType(const chromeos::ManagedState* managed,
32 const std::string& match_type) { 31 const std::string& match_type) {
33 const std::string& type = managed->type(); 32 const std::string& type = managed->type();
34 if (match_type == chromeos::NetworkStateHandler::kMatchTypeDefault) 33 if (match_type == chromeos::NetworkStateHandler::kMatchTypeDefault)
35 return true; 34 return true;
36 if (match_type == type) 35 if (match_type == type)
37 return true; 36 return true;
38 if (match_type == chromeos::NetworkStateHandler::kMatchTypeNonVirtual && 37 if (match_type == chromeos::NetworkStateHandler::kMatchTypeNonVirtual &&
39 type != flimflam::kTypeVPN) { 38 type != flimflam::kTypeVPN) {
40 return true; 39 return true;
41 } 40 }
42 if (match_type == chromeos::NetworkStateHandler::kMatchTypeWireless && 41 if (match_type == chromeos::NetworkStateHandler::kMatchTypeWireless &&
43 type != flimflam::kTypeEthernet && type != flimflam::kTypeVPN) { 42 type != flimflam::kTypeEthernet && type != flimflam::kTypeVPN) {
44 return true; 43 return true;
45 } 44 }
46 if (match_type == chromeos::NetworkStateHandler::kMatchTypeMobile && 45 if (match_type == chromeos::NetworkStateHandler::kMatchTypeMobile &&
47 (type == flimflam::kTypeCellular || type == flimflam::kTypeWimax)) { 46 (type == flimflam::kTypeCellular || type == flimflam::kTypeWimax)) {
48 return true; 47 return true;
49 } 48 }
50 return false; 49 return false;
51 } 50 }
52 51
53 std::string ValueAsString(const base::Value& value) {
54 if (value.GetType() == base::Value::TYPE_BOOLEAN) {
55 bool bval = false;
56 value.GetAsBoolean(&bval);
57 return bval ? "true" : "false";
58 } else if (value.GetType() == base::Value::TYPE_INTEGER) {
59 int intval = 0;
60 value.GetAsInteger(&intval);
61 return base::StringPrintf("%d", intval);
62 } else if (value.GetType() == base::Value::TYPE_DOUBLE) {
63 double dval = 0;
64 value.GetAsDouble(&dval);
65 return base::StringPrintf("%g", dval);
66 } else if (value.GetType() == base::Value::TYPE_STRING) {
67 std::string vstr;
68 value.GetAsString(&vstr);
69 return vstr;
70 }
71 return "";
72 }
73
74 bool ConnectionStateChanged(chromeos::NetworkState* network, 52 bool ConnectionStateChanged(chromeos::NetworkState* network,
75 const std::string& prev_connection_state) { 53 const std::string& prev_connection_state) {
76 return (network->connection_state() != prev_connection_state) && 54 return (network->connection_state() != prev_connection_state) &&
77 (network->connection_state() != flimflam::kStateIdle || 55 (network->connection_state() != flimflam::kStateIdle ||
78 !prev_connection_state.empty()); 56 !prev_connection_state.empty());
79 } 57 }
80 58
59 std::string GetManagedStateLogName(const chromeos::ManagedState* state) {
60 if (!state)
61 return "None";
62 return base::StringPrintf("%s (%s)", state->name().c_str(),
63 state->path().c_str());
64 }
65
81 } // namespace 66 } // namespace
82 67
83 namespace chromeos { 68 namespace chromeos {
84 69
85 const char NetworkStateHandler::kMatchTypeDefault[] = "default"; 70 const char NetworkStateHandler::kMatchTypeDefault[] = "default";
86 const char NetworkStateHandler::kMatchTypeWireless[] = "wireless"; 71 const char NetworkStateHandler::kMatchTypeWireless[] = "wireless";
87 const char NetworkStateHandler::kMatchTypeMobile[] = "mobile"; 72 const char NetworkStateHandler::kMatchTypeMobile[] = "mobile";
88 const char NetworkStateHandler::kMatchTypeNonVirtual[] = "non-virtual"; 73 const char NetworkStateHandler::kMatchTypeNonVirtual[] = "non-virtual";
89 74
90 static NetworkStateHandler* g_network_state_handler = NULL; 75 static NetworkStateHandler* g_network_state_handler = NULL;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 state = TECHNOLOGY_UNAVAILABLE; 138 state = TECHNOLOGY_UNAVAILABLE;
154 VLOG(2) << "GetTechnologyState: " << type << " = " << state; 139 VLOG(2) << "GetTechnologyState: " << type << " = " << state;
155 return state; 140 return state;
156 } 141 }
157 142
158 void NetworkStateHandler::SetTechnologyEnabled( 143 void NetworkStateHandler::SetTechnologyEnabled(
159 const std::string& type, 144 const std::string& type,
160 bool enabled, 145 bool enabled,
161 const network_handler::ErrorCallback& error_callback) { 146 const network_handler::ErrorCallback& error_callback) {
162 std::string technology = GetTechnologyForType(type); 147 std::string technology = GetTechnologyForType(type);
163 network_event_log::AddEntry( 148 NET_LOG_EVENT("SetTechnologyEnabled",
164 kLogModule, "SetTechnologyEnabled", 149 base::StringPrintf("%s:%d", technology.c_str(), enabled));
165 base::StringPrintf("%s:%d", technology.c_str(), enabled));
166 shill_property_handler_->SetTechnologyEnabled( 150 shill_property_handler_->SetTechnologyEnabled(
167 technology, enabled, error_callback); 151 technology, enabled, error_callback);
168 ManagerPropertyChanged(); // Technology state changed -> ENABLING 152 // Signal Technology state changed -> ENABLING
153 NotifyManagerPropertyChanged();
169 } 154 }
170 155
171 const DeviceState* NetworkStateHandler::GetDeviceState( 156 const DeviceState* NetworkStateHandler::GetDeviceState(
172 const std::string& device_path) const { 157 const std::string& device_path) const {
173 return GetModifiableDeviceState(device_path); 158 return GetModifiableDeviceState(device_path);
174 } 159 }
175 160
176 const DeviceState* NetworkStateHandler::GetDeviceStateByType( 161 const DeviceState* NetworkStateHandler::GetDeviceStateByType(
177 const std::string& type) const { 162 const std::string& type) const {
178 for (ManagedStateList::const_iterator iter = device_list_.begin(); 163 for (ManagedStateList::const_iterator iter = device_list_.begin();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 list->clear(); 270 list->clear();
286 for (ManagedStateList::const_iterator iter = network_list_.begin(); 271 for (ManagedStateList::const_iterator iter = network_list_.begin();
287 iter != network_list_.end(); ++iter) { 272 iter != network_list_.end(); ++iter) {
288 const NetworkState* network = (*iter)->AsNetworkState(); 273 const NetworkState* network = (*iter)->AsNetworkState();
289 DCHECK(network); 274 DCHECK(network);
290 list->push_back(network); 275 list->push_back(network);
291 } 276 }
292 } 277 }
293 278
294 void NetworkStateHandler::RequestScan() const { 279 void NetworkStateHandler::RequestScan() const {
295 network_event_log::AddEntry(kLogModule, "RequestScan", ""); 280 NET_LOG_EVENT("RequestScan", "");
296 shill_property_handler_->RequestScan(); 281 shill_property_handler_->RequestScan();
297 } 282 }
298 283
299 void NetworkStateHandler::WaitForScan(const std::string& type, 284 void NetworkStateHandler::WaitForScan(const std::string& type,
300 const base::Closure& callback) { 285 const base::Closure& callback) {
301 scan_complete_callbacks_[type].push_back(callback); 286 scan_complete_callbacks_[type].push_back(callback);
302 if (!GetScanningByType(type)) 287 if (!GetScanningByType(type))
303 RequestScan(); 288 RequestScan();
304 } 289 }
305 290
306 void NetworkStateHandler::ConnectToBestWifiNetwork() { 291 void NetworkStateHandler::ConnectToBestWifiNetwork() {
307 network_event_log::AddEntry(kLogModule, "ConnectToBestWifiNetwork", ""); 292 NET_LOG_EVENT("ConnectToBestWifiNetwork", "");
308 WaitForScan(flimflam::kTypeWifi, 293 WaitForScan(flimflam::kTypeWifi,
309 base::Bind(&internal::ShillPropertyHandler::ConnectToBestServices, 294 base::Bind(&internal::ShillPropertyHandler::ConnectToBestServices,
310 shill_property_handler_->AsWeakPtr())); 295 shill_property_handler_->AsWeakPtr()));
311 } 296 }
312 297
313 void NetworkStateHandler::SetConnectingNetwork( 298 void NetworkStateHandler::SetConnectingNetwork(
314 const std::string& service_path) { 299 const std::string& service_path) {
315 connecting_network_ = service_path; 300 connecting_network_ = service_path;
316 network_event_log::AddEntry( 301 const NetworkState* network = GetNetworkState(service_path);
317 kLogModule, "SetConnectingNetwork", service_path); 302 if (network)
303 NET_LOG_EVENT("SetConnectingNetwork", GetManagedStateLogName(network));
304 else
305 NET_LOG_ERROR("SetConnectingNetwork to unknown network", service_path);
318 } 306 }
319 307
320 void NetworkStateHandler::GetNetworkStatePropertiesForTest( 308 void NetworkStateHandler::GetNetworkStatePropertiesForTest(
321 base::DictionaryValue* dictionary) const { 309 base::DictionaryValue* dictionary) const {
322 for (ManagedStateList::const_iterator iter = network_list_.begin(); 310 for (ManagedStateList::const_iterator iter = network_list_.begin();
323 iter != network_list_.end(); ++iter) { 311 iter != network_list_.end(); ++iter) {
324 base::DictionaryValue* network_dict = new base::DictionaryValue; 312 base::DictionaryValue* network_dict = new base::DictionaryValue;
325 (*iter)->AsNetworkState()->GetProperties(network_dict); 313 (*iter)->AsNetworkState()->GetProperties(network_dict);
326 dictionary->SetWithoutPathExpansion((*iter)->path(), network_dict); 314 dictionary->SetWithoutPathExpansion((*iter)->path(), network_dict);
327 } 315 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 if (is_observing) 356 if (is_observing)
369 managed->set_is_observed(true); 357 managed->set_is_observed(true);
370 if (request_properties) 358 if (request_properties)
371 shill_property_handler_->RequestProperties(type, path); 359 shill_property_handler_->RequestProperties(type, path);
372 } 360 }
373 // Delete any remaning entries in managed_map. 361 // Delete any remaning entries in managed_map.
374 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); 362 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end());
375 } 363 }
376 364
377 void NetworkStateHandler::ProfileListChanged() { 365 void NetworkStateHandler::ProfileListChanged() {
378 network_event_log::AddEntry( 366 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties");
379 kLogModule, "ProfileListChanged", "Re-Requesting Network Properties");
380 for (ManagedStateList::iterator iter = network_list_.begin(); 367 for (ManagedStateList::iterator iter = network_list_.begin();
381 iter != network_list_.end(); ++iter) { 368 iter != network_list_.end(); ++iter) {
382 shill_property_handler_->RequestProperties( 369 shill_property_handler_->RequestProperties(
383 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path()); 370 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path());
384 } 371 }
385 } 372 }
386 373
387 void NetworkStateHandler::UpdateManagedStateProperties( 374 void NetworkStateHandler::UpdateManagedStateProperties(
388 ManagedState::ManagedType type, 375 ManagedState::ManagedType type,
389 const std::string& path, 376 const std::string& path,
(...skipping 10 matching lines...) Expand all
400 for (base::DictionaryValue::Iterator iter(properties); 387 for (base::DictionaryValue::Iterator iter(properties);
401 !iter.IsAtEnd(); iter.Advance()) { 388 !iter.IsAtEnd(); iter.Advance()) {
402 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 389 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
403 if (managed->PropertyChanged(iter.key(), iter.value())) 390 if (managed->PropertyChanged(iter.key(), iter.value()))
404 network_property_updated = true; 391 network_property_updated = true;
405 } else { 392 } else {
406 managed->PropertyChanged(iter.key(), iter.value()); 393 managed->PropertyChanged(iter.key(), iter.value());
407 } 394 }
408 } 395 }
409 managed->InitialPropertiesReceived(); 396 managed->InitialPropertiesReceived();
410 network_event_log::AddEntry( 397 NET_LOG_DEBUG("PropertiesReceived", GetManagedStateLogName(managed));
411 kLogModule, "PropertiesReceived",
412 base::StringPrintf("%s (%s)", path.c_str(), managed->name().c_str()));
413 // Notify observers. 398 // Notify observers.
414 if (network_property_updated) { 399 if (network_property_updated) {
415 NetworkState* network = managed->AsNetworkState(); 400 NetworkState* network = managed->AsNetworkState();
416 DCHECK(network); 401 DCHECK(network);
417 // Signal connection state changed after all properties have been updated. 402 // Signal connection state changed after all properties have been updated.
418 if (ConnectionStateChanged(network, prev_connection_state)) 403 if (ConnectionStateChanged(network, prev_connection_state))
419 OnNetworkConnectionStateChanged(network); 404 OnNetworkConnectionStateChanged(network);
420 NetworkPropertiesUpdated(network); 405 NetworkPropertiesUpdated(network);
421 } 406 }
422 } 407 }
(...skipping 13 matching lines...) Expand all
436 if (ConnectionStateChanged(network, prev_connection_state)) 421 if (ConnectionStateChanged(network, prev_connection_state))
437 OnNetworkConnectionStateChanged(network); 422 OnNetworkConnectionStateChanged(network);
438 } else { 423 } else {
439 if (network->path() == default_network_path_ && 424 if (network->path() == default_network_path_ &&
440 key != flimflam::kSignalStrengthProperty) { 425 key != flimflam::kSignalStrengthProperty) {
441 // WiFi signal strength updates are too noisy, so don't 426 // WiFi signal strength updates are too noisy, so don't
442 // trigger default network updates for those changes. 427 // trigger default network updates for those changes.
443 OnDefaultNetworkChanged(); 428 OnDefaultNetworkChanged();
444 } 429 }
445 std::string detail = network->name() + "." + key; 430 std::string detail = network->name() + "." + key;
446 std::string vstr = ValueAsString(value); 431 std::string vstr;
432 base::JSONWriter::Write(&value, &vstr);
447 if (!vstr.empty()) 433 if (!vstr.empty())
pneubeck (no reviews) 2013/05/16 08:21:07 write should never fail. empty should be a valid v
stevenjb 2013/05/16 17:09:53 It could be an empty string, and I did not see tha
448 detail += " = " + vstr; 434 detail += " = " + vstr;
449 network_event_log::AddEntry(kLogModule, "NetworkPropertyUpdated", detail); 435 network_event_log::LogLevel log_level =
436 (key == flimflam::kSignalStrengthProperty)
437 ? network_event_log::LOG_LEVEL_DEBUG
438 : network_event_log::LOG_LEVEL_EVENT;
439 NET_LOG_LEVEL(log_level, "NetworkPropertyUpdated", detail);
450 } 440 }
451 NetworkPropertiesUpdated(network); 441 NetworkPropertiesUpdated(network);
452 } 442 }
453 443
454 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, 444 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path,
455 const std::string& key, 445 const std::string& key,
456 const base::Value& value) { 446 const base::Value& value) {
457 DeviceState* device = GetModifiableDeviceState(device_path); 447 DeviceState* device = GetModifiableDeviceState(device_path);
458 if (!device) 448 if (!device)
459 return; 449 return;
460 if (!device->PropertyChanged(key, value)) 450 if (!device->PropertyChanged(key, value))
461 return; 451 return;
462 452
463 std::string detail = device->name() + "." + key; 453 std::string detail = device->name() + "." + key;
464 std::string vstr = ValueAsString(value); 454 std::string vstr;
455 base::JSONWriter::Write(&value, &vstr);
465 if (!vstr.empty()) 456 if (!vstr.empty())
pneubeck (no reviews) 2013/05/16 08:21:07 same here.
466 detail += " = " + vstr; 457 detail += " = " + vstr;
467 network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail); 458 NET_LOG_EVENT("DevicePropertyUpdated", detail);
468 459
469 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 460 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
470 DeviceListChanged()); 461 DeviceListChanged());
471 462
472 if (key == flimflam::kScanningProperty && device->scanning() == false) 463 if (key == flimflam::kScanningProperty && device->scanning() == false)
473 ScanCompleted(device->type()); 464 ScanCompleted(device->type());
474 } 465 }
475 466
476 void NetworkStateHandler::ManagerPropertyChanged() { 467 void NetworkStateHandler::NotifyManagerPropertyChanged() {
477 network_event_log::AddEntry(kLogModule, "NetworkManagerChanged", ""); 468 NET_LOG_DEBUG("NotifyManagerPropertyChanged", "");
478 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 469 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
479 NetworkManagerChanged()); 470 NetworkManagerChanged());
480 } 471 }
481 472
482 void NetworkStateHandler::ManagedStateListChanged( 473 void NetworkStateHandler::ManagedStateListChanged(
483 ManagedState::ManagedType type) { 474 ManagedState::ManagedType type) {
484 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 475 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
485 // Notify observers that the list of networks has changed. 476 // Notify observers that the list of networks has changed.
486 network_event_log::AddEntry( 477 NET_LOG_EVENT("NetworkListChanged",
487 kLogModule, "NetworkListChanged", 478 base::StringPrintf("Size:%"PRIuS, network_list_.size()));
488 base::StringPrintf("Size:%"PRIuS, network_list_.size()));
489 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 479 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
490 NetworkListChanged()); 480 NetworkListChanged());
491 // The list order may have changed, so check if the default network changed. 481 // The list order may have changed, so check if the default network changed.
492 if (CheckDefaultNetworkChanged()) 482 if (CheckDefaultNetworkChanged())
493 OnDefaultNetworkChanged(); 483 OnDefaultNetworkChanged();
494 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 484 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
495 network_event_log::AddEntry( 485 NET_LOG_DEBUG("DeviceListChanged",
496 kLogModule, "DeviceListChanged", 486 base::StringPrintf("Size:%"PRIuS, device_list_.size()));
497 base::StringPrintf("Size:%"PRIuS, device_list_.size()));
498 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 487 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
499 DeviceListChanged()); 488 DeviceListChanged());
500 } else { 489 } else {
501 NOTREACHED(); 490 NOTREACHED();
502 } 491 }
503 } 492 }
504 493
505 //------------------------------------------------------------------------------ 494 //------------------------------------------------------------------------------
506 // Private methods 495 // Private methods
507 496
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 case ManagedState::MANAGED_TYPE_DEVICE: 531 case ManagedState::MANAGED_TYPE_DEVICE:
543 return &device_list_; 532 return &device_list_;
544 } 533 }
545 NOTREACHED(); 534 NOTREACHED();
546 return NULL; 535 return NULL;
547 } 536 }
548 537
549 void NetworkStateHandler::OnNetworkConnectionStateChanged( 538 void NetworkStateHandler::OnNetworkConnectionStateChanged(
550 NetworkState* network) { 539 NetworkState* network) {
551 DCHECK(network); 540 DCHECK(network);
552 network_event_log::AddEntry( 541 NET_LOG_EVENT("NetworkConnectionStateChanged", base::StringPrintf(
553 kLogModule, "NetworkConnectionStateChanged", 542 "%s:%s", GetManagedStateLogName(network).c_str(),
554 base::StringPrintf("%s:%s", network->path().c_str(), 543 network->connection_state().c_str()));
555 network->connection_state().c_str()));
556 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 544 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
557 NetworkConnectionStateChanged(network)); 545 NetworkConnectionStateChanged(network));
558 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) 546 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_)
559 OnDefaultNetworkChanged(); 547 OnDefaultNetworkChanged();
560 } 548 }
561 549
562 bool NetworkStateHandler::CheckDefaultNetworkChanged() { 550 bool NetworkStateHandler::CheckDefaultNetworkChanged() {
563 std::string new_default_network_path; 551 std::string new_default_network_path;
564 const NetworkState* new_default_network = DefaultNetwork(); 552 const NetworkState* new_default_network = DefaultNetwork();
565 if (new_default_network) 553 if (new_default_network)
566 new_default_network_path = new_default_network->path(); 554 new_default_network_path = new_default_network->path();
567 if (new_default_network_path == default_network_path_) 555 if (new_default_network_path == default_network_path_)
568 return false; 556 return false;
569 default_network_path_ = new_default_network_path; 557 default_network_path_ = new_default_network_path;
570 return true; 558 return true;
571 } 559 }
572 560
573 void NetworkStateHandler::OnDefaultNetworkChanged() { 561 void NetworkStateHandler::OnDefaultNetworkChanged() {
574 const NetworkState* default_network = DefaultNetwork(); 562 const NetworkState* default_network = DefaultNetwork();
575 network_event_log::AddEntry( 563 NET_LOG_EVENT("DefaultNetworkChanged",
576 kLogModule, "DefaultNetworkChanged", 564 GetManagedStateLogName(default_network));
577 default_network ? default_network->path() : "None");
578 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 565 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
579 DefaultNetworkChanged(default_network)); 566 DefaultNetworkChanged(default_network));
580 } 567 }
581 568
582 void NetworkStateHandler::NetworkPropertiesUpdated( 569 void NetworkStateHandler::NetworkPropertiesUpdated(
583 const NetworkState* network) { 570 const NetworkState* network) {
584 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 571 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
585 NetworkPropertiesUpdated(network)); 572 NetworkPropertiesUpdated(network));
586 // If |connecting_network_| transitions to a non-idle, non-connecting state, 573 // If |connecting_network_| transitions to a non-idle, non-connecting state,
587 // clear it *after* signalling observers. 574 // clear it *after* signalling observers.
588 if (network->path() == connecting_network_ && 575 if (network->path() == connecting_network_ &&
589 !network->IsConnectingState() && 576 !network->IsConnectingState() &&
590 network->connection_state() != flimflam::kStateIdle) { 577 network->connection_state() != flimflam::kStateIdle) {
591 connecting_network_.clear(); 578 connecting_network_.clear();
592 network_event_log::AddEntry( 579 NET_LOG_EVENT("ClearConnectingNetwork", base::StringPrintf(
593 kLogModule, "ClearConnectingNetwork", 580 "%s:%s", GetManagedStateLogName(network).c_str(),
594 base::StringPrintf("%s:%s", network->path().c_str(), 581 network->connection_state().c_str()));
595 network->connection_state().c_str()));
596 } 582 }
597 } 583 }
598 584
599 void NetworkStateHandler::ScanCompleted(const std::string& type) { 585 void NetworkStateHandler::ScanCompleted(const std::string& type) {
600 size_t num_callbacks = scan_complete_callbacks_.count(type); 586 size_t num_callbacks = scan_complete_callbacks_.count(type);
601 network_event_log::AddEntry( 587 NET_LOG_EVENT("ScanCompleted",
602 kLogModule, "ScanCompleted", 588 base::StringPrintf("%s:%"PRIuS, type.c_str(), num_callbacks));
603 base::StringPrintf("%s:%"PRIuS, type.c_str(), num_callbacks));
604 if (num_callbacks == 0) 589 if (num_callbacks == 0)
605 return; 590 return;
606 ScanCallbackList& callback_list = scan_complete_callbacks_[type]; 591 ScanCallbackList& callback_list = scan_complete_callbacks_[type];
607 for (ScanCallbackList::iterator iter = callback_list.begin(); 592 for (ScanCallbackList::iterator iter = callback_list.begin();
608 iter != callback_list.end(); ++iter) { 593 iter != callback_list.end(); ++iter) {
609 (*iter).Run(); 594 (*iter).Run();
610 } 595 }
611 scan_complete_callbacks_.erase(type); 596 scan_complete_callbacks_.erase(type);
612 } 597 }
613 598
614 std::string NetworkStateHandler::GetTechnologyForType( 599 std::string NetworkStateHandler::GetTechnologyForType(
615 const std::string& type) const { 600 const std::string& type) const {
616 if (type == kMatchTypeMobile) { 601 if (type == kMatchTypeMobile) {
617 if (shill_property_handler_->IsTechnologyAvailable(flimflam::kTypeWimax)) 602 if (shill_property_handler_->IsTechnologyAvailable(flimflam::kTypeWimax))
618 return flimflam::kTypeWimax; 603 return flimflam::kTypeWimax;
619 else 604 else
620 return flimflam::kTypeCellular; 605 return flimflam::kTypeCellular;
621 } 606 }
622 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual || 607 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual ||
623 type == kMatchTypeWireless) { 608 type == kMatchTypeWireless) {
624 NOTREACHED(); 609 NOTREACHED();
625 return flimflam::kTypeWifi; 610 return flimflam::kTypeWifi;
626 } 611 }
627 return type; 612 return type;
628 } 613 }
629 614
630 } // namespace chromeos 615 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698