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 <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 void OnRendererReady(const Value* value); | 145 void OnRendererReady(const Value* value); |
146 | 146 |
147 void OnGetProxySettings(const Value* value); | 147 void OnGetProxySettings(const Value* value); |
148 void OnReloadProxySettings(const Value* value); | 148 void OnReloadProxySettings(const Value* value); |
149 void OnGetBadProxies(const Value* value); | 149 void OnGetBadProxies(const Value* value); |
150 void OnClearBadProxies(const Value* value); | 150 void OnClearBadProxies(const Value* value); |
151 void OnGetHostResolverCache(const Value* value); | 151 void OnGetHostResolverCache(const Value* value); |
152 void OnClearHostResolverCache(const Value* value); | 152 void OnClearHostResolverCache(const Value* value); |
153 | 153 |
154 // ChromeNetLog::Observer implementation: | 154 // ChromeNetLog::Observer implementation: |
155 virtual void OnAddEntry(const net::NetLog::Entry& entry); | 155 virtual void OnAddEntry(net::NetLog::EventType type, |
| 156 const base::TimeTicks& time, |
| 157 const net::NetLog::Source& source, |
| 158 net::NetLog::EventPhase phase, |
| 159 net::NetLog::EventParameters* extra_parameters); |
156 | 160 |
157 private: | 161 private: |
158 class CallbackHelper; | 162 class CallbackHelper; |
159 | 163 |
160 // Helper that runs |method| with |arg|, and deletes |arg| on completion. | 164 // Helper that runs |method| with |arg|, and deletes |arg| on completion. |
161 void DispatchToMessageHandler(Value* arg, MessageHandler method); | 165 void DispatchToMessageHandler(Value* arg, MessageHandler method); |
162 | 166 |
163 // Helper that executes |function_name| in the attached renderer. | 167 // Helper that executes |function_name| in the attached renderer. |
164 // The function takes ownership of |arg|. | 168 // The function takes ownership of |arg|. |
165 void CallJavascriptFunction(const std::wstring& function_name, | 169 void CallJavascriptFunction(const std::wstring& function_name, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 dict->SetInteger(L"NONE", net::NetLog::SOURCE_NONE); | 396 dict->SetInteger(L"NONE", net::NetLog::SOURCE_NONE); |
393 dict->SetInteger(L"URL_REQUEST", net::NetLog::SOURCE_URL_REQUEST); | 397 dict->SetInteger(L"URL_REQUEST", net::NetLog::SOURCE_URL_REQUEST); |
394 dict->SetInteger(L"SOCKET_STREAM", net::NetLog::SOURCE_SOCKET_STREAM); | 398 dict->SetInteger(L"SOCKET_STREAM", net::NetLog::SOURCE_SOCKET_STREAM); |
395 dict->SetInteger(L"INIT_PROXY_RESOLVER", | 399 dict->SetInteger(L"INIT_PROXY_RESOLVER", |
396 net::NetLog::SOURCE_INIT_PROXY_RESOLVER); | 400 net::NetLog::SOURCE_INIT_PROXY_RESOLVER); |
397 dict->SetInteger(L"CONNECT_JOB", net::NetLog::SOURCE_CONNECT_JOB); | 401 dict->SetInteger(L"CONNECT_JOB", net::NetLog::SOURCE_CONNECT_JOB); |
398 | 402 |
399 CallJavascriptFunction(L"g_browser.receivedLogSourceTypeConstants", dict); | 403 CallJavascriptFunction(L"g_browser.receivedLogSourceTypeConstants", dict); |
400 } | 404 } |
401 | 405 |
402 // Tell the javascript about the relationship between entry type enums and | |
403 // their symbolic name. | |
404 { | |
405 DictionaryValue* dict = new DictionaryValue(); | |
406 | |
407 dict->SetInteger(L"TYPE_EVENT", net::NetLog::Entry::TYPE_EVENT); | |
408 dict->SetInteger(L"TYPE_STRING", net::NetLog::Entry::TYPE_STRING); | |
409 dict->SetInteger(L"TYPE_ERROR_CODE", net::NetLog::Entry::TYPE_ERROR_CODE); | |
410 | |
411 CallJavascriptFunction(L"g_browser.receivedLogEntryTypeConstants", dict); | |
412 } | |
413 | |
414 // Tell the javascript how the "time ticks" values we have given it relate to | 406 // Tell the javascript how the "time ticks" values we have given it relate to |
415 // actual system times. (We used time ticks throughout since they are stable | 407 // actual system times. (We used time ticks throughout since they are stable |
416 // across system clock changes). | 408 // across system clock changes). |
417 { | 409 { |
418 int64 cur_time_ms = (base::Time::Now() - base::Time()).InMilliseconds(); | 410 int64 cur_time_ms = (base::Time::Now() - base::Time()).InMilliseconds(); |
419 | 411 |
420 int64 cur_time_ticks_ms = | 412 int64 cur_time_ticks_ms = |
421 (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds(); | 413 (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds(); |
422 | 414 |
423 // If we add this number to a time tick value, it gives the timestamp. | 415 // If we add this number to a time tick value, it gives the timestamp. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 GetHostResolverCache(context_getter_->GetURLRequestContext()); | 561 GetHostResolverCache(context_getter_->GetURLRequestContext()); |
570 | 562 |
571 if (cache) | 563 if (cache) |
572 cache->clear(); | 564 cache->clear(); |
573 | 565 |
574 // Cause the renderer to be notified of the new values. | 566 // Cause the renderer to be notified of the new values. |
575 OnGetHostResolverCache(NULL); | 567 OnGetHostResolverCache(NULL); |
576 } | 568 } |
577 | 569 |
578 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 570 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
579 const net::NetLog::Entry& entry) { | 571 net::NetLog::EventType type, |
| 572 const base::TimeTicks& time, |
| 573 const net::NetLog::Source& source, |
| 574 net::NetLog::EventPhase phase, |
| 575 net::NetLog::EventParameters* extra_parameters) { |
580 DCHECK(is_observing_log_); | 576 DCHECK(is_observing_log_); |
581 | 577 |
582 // JSONify the NetLog::Entry. | 578 // JSONify the NetLog::Entry. |
583 // TODO(eroman): Need a better format for this. | 579 // TODO(eroman): Need a better format for this. |
584 DictionaryValue* entry_dict = new DictionaryValue(); | 580 DictionaryValue* entry_dict = new DictionaryValue(); |
585 | 581 |
586 // Set the entry type. | |
587 { | |
588 net::NetLog::Entry::Type entry_type = entry.type; | |
589 if (entry_type == net::NetLog::Entry::TYPE_STRING_LITERAL) | |
590 entry_type = net::NetLog::Entry::TYPE_STRING; | |
591 entry_dict->SetInteger(L"type", static_cast<int>(entry_type)); | |
592 } | |
593 | |
594 // Set the entry time. (Note that we send it as a string since integers | 582 // Set the entry time. (Note that we send it as a string since integers |
595 // might overflow). | 583 // might overflow). |
596 entry_dict->SetString(L"time", TickCountToString(entry.time)); | 584 entry_dict->SetString(L"time", TickCountToString(time)); |
597 | 585 |
598 // Set the entry source. | 586 // Set the entry source. |
599 DictionaryValue* source_dict = new DictionaryValue(); | 587 DictionaryValue* source_dict = new DictionaryValue(); |
600 source_dict->SetInteger(L"id", entry.source.id); | 588 source_dict->SetInteger(L"id", source.id); |
601 source_dict->SetInteger(L"type", static_cast<int>(entry.source.type)); | 589 source_dict->SetInteger(L"type", static_cast<int>(source.type)); |
602 entry_dict->Set(L"source", source_dict); | 590 entry_dict->Set(L"source", source_dict); |
603 | 591 |
604 // Set the event info (if it is an event entry). | 592 // Set the event info. |
605 if (entry.type == net::NetLog::Entry::TYPE_EVENT) { | 593 entry_dict->SetInteger(L"type", static_cast<int>(type)); |
606 DictionaryValue* event_dict = new DictionaryValue(); | 594 entry_dict->SetInteger(L"phase", static_cast<int>(phase)); |
607 event_dict->SetInteger(L"type", static_cast<int>(entry.event.type)); | |
608 event_dict->SetInteger(L"phase", static_cast<int>(entry.event.phase)); | |
609 entry_dict->Set(L"event", event_dict); | |
610 } | |
611 | 595 |
612 // Add the string information (events my have a string too, due to current | 596 // Set the event-specific parameters. |
613 // hacks). | 597 if (extra_parameters) |
614 if (entry.type == net::NetLog::Entry::TYPE_STRING || !entry.string.empty()) { | 598 entry_dict->SetString(L"extra_parameters", extra_parameters->ToString()); |
615 entry_dict->SetString(L"string", entry.string); | |
616 } | |
617 | |
618 // Treat string literals the same as strings. | |
619 if (entry.type == net::NetLog::Entry::TYPE_STRING_LITERAL) { | |
620 entry_dict->SetString(L"string", entry.literal); | |
621 } | |
622 | |
623 if (entry.type == net::NetLog::Entry::TYPE_ERROR_CODE) { | |
624 entry_dict->SetInteger(L"error_code", entry.error_code); | |
625 } | |
626 | 599 |
627 CallJavascriptFunction(L"g_browser.receivedLogEntry", entry_dict); | 600 CallJavascriptFunction(L"g_browser.receivedLogEntry", entry_dict); |
628 } | 601 } |
629 | 602 |
630 void NetInternalsMessageHandler::IOThreadImpl::DispatchToMessageHandler( | 603 void NetInternalsMessageHandler::IOThreadImpl::DispatchToMessageHandler( |
631 Value* arg, MessageHandler method) { | 604 Value* arg, MessageHandler method) { |
632 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 605 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
633 (this->*method)(arg); | 606 (this->*method)(arg); |
634 delete arg; | 607 delete arg; |
635 } | 608 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 651 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
679 | 652 |
680 // Set up the chrome://net-internals/ source. | 653 // Set up the chrome://net-internals/ source. |
681 ChromeThread::PostTask( | 654 ChromeThread::PostTask( |
682 ChromeThread::IO, FROM_HERE, | 655 ChromeThread::IO, FROM_HERE, |
683 NewRunnableMethod( | 656 NewRunnableMethod( |
684 Singleton<ChromeURLDataManager>::get(), | 657 Singleton<ChromeURLDataManager>::get(), |
685 &ChromeURLDataManager::AddDataSource, | 658 &ChromeURLDataManager::AddDataSource, |
686 make_scoped_refptr(html_source))); | 659 make_scoped_refptr(html_source))); |
687 } | 660 } |
OLD | NEW |