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

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

Issue 267433005: Provide IPConfigs in networkingPrivate.GetProperties (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/network/network_state.h ('k') | chromeos/network/network_state_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chromeos/network/network_event_log.h" 9 #include "chromeos/network/network_event_log.h"
10 #include "chromeos/network/network_profile_handler.h" 10 #include "chromeos/network/network_profile_handler.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } else if (key == shill::kConnectableProperty) { 83 } else if (key == shill::kConnectableProperty) {
84 return GetBooleanValue(key, value, &connectable_); 84 return GetBooleanValue(key, value, &connectable_);
85 } else if (key == shill::kErrorProperty) { 85 } else if (key == shill::kErrorProperty) {
86 if (!GetStringValue(key, value, &error_)) 86 if (!GetStringValue(key, value, &error_))
87 return false; 87 return false;
88 if (ErrorIsValid(error_)) 88 if (ErrorIsValid(error_))
89 last_error_ = error_; 89 last_error_ = error_;
90 else 90 else
91 error_.clear(); 91 error_.clear();
92 return true; 92 return true;
93 } else if (key == IPConfigProperty(shill::kAddressProperty)) {
94 return GetStringValue(key, value, &ip_address_);
95 } else if (key == IPConfigProperty(shill::kGatewayProperty)) {
96 return GetStringValue(key, value, &gateway_);
97 } else if (key == IPConfigProperty(shill::kNameServersProperty)) {
98 const base::ListValue* dns_servers;
99 if (!value.GetAsList(&dns_servers))
100 return false;
101 dns_servers_.clear();
102 ConvertListValueToStringVector(*dns_servers, &dns_servers_);
103 return true;
104 } else if (key == IPConfigProperty(shill::kPrefixlenProperty)) {
105 return GetIntegerValue(key, value, &prefix_length_);
106 } else if (key == IPConfigProperty(
107 shill::kWebProxyAutoDiscoveryUrlProperty)) {
108 std::string url_string;
109 if (!GetStringValue(key, value, &url_string))
110 return false;
111 if (url_string.empty()) {
112 web_proxy_auto_discovery_url_ = GURL();
113 } else {
114 GURL gurl(url_string);
115 if (!gurl.is_valid()) {
116 web_proxy_auto_discovery_url_ = gurl;
117 } else {
118 NET_LOG_ERROR("Invalid WebProxyAutoDiscoveryUrl: " + url_string,
119 path());
120 web_proxy_auto_discovery_url_ = GURL();
121 }
122 }
123 return true;
124 } else if (key == shill::kActivationStateProperty) { 93 } else if (key == shill::kActivationStateProperty) {
125 return GetStringValue(key, value, &activation_state_); 94 return GetStringValue(key, value, &activation_state_);
126 } else if (key == shill::kRoamingStateProperty) { 95 } else if (key == shill::kRoamingStateProperty) {
127 return GetStringValue(key, value, &roaming_); 96 return GetStringValue(key, value, &roaming_);
128 } else if (key == shill::kSecurityProperty) { 97 } else if (key == shill::kSecurityProperty) {
129 return GetStringValue(key, value, &security_); 98 return GetStringValue(key, value, &security_);
130 } else if (key == shill::kEapMethodProperty) { 99 } else if (key == shill::kEapMethodProperty) {
131 return GetStringValue(key, value, &eap_method_); 100 return GetStringValue(key, value, &eap_method_);
132 } else if (key == shill::kUIDataProperty) { 101 } else if (key == shill::kUIDataProperty) {
133 scoped_ptr<NetworkUIData> new_ui_data = 102 scoped_ptr<NetworkUIData> new_ui_data =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return changed; 139 return changed;
171 } 140 }
172 141
173 void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const { 142 void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const {
174 ManagedState::GetStateProperties(dictionary); 143 ManagedState::GetStateProperties(dictionary);
175 144
176 // Properties shared by all types. 145 // Properties shared by all types.
177 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid()); 146 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid());
178 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, 147 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty,
179 connection_state()); 148 connection_state());
180 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error());
181 dictionary->SetStringWithoutPathExpansion(shill::kSecurityProperty, 149 dictionary->SetStringWithoutPathExpansion(shill::kSecurityProperty,
182 security()); 150 security());
151 if (!error().empty())
152 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error());
183 153
184 if (!NetworkTypePattern::Wireless().MatchesType(type())) 154 if (!NetworkTypePattern::Wireless().MatchesType(type()))
185 return; 155 return;
186 156
187 // Wireless properties 157 // Wireless properties
188 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, 158 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty,
189 connectable()); 159 connectable());
190 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, 160 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty,
191 signal_strength()); 161 signal_strength());
192 162
193 // Wifi properties 163 // Wifi properties
194 if (!NetworkTypePattern::WiFi().MatchesType(type())) { 164 if (NetworkTypePattern::WiFi().MatchesType(type())) {
195 dictionary->SetStringWithoutPathExpansion(shill::kEapMethodProperty, 165 dictionary->SetStringWithoutPathExpansion(shill::kEapMethodProperty,
196 eap_method()); 166 eap_method());
197 } 167 }
198 168
199 // Mobile properties 169 // Mobile properties
200 if (NetworkTypePattern::Mobile().MatchesType(type())) { 170 if (NetworkTypePattern::Mobile().MatchesType(type())) {
201 dictionary->SetStringWithoutPathExpansion( 171 dictionary->SetStringWithoutPathExpansion(
202 shill::kNetworkTechnologyProperty, 172 shill::kNetworkTechnologyProperty,
203 network_technology()); 173 network_technology());
204 dictionary->SetStringWithoutPathExpansion(shill::kActivationStateProperty, 174 dictionary->SetStringWithoutPathExpansion(shill::kActivationStateProperty,
205 activation_state()); 175 activation_state());
206 dictionary->SetStringWithoutPathExpansion(shill::kRoamingStateProperty, 176 dictionary->SetStringWithoutPathExpansion(shill::kRoamingStateProperty,
207 roaming()); 177 roaming());
208 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, 178 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty,
209 cellular_out_of_credits()); 179 cellular_out_of_credits());
210 } 180 }
211 } 181 }
212 182
183 void NetworkState::IPConfigPropertiesChanged(
184 const base::DictionaryValue& properties) {
185 for (base::DictionaryValue::Iterator iter(properties);
186 !iter.IsAtEnd(); iter.Advance()) {
187 std::string key = iter.key();
188 const base::Value& value = iter.value();
189
190 if (key == shill::kAddressProperty) {
191 GetStringValue(key, value, &ip_address_);
192 } else if (key == shill::kGatewayProperty) {
193 GetStringValue(key, value, &gateway_);
194 } else if (key == shill::kNameServersProperty) {
195 const base::ListValue* dns_servers;
196 if (value.GetAsList(&dns_servers)) {
197 dns_servers_.clear();
198 ConvertListValueToStringVector(*dns_servers, &dns_servers_);
199 }
200 } else if (key == shill::kPrefixlenProperty) {
201 GetIntegerValue(key, value, &prefix_length_);
202 } else if (key == shill::kWebProxyAutoDiscoveryUrlProperty) {
203 std::string url_string;
204 if (GetStringValue(key, value, &url_string)) {
205 if (url_string.empty()) {
206 web_proxy_auto_discovery_url_ = GURL();
207 } else {
208 GURL gurl(url_string);
209 if (gurl.is_valid()) {
210 web_proxy_auto_discovery_url_ = gurl;
211 } else {
212 NET_LOG_ERROR("Invalid WebProxyAutoDiscoveryUrl: " + url_string,
213 path());
214 web_proxy_auto_discovery_url_ = GURL();
215 }
216 }
217 }
218 }
219 }
220 }
221
213 bool NetworkState::RequiresActivation() const { 222 bool NetworkState::RequiresActivation() const {
214 return (type() == shill::kTypeCellular && 223 return (type() == shill::kTypeCellular &&
215 activation_state() != shill::kActivationStateActivated && 224 activation_state() != shill::kActivationStateActivated &&
216 activation_state() != shill::kActivationStateUnknown); 225 activation_state() != shill::kActivationStateUnknown);
217 } 226 }
218 227
219 bool NetworkState::IsConnectedState() const { 228 bool NetworkState::IsConnectedState() const {
220 return StateIsConnected(connection_state_); 229 return StateIsConnected(connection_state_);
221 } 230 }
222 231
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 connection_state == shill::kStateConfiguration || 275 connection_state == shill::kStateConfiguration ||
267 connection_state == shill::kStateCarrier); 276 connection_state == shill::kStateCarrier);
268 } 277 }
269 278
270 // static 279 // static
271 bool NetworkState::ErrorIsValid(const std::string& error) { 280 bool NetworkState::ErrorIsValid(const std::string& error) {
272 // Shill uses "Unknown" to indicate an unset or cleared error state. 281 // Shill uses "Unknown" to indicate an unset or cleared error state.
273 return !error.empty() && error != kErrorUnknown; 282 return !error.empty() && error != kErrorUnknown;
274 } 283 }
275 284
276 // static
277 std::string NetworkState::IPConfigProperty(const char* key) {
278 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key);
279 }
280
281 } // namespace chromeos 285 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state.h ('k') | chromeos/network/network_state_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698