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/managed_state.h" | 5 #include "chromeos/network/managed_state.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chromeos/network/device_state.h" | 9 #include "chromeos/network/device_state.h" |
10 #include "chromeos/network/favorite_state.h" | 10 #include "chromeos/network/favorite_state.h" |
11 #include "chromeos/network/network_event_log.h" | 11 #include "chromeos/network/network_event_log.h" |
12 #include "chromeos/network/network_state.h" | 12 #include "chromeos/network/network_state.h" |
13 #include "chromeos/network/shill_property_util.h" | 13 #include "chromeos/network/shill_property_util.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 14 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | 17 |
18 bool ManagedState::Matches(const NetworkTypePattern& pattern) const { | 18 bool ManagedState::Matches(const NetworkTypePattern& pattern) const { |
19 return pattern.MatchesType(type()); | 19 return pattern.MatchesType(type()); |
20 } | 20 } |
21 | 21 |
| 22 // static |
| 23 std::string ManagedState::TypeToString(ManagedType type) { |
| 24 switch (type) { |
| 25 case MANAGED_TYPE_NETWORK: |
| 26 return "Network"; |
| 27 case MANAGED_TYPE_FAVORITE: |
| 28 return "Favorite"; |
| 29 case MANAGED_TYPE_DEVICE: |
| 30 return "Device"; |
| 31 } |
| 32 return "Unknown"; |
| 33 } |
| 34 |
22 ManagedState::ManagedState(ManagedType type, const std::string& path) | 35 ManagedState::ManagedState(ManagedType type, const std::string& path) |
23 : managed_type_(type), | 36 : managed_type_(type), |
24 path_(path), | 37 path_(path), |
25 update_received_(false), | 38 update_received_(false), |
26 update_requested_(false) { | 39 update_requested_(false) { |
27 } | 40 } |
28 | 41 |
29 ManagedState::~ManagedState() { | 42 ManagedState::~ManagedState() { |
30 } | 43 } |
31 | 44 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 return false; | 113 return false; |
101 *out_value = new_value; | 114 *out_value = new_value; |
102 return true; | 115 return true; |
103 } | 116 } |
104 | 117 |
105 bool ManagedState::GetStringValue(const std::string& key, | 118 bool ManagedState::GetStringValue(const std::string& key, |
106 const base::Value& value, | 119 const base::Value& value, |
107 std::string* out_value) { | 120 std::string* out_value) { |
108 std::string new_value; | 121 std::string new_value; |
109 if (!value.GetAsString(&new_value)) { | 122 if (!value.GetAsString(&new_value)) { |
110 NET_LOG_ERROR("Error parsing state value", path() + "." + key); | 123 NET_LOG_ERROR("Error parsing state: " + key, path()); |
111 return false; | 124 return false; |
112 } | 125 } |
113 if (*out_value == new_value) | 126 if (*out_value == new_value) |
114 return false; | 127 return false; |
115 *out_value = new_value; | 128 *out_value = new_value; |
116 return true; | 129 return true; |
117 } | 130 } |
118 | 131 |
119 bool ManagedState::GetUInt32Value(const std::string& key, | 132 bool ManagedState::GetUInt32Value(const std::string& key, |
120 const base::Value& value, | 133 const base::Value& value, |
121 uint32* out_value) { | 134 uint32* out_value) { |
122 // base::Value restricts the number types to BOOL, INTEGER, and DOUBLE only. | 135 // base::Value restricts the number types to BOOL, INTEGER, and DOUBLE only. |
123 // uint32 will automatically get converted to a double, which is why we try | 136 // uint32 will automatically get converted to a double, which is why we try |
124 // to obtain the value as a double (see dbus/values_util.h). | 137 // to obtain the value as a double (see dbus/values_util.h). |
125 uint32 new_value; | 138 uint32 new_value; |
126 double double_value; | 139 double double_value; |
127 if (!value.GetAsDouble(&double_value) || double_value < 0) { | 140 if (!value.GetAsDouble(&double_value) || double_value < 0) { |
128 NET_LOG_ERROR("Error parsing state value", path() + "." + key); | 141 NET_LOG_ERROR("Error parsing state value", path() + "." + key); |
129 return false; | 142 return false; |
130 } | 143 } |
131 new_value = static_cast<uint32>(double_value); | 144 new_value = static_cast<uint32>(double_value); |
132 if (*out_value == new_value) | 145 if (*out_value == new_value) |
133 return false; | 146 return false; |
134 *out_value = new_value; | 147 *out_value = new_value; |
135 return true; | 148 return true; |
136 } | 149 } |
137 | 150 |
138 } // namespace chromeos | 151 } // namespace chromeos |
OLD | NEW |