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 "chrome/browser/chromeos/cros/network_parser.h" | 5 #include "chrome/browser/chromeos/cros/network_parser.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" // for debug output only. | 8 #include "base/json/json_writer.h" // for debug output only. |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 iter != info.end_keys(); ++iter) { | 39 iter != info.end_keys(); ++iter) { |
40 const std::string& key = *iter; | 40 const std::string& key = *iter; |
41 base::Value* value; | 41 base::Value* value; |
42 bool result = info.GetWithoutPathExpansion(key, &value); | 42 bool result = info.GetWithoutPathExpansion(key, &value); |
43 DCHECK(result); | 43 DCHECK(result); |
44 if (result) | 44 if (result) |
45 UpdateStatus(key, *value, device, NULL); | 45 UpdateStatus(key, *value, device, NULL); |
46 } | 46 } |
47 if (VLOG_IS_ON(2)) { | 47 if (VLOG_IS_ON(2)) { |
48 std::string json; | 48 std::string json; |
49 base::JSONWriter::Write(&info, true, &json); | 49 base::JSONWriter::WriteWithOptions(&info, |
| 50 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 51 &json); |
50 VLOG(2) << "Updated device for path " | 52 VLOG(2) << "Updated device for path " |
51 << device->device_path() << ": " << json; | 53 << device->device_path() << ": " << json; |
52 } | 54 } |
53 return true; | 55 return true; |
54 } | 56 } |
55 | 57 |
56 bool NetworkDeviceParser::UpdateStatus(const std::string& key, | 58 bool NetworkDeviceParser::UpdateStatus(const std::string& key, |
57 const base::Value& value, | 59 const base::Value& value, |
58 NetworkDevice* device, | 60 NetworkDevice* device, |
59 PropertyIndex* index) { | 61 PropertyIndex* index) { |
60 PropertyIndex found_index = mapper().Get(key); | 62 PropertyIndex found_index = mapper().Get(key); |
61 if (index) | 63 if (index) |
62 *index = found_index; | 64 *index = found_index; |
63 if (!ParseValue(found_index, value, device)) { | 65 if (!ParseValue(found_index, value, device)) { |
64 VLOG(1) << "NetworkDeviceParser: Unhandled key: " << key; | 66 VLOG(1) << "NetworkDeviceParser: Unhandled key: " << key; |
65 return false; | 67 return false; |
66 } | 68 } |
67 if (VLOG_IS_ON(2)) { | 69 if (VLOG_IS_ON(2)) { |
68 std::string value_json; | 70 std::string value_json; |
69 base::JSONWriter::Write(&value, true, &value_json); | 71 base::JSONWriter::WriteWithOptions(&value, |
| 72 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 73 &value_json); |
70 VLOG(2) << "Updated value on device: " | 74 VLOG(2) << "Updated value on device: " |
71 << device->device_path() << "[" << key << "] = " << value_json; | 75 << device->device_path() << "[" << key << "] = " << value_json; |
72 } | 76 } |
73 return true; | 77 return true; |
74 } | 78 } |
75 | 79 |
76 NetworkDevice* NetworkDeviceParser::CreateNewNetworkDevice( | 80 NetworkDevice* NetworkDeviceParser::CreateNewNetworkDevice( |
77 const std::string&device_path) { | 81 const std::string&device_path) { |
78 return new NetworkDevice(device_path); | 82 return new NetworkDevice(device_path); |
79 } | 83 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 *index = found_index; | 135 *index = found_index; |
132 network->UpdatePropertyMap(found_index, &value); | 136 network->UpdatePropertyMap(found_index, &value); |
133 if (!ParseValue(found_index, value, network)) { | 137 if (!ParseValue(found_index, value, network)) { |
134 VLOG(1) << "Unhandled key '" << key << "' in Network: " << network->name() | 138 VLOG(1) << "Unhandled key '" << key << "' in Network: " << network->name() |
135 << " ID: " << network->unique_id() | 139 << " ID: " << network->unique_id() |
136 << " Type: " << ConnectionTypeToString(network->type()); | 140 << " Type: " << ConnectionTypeToString(network->type()); |
137 return false; | 141 return false; |
138 } | 142 } |
139 if (VLOG_IS_ON(2)) { | 143 if (VLOG_IS_ON(2)) { |
140 std::string value_json; | 144 std::string value_json; |
141 base::JSONWriter::Write(&value, true, &value_json); | 145 base::JSONWriter::WriteWithOptions(&value, |
| 146 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 147 &value_json); |
142 VLOG(2) << "Updated value on network: " | 148 VLOG(2) << "Updated value on network: " |
143 << network->unique_id() << "[" << key << "] = " << value_json; | 149 << network->unique_id() << "[" << key << "] = " << value_json; |
144 } | 150 } |
145 return true; | 151 return true; |
146 } | 152 } |
147 | 153 |
148 Network* NetworkParser::CreateNewNetwork( | 154 Network* NetworkParser::CreateNewNetwork( |
149 ConnectionType type, const std::string& service_path) { | 155 ConnectionType type, const std::string& service_path) { |
150 switch (type) { | 156 switch (type) { |
151 case TYPE_ETHERNET: { | 157 case TYPE_ETHERNET: { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 static_cast<base::DictionaryValue*>(ui_data.get())); | 224 static_cast<base::DictionaryValue*>(ui_data.get())); |
219 return true; | 225 return true; |
220 } | 226 } |
221 default: | 227 default: |
222 break; | 228 break; |
223 } | 229 } |
224 return false; | 230 return false; |
225 } | 231 } |
226 | 232 |
227 } // namespace chromeos | 233 } // namespace chromeos |
OLD | NEW |