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/dom_ui/net_internals_ui.h" | 5 #include "chrome/browser/dom_ui/net_internals_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Serializes the specified event to a DictionaryValue. | 82 // Serializes the specified event to a DictionaryValue. |
83 Value* EntryToDictionaryValue(net::NetLog::EventType type, | 83 Value* EntryToDictionaryValue(net::NetLog::EventType type, |
84 const base::TimeTicks& time, | 84 const base::TimeTicks& time, |
85 const net::NetLog::Source& source, | 85 const net::NetLog::Source& source, |
86 net::NetLog::EventPhase phase, | 86 net::NetLog::EventPhase phase, |
87 net::NetLog::EventParameters* params) { | 87 net::NetLog::EventParameters* params) { |
88 DictionaryValue* entry_dict = new DictionaryValue(); | 88 DictionaryValue* entry_dict = new DictionaryValue(); |
89 | 89 |
90 // Set the entry time. (Note that we send it as a string since integers | 90 // Set the entry time. (Note that we send it as a string since integers |
91 // might overflow). | 91 // might overflow). |
92 entry_dict->SetString(L"time", TickCountToString(time)); | 92 entry_dict->SetString("time", TickCountToString(time)); |
93 | 93 |
94 // Set the entry source. | 94 // Set the entry source. |
95 DictionaryValue* source_dict = new DictionaryValue(); | 95 DictionaryValue* source_dict = new DictionaryValue(); |
96 source_dict->SetInteger(L"id", source.id); | 96 source_dict->SetInteger("id", source.id); |
97 source_dict->SetInteger(L"type", static_cast<int>(source.type)); | 97 source_dict->SetInteger("type", static_cast<int>(source.type)); |
98 entry_dict->Set(L"source", source_dict); | 98 entry_dict->Set("source", source_dict); |
99 | 99 |
100 // Set the event info. | 100 // Set the event info. |
101 entry_dict->SetInteger(L"type", static_cast<int>(type)); | 101 entry_dict->SetInteger("type", static_cast<int>(type)); |
102 entry_dict->SetInteger(L"phase", static_cast<int>(phase)); | 102 entry_dict->SetInteger("phase", static_cast<int>(phase)); |
103 | 103 |
104 // Set the event-specific parameters. | 104 // Set the event-specific parameters. |
105 if (params) | 105 if (params) |
106 entry_dict->Set(L"params", params->ToValue()); | 106 entry_dict->Set("params", params->ToValue()); |
107 | 107 |
108 return entry_dict; | 108 return entry_dict; |
109 } | 109 } |
110 | 110 |
111 Value* ExperimentToValue(const ConnectionTester::Experiment& experiment) { | 111 Value* ExperimentToValue(const ConnectionTester::Experiment& experiment) { |
112 DictionaryValue* dict = new DictionaryValue(); | 112 DictionaryValue* dict = new DictionaryValue(); |
113 | 113 |
114 if (experiment.url.is_valid()) | 114 if (experiment.url.is_valid()) |
115 dict->SetString(L"url", experiment.url.spec()); | 115 dict->SetString("url", experiment.url.spec()); |
116 | 116 |
117 dict->SetStringFromUTF16( | 117 dict->SetString("proxy_settings_experiment", |
118 L"proxy_settings_experiment", | 118 ConnectionTester::ProxySettingsExperimentDescription( |
119 ConnectionTester::ProxySettingsExperimentDescription( | 119 experiment.proxy_settings_experiment)); |
120 experiment.proxy_settings_experiment)); | 120 dict->SetString("host_resolver_experiment", |
121 dict->SetStringFromUTF16( | 121 ConnectionTester::HostResolverExperimentDescription( |
122 L"host_resolver_experiment", | 122 experiment.host_resolver_experiment)); |
123 ConnectionTester::HostResolverExperimentDescription( | |
124 experiment.host_resolver_experiment)); | |
125 return dict; | 123 return dict; |
126 } | 124 } |
127 | 125 |
128 class NetInternalsHTMLSource : public ChromeURLDataManager::DataSource { | 126 class NetInternalsHTMLSource : public ChromeURLDataManager::DataSource { |
129 public: | 127 public: |
130 NetInternalsHTMLSource(); | 128 NetInternalsHTMLSource(); |
131 | 129 |
132 // Called when the network layer has requested a resource underneath | 130 // Called when the network layer has requested a resource underneath |
133 // the path we registered. | 131 // the path we registered. |
134 virtual void StartDataRequest(const std::string& path, | 132 virtual void StartDataRequest(const std::string& path, |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 DictionaryValue* dict = new DictionaryValue(); | 487 DictionaryValue* dict = new DictionaryValue(); |
490 | 488 |
491 scoped_ptr<FileVersionInfo> version_info( | 489 scoped_ptr<FileVersionInfo> version_info( |
492 chrome::GetChromeVersionInfo()); | 490 chrome::GetChromeVersionInfo()); |
493 | 491 |
494 if (version_info == NULL) { | 492 if (version_info == NULL) { |
495 DLOG(ERROR) << "Unable to create FileVersionInfo object"; | 493 DLOG(ERROR) << "Unable to create FileVersionInfo object"; |
496 | 494 |
497 } else { | 495 } else { |
498 // We have everything we need to send the right values. | 496 // We have everything we need to send the right values. |
499 dict->SetString(L"version", version_info->file_version()); | 497 dict->SetString("version", WideToUTF16Hack(version_info->file_version())); |
500 dict->SetString(L"cl", version_info->last_change()); | 498 dict->SetString("cl", WideToUTF16Hack(version_info->last_change())); |
501 dict->SetStringFromUTF16(L"version_mod", | 499 dict->SetString("version_mod", platform_util::GetVersionStringModifier()); |
502 platform_util::GetVersionStringModifier()); | |
503 | 500 |
504 if (version_info->is_official_build()) { | 501 if (version_info->is_official_build()) { |
505 dict->SetString(L"official", | 502 dict->SetString("official", |
506 l10n_util::GetString(IDS_ABOUT_VERSION_OFFICIAL)); | 503 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OFFICIAL)); |
507 } else { | 504 } else { |
508 dict->SetString(L"official", | 505 dict->SetString("official", |
509 l10n_util::GetString(IDS_ABOUT_VERSION_UNOFFICIAL)); | 506 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_UNOFFICIAL)); |
510 } | 507 } |
511 | 508 |
512 dict->SetString(L"command_line", | 509 dict->SetString("command_line", |
513 CommandLine::ForCurrentProcess()->command_line_string()); | 510 CommandLine::ForCurrentProcess()->command_line_string()); |
514 } | 511 } |
515 | 512 |
516 CallJavascriptFunction(L"g_browser.receivedClientInfo", | 513 CallJavascriptFunction(L"g_browser.receivedClientInfo", |
517 dict); | 514 dict); |
518 } | 515 } |
519 | 516 |
520 // Tell the javascript about the relationship between load flag enums and | 517 // Tell the javascript about the relationship between load flag enums and |
521 // their symbolic name. | 518 // their symbolic name. |
522 { | 519 { |
(...skipping 18 matching lines...) Expand all Loading... |
541 #undef NET_ERROR | 538 #undef NET_ERROR |
542 | 539 |
543 CallJavascriptFunction(L"g_browser.receivedNetErrorConstants", dict); | 540 CallJavascriptFunction(L"g_browser.receivedNetErrorConstants", dict); |
544 } | 541 } |
545 | 542 |
546 // Tell the javascript about the relationship between event phase enums and | 543 // Tell the javascript about the relationship between event phase enums and |
547 // their symbolic name. | 544 // their symbolic name. |
548 { | 545 { |
549 DictionaryValue* dict = new DictionaryValue(); | 546 DictionaryValue* dict = new DictionaryValue(); |
550 | 547 |
551 dict->SetInteger(L"PHASE_BEGIN", net::NetLog::PHASE_BEGIN); | 548 dict->SetInteger("PHASE_BEGIN", net::NetLog::PHASE_BEGIN); |
552 dict->SetInteger(L"PHASE_END", net::NetLog::PHASE_END); | 549 dict->SetInteger("PHASE_END", net::NetLog::PHASE_END); |
553 dict->SetInteger(L"PHASE_NONE", net::NetLog::PHASE_NONE); | 550 dict->SetInteger("PHASE_NONE", net::NetLog::PHASE_NONE); |
554 | 551 |
555 CallJavascriptFunction(L"g_browser.receivedLogEventPhaseConstants", dict); | 552 CallJavascriptFunction(L"g_browser.receivedLogEventPhaseConstants", dict); |
556 } | 553 } |
557 | 554 |
558 // Tell the javascript about the relationship between source type enums and | 555 // Tell the javascript about the relationship between source type enums and |
559 // their symbolic name. | 556 // their symbolic name. |
560 { | 557 { |
561 DictionaryValue* dict = new DictionaryValue(); | 558 DictionaryValue* dict = new DictionaryValue(); |
562 | 559 |
563 #define SOURCE_TYPE(label, value) dict->SetInteger(ASCIIToWide(# label), value); | 560 #define SOURCE_TYPE(label, value) dict->SetInteger(ASCIIToWide(# label), value); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 context->proxy_service()->proxy_retry_info(); | 633 context->proxy_service()->proxy_retry_info(); |
637 | 634 |
638 ListValue* list = new ListValue(); | 635 ListValue* list = new ListValue(); |
639 | 636 |
640 for (net::ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin(); | 637 for (net::ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin(); |
641 it != bad_proxies_map.end(); ++it) { | 638 it != bad_proxies_map.end(); ++it) { |
642 const std::string& proxy_uri = it->first; | 639 const std::string& proxy_uri = it->first; |
643 const net::ProxyRetryInfo& retry_info = it->second; | 640 const net::ProxyRetryInfo& retry_info = it->second; |
644 | 641 |
645 DictionaryValue* dict = new DictionaryValue(); | 642 DictionaryValue* dict = new DictionaryValue(); |
646 dict->SetString(L"proxy_uri", proxy_uri); | 643 dict->SetString("proxy_uri", proxy_uri); |
647 dict->SetString(L"bad_until", TickCountToString(retry_info.bad_until)); | 644 dict->SetString("bad_until", TickCountToString(retry_info.bad_until)); |
648 | 645 |
649 list->Append(dict); | 646 list->Append(dict); |
650 } | 647 } |
651 | 648 |
652 CallJavascriptFunction(L"g_browser.receivedBadProxies", list); | 649 CallJavascriptFunction(L"g_browser.receivedBadProxies", list); |
653 } | 650 } |
654 | 651 |
655 void NetInternalsMessageHandler::IOThreadImpl::OnClearBadProxies( | 652 void NetInternalsMessageHandler::IOThreadImpl::OnClearBadProxies( |
656 const Value* value) { | 653 const Value* value) { |
657 URLRequestContext* context = context_getter_->GetURLRequestContext(); | 654 URLRequestContext* context = context_getter_->GetURLRequestContext(); |
658 context->proxy_service()->ClearBadProxiesCache(); | 655 context->proxy_service()->ClearBadProxiesCache(); |
659 | 656 |
660 // Cause the renderer to be notified of the new values. | 657 // Cause the renderer to be notified of the new values. |
661 OnGetBadProxies(NULL); | 658 OnGetBadProxies(NULL); |
662 } | 659 } |
663 | 660 |
664 void NetInternalsMessageHandler::IOThreadImpl::OnGetHostResolverCache( | 661 void NetInternalsMessageHandler::IOThreadImpl::OnGetHostResolverCache( |
665 const Value* value) { | 662 const Value* value) { |
666 | 663 |
667 net::HostCache* cache = | 664 net::HostCache* cache = |
668 GetHostResolverCache(context_getter_->GetURLRequestContext()); | 665 GetHostResolverCache(context_getter_->GetURLRequestContext()); |
669 | 666 |
670 if (!cache) { | 667 if (!cache) { |
671 CallJavascriptFunction(L"g_browser.receivedHostResolverCache", NULL); | 668 CallJavascriptFunction(L"g_browser.receivedHostResolverCache", NULL); |
672 return; | 669 return; |
673 } | 670 } |
674 | 671 |
675 DictionaryValue* dict = new DictionaryValue(); | 672 DictionaryValue* dict = new DictionaryValue(); |
676 | 673 |
677 dict->SetInteger(L"capacity", static_cast<int>(cache->max_entries())); | 674 dict->SetInteger("capacity", static_cast<int>(cache->max_entries())); |
678 dict->SetInteger( | 675 dict->SetInteger( |
679 L"ttl_success_ms", | 676 "ttl_success_ms", |
680 static_cast<int>(cache->success_entry_ttl().InMilliseconds())); | 677 static_cast<int>(cache->success_entry_ttl().InMilliseconds())); |
681 dict->SetInteger( | 678 dict->SetInteger( |
682 L"ttl_failure_ms", | 679 "ttl_failure_ms", |
683 static_cast<int>(cache->failure_entry_ttl().InMilliseconds())); | 680 static_cast<int>(cache->failure_entry_ttl().InMilliseconds())); |
684 | 681 |
685 ListValue* entry_list = new ListValue(); | 682 ListValue* entry_list = new ListValue(); |
686 | 683 |
687 for (net::HostCache::EntryMap::const_iterator it = | 684 for (net::HostCache::EntryMap::const_iterator it = |
688 cache->entries().begin(); | 685 cache->entries().begin(); |
689 it != cache->entries().end(); | 686 it != cache->entries().end(); |
690 ++it) { | 687 ++it) { |
691 const net::HostCache::Key& key = it->first; | 688 const net::HostCache::Key& key = it->first; |
692 const net::HostCache::Entry* entry = it->second.get(); | 689 const net::HostCache::Entry* entry = it->second.get(); |
693 | 690 |
694 DictionaryValue* entry_dict = new DictionaryValue(); | 691 DictionaryValue* entry_dict = new DictionaryValue(); |
695 | 692 |
696 entry_dict->SetString(L"hostname", key.hostname); | 693 entry_dict->SetString("hostname", key.hostname); |
697 entry_dict->SetInteger(L"address_family", | 694 entry_dict->SetInteger("address_family", |
698 static_cast<int>(key.address_family)); | 695 static_cast<int>(key.address_family)); |
699 entry_dict->SetString(L"expiration", TickCountToString(entry->expiration)); | 696 entry_dict->SetString("expiration", TickCountToString(entry->expiration)); |
700 | 697 |
701 if (entry->error != net::OK) { | 698 if (entry->error != net::OK) { |
702 entry_dict->SetInteger(L"error", entry->error); | 699 entry_dict->SetInteger("error", entry->error); |
703 } else { | 700 } else { |
704 // Append all of the resolved addresses. | 701 // Append all of the resolved addresses. |
705 ListValue* address_list = new ListValue(); | 702 ListValue* address_list = new ListValue(); |
706 const struct addrinfo* current_address = entry->addrlist.head(); | 703 const struct addrinfo* current_address = entry->addrlist.head(); |
707 while (current_address) { | 704 while (current_address) { |
708 address_list->Append(Value::CreateStringValue( | 705 address_list->Append(Value::CreateStringValue( |
709 net::NetAddressToStringWithPort(current_address))); | 706 net::NetAddressToStringWithPort(current_address))); |
710 current_address = current_address->ai_next; | 707 current_address = current_address->ai_next; |
711 } | 708 } |
712 entry_dict->Set(L"addresses", address_list); | 709 entry_dict->Set("addresses", address_list); |
713 } | 710 } |
714 | 711 |
715 entry_list->Append(entry_dict); | 712 entry_list->Append(entry_dict); |
716 } | 713 } |
717 | 714 |
718 dict->Set(L"entries", entry_list); | 715 dict->Set("entries", entry_list); |
719 | 716 |
720 CallJavascriptFunction(L"g_browser.receivedHostResolverCache", dict); | 717 CallJavascriptFunction(L"g_browser.receivedHostResolverCache", dict); |
721 } | 718 } |
722 | 719 |
723 void NetInternalsMessageHandler::IOThreadImpl::OnClearHostResolverCache( | 720 void NetInternalsMessageHandler::IOThreadImpl::OnClearHostResolverCache( |
724 const Value* value) { | 721 const Value* value) { |
725 net::HostCache* cache = | 722 net::HostCache* cache = |
726 GetHostResolverCache(context_getter_->GetURLRequestContext()); | 723 GetHostResolverCache(context_getter_->GetURLRequestContext()); |
727 | 724 |
728 if (cache) | 725 if (cache) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 if (disk_cache) { | 777 if (disk_cache) { |
781 // Extract the statistics key/value pairs from the backend. | 778 // Extract the statistics key/value pairs from the backend. |
782 std::vector<std::pair<std::string, std::string> > stats; | 779 std::vector<std::pair<std::string, std::string> > stats; |
783 disk_cache->GetStats(&stats); | 780 disk_cache->GetStats(&stats); |
784 for (size_t i = 0; i < stats.size(); ++i) { | 781 for (size_t i = 0; i < stats.size(); ++i) { |
785 stats_dict->Set(ASCIIToWide(stats[i].first), | 782 stats_dict->Set(ASCIIToWide(stats[i].first), |
786 Value::CreateStringValue(stats[i].second)); | 783 Value::CreateStringValue(stats[i].second)); |
787 } | 784 } |
788 } | 785 } |
789 | 786 |
790 info_dict->Set(L"stats", stats_dict); | 787 info_dict->Set("stats", stats_dict); |
791 | 788 |
792 CallJavascriptFunction(L"g_browser.receivedHttpCacheInfo", info_dict); | 789 CallJavascriptFunction(L"g_browser.receivedHttpCacheInfo", info_dict); |
793 } | 790 } |
794 | 791 |
795 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 792 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
796 net::NetLog::EventType type, | 793 net::NetLog::EventType type, |
797 const base::TimeTicks& time, | 794 const base::TimeTicks& time, |
798 const net::NetLog::Source& source, | 795 const net::NetLog::Source& source, |
799 net::NetLog::EventPhase phase, | 796 net::NetLog::EventPhase phase, |
800 net::NetLog::EventParameters* params) { | 797 net::NetLog::EventParameters* params) { |
(...skipping 14 matching lines...) Expand all Loading... |
815 L"g_browser.receivedStartConnectionTestExperiment", | 812 L"g_browser.receivedStartConnectionTestExperiment", |
816 ExperimentToValue(experiment)); | 813 ExperimentToValue(experiment)); |
817 } | 814 } |
818 | 815 |
819 void | 816 void |
820 NetInternalsMessageHandler::IOThreadImpl::OnCompletedConnectionTestExperiment( | 817 NetInternalsMessageHandler::IOThreadImpl::OnCompletedConnectionTestExperiment( |
821 const ConnectionTester::Experiment& experiment, | 818 const ConnectionTester::Experiment& experiment, |
822 int result) { | 819 int result) { |
823 DictionaryValue* dict = new DictionaryValue(); | 820 DictionaryValue* dict = new DictionaryValue(); |
824 | 821 |
825 dict->Set(L"experiment", ExperimentToValue(experiment)); | 822 dict->Set("experiment", ExperimentToValue(experiment)); |
826 dict->SetInteger(L"result", result); | 823 dict->SetInteger("result", result); |
827 | 824 |
828 CallJavascriptFunction( | 825 CallJavascriptFunction( |
829 L"g_browser.receivedCompletedConnectionTestExperiment", | 826 L"g_browser.receivedCompletedConnectionTestExperiment", |
830 dict); | 827 dict); |
831 } | 828 } |
832 | 829 |
833 void | 830 void |
834 NetInternalsMessageHandler::IOThreadImpl::OnCompletedConnectionTestSuite() { | 831 NetInternalsMessageHandler::IOThreadImpl::OnCompletedConnectionTestSuite() { |
835 CallJavascriptFunction( | 832 CallJavascriptFunction( |
836 L"g_browser.receivedCompletedConnectionTestSuite", | 833 L"g_browser.receivedCompletedConnectionTestSuite", |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 884 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
888 | 885 |
889 // Set up the chrome://net-internals/ source. | 886 // Set up the chrome://net-internals/ source. |
890 ChromeThread::PostTask( | 887 ChromeThread::PostTask( |
891 ChromeThread::IO, FROM_HERE, | 888 ChromeThread::IO, FROM_HERE, |
892 NewRunnableMethod( | 889 NewRunnableMethod( |
893 Singleton<ChromeURLDataManager>::get(), | 890 Singleton<ChromeURLDataManager>::get(), |
894 &ChromeURLDataManager::AddDataSource, | 891 &ChromeURLDataManager::AddDataSource, |
895 make_scoped_refptr(html_source))); | 892 make_scoped_refptr(html_source))); |
896 } | 893 } |
OLD | NEW |