| 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/guid.h" | 9 #include "base/guid.h" | 
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 22 #include "chromeos/network/network_state.h" | 22 #include "chromeos/network/network_state.h" | 
| 23 #include "chromeos/network/network_state_handler_observer.h" | 23 #include "chromeos/network/network_state_handler_observer.h" | 
| 24 #include "chromeos/network/shill_property_handler.h" | 24 #include "chromeos/network/shill_property_handler.h" | 
| 25 #include "third_party/cros_system_api/dbus/service_constants.h" | 25 #include "third_party/cros_system_api/dbus/service_constants.h" | 
| 26 | 26 | 
| 27 namespace chromeos { | 27 namespace chromeos { | 
| 28 | 28 | 
| 29 namespace { | 29 namespace { | 
| 30 | 30 | 
| 31 bool ConnectionStateChanged(NetworkState* network, | 31 bool ConnectionStateChanged(NetworkState* network, | 
| 32                             const std::string& prev_connection_state) { | 32                             const std::string& prev_connection_state, | 
| 33   return (network->connection_state() != prev_connection_state) && | 33                             bool prev_is_captive_portal) { | 
| 34          (network->connection_state() != shill::kStateIdle || | 34   return ((network->connection_state() != prev_connection_state) && | 
| 35           !prev_connection_state.empty()); | 35           !((network->connection_state() == shill::kStateIdle) && | 
|  | 36             prev_connection_state.empty())) || | 
|  | 37          (network->is_captive_portal() != prev_is_captive_portal); | 
| 36 } | 38 } | 
| 37 | 39 | 
| 38 std::string GetManagedStateLogType(const ManagedState* state) { | 40 std::string GetManagedStateLogType(const ManagedState* state) { | 
| 39   switch (state->managed_type()) { | 41   switch (state->managed_type()) { | 
| 40     case ManagedState::MANAGED_TYPE_NETWORK: | 42     case ManagedState::MANAGED_TYPE_NETWORK: | 
| 41       return "Network"; | 43       return "Network"; | 
| 42     case ManagedState::MANAGED_TYPE_DEVICE: | 44     case ManagedState::MANAGED_TYPE_DEVICE: | 
| 43       return "Device"; | 45       return "Device"; | 
| 44   } | 46   } | 
| 45   NOTREACHED(); | 47   NOTREACHED(); | 
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 512   } | 514   } | 
| 513   managed->set_update_requested(false); | 515   managed->set_update_requested(false); | 
| 514 } | 516 } | 
| 515 | 517 | 
| 516 void NetworkStateHandler::UpdateNetworkStateProperties( | 518 void NetworkStateHandler::UpdateNetworkStateProperties( | 
| 517     NetworkState* network, | 519     NetworkState* network, | 
| 518     const base::DictionaryValue& properties) { | 520     const base::DictionaryValue& properties) { | 
| 519   DCHECK(network); | 521   DCHECK(network); | 
| 520   bool network_property_updated = false; | 522   bool network_property_updated = false; | 
| 521   std::string prev_connection_state = network->connection_state(); | 523   std::string prev_connection_state = network->connection_state(); | 
|  | 524   bool prev_is_captive_portal = network->is_captive_portal(); | 
| 522   for (base::DictionaryValue::Iterator iter(properties); | 525   for (base::DictionaryValue::Iterator iter(properties); | 
| 523        !iter.IsAtEnd(); iter.Advance()) { | 526        !iter.IsAtEnd(); iter.Advance()) { | 
| 524     if (network->PropertyChanged(iter.key(), iter.value())) | 527     if (network->PropertyChanged(iter.key(), iter.value())) | 
| 525       network_property_updated = true; | 528       network_property_updated = true; | 
| 526   } | 529   } | 
| 527   network_property_updated |= network->InitialPropertiesReceived(properties); | 530   network_property_updated |= network->InitialPropertiesReceived(properties); | 
| 528   UpdateGuid(network); | 531   UpdateGuid(network); | 
| 529   network_list_sorted_ = false; | 532   network_list_sorted_ = false; | 
| 530 | 533 | 
| 531   // Notify observers of NetworkState changes. | 534   // Notify observers of NetworkState changes. | 
| 532   if (network_property_updated || network->update_requested()) { | 535   if (network_property_updated || network->update_requested()) { | 
| 533     // Signal connection state changed after all properties have been updated. | 536     // Signal connection state changed after all properties have been updated. | 
| 534     if (ConnectionStateChanged(network, prev_connection_state)) | 537     if (ConnectionStateChanged(network, prev_connection_state, | 
|  | 538                                prev_is_captive_portal)) { | 
| 535       OnNetworkConnectionStateChanged(network); | 539       OnNetworkConnectionStateChanged(network); | 
|  | 540     } | 
| 536     NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network)); | 541     NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network)); | 
| 537     NotifyNetworkPropertiesUpdated(network); | 542     NotifyNetworkPropertiesUpdated(network); | 
| 538   } | 543   } | 
| 539 } | 544 } | 
| 540 | 545 | 
| 541 void NetworkStateHandler::UpdateNetworkServiceProperty( | 546 void NetworkStateHandler::UpdateNetworkServiceProperty( | 
| 542     const std::string& service_path, | 547     const std::string& service_path, | 
| 543     const std::string& key, | 548     const std::string& key, | 
| 544     const base::Value& value) { | 549     const base::Value& value) { | 
| 545   SCOPED_NET_LOG_IF_SLOW(); | 550   SCOPED_NET_LOG_IF_SLOW(); | 
| 546   bool changed = false; | 551   bool changed = false; | 
| 547   NetworkState* network = GetModifiableNetworkState(service_path); | 552   NetworkState* network = GetModifiableNetworkState(service_path); | 
| 548   if (!network) | 553   if (!network) | 
| 549     return; | 554     return; | 
| 550   std::string prev_connection_state = network->connection_state(); | 555   std::string prev_connection_state = network->connection_state(); | 
|  | 556   bool prev_is_captive_portal = network->is_captive_portal(); | 
| 551   std::string prev_profile_path = network->profile_path(); | 557   std::string prev_profile_path = network->profile_path(); | 
| 552   changed |= network->PropertyChanged(key, value); | 558   changed |= network->PropertyChanged(key, value); | 
| 553   if (!changed) | 559   if (!changed) | 
| 554     return; | 560     return; | 
| 555 | 561 | 
| 556   if (key == shill::kStateProperty || key == shill::kVisibleProperty) { | 562   if (key == shill::kStateProperty || key == shill::kVisibleProperty) { | 
| 557     network_list_sorted_ = false; | 563     network_list_sorted_ = false; | 
| 558     if (ConnectionStateChanged(network, prev_connection_state)) { | 564     if (ConnectionStateChanged(network, prev_connection_state, | 
|  | 565                                prev_is_captive_portal)) { | 
| 559       OnNetworkConnectionStateChanged(network); | 566       OnNetworkConnectionStateChanged(network); | 
| 560       // If the connection state changes, other properties such as IPConfig | 567       // If the connection state changes, other properties such as IPConfig | 
| 561       // may have changed, so request a full update. | 568       // may have changed, so request a full update. | 
| 562       RequestUpdateForNetwork(service_path); | 569       RequestUpdateForNetwork(service_path); | 
| 563     } | 570     } | 
| 564   } else { | 571   } else { | 
| 565     std::string value_str; | 572     std::string value_str; | 
| 566     value.GetAsString(&value_str); | 573     value.GetAsString(&value_str); | 
| 567     // Some property changes are noisy and not interesting: | 574     // Some property changes are noisy and not interesting: | 
| 568     // * Wifi SignalStrength | 575     // * Wifi SignalStrength | 
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 961   if (type.MatchesType(shill::kTypeBluetooth)) | 968   if (type.MatchesType(shill::kTypeBluetooth)) | 
| 962     technologies.push_back(new std::string(shill::kTypeBluetooth)); | 969     technologies.push_back(new std::string(shill::kTypeBluetooth)); | 
| 963   if (type.MatchesType(shill::kTypeVPN)) | 970   if (type.MatchesType(shill::kTypeVPN)) | 
| 964     technologies.push_back(new std::string(shill::kTypeVPN)); | 971     technologies.push_back(new std::string(shill::kTypeVPN)); | 
| 965 | 972 | 
| 966   CHECK_GT(technologies.size(), 0ul); | 973   CHECK_GT(technologies.size(), 0ul); | 
| 967   return technologies.Pass(); | 974   return technologies.Pass(); | 
| 968 } | 975 } | 
| 969 | 976 | 
| 970 }  // namespace chromeos | 977 }  // namespace chromeos | 
| OLD | NEW | 
|---|