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

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

Issue 2818593003: [CrOS Tether] Add tether network properties (battery percentage, carrier, and signal strength) to t… (Closed)
Patch Set: Tether networks connectable by default, and generated Closure compiler externs. Created 3 years, 8 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
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.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
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 dictionary->SetIntegerWithoutPathExpansion(kTetherBatteryPercentage,
300 battery_percentage());
301 dictionary->SetStringWithoutPathExpansion(kTetherCarrier, carrier());
302 dictionary->SetIntegerWithoutPathExpansion(kTetherSignalStrength,
303 signal_strength());
304 }
295 } 305 }
296 306
297 void NetworkState::IPConfigPropertiesChanged( 307 void NetworkState::IPConfigPropertiesChanged(
298 const base::DictionaryValue& properties) { 308 const base::DictionaryValue& properties) {
299 for (base::DictionaryValue::Iterator iter(properties); !iter.IsAtEnd(); 309 for (base::DictionaryValue::Iterator iter(properties); !iter.IsAtEnd();
300 iter.Advance()) { 310 iter.Advance()) {
301 std::string key = iter.key(); 311 std::string key = iter.key();
302 const base::Value& value = iter.value(); 312 const base::Value& value = iter.value();
303 313
304 if (key == shill::kAddressProperty) { 314 if (key == shill::kAddressProperty) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 if (!visible()) 353 if (!visible())
344 return shill::kStateDisconnect; 354 return shill::kStateDisconnect;
345 return connection_state_; 355 return connection_state_;
346 } 356 }
347 357
348 void NetworkState::set_connection_state(const std::string connection_state) { 358 void NetworkState::set_connection_state(const std::string connection_state) {
349 last_connection_state_ = connection_state_; 359 last_connection_state_ = connection_state_;
350 connection_state_ = connection_state; 360 connection_state_ = connection_state;
351 } 361 }
352 362
363 void NetworkState::SetTetherSignalStrength(int signal_strength) {
364 DCHECK(kTypeTether == type());
365 signal_strength_ = signal_strength;
366 }
367
368 void NetworkState::SetBatteryPercentage(int battery_percentage) {
369 DCHECK(kTypeTether == type());
370 battery_percentage_ = battery_percentage;
371 }
372
373 void NetworkState::SetCarrier(const std::string& carrier) {
374 DCHECK(kTypeTether == type());
375 carrier_ = carrier;
376 }
377
353 bool NetworkState::IsDynamicWep() const { 378 bool NetworkState::IsDynamicWep() const {
354 return security_class_ == shill::kSecurityWep && 379 return security_class_ == shill::kSecurityWep &&
355 eap_key_mgmt_ == shill::kKeyManagementIEEE8021X; 380 eap_key_mgmt_ == shill::kKeyManagementIEEE8021X;
356 } 381 }
357 382
358 bool NetworkState::IsConnectedState() const { 383 bool NetworkState::IsConnectedState() const {
359 return visible() && StateIsConnected(connection_state_); 384 return visible() && StateIsConnected(connection_state_);
360 } 385 }
361 386
362 bool NetworkState::IsConnectingState() const { 387 bool NetworkState::IsConnectingState() const {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 return IsCaptivePortalState(shill_properties, false /* log */); 475 return IsCaptivePortalState(shill_properties, false /* log */);
451 } 476 }
452 477
453 // static 478 // static
454 bool NetworkState::ErrorIsValid(const std::string& error) { 479 bool NetworkState::ErrorIsValid(const std::string& error) {
455 // Shill uses "Unknown" to indicate an unset or cleared error state. 480 // Shill uses "Unknown" to indicate an unset or cleared error state.
456 return !error.empty() && error != kErrorUnknown; 481 return !error.empty() && error != kErrorUnknown;
457 } 482 }
458 483
459 } // namespace chromeos 484 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698