network_state.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 3// found in the LICENSE file. 4 5#include "chromeos/network/network_state.h" 6 7#include "base/values.h" 8#include "third_party/cros_system_api/dbus/service_constants.h" 9 10namespace chromeos { 11 12NetworkState::NetworkState(const std::string& path) 13 : ManagedState(MANAGED_TYPE_NETWORK, path), 14 signal_strength_(0) { 15} 16 17NetworkState::~NetworkState() { 18} 19 20bool NetworkState::PropertyChanged(const std::string& key, 21 const base::Value& value) { 22 // Keep care that these properties are the same as in |GetProperties|. 23 if (ManagedStatePropertyChanged(key, value)) 24 return true; 25 if (key == flimflam::kSignalStrengthProperty) { 26 return GetIntegerValue(key, value, &signal_strength_); 27 } else if (key == flimflam::kStateProperty) { 28 return GetStringValue(key, value, &connection_state_); 29 } else if (key == flimflam::kErrorProperty) { 30 return GetStringValue(key, value, &error_); 31 } else if (key == flimflam::kActivationStateProperty) { 32 return GetStringValue(key, value, &activation_state_); 33 } else if (key == flimflam::kRoamingStateProperty) { 34 return GetStringValue(key, value, &roaming_); 35 } else if (key == flimflam::kSecurityProperty) { 36 return GetStringValue(key, value, &security_); 37 } else if (key == flimflam::kNetworkTechnologyProperty) { 38 return GetStringValue(key, value, &technology_); 39 } else if (key == flimflam::kDeviceProperty) { 40 return GetStringValue(key, value, &device_path_); 41 } else if (key == flimflam::kGuidProperty) { 42 return GetStringValue(key, value, &guid_); 43 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { 44 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); 45 } else if (key == shill::kOutOfCreditsProperty) { 46 return GetBooleanValue(key, value, &cellular_out_of_credits_); 47 } 48 return false; 49} 50 51void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { 52 // Keep care that these properties are the same as in |PropertyChanged|. 53 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); 54 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); 55 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, 56 signal_strength()); 57 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, 58 connection_state()); 59 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, 60 error()); 61 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, 62 activation_state()); 63 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, 64 roaming()); 65 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, 66 security()); 67 dictionary->SetStringWithoutPathExpansion( 68 flimflam::kNetworkTechnologyProperty, 69 technology()); 70 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, 71 device_path()); 72 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid()); 73 dictionary->SetBooleanWithoutPathExpansion( 74 shill::kActivateOverNonCellularNetworkProperty, 75 activate_over_non_cellular_networks()); 76 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, 77 cellular_out_of_credits()); 78} 79 80bool NetworkState::IsConnectedState() const { 81 return StateIsConnected(connection_state_); 82} 83 84bool NetworkState::IsConnectingState() const { 85 return StateIsConnecting(connection_state_); 86} 87 88// static 89bool NetworkState::StateIsConnected(const std::string& connection_state) { 90 return (connection_state == flimflam::kStateReady || 91 connection_state == flimflam::kStateOnline || 92 connection_state == flimflam::kStatePortal); 93} 94 95// static 96bool NetworkState::StateIsConnecting(const std::string& connection_state) { 97 return (connection_state == flimflam::kStateAssociation || 98 connection_state == flimflam::kStateConfiguration || 99 connection_state == flimflam::kStateCarrier); 100} 101 102} // namespace chromeos 103