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(battery_percentage() >= 0 && battery_percentage() <= 100); | |
300 DCHECK(!carrier().empty()); | |
301 DCHECK(signal_strength() >= 0 && signal_strength() <= 100); | |
stevenjb
2017/04/19 17:34:17
We generally shouldn't put DCHECK in getters. Thes
Kyle Horimoto
2017/04/19 19:23:28
Done.
| |
302 dictionary->SetIntegerWithoutPathExpansion(kTetherBatteryPercentage, | |
303 battery_percentage()); | |
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::SetTetherNetworkConnectable() { | |
367 DCHECK(kTypeTether == type()); | |
368 connectable_ = true; | |
369 } | |
370 | |
371 void NetworkState::SetTetherSignalStrength(int signal_strength) { | |
372 DCHECK(kTypeTether == type()); | |
373 signal_strength_ = signal_strength; | |
374 } | |
375 | |
376 void NetworkState::SetBatteryPercentage(int battery_percentage) { | |
377 DCHECK(kTypeTether == type()); | |
378 battery_percentage_ = battery_percentage; | |
379 } | |
380 | |
381 void NetworkState::SetCarrier(const std::string& carrier) { | |
382 DCHECK(kTypeTether == type()); | |
383 carrier_ = carrier; | |
384 } | |
385 | |
353 bool NetworkState::IsDynamicWep() const { | 386 bool NetworkState::IsDynamicWep() const { |
354 return security_class_ == shill::kSecurityWep && | 387 return security_class_ == shill::kSecurityWep && |
355 eap_key_mgmt_ == shill::kKeyManagementIEEE8021X; | 388 eap_key_mgmt_ == shill::kKeyManagementIEEE8021X; |
356 } | 389 } |
357 | 390 |
358 bool NetworkState::IsConnectedState() const { | 391 bool NetworkState::IsConnectedState() const { |
359 return visible() && StateIsConnected(connection_state_); | 392 return visible() && StateIsConnected(connection_state_); |
360 } | 393 } |
361 | 394 |
362 bool NetworkState::IsConnectingState() const { | 395 bool NetworkState::IsConnectingState() const { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 return IsCaptivePortalState(shill_properties, false /* log */); | 483 return IsCaptivePortalState(shill_properties, false /* log */); |
451 } | 484 } |
452 | 485 |
453 // static | 486 // static |
454 bool NetworkState::ErrorIsValid(const std::string& error) { | 487 bool NetworkState::ErrorIsValid(const std::string& error) { |
455 // Shill uses "Unknown" to indicate an unset or cleared error state. | 488 // Shill uses "Unknown" to indicate an unset or cleared error state. |
456 return !error.empty() && error != kErrorUnknown; | 489 return !error.empty() && error != kErrorUnknown; |
457 } | 490 } |
458 | 491 |
459 } // namespace chromeos | 492 } // namespace chromeos |
OLD | NEW |