OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "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/location.h" | 9 #include "base/location.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chromeos/network/shill_property_util.h" | 22 #include "chromeos/network/shill_property_util.h" |
23 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
24 | 24 |
25 namespace chromeos { | 25 namespace chromeos { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 bool ConnectionStateChanged(NetworkState* network, | 29 bool ConnectionStateChanged(NetworkState* network, |
30 const std::string& prev_connection_state) { | 30 const std::string& prev_connection_state) { |
31 return (network->connection_state() != prev_connection_state) && | 31 return (network->connection_state() != prev_connection_state) && |
32 (network->connection_state() != flimflam::kStateIdle || | 32 (network->connection_state() != shill::kStateIdle || |
33 !prev_connection_state.empty()); | 33 !prev_connection_state.empty()); |
34 } | 34 } |
35 | 35 |
36 std::string GetManagedStateLogType(const ManagedState* state) { | 36 std::string GetManagedStateLogType(const ManagedState* state) { |
37 switch (state->managed_type()) { | 37 switch (state->managed_type()) { |
38 case ManagedState::MANAGED_TYPE_NETWORK: | 38 case ManagedState::MANAGED_TYPE_NETWORK: |
39 return "Network"; | 39 return "Network"; |
40 case ManagedState::MANAGED_TYPE_FAVORITE: | 40 case ManagedState::MANAGED_TYPE_FAVORITE: |
41 return "Favorite"; | 41 return "Favorite"; |
42 case ManagedState::MANAGED_TYPE_DEVICE: | 42 case ManagedState::MANAGED_TYPE_DEVICE: |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 323 |
324 void NetworkStateHandler::WaitForScan(const std::string& type, | 324 void NetworkStateHandler::WaitForScan(const std::string& type, |
325 const base::Closure& callback) { | 325 const base::Closure& callback) { |
326 scan_complete_callbacks_[type].push_back(callback); | 326 scan_complete_callbacks_[type].push_back(callback); |
327 if (!GetScanningByType(NetworkTypePattern::Primitive(type))) | 327 if (!GetScanningByType(NetworkTypePattern::Primitive(type))) |
328 RequestScan(); | 328 RequestScan(); |
329 } | 329 } |
330 | 330 |
331 void NetworkStateHandler::ConnectToBestWifiNetwork() { | 331 void NetworkStateHandler::ConnectToBestWifiNetwork() { |
332 NET_LOG_USER("ConnectToBestWifiNetwork", ""); | 332 NET_LOG_USER("ConnectToBestWifiNetwork", ""); |
333 WaitForScan(flimflam::kTypeWifi, | 333 WaitForScan(shill::kTypeWifi, |
334 base::Bind(&internal::ShillPropertyHandler::ConnectToBestServices, | 334 base::Bind(&internal::ShillPropertyHandler::ConnectToBestServices, |
335 shill_property_handler_->AsWeakPtr())); | 335 shill_property_handler_->AsWeakPtr())); |
336 } | 336 } |
337 | 337 |
338 void NetworkStateHandler::RequestUpdateForNetwork( | 338 void NetworkStateHandler::RequestUpdateForNetwork( |
339 const std::string& service_path) { | 339 const std::string& service_path) { |
340 NetworkState* network = GetModifiableNetworkState(service_path); | 340 NetworkState* network = GetModifiableNetworkState(service_path); |
341 if (network) | 341 if (network) |
342 network->set_update_requested(true); | 342 network->set_update_requested(true); |
343 NET_LOG_EVENT("RequestUpdate", service_path); | 343 NET_LOG_EVENT("RequestUpdate", service_path); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 500 |
501 // Update the NetworkState. | 501 // Update the NetworkState. |
502 NetworkState* network = GetModifiableNetworkState(service_path); | 502 NetworkState* network = GetModifiableNetworkState(service_path); |
503 if (!network) | 503 if (!network) |
504 return; | 504 return; |
505 std::string prev_connection_state = network->connection_state(); | 505 std::string prev_connection_state = network->connection_state(); |
506 std::string prev_profile_path = network->profile_path(); | 506 std::string prev_profile_path = network->profile_path(); |
507 if (!network->PropertyChanged(key, value)) | 507 if (!network->PropertyChanged(key, value)) |
508 return; | 508 return; |
509 | 509 |
510 if (key == flimflam::kStateProperty) { | 510 if (key == shill::kStateProperty) { |
511 if (ConnectionStateChanged(network, prev_connection_state)) { | 511 if (ConnectionStateChanged(network, prev_connection_state)) { |
512 OnNetworkConnectionStateChanged(network); | 512 OnNetworkConnectionStateChanged(network); |
513 // If the connection state changes, other properties such as IPConfig | 513 // If the connection state changes, other properties such as IPConfig |
514 // may have changed, so request a full update. | 514 // may have changed, so request a full update. |
515 RequestUpdateForNetwork(service_path); | 515 RequestUpdateForNetwork(service_path); |
516 } | 516 } |
517 } else { | 517 } else { |
518 bool noisy_property = | 518 bool noisy_property = |
519 key == flimflam::kSignalStrengthProperty || | 519 key == shill::kSignalStrengthProperty || |
520 key == shill::kWifiFrequencyListProperty; | 520 key == shill::kWifiFrequencyListProperty; |
521 if (network->path() == default_network_path_ && !noisy_property) { | 521 if (network->path() == default_network_path_ && !noisy_property) { |
522 // Wifi SignalStrength and WifiFrequencyList updates are too noisy, so | 522 // Wifi SignalStrength and WifiFrequencyList updates are too noisy, so |
523 // don't trigger default network updates for those changes. | 523 // don't trigger default network updates for those changes. |
524 OnDefaultNetworkChanged(); | 524 OnDefaultNetworkChanged(); |
525 } | 525 } |
526 if (prev_profile_path.empty() && !network->profile_path().empty()) { | 526 if (prev_profile_path.empty() && !network->profile_path().empty()) { |
527 // If added to a Profile, request a full update so that a FavoriteState | 527 // If added to a Profile, request a full update so that a FavoriteState |
528 // gets created. | 528 // gets created. |
529 RequestUpdateForNetwork(service_path); | 529 RequestUpdateForNetwork(service_path); |
530 } | 530 } |
531 if (!noisy_property) { | 531 if (!noisy_property) { |
532 std::string detail = network->name() + "." + key; | 532 std::string detail = network->name() + "." + key; |
533 detail += " = " + network_event_log::ValueAsString(value); | 533 detail += " = " + network_event_log::ValueAsString(value); |
534 network_event_log::LogLevel log_level; | 534 network_event_log::LogLevel log_level; |
535 if (key == flimflam::kErrorProperty || | 535 if (key == shill::kErrorProperty || key == shill::kErrorDetailsProperty) { |
536 key == shill::kErrorDetailsProperty) { | |
537 log_level = network_event_log::LOG_LEVEL_ERROR; | 536 log_level = network_event_log::LOG_LEVEL_ERROR; |
538 } else { | 537 } else { |
539 log_level = network_event_log::LOG_LEVEL_EVENT; | 538 log_level = network_event_log::LOG_LEVEL_EVENT; |
540 } | 539 } |
541 NET_LOG_LEVEL(log_level, "NetworkPropertyUpdated", detail); | 540 NET_LOG_LEVEL(log_level, "NetworkPropertyUpdated", detail); |
542 } | 541 } |
543 } | 542 } |
544 NetworkPropertiesUpdated(network); | 543 NetworkPropertiesUpdated(network); |
545 } | 544 } |
546 | 545 |
547 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, | 546 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, |
548 const std::string& key, | 547 const std::string& key, |
549 const base::Value& value) { | 548 const base::Value& value) { |
550 DeviceState* device = GetModifiableDeviceState(device_path); | 549 DeviceState* device = GetModifiableDeviceState(device_path); |
551 if (!device) | 550 if (!device) |
552 return; | 551 return; |
553 if (!device->PropertyChanged(key, value)) | 552 if (!device->PropertyChanged(key, value)) |
554 return; | 553 return; |
555 | 554 |
556 std::string detail = device->name() + "." + key; | 555 std::string detail = device->name() + "." + key; |
557 detail += " = " + network_event_log::ValueAsString(value); | 556 detail += " = " + network_event_log::ValueAsString(value); |
558 NET_LOG_EVENT("DevicePropertyUpdated", detail); | 557 NET_LOG_EVENT("DevicePropertyUpdated", detail); |
559 | 558 |
560 NotifyDeviceListChanged(); | 559 NotifyDeviceListChanged(); |
561 | 560 |
562 if (key == flimflam::kScanningProperty && device->scanning() == false) | 561 if (key == shill::kScanningProperty && device->scanning() == false) |
563 ScanCompleted(device->type()); | 562 ScanCompleted(device->type()); |
564 } | 563 } |
565 | 564 |
566 void NetworkStateHandler::CheckPortalListChanged( | 565 void NetworkStateHandler::CheckPortalListChanged( |
567 const std::string& check_portal_list) { | 566 const std::string& check_portal_list) { |
568 check_portal_list_ = check_portal_list; | 567 check_portal_list_ = check_portal_list; |
569 } | 568 } |
570 | 569 |
571 void NetworkStateHandler::TechnologyListChanged() { | 570 void NetworkStateHandler::TechnologyListChanged() { |
572 // Eventually we would like to replace Technology state with Device state. | 571 // Eventually we would like to replace Technology state with Device state. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 ScanCallbackList& callback_list = scan_complete_callbacks_[type]; | 712 ScanCallbackList& callback_list = scan_complete_callbacks_[type]; |
714 for (ScanCallbackList::iterator iter = callback_list.begin(); | 713 for (ScanCallbackList::iterator iter = callback_list.begin(); |
715 iter != callback_list.end(); ++iter) { | 714 iter != callback_list.end(); ++iter) { |
716 (*iter).Run(); | 715 (*iter).Run(); |
717 } | 716 } |
718 scan_complete_callbacks_.erase(type); | 717 scan_complete_callbacks_.erase(type); |
719 } | 718 } |
720 | 719 |
721 std::string NetworkStateHandler::GetTechnologyForType( | 720 std::string NetworkStateHandler::GetTechnologyForType( |
722 const NetworkTypePattern& type) const { | 721 const NetworkTypePattern& type) const { |
723 if (type.MatchesType(flimflam::kTypeEthernet)) | 722 if (type.MatchesType(shill::kTypeEthernet)) |
724 return flimflam::kTypeEthernet; | 723 return shill::kTypeEthernet; |
725 | 724 |
726 if (type.MatchesType(flimflam::kTypeWifi)) | 725 if (type.MatchesType(shill::kTypeWifi)) |
727 return flimflam::kTypeWifi; | 726 return shill::kTypeWifi; |
728 | 727 |
729 if (type.Equals(NetworkTypePattern::Wimax())) | 728 if (type.Equals(NetworkTypePattern::Wimax())) |
730 return flimflam::kTypeWimax; | 729 return shill::kTypeWimax; |
731 | 730 |
732 // Prefer Wimax over Cellular only if it's available. | 731 // Prefer Wimax over Cellular only if it's available. |
733 if (type.MatchesType(flimflam::kTypeWimax) && | 732 if (type.MatchesType(shill::kTypeWimax) && |
734 shill_property_handler_->IsTechnologyAvailable(flimflam::kTypeWimax)) { | 733 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) { |
735 return flimflam::kTypeWimax; | 734 return shill::kTypeWimax; |
736 } | 735 } |
737 | 736 |
738 if (type.MatchesType(flimflam::kTypeCellular)) | 737 if (type.MatchesType(shill::kTypeCellular)) |
739 return flimflam::kTypeCellular; | 738 return shill::kTypeCellular; |
740 | 739 |
741 NOTREACHED(); | 740 NOTREACHED(); |
742 return std::string(); | 741 return std::string(); |
743 } | 742 } |
744 | 743 |
745 } // namespace chromeos | 744 } // namespace chromeos |
OLD | NEW |