| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/net/view_net_internals_job_factory.h" | 5 #include "chrome/browser/net/view_net_internals_job_factory.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 host_cache->size(), | 342 host_cache->size(), |
| 343 host_cache->max_entries(), | 343 host_cache->max_entries(), |
| 344 host_cache->success_entry_ttl().InMilliseconds(), | 344 host_cache->success_entry_ttl().InMilliseconds(), |
| 345 host_cache->failure_entry_ttl().InMilliseconds()); | 345 host_cache->failure_entry_ttl().InMilliseconds()); |
| 346 | 346 |
| 347 out->append("<table border=1>" | 347 out->append("<table border=1>" |
| 348 "<tr>" | 348 "<tr>" |
| 349 "<th>Host</th>" | 349 "<th>Host</th>" |
| 350 "<th>Address family</th>" | 350 "<th>Address family</th>" |
| 351 "<th>Address list</th>" | 351 "<th>Address list</th>" |
| 352 "<th>Canonical name</th>" | |
| 353 "<th>Time to live (ms)</th>" | 352 "<th>Time to live (ms)</th>" |
| 354 "</tr>"); | 353 "</tr>"); |
| 355 | 354 |
| 356 for (net::HostCache::EntryMap::const_iterator it = | 355 for (net::HostCache::EntryMap::const_iterator it = |
| 357 host_cache->entries().begin(); | 356 host_cache->entries().begin(); |
| 358 it != host_cache->entries().end(); | 357 it != host_cache->entries().end(); |
| 359 ++it) { | 358 ++it) { |
| 360 const net::HostCache::Key& key = it->first; | 359 const net::HostCache::Key& key = it->first; |
| 361 const net::HostCache::Entry* entry = it->second.get(); | 360 const net::HostCache::Entry* entry = it->second.get(); |
| 362 | 361 |
| 363 std::string address_family_str = | 362 std::string address_family_str = |
| 364 AddressFamilyToString(key.address_family); | 363 AddressFamilyToString(key.address_family); |
| 365 | 364 |
| 366 // Note that ttl_ms may be negative, for the cases where entries have | 365 // Note that ttl_ms may be negative, for the cases where entries have |
| 367 // expired but not been garbage collected yet. | 366 // expired but not been garbage collected yet. |
| 368 int ttl_ms = static_cast<int>( | 367 int ttl_ms = static_cast<int>( |
| 369 (entry->expiration - base::TimeTicks::Now()).InMilliseconds()); | 368 (entry->expiration - base::TimeTicks::Now()).InMilliseconds()); |
| 370 | 369 |
| 371 // Color expired entries blue. | 370 // Color expired entries blue. |
| 372 if (ttl_ms > 0) { | 371 if (ttl_ms > 0) { |
| 373 out->append("<tr>"); | 372 out->append("<tr>"); |
| 374 } else { | 373 } else { |
| 375 out->append("<tr style='color:blue'>"); | 374 out->append("<tr style='color:blue'>"); |
| 376 } | 375 } |
| 377 | 376 |
| 378 // Stringify all of the addresses in the address list, separated | 377 // Stringify all of the addresses in the address list, separated |
| 379 // by newlines (br). | 378 // by newlines (br). |
| 380 std::string address_list_html; | 379 std::string address_list_html; |
| 381 std::string canonical_name_html; | |
| 382 | 380 |
| 383 if (entry->error != net::OK) { | 381 if (entry->error != net::OK) { |
| 384 address_list_html = "<span style='font-weight: bold; color:red'>" + | 382 address_list_html = "<span style='font-weight: bold; color:red'>" + |
| 385 EscapeForHTML(net::ErrorToString(entry->error)) + | 383 EscapeForHTML(net::ErrorToString(entry->error)) + |
| 386 "</span>"; | 384 "</span>"; |
| 387 } else { | 385 } else { |
| 388 const struct addrinfo* current_address = entry->addrlist.head(); | 386 const struct addrinfo* current_address = entry->addrlist.head(); |
| 389 while (current_address) { | 387 while (current_address) { |
| 390 if (!address_list_html.empty()) | 388 if (!address_list_html.empty()) |
| 391 address_list_html += "<br>"; | 389 address_list_html += "<br>"; |
| 392 address_list_html += EscapeForHTML( | 390 address_list_html += EscapeForHTML( |
| 393 net::NetAddressToString(current_address)); | 391 net::NetAddressToString(current_address)); |
| 394 current_address = current_address->ai_next; | 392 current_address = current_address->ai_next; |
| 395 } | 393 } |
| 396 std::string canonical_name; | |
| 397 if (entry->addrlist.GetCanonicalName(&canonical_name)) { | |
| 398 canonical_name_html = EscapeForHTML(canonical_name); | |
| 399 } | |
| 400 } | 394 } |
| 401 | 395 |
| 402 StringAppendF(out, | 396 StringAppendF(out, |
| 403 "<td>%s</td><td>%s</td><td>%s</td>" | 397 "<td>%s</td><td>%s</td><td>%s</td>" |
| 404 "<td>%s</td><td>%d</td></tr>", | 398 "<td>%d</td></tr>", |
| 405 EscapeForHTML(key.hostname).c_str(), | 399 EscapeForHTML(key.hostname).c_str(), |
| 406 EscapeForHTML(address_family_str).c_str(), | 400 EscapeForHTML(address_family_str).c_str(), |
| 407 address_list_html.c_str(), | 401 address_list_html.c_str(), |
| 408 canonical_name_html.c_str(), | |
| 409 ttl_ms); | 402 ttl_ms); |
| 410 } | 403 } |
| 411 | 404 |
| 412 out->append("</table>"); | 405 out->append("</table>"); |
| 413 } | 406 } |
| 414 | 407 |
| 415 static std::string AddressFamilyToString(net::AddressFamily address_family) { | 408 static std::string AddressFamilyToString(net::AddressFamily address_family) { |
| 416 switch (address_family) { | 409 switch (address_family) { |
| 417 case net::ADDRESS_FAMILY_IPV4: | 410 case net::ADDRESS_FAMILY_IPV4: |
| 418 return "IPV4"; | 411 return "IPV4"; |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 return StartsWithASCII(url.spec(), | 834 return StartsWithASCII(url.spec(), |
| 842 chrome::kNetworkViewInternalsURL, | 835 chrome::kNetworkViewInternalsURL, |
| 843 true /*case_sensitive*/); | 836 true /*case_sensitive*/); |
| 844 } | 837 } |
| 845 | 838 |
| 846 // static | 839 // static |
| 847 URLRequestJob* ViewNetInternalsJobFactory::CreateJobForRequest( | 840 URLRequestJob* ViewNetInternalsJobFactory::CreateJobForRequest( |
| 848 URLRequest* request) { | 841 URLRequest* request) { |
| 849 return new ViewNetInternalsJob(request); | 842 return new ViewNetInternalsJob(request); |
| 850 } | 843 } |
| OLD | NEW |