| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "net/url_request/url_request_view_net_internals_job.h" | 5 #include "net/url_request/url_request_view_net_internals_job.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <ws2tcpip.h> | 8 #include <ws2tcpip.h> |
| 9 #else | 9 #else |
| 10 #include <netdb.h> | 10 #include <netdb.h> |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 out->append(StringPrintf("<ul><li>Size: %u</li>" | 218 out->append(StringPrintf("<ul><li>Size: %u</li>" |
| 219 "<li>Capacity: %u</li>" | 219 "<li>Capacity: %u</li>" |
| 220 "<li>Time to live (ms): %u</li></ul>", | 220 "<li>Time to live (ms): %u</li></ul>", |
| 221 host_cache->size(), | 221 host_cache->size(), |
| 222 host_cache->max_entries(), | 222 host_cache->max_entries(), |
| 223 host_cache->cache_duration_ms())); | 223 host_cache->cache_duration_ms())); |
| 224 | 224 |
| 225 out->append("<table border=1>" | 225 out->append("<table border=1>" |
| 226 "<tr>" | 226 "<tr>" |
| 227 "<th>Host</th>" | 227 "<th>Host</th>" |
| 228 "<th>Address family</th>" |
| 228 "<th>Address list</th>" | 229 "<th>Address list</th>" |
| 229 "<th>Time to live (ms)</th>" | 230 "<th>Time to live (ms)</th>" |
| 230 "</tr>"); | 231 "</tr>"); |
| 231 | 232 |
| 232 for (net::HostCache::EntryMap::const_iterator it = | 233 for (net::HostCache::EntryMap::const_iterator it = |
| 233 host_cache->entries().begin(); | 234 host_cache->entries().begin(); |
| 234 it != host_cache->entries().end(); | 235 it != host_cache->entries().end(); |
| 235 ++it) { | 236 ++it) { |
| 236 const std::string& host = it->first; | 237 const net::HostCache::Key& key = it->first; |
| 237 const net::HostCache::Entry* entry = it->second.get(); | 238 const net::HostCache::Entry* entry = it->second.get(); |
| 238 | 239 |
| 240 std::string address_family_str = |
| 241 AddressFamilyToString(key.address_family); |
| 242 |
| 239 if (entry->error == net::OK) { | 243 if (entry->error == net::OK) { |
| 240 // Note that ttl_ms may be negative, for the cases where entries have | 244 // Note that ttl_ms may be negative, for the cases where entries have |
| 241 // expired but not been garbage collected yet. | 245 // expired but not been garbage collected yet. |
| 242 int ttl_ms = static_cast<int>( | 246 int ttl_ms = static_cast<int>( |
| 243 (entry->expiration - base::TimeTicks::Now()).InMilliseconds()); | 247 (entry->expiration - base::TimeTicks::Now()).InMilliseconds()); |
| 244 | 248 |
| 245 // Color expired entries blue. | 249 // Color expired entries blue. |
| 246 if (ttl_ms > 0) { | 250 if (ttl_ms > 0) { |
| 247 out->append("<tr>"); | 251 out->append("<tr>"); |
| 248 } else { | 252 } else { |
| 249 out->append("<tr style='color:blue'>"); | 253 out->append("<tr style='color:blue'>"); |
| 250 } | 254 } |
| 251 | 255 |
| 252 // Stringify all of the addresses in the address list, separated | 256 // Stringify all of the addresses in the address list, separated |
| 253 // by newlines (br). | 257 // by newlines (br). |
| 254 std::string address_list_html; | 258 std::string address_list_html; |
| 255 const struct addrinfo* current_address = entry->addrlist.head(); | 259 const struct addrinfo* current_address = entry->addrlist.head(); |
| 256 while (current_address) { | 260 while (current_address) { |
| 257 if (!address_list_html.empty()) | 261 if (!address_list_html.empty()) |
| 258 address_list_html += "<br>"; | 262 address_list_html += "<br>"; |
| 259 address_list_html += EscapeForHTML( | 263 address_list_html += EscapeForHTML( |
| 260 net::NetAddressToString(current_address)); | 264 net::NetAddressToString(current_address)); |
| 261 current_address = current_address->ai_next; | 265 current_address = current_address->ai_next; |
| 262 } | 266 } |
| 263 | 267 |
| 264 out->append(StringPrintf("<td>%s</td><td>%s</td><td>%d</td></tr>", | 268 out->append(StringPrintf("<td>%s</td><td>%s</td><td>%s</td>" |
| 265 EscapeForHTML(host).c_str(), | 269 "<td>%d</td></tr>", |
| 270 EscapeForHTML(key.hostname).c_str(), |
| 271 EscapeForHTML(address_family_str).c_str(), |
| 266 address_list_html.c_str(), | 272 address_list_html.c_str(), |
| 267 ttl_ms)); | 273 ttl_ms)); |
| 268 } else { | 274 } else { |
| 269 // This was an entry that failed to be resolved. | 275 // This was an entry that failed to be resolved. |
| 270 // Color negative entries red. | 276 // Color negative entries red. |
| 271 out->append(StringPrintf( | 277 out->append(StringPrintf( |
| 272 "<tr style='color:red'><td>%s</td>" | 278 "<tr style='color:red'><td>%s</td><td>%s</td>" |
| 273 "<td colspan=2>%s</td></tr>", | 279 "<td colspan=2>%s</td></tr>", |
| 274 EscapeForHTML(host).c_str(), | 280 EscapeForHTML(key.hostname).c_str(), |
| 281 EscapeForHTML(address_family_str).c_str(), |
| 275 EscapeForHTML(net::ErrorToString(entry->error)).c_str())); | 282 EscapeForHTML(net::ErrorToString(entry->error)).c_str())); |
| 276 } | 283 } |
| 277 } | 284 } |
| 278 | 285 |
| 279 out->append("</table>"); | 286 out->append("</table>"); |
| 280 } | 287 } |
| 288 |
| 289 static std::string AddressFamilyToString(net::AddressFamily address_family) { |
| 290 switch (address_family) { |
| 291 case net::ADDRESS_FAMILY_IPV4_ONLY: |
| 292 return "IPV4_ONLY"; |
| 293 default: |
| 294 return "UNSPECIFIED"; |
| 295 } |
| 296 } |
| 281 }; | 297 }; |
| 282 | 298 |
| 283 class HostResolverSubSection : public SubSection { | 299 class HostResolverSubSection : public SubSection { |
| 284 public: | 300 public: |
| 285 HostResolverSubSection(SubSection* parent) | 301 HostResolverSubSection(SubSection* parent) |
| 286 : SubSection(parent, "hostresolver", "HostResolver") { | 302 : SubSection(parent, "hostresolver", "HostResolver") { |
| 287 AddSubSection(new HostResolverCacheSubSection(this)); | 303 AddSubSection(new HostResolverCacheSubSection(this)); |
| 288 } | 304 } |
| 289 }; | 305 }; |
| 290 | 306 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 data->append("<i>Nothing found for \""); | 474 data->append("<i>Nothing found for \""); |
| 459 data->append(EscapeForHTML(details)); | 475 data->append(EscapeForHTML(details)); |
| 460 data->append("\"</i>"); | 476 data->append("\"</i>"); |
| 461 } | 477 } |
| 462 | 478 |
| 463 data->append("</body></html>"); | 479 data->append("</body></html>"); |
| 464 | 480 |
| 465 return true; | 481 return true; |
| 466 } | 482 } |
| 467 | 483 |
| OLD | NEW |