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

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

Issue 2819383002: [CrOS Tether] Update NetworkState to include tether properties and integrate into NetworkStateHandl… (Closed)
Patch Set: Rebased. 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 provider_property->SetStringWithoutPathExpansion(shill::kTypeProperty, 255 provider_property->SetStringWithoutPathExpansion(shill::kTypeProperty,
255 vpn_provider_type_); 256 vpn_provider_type_);
256 if (vpn_provider_type_ == shill::kProviderThirdPartyVpn) { 257 if (vpn_provider_type_ == shill::kProviderThirdPartyVpn) {
257 provider_property->SetStringWithoutPathExpansion( 258 provider_property->SetStringWithoutPathExpansion(
258 shill::kHostProperty, third_party_vpn_provider_extension_id_); 259 shill::kHostProperty, third_party_vpn_provider_extension_id_);
259 } 260 }
260 dictionary->SetWithoutPathExpansion(shill::kProviderProperty, 261 dictionary->SetWithoutPathExpansion(shill::kProviderProperty,
261 provider_property.release()); 262 provider_property.release());
262 } 263 }
263 264
265 // Tether properties
266 if (NetworkTypePattern::Tether().MatchesType(type())) {
267 DCHECK(battery_percentage() >= 0 && battery_percentage() <= 100);
268 DCHECK(!carrier().empty());
269 DCHECK(signal_strength() >= 0 && signal_strength() <= 100);
270 dictionary->SetIntegerWithoutPathExpansion(kTetherBatteryPercentage,
271 battery_percentage());
272 dictionary->SetStringWithoutPathExpansion(kTetherCarrier, carrier());
273 dictionary->SetIntegerWithoutPathExpansion(kTetherSignalStrength,
274 signal_strength());
275 }
276
264 // Wireless properties 277 // Wireless properties
265 if (!NetworkTypePattern::Wireless().MatchesType(type())) 278 if (!NetworkTypePattern::Wireless().MatchesType(type()))
266 return; 279 return;
267 280
268 if (visible()) { 281 if (visible()) {
269 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, 282 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty,
270 connectable()); 283 connectable());
271 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, 284 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty,
272 signal_strength()); 285 signal_strength());
273 } 286 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698