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 "base/values.h" | 7 #include "base/values.h" |
8 #include "third_party/cros_system_api/dbus/service_constants.h" | 8 #include "third_party/cros_system_api/dbus/service_constants.h" |
9 | 9 |
10 namespace { | |
11 | |
12 bool ConvertListValueToStringVector(const base::ListValue& string_list, | |
13 std::vector<std::string>* result) { | |
14 for (size_t i = 0; i < string_list.GetSize(); ++i) { | |
15 std::string str; | |
16 if (!string_list.GetString(i, &str)) | |
17 return false; | |
18 result->push_back(str); | |
19 } | |
20 return true; | |
21 } | |
22 | |
23 } // namespace | |
24 | |
10 namespace chromeos { | 25 namespace chromeos { |
11 | 26 |
12 NetworkState::NetworkState(const std::string& path) | 27 NetworkState::NetworkState(const std::string& path) |
13 : ManagedState(MANAGED_TYPE_NETWORK, path), | 28 : ManagedState(MANAGED_TYPE_NETWORK, path), |
14 signal_strength_(0) { | 29 signal_strength_(0) { |
15 } | 30 } |
16 | 31 |
17 NetworkState::~NetworkState() { | 32 NetworkState::~NetworkState() { |
18 } | 33 } |
19 | 34 |
20 bool NetworkState::PropertyChanged(const std::string& key, | 35 bool NetworkState::PropertyChanged(const std::string& key, |
21 const base::Value& value) { | 36 const base::Value& value) { |
22 // Keep care that these properties are the same as in |GetProperties|. | 37 // Keep care that these properties are the same as in |GetProperties|. |
23 if (ManagedStatePropertyChanged(key, value)) | 38 if (ManagedStatePropertyChanged(key, value)) |
24 return true; | 39 return true; |
25 if (key == flimflam::kSignalStrengthProperty) { | 40 if (key == flimflam::kSignalStrengthProperty) { |
26 return GetIntegerValue(key, value, &signal_strength_); | 41 return GetIntegerValue(key, value, &signal_strength_); |
27 } else if (key == flimflam::kStateProperty) { | 42 } else if (key == flimflam::kStateProperty) { |
28 return GetStringValue(key, value, &connection_state_); | 43 return GetStringValue(key, value, &connection_state_); |
29 } else if (key == flimflam::kErrorProperty) { | 44 } else if (key == flimflam::kErrorProperty) { |
30 return GetStringValue(key, value, &error_); | 45 return GetStringValue(key, value, &error_); |
46 } else if (key == flimflam::kAddressProperty) { | |
47 return GetStringValue(key, value, &ip_address_); | |
48 } else if (key == flimflam::kNameServersProperty) { | |
49 dns_servers_.clear(); | |
50 const base::ListValue* dns_servers; | |
51 if (value.GetAsList(&dns_servers) && | |
52 ConvertListValueToStringVector(*dns_servers, &dns_servers_)) | |
53 return true; | |
31 } else if (key == flimflam::kActivationStateProperty) { | 54 } else if (key == flimflam::kActivationStateProperty) { |
32 return GetStringValue(key, value, &activation_state_); | 55 return GetStringValue(key, value, &activation_state_); |
33 } else if (key == flimflam::kRoamingStateProperty) { | 56 } else if (key == flimflam::kRoamingStateProperty) { |
34 return GetStringValue(key, value, &roaming_); | 57 return GetStringValue(key, value, &roaming_); |
35 } else if (key == flimflam::kSecurityProperty) { | 58 } else if (key == flimflam::kSecurityProperty) { |
36 return GetStringValue(key, value, &security_); | 59 return GetStringValue(key, value, &security_); |
37 } else if (key == flimflam::kNetworkTechnologyProperty) { | 60 } else if (key == flimflam::kNetworkTechnologyProperty) { |
38 return GetStringValue(key, value, &technology_); | 61 return GetStringValue(key, value, &technology_); |
39 } else if (key == flimflam::kDeviceProperty) { | 62 } else if (key == flimflam::kDeviceProperty) { |
40 return GetStringValue(key, value, &device_path_); | 63 return GetStringValue(key, value, &device_path_); |
(...skipping 10 matching lines...) Expand all Loading... | |
51 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { | 74 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { |
52 // Keep care that these properties are the same as in |PropertyChanged|. | 75 // Keep care that these properties are the same as in |PropertyChanged|. |
53 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); | 76 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); |
54 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); | 77 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); |
55 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, | 78 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, |
56 signal_strength()); | 79 signal_strength()); |
57 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, | 80 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, |
58 connection_state()); | 81 connection_state()); |
59 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, | 82 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, |
60 error()); | 83 error()); |
84 dictionary->SetStringWithoutPathExpansion(flimflam::kAddressProperty, | |
pneubeck (no reviews)
2013/03/29 19:16:53
My veto here:
The only usage for this function is
stevenjb
2013/03/29 19:41:25
OK, now I understand the concern, and agree that t
gauravsh
2013/04/01 20:02:06
Done.
| |
85 ip_address()); | |
86 base::ListValue* value = new ListValue; | |
87 value->AppendStrings(dns_servers()); | |
88 dictionary->SetWithoutPathExpansion(flimflam::kNameServersProperty, | |
89 value); | |
stevenjb
2013/03/29 00:52:10
nit: one line?
gauravsh
2013/04/01 20:02:06
Done.
| |
61 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, | 90 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, |
62 activation_state()); | 91 activation_state()); |
63 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 92 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
64 roaming()); | 93 roaming()); |
65 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 94 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
66 security()); | 95 security()); |
67 dictionary->SetStringWithoutPathExpansion( | 96 dictionary->SetStringWithoutPathExpansion( |
68 flimflam::kNetworkTechnologyProperty, | 97 flimflam::kNetworkTechnologyProperty, |
69 technology()); | 98 technology()); |
70 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 99 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
(...skipping 22 matching lines...) Expand all Loading... | |
93 } | 122 } |
94 | 123 |
95 // static | 124 // static |
96 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 125 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
97 return (connection_state == flimflam::kStateAssociation || | 126 return (connection_state == flimflam::kStateAssociation || |
98 connection_state == flimflam::kStateConfiguration || | 127 connection_state == flimflam::kStateConfiguration || |
99 connection_state == flimflam::kStateCarrier); | 128 connection_state == flimflam::kStateCarrier); |
100 } | 129 } |
101 | 130 |
102 } // namespace chromeos | 131 } // namespace chromeos |
OLD | NEW |