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

Side by Side Diff: chrome/browser/resources/net_internals/dns_view.js

Issue 2773023003: Add more data to net-internals view of DNS cache (Closed)
Patch Set: undefined -> empty string Created 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 /** 5 /**
6 * This view displays information on the host resolver: 6 * This view displays information on the host resolver:
7 * 7 *
8 * - Shows the default address family. 8 * - Shows the default address family.
9 * - Shows the current host cache contents. 9 * - Shows the current host cache contents.
10 * - Has a button to clear the host cache. 10 * - Has a button to clear the host cache.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 DnsView.INTERNAL_DNS_ENABLED_SPAN_ID = 'dns-view-internal-dns-enabled'; 48 DnsView.INTERNAL_DNS_ENABLED_SPAN_ID = 'dns-view-internal-dns-enabled';
49 DnsView.INTERNAL_DNS_INVALID_CONFIG_SPAN_ID = 49 DnsView.INTERNAL_DNS_INVALID_CONFIG_SPAN_ID =
50 'dns-view-internal-dns-invalid-config'; 50 'dns-view-internal-dns-invalid-config';
51 DnsView.INTERNAL_DNS_CONFIG_TBODY_ID = 'dns-view-internal-dns-config-tbody'; 51 DnsView.INTERNAL_DNS_CONFIG_TBODY_ID = 'dns-view-internal-dns-config-tbody';
52 52
53 DnsView.CLEAR_CACHE_BUTTON_ID = 'dns-view-clear-cache'; 53 DnsView.CLEAR_CACHE_BUTTON_ID = 'dns-view-clear-cache';
54 DnsView.CAPACITY_SPAN_ID = 'dns-view-cache-capacity'; 54 DnsView.CAPACITY_SPAN_ID = 'dns-view-cache-capacity';
55 55
56 DnsView.ACTIVE_SPAN_ID = 'dns-view-cache-active'; 56 DnsView.ACTIVE_SPAN_ID = 'dns-view-cache-active';
57 DnsView.EXPIRED_SPAN_ID = 'dns-view-cache-expired'; 57 DnsView.EXPIRED_SPAN_ID = 'dns-view-cache-expired';
58 DnsView.NETWORK_SPAN_ID = 'dns-view-network-changes';
58 DnsView.CACHE_TBODY_ID = 'dns-view-cache-tbody'; 59 DnsView.CACHE_TBODY_ID = 'dns-view-cache-tbody';
59 60
60 cr.addSingletonGetter(DnsView); 61 cr.addSingletonGetter(DnsView);
61 62
62 DnsView.prototype = { 63 DnsView.prototype = {
63 // Inherit the superclass's methods. 64 // Inherit the superclass's methods.
64 __proto__: superClass.prototype, 65 __proto__: superClass.prototype,
65 66
66 onLoadLogFinish: function(data) { 67 onLoadLogFinish: function(data) {
67 return this.onHostResolverInfoChanged(data.hostResolverInfo); 68 return this.onHostResolverInfoChanged(data.hostResolverInfo);
68 }, 69 },
69 70
70 onHostResolverInfoChanged: function(hostResolverInfo) { 71 onHostResolverInfoChanged: function(hostResolverInfo) {
71 // Clear the existing values. 72 // Clear the existing values.
72 $(DnsView.CAPACITY_SPAN_ID).innerHTML = ''; 73 $(DnsView.CAPACITY_SPAN_ID).innerHTML = '';
73 $(DnsView.CACHE_TBODY_ID).innerHTML = ''; 74 $(DnsView.CACHE_TBODY_ID).innerHTML = '';
74 $(DnsView.ACTIVE_SPAN_ID).innerHTML = '0'; 75 $(DnsView.ACTIVE_SPAN_ID).innerHTML = '0';
75 $(DnsView.EXPIRED_SPAN_ID).innerHTML = '0'; 76 $(DnsView.EXPIRED_SPAN_ID).innerHTML = '0';
77 $(DnsView.NETWORK_SPAN_ID).innerHTML = '0';
76 78
77 // Update fields containing async DNS configuration information. 79 // Update fields containing async DNS configuration information.
78 displayAsyncDnsConfig_(hostResolverInfo); 80 displayAsyncDnsConfig_(hostResolverInfo);
79 81
80 // No info. 82 // No info.
81 if (!hostResolverInfo || !hostResolverInfo.cache) 83 if (!hostResolverInfo || !hostResolverInfo.cache)
82 return false; 84 return false;
83 85
84 // Fill in the basic cache information. 86 // Fill in the basic cache information.
85 var hostResolverCache = hostResolverInfo.cache; 87 var hostResolverCache = hostResolverInfo.cache;
86 $(DnsView.CAPACITY_SPAN_ID).innerText = hostResolverCache.capacity; 88 $(DnsView.CAPACITY_SPAN_ID).innerText = hostResolverCache.capacity;
89 $(DnsView.NETWORK_SPAN_ID).innerText =
90 valueOrDefault(hostResolverCache.network_changes, '');
87 91
88 var expiredEntries = 0; 92 var expiredEntries = 0;
89 // Date the cache was logged. This will be either now, when actively 93 // Date the cache was logged. This will be either now, when actively
90 // logging data, or the date the log dump was created. 94 // logging data, or the date the log dump was created.
91 var logDate; 95 var logDate;
92 if (MainView.isViewingLoadedLog()) { 96 if (MainView.isViewingLoadedLog()) {
93 logDate = new Date(ClientInfo.numericDate); 97 logDate = new Date(ClientInfo.numericDate);
94 } else { 98 } else {
95 logDate = new Date(); 99 logDate = new Date();
96 } 100 }
97 101
98 // Fill in the cache contents table. 102 // Fill in the cache contents table.
99 for (var i = 0; i < hostResolverCache.entries.length; ++i) { 103 for (var i = 0; i < hostResolverCache.entries.length; ++i) {
100 var e = hostResolverCache.entries[i]; 104 var e = hostResolverCache.entries[i];
101 var tr = addNode($(DnsView.CACHE_TBODY_ID), 'tr'); 105 var tr = addNode($(DnsView.CACHE_TBODY_ID), 'tr');
106 var expired = false;
102 107
103 var hostnameCell = addNode(tr, 'td'); 108 var hostnameCell = addNode(tr, 'td');
104 addTextNode(hostnameCell, e.hostname); 109 addTextNode(hostnameCell, e.hostname);
105 110
106 var familyCell = addNode(tr, 'td'); 111 var familyCell = addNode(tr, 'td');
107 addTextNode(familyCell, addressFamilyToString(e.address_family)); 112 addTextNode(familyCell, addressFamilyToString(e.address_family));
108 113
109 var addressesCell = addNode(tr, 'td'); 114 var addressesCell = addNode(tr, 'td');
110 115
111 if (e.error != undefined) { 116 if (e.error != undefined) {
112 var errorText = e.error + ' (' + netErrorToString(e.error) + ')'; 117 var errorText = e.error + ' (' + netErrorToString(e.error) + ')';
113 var errorNode = addTextNode(addressesCell, 'error: ' + errorText); 118 var errorNode = addTextNode(addressesCell, 'error: ' + errorText);
114 addressesCell.classList.add('warning-text'); 119 addressesCell.classList.add('warning-text');
115 } else { 120 } else {
116 addListToNode_(addNode(addressesCell, 'div'), e.addresses); 121 addListToNode_(addNode(addressesCell, 'div'), e.addresses);
117 } 122 }
118 123
124 var ttlCell = addNode(tr, 'td');
125 addTextNode(ttlCell, valueOrDefault(e.ttl, ''));
126
119 var expiresDate = timeutil.convertTimeTicksToDate(e.expiration); 127 var expiresDate = timeutil.convertTimeTicksToDate(e.expiration);
120 var expiresCell = addNode(tr, 'td'); 128 var expiresCell = addNode(tr, 'td');
121 timeutil.addNodeWithDate(expiresCell, expiresDate); 129 timeutil.addNodeWithDate(expiresCell, expiresDate);
122 if (logDate > timeutil.convertTimeTicksToDate(e.expiration)) { 130 if (logDate > timeutil.convertTimeTicksToDate(e.expiration)) {
123 ++expiredEntries; 131 expired = true;
124 var expiredSpan = addNode(expiresCell, 'span'); 132 var expiredSpan = addNode(expiresCell, 'span');
125 expiredSpan.classList.add('warning-text'); 133 expiredSpan.classList.add('warning-text');
126 addTextNode(expiredSpan, ' [Expired]'); 134 addTextNode(expiredSpan, ' [Expired]');
127 } 135 }
136
137 // HostCache keeps track of how many network changes have happened since
138 // it was created, and entries store what that number was at the time
139 // they were created. If more network changes have happened since an
140 // entry was created, the entry is expired.
141 var networkChangesCell = addNode(tr, 'td');
142 addTextNode(networkChangesCell, valueOrDefault(e.network_changes, ''));
143 if (e.network_changes < hostResolverCache.network_changes) {
144 expired = true;
145 var expiredSpan = addNode(networkChangesCell, 'span');
146 expiredSpan.classList.add('warning-text');
147 addTextNode(expiredSpan, ' [Expired]');
148 }
149
150 if (expired) {
151 expiredEntries++;
152 }
128 } 153 }
129 154
130 $(DnsView.ACTIVE_SPAN_ID).innerText = 155 $(DnsView.ACTIVE_SPAN_ID).innerText =
131 hostResolverCache.entries.length - expiredEntries; 156 hostResolverCache.entries.length - expiredEntries;
132 $(DnsView.EXPIRED_SPAN_ID).innerText = expiredEntries; 157 $(DnsView.EXPIRED_SPAN_ID).innerText = expiredEntries;
133 return true; 158 return true;
134 }, 159 },
135 }; 160 };
136 161
137 /** 162 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 * Takes a last of strings and adds them all to a DOM node, displaying them 210 * Takes a last of strings and adds them all to a DOM node, displaying them
186 * on separate lines. 211 * on separate lines.
187 * @param {DomNode} node The parent node. 212 * @param {DomNode} node The parent node.
188 * @param {Array<string>} list List of strings to add to the node. 213 * @param {Array<string>} list List of strings to add to the node.
189 */ 214 */
190 function addListToNode_(node, list) { 215 function addListToNode_(node, list) {
191 for (var i = 0; i < list.length; ++i) 216 for (var i = 0; i < list.length; ++i)
192 addNodeWithText(node, 'div', list[i]); 217 addNodeWithText(node, 'div', list[i]);
193 } 218 }
194 219
220 // TODO(mgersh): The |ttl| and |network_changes| properties were introduced in
221 // M59 and may not exist when loading older logs. This can be removed in M62.
222 function valueOrDefault(value, defaultValue) {
223 if (value != undefined)
224 return value;
225 return defaultValue;
226 }
227
195 return DnsView; 228 return DnsView;
196 })(); 229 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698