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

Side by Side Diff: chrome/browser/net/view_net_internals_job_factory.cc

Issue 1593015: HostResolver supports optional CNAME lookups. (Closed)
Patch Set: Addressing wtc's nits. Created 10 years, 8 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
OLDNEW
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
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>"
352 "<th>Time to live (ms)</th>" 353 "<th>Time to live (ms)</th>"
353 "</tr>"); 354 "</tr>");
354 355
355 for (net::HostCache::EntryMap::const_iterator it = 356 for (net::HostCache::EntryMap::const_iterator it =
356 host_cache->entries().begin(); 357 host_cache->entries().begin();
357 it != host_cache->entries().end(); 358 it != host_cache->entries().end();
358 ++it) { 359 ++it) {
359 const net::HostCache::Key& key = it->first; 360 const net::HostCache::Key& key = it->first;
360 const net::HostCache::Entry* entry = it->second.get(); 361 const net::HostCache::Entry* entry = it->second.get();
361 362
362 std::string address_family_str = 363 std::string address_family_str =
363 AddressFamilyToString(key.address_family); 364 AddressFamilyToString(key.address_family);
364 365
365 // Note that ttl_ms may be negative, for the cases where entries have 366 // Note that ttl_ms may be negative, for the cases where entries have
366 // expired but not been garbage collected yet. 367 // expired but not been garbage collected yet.
367 int ttl_ms = static_cast<int>( 368 int ttl_ms = static_cast<int>(
368 (entry->expiration - base::TimeTicks::Now()).InMilliseconds()); 369 (entry->expiration - base::TimeTicks::Now()).InMilliseconds());
369 370
370 // Color expired entries blue. 371 // Color expired entries blue.
371 if (ttl_ms > 0) { 372 if (ttl_ms > 0) {
372 out->append("<tr>"); 373 out->append("<tr>");
373 } else { 374 } else {
374 out->append("<tr style='color:blue'>"); 375 out->append("<tr style='color:blue'>");
375 } 376 }
376 377
377 // Stringify all of the addresses in the address list, separated 378 // Stringify all of the addresses in the address list, separated
378 // by newlines (br). 379 // by newlines (br).
379 std::string address_list_html; 380 std::string address_list_html;
381 std::string canonical_name_html;
380 382
381 if (entry->error != net::OK) { 383 if (entry->error != net::OK) {
382 address_list_html = "<span style='font-weight: bold; color:red'>" + 384 address_list_html = "<span style='font-weight: bold; color:red'>" +
383 EscapeForHTML(net::ErrorToString(entry->error)) + 385 EscapeForHTML(net::ErrorToString(entry->error)) +
384 "</span>"; 386 "</span>";
385 } else { 387 } else {
386 const struct addrinfo* current_address = entry->addrlist.head(); 388 const struct addrinfo* current_address = entry->addrlist.head();
387 while (current_address) { 389 while (current_address) {
388 if (!address_list_html.empty()) 390 if (!address_list_html.empty())
389 address_list_html += "<br>"; 391 address_list_html += "<br>";
390 address_list_html += EscapeForHTML( 392 address_list_html += EscapeForHTML(
391 net::NetAddressToString(current_address)); 393 net::NetAddressToString(current_address));
392 current_address = current_address->ai_next; 394 current_address = current_address->ai_next;
393 } 395 }
396 std::string canonical_name;
397 if (entry->addrlist.GetCanonicalName(&canonical_name))
398 canonical_name_html = EscapeForHTML(canonical_name);
394 } 399 }
395 400
396 StringAppendF(out, 401 StringAppendF(out,
397 "<td>%s</td><td>%s</td><td>%s</td>" 402 "<td>%s</td><td>%s</td><td>%s</td>"
398 "<td>%d</td></tr>", 403 "<td>%s</td><td>%d</td></tr>",
399 EscapeForHTML(key.hostname).c_str(), 404 EscapeForHTML(key.hostname).c_str(),
400 EscapeForHTML(address_family_str).c_str(), 405 EscapeForHTML(address_family_str).c_str(),
401 address_list_html.c_str(), 406 address_list_html.c_str(),
407 canonical_name_html.c_str(),
402 ttl_ms); 408 ttl_ms);
403 } 409 }
404 410
405 out->append("</table>"); 411 out->append("</table>");
406 } 412 }
407 413
408 static std::string AddressFamilyToString(net::AddressFamily address_family) { 414 static std::string AddressFamilyToString(net::AddressFamily address_family) {
409 switch (address_family) { 415 switch (address_family) {
410 case net::ADDRESS_FAMILY_IPV4: 416 case net::ADDRESS_FAMILY_IPV4:
411 return "IPV4"; 417 return "IPV4";
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 return StartsWithASCII(url.spec(), 840 return StartsWithASCII(url.spec(),
835 chrome::kNetworkViewInternalsURL, 841 chrome::kNetworkViewInternalsURL,
836 true /*case_sensitive*/); 842 true /*case_sensitive*/);
837 } 843 }
838 844
839 // static 845 // static
840 URLRequestJob* ViewNetInternalsJobFactory::CreateJobForRequest( 846 URLRequestJob* ViewNetInternalsJobFactory::CreateJobForRequest(
841 URLRequest* request) { 847 URLRequest* request) {
842 return new ViewNetInternalsJob(request); 848 return new ViewNetInternalsJob(request);
843 } 849 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698