Chromium Code Reviews| 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.h" | 5 #include "chromeos/network/network_state.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "chromeos/network/network_profile_handler.h" | 13 #include "chromeos/network/network_profile_handler.h" |
| 14 #include "chromeos/network/network_type_pattern.h" | 14 #include "chromeos/network/network_type_pattern.h" |
| 15 #include "chromeos/network/network_util.h" | 15 #include "chromeos/network/network_util.h" |
| 16 #include "chromeos/network/onc/onc_utils.h" | 16 #include "chromeos/network/onc/onc_utils.h" |
| 17 #include "chromeos/network/shill_property_util.h" | 17 #include "chromeos/network/shill_property_util.h" |
| 18 #include "chromeos/network/tether_constants.h" | |
| 18 #include "components/device_event_log/device_event_log.h" | 19 #include "components/device_event_log/device_event_log.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 kErrorUnknown[] = "Unknown"; | 24 const char kErrorUnknown[] = "Unknown"; |
| 24 | 25 |
| 25 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 26 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
| 26 std::vector<std::string>* result) { | 27 std::vector<std::string>* result) { |
| 27 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 28 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 if (NetworkTypePattern::Mobile().MatchesType(type())) { | 286 if (NetworkTypePattern::Mobile().MatchesType(type())) { |
| 286 dictionary->SetStringWithoutPathExpansion(shill::kNetworkTechnologyProperty, | 287 dictionary->SetStringWithoutPathExpansion(shill::kNetworkTechnologyProperty, |
| 287 network_technology()); | 288 network_technology()); |
| 288 dictionary->SetStringWithoutPathExpansion(shill::kActivationStateProperty, | 289 dictionary->SetStringWithoutPathExpansion(shill::kActivationStateProperty, |
| 289 activation_state()); | 290 activation_state()); |
| 290 dictionary->SetStringWithoutPathExpansion(shill::kRoamingStateProperty, | 291 dictionary->SetStringWithoutPathExpansion(shill::kRoamingStateProperty, |
| 291 roaming()); | 292 roaming()); |
| 292 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, | 293 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, |
| 293 cellular_out_of_credits()); | 294 cellular_out_of_credits()); |
| 294 } | 295 } |
| 296 | |
| 297 // Tether properties | |
| 298 if (NetworkTypePattern::Tether().MatchesType(type())) { | |
| 299 DCHECK(!carrier().empty()); | |
| 300 DCHECK(battery_percentage() >= 0 && battery_percentage() <= 100); | |
| 301 DCHECK(signal_strength() >= 0 && signal_strength() <= 100); | |
|
Ryan Hansberry
2017/04/18 16:08:55
0 <= signal strength <= 4
Kyle Horimoto
2017/04/18 17:15:23
Not on Chrome OS.
| |
| 302 dictionary->SetIntegerWithoutPathExpansion(kTetherBatteryPercentage, | |
| 303 battery_percentage()); | |
|
Ryan Hansberry
2017/04/18 16:08:55
nit: the dchecks are in order 1. carrier, 2. batte
Kyle Horimoto
2017/04/18 17:15:23
Done.
| |
| 304 dictionary->SetStringWithoutPathExpansion(kTetherCarrier, carrier()); | |
| 305 dictionary->SetIntegerWithoutPathExpansion(kTetherSignalStrength, | |
| 306 signal_strength()); | |
| 307 } | |
| 295 } | 308 } |
| 296 | 309 |
| 297 void NetworkState::IPConfigPropertiesChanged( | 310 void NetworkState::IPConfigPropertiesChanged( |
| 298 const base::DictionaryValue& properties) { | 311 const base::DictionaryValue& properties) { |
| 299 for (base::DictionaryValue::Iterator iter(properties); !iter.IsAtEnd(); | 312 for (base::DictionaryValue::Iterator iter(properties); !iter.IsAtEnd(); |
| 300 iter.Advance()) { | 313 iter.Advance()) { |
| 301 std::string key = iter.key(); | 314 std::string key = iter.key(); |
| 302 const base::Value& value = iter.value(); | 315 const base::Value& value = iter.value(); |
| 303 | 316 |
| 304 if (key == shill::kAddressProperty) { | 317 if (key == shill::kAddressProperty) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 if (!visible()) | 356 if (!visible()) |
| 344 return shill::kStateDisconnect; | 357 return shill::kStateDisconnect; |
| 345 return connection_state_; | 358 return connection_state_; |
| 346 } | 359 } |
| 347 | 360 |
| 348 void NetworkState::set_connection_state(const std::string connection_state) { | 361 void NetworkState::set_connection_state(const std::string connection_state) { |
| 349 last_connection_state_ = connection_state_; | 362 last_connection_state_ = connection_state_; |
| 350 connection_state_ = connection_state; | 363 connection_state_ = connection_state; |
| 351 } | 364 } |
| 352 | 365 |
| 366 void NetworkState::SetTetherSignalStrength(int signal_strength) { | |
| 367 DCHECK(kTypeTether == type()); | |
|
Ryan Hansberry
2017/04/18 16:08:55
This is kind of odd looking -- can you use Equals(
Kyle Horimoto
2017/04/18 17:15:23
I'm not sure what you mean. std::string doesn't ha
| |
| 368 signal_strength_ = signal_strength; | |
| 369 } | |
| 370 | |
| 371 void NetworkState::SetBatteryPercentage(int battery_percentage) { | |
| 372 DCHECK(kTypeTether == type()); | |
| 373 battery_percentage_ = battery_percentage; | |
| 374 } | |
| 375 | |
| 376 void NetworkState::SetCarrier(const std::string& carrier) { | |
| 377 DCHECK(kTypeTether == type()); | |
| 378 carrier_ = carrier; | |
| 379 } | |
| 380 | |
| 353 bool NetworkState::IsDynamicWep() const { | 381 bool NetworkState::IsDynamicWep() const { |
| 354 return security_class_ == shill::kSecurityWep && | 382 return security_class_ == shill::kSecurityWep && |
| 355 eap_key_mgmt_ == shill::kKeyManagementIEEE8021X; | 383 eap_key_mgmt_ == shill::kKeyManagementIEEE8021X; |
| 356 } | 384 } |
| 357 | 385 |
| 358 bool NetworkState::IsConnectedState() const { | 386 bool NetworkState::IsConnectedState() const { |
| 359 return visible() && StateIsConnected(connection_state_); | 387 return visible() && StateIsConnected(connection_state_); |
| 360 } | 388 } |
| 361 | 389 |
| 362 bool NetworkState::IsConnectingState() const { | 390 bool NetworkState::IsConnectingState() const { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 return IsCaptivePortalState(shill_properties, false /* log */); | 478 return IsCaptivePortalState(shill_properties, false /* log */); |
| 451 } | 479 } |
| 452 | 480 |
| 453 // static | 481 // static |
| 454 bool NetworkState::ErrorIsValid(const std::string& error) { | 482 bool NetworkState::ErrorIsValid(const std::string& error) { |
| 455 // Shill uses "Unknown" to indicate an unset or cleared error state. | 483 // Shill uses "Unknown" to indicate an unset or cleared error state. |
| 456 return !error.empty() && error != kErrorUnknown; | 484 return !error.empty() && error != kErrorUnknown; |
| 457 } | 485 } |
| 458 | 486 |
| 459 } // namespace chromeos | 487 } // namespace chromeos |
| OLD | NEW |