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

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

Issue 14876021: Re-factor network_event_log (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 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
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/i18n/icu_encoding_detection.h" 7 #include "base/i18n/icu_encoding_detection.h"
8 #include "base/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversion_utils.h" 12 #include "base/strings/utf_string_conversion_utils.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chromeos/network/network_event_log.h" 14 #include "chromeos/network/network_event_log.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 16
17 namespace { 17 namespace {
18 18
19 const char kLogModule[] = "NetworkState";
20
21 bool ConvertListValueToStringVector(const base::ListValue& string_list, 19 bool ConvertListValueToStringVector(const base::ListValue& string_list,
22 std::vector<std::string>* result) { 20 std::vector<std::string>* result) {
23 for (size_t i = 0; i < string_list.GetSize(); ++i) { 21 for (size_t i = 0; i < string_list.GetSize(); ++i) {
24 std::string str; 22 std::string str;
25 if (!string_list.GetString(i, &str)) 23 if (!string_list.GetString(i, &str))
26 return false; 24 return false;
27 result->push_back(str); 25 result->push_back(str);
28 } 26 }
29 return true; 27 return true;
30 } 28 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 bool NetworkState::IsConnectingState() const { 177 bool NetworkState::IsConnectingState() const {
180 return StateIsConnecting(connection_state_); 178 return StateIsConnecting(connection_state_);
181 } 179 }
182 180
183 void NetworkState::UpdateName() { 181 void NetworkState::UpdateName() {
184 if (hex_ssid_.empty()) { 182 if (hex_ssid_.empty()) {
185 // Validate name for UTF8. 183 // Validate name for UTF8.
186 std::string valid_ssid = ValidateUTF8(name()); 184 std::string valid_ssid = ValidateUTF8(name());
187 if (valid_ssid != name()) { 185 if (valid_ssid != name()) {
188 set_name(valid_ssid); 186 set_name(valid_ssid);
189 network_event_log::AddEntry( 187 NET_LOG_DEBUG("UpdateName", base::StringPrintf(
190 kLogModule, "UpdateName", 188 "%s: UTF8: %s", path().c_str(), name().c_str()));
191 base::StringPrintf("%s: UTF8: %s", path().c_str(), name().c_str()));
192 } 189 }
193 return; 190 return;
194 } 191 }
195 192
196 std::string ssid; 193 std::string ssid;
197 std::vector<uint8> raw_ssid_bytes; 194 std::vector<uint8> raw_ssid_bytes;
198 if (base::HexStringToBytes(hex_ssid_, &raw_ssid_bytes)) { 195 if (base::HexStringToBytes(hex_ssid_, &raw_ssid_bytes)) {
199 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); 196 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end());
200 } else { 197 } else {
201 std::string desc = base::StringPrintf("%s: Error processing: %s", 198 std::string desc = base::StringPrintf("%s: Error processing: %s",
202 path().c_str(), hex_ssid_.c_str()); 199 path().c_str(), hex_ssid_.c_str());
203 network_event_log::AddEntry(kLogModule, "UpdateName", desc); 200 NET_LOG_DEBUG("UpdateName", desc);
204 LOG(ERROR) << desc; 201 LOG(ERROR) << desc;
205 ssid = name(); 202 ssid = name();
206 } 203 }
207 204
208 if (IsStringUTF8(ssid)) { 205 if (IsStringUTF8(ssid)) {
209 if (ssid != name()) { 206 if (ssid != name()) {
210 set_name(ssid); 207 set_name(ssid);
211 network_event_log::AddEntry( 208 NET_LOG_DEBUG("UpdateName", base::StringPrintf(
212 kLogModule, "UpdateName", 209 "%s: UTF8: %s", path().c_str(), name().c_str()));
213 base::StringPrintf("%s: UTF8: %s", path().c_str(), name().c_str()));
214 } 210 }
215 return; 211 return;
216 } 212 }
217 213
218 // Detect encoding and convert to UTF-8. 214 // Detect encoding and convert to UTF-8.
219 std::string encoding; 215 std::string encoding;
220 if (!base::DetectEncoding(ssid, &encoding)) { 216 if (!base::DetectEncoding(ssid, &encoding)) {
221 // TODO(stevenjb): Test this. See comment in PropertyChanged() under 217 // TODO(stevenjb): Test this. See comment in PropertyChanged() under
222 // flimflam::kCountryProperty. 218 // flimflam::kCountryProperty.
223 encoding = country_code_; 219 encoding = country_code_;
224 } 220 }
225 if (!encoding.empty()) { 221 if (!encoding.empty()) {
226 std::string utf8_ssid; 222 std::string utf8_ssid;
227 if (base::ConvertToUtf8AndNormalize(ssid, encoding, &utf8_ssid)) { 223 if (base::ConvertToUtf8AndNormalize(ssid, encoding, &utf8_ssid)) {
228 set_name(utf8_ssid); 224 set_name(utf8_ssid);
229 network_event_log::AddEntry( 225 NET_LOG_DEBUG("UpdateName", base::StringPrintf(
230 kLogModule, "UpdateName", 226 "%s: Encoding=%s: %s", path().c_str(),
231 base::StringPrintf("%s: Encoding=%s: %s", path().c_str(), 227 encoding.c_str(), name().c_str()));
232 encoding.c_str(), name().c_str()));
233 return; 228 return;
234 } 229 }
235 } 230 }
236 231
237 // Unrecognized encoding. Only use raw bytes if name_ is empty. 232 // Unrecognized encoding. Only use raw bytes if name_ is empty.
238 if (name().empty()) 233 if (name().empty())
239 set_name(ssid); 234 set_name(ssid);
240 network_event_log::AddEntry( 235 NET_LOG_DEBUG("UpdateName", base::StringPrintf(
241 kLogModule, "UpdateName", 236 "%s: Unrecognized Encoding=%s: %s", path().c_str(),
242 base::StringPrintf("%s: Unrecognized Encoding=%s: %s", path().c_str(), 237 encoding.c_str(), name().c_str()));
243 encoding.c_str(), name().c_str()));
244 } 238 }
245 239
246 // static 240 // static
247 bool NetworkState::StateIsConnected(const std::string& connection_state) { 241 bool NetworkState::StateIsConnected(const std::string& connection_state) {
248 return (connection_state == flimflam::kStateReady || 242 return (connection_state == flimflam::kStateReady ||
249 connection_state == flimflam::kStateOnline || 243 connection_state == flimflam::kStateOnline ||
250 connection_state == flimflam::kStatePortal); 244 connection_state == flimflam::kStatePortal);
251 } 245 }
252 246
253 // static 247 // static
254 bool NetworkState::StateIsConnecting(const std::string& connection_state) { 248 bool NetworkState::StateIsConnecting(const std::string& connection_state) {
255 return (connection_state == flimflam::kStateAssociation || 249 return (connection_state == flimflam::kStateAssociation ||
256 connection_state == flimflam::kStateConfiguration || 250 connection_state == flimflam::kStateConfiguration ||
257 connection_state == flimflam::kStateCarrier); 251 connection_state == flimflam::kStateCarrier);
258 } 252 }
259 253
260 // static 254 // static
261 std::string NetworkState::IPConfigProperty(const char* key) { 255 std::string NetworkState::IPConfigProperty(const char* key) {
262 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); 256 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key);
263 } 257 }
264 258
265 } // namespace chromeos 259 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698