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

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

Issue 7531005: Rename the net_internals file names to include hyphens. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Add some missing files Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * A SourceEntry gathers all log entries with the same source.
7 *
8 * @constructor
9 */
10 function SourceEntry(logEntry, maxPreviousSourceId) {
11 this.maxPreviousSourceId_ = maxPreviousSourceId;
12 this.entries_ = [];
13 this.description_ = '';
14
15 // Set to true on most net errors.
16 this.isError_ = false;
17
18 // If the first entry is a BEGIN_PHASE, set to false.
19 // Set to true when an END_PHASE matching the first entry is encountered.
20 this.isInactive_ = true;
21
22 if (logEntry.phase == LogEventPhase.PHASE_BEGIN)
23 this.isInactive_ = false;
24
25 this.update(logEntry);
26 }
27
28 SourceEntry.prototype.update = function(logEntry) {
29 // Only the last event should have the same type first event,
30 if (!this.isInactive_ &&
31 logEntry.phase == LogEventPhase.PHASE_END &&
32 logEntry.type == this.entries_[0].type) {
33 this.isInactive_ = true;
34 }
35
36 // If we have a net error code, update |this.isError_| if apporpriate.
37 if (logEntry.params) {
38 var netErrorCode = logEntry.params.net_error;
39 // Skip both cases where netErrorCode is undefined, and cases where it is
40 // 0, indicating no actual error occurred.
41 if (netErrorCode) {
42 // Ignore error code caused by not finding an entry in the cache.
43 if (logEntry.type != LogEventType.HTTP_CACHE_OPEN_ENTRY ||
44 netErrorCode != NetError.FAILED) {
45 this.isError_ = true;
46 }
47 }
48 }
49
50 var prevStartEntry = this.getStartEntry_();
51 this.entries_.push(logEntry);
52 var curStartEntry = this.getStartEntry_();
53
54 // If we just got the first entry for this source.
55 if (prevStartEntry != curStartEntry)
56 this.updateDescription_();
57 };
58
59 SourceEntry.prototype.updateDescription_ = function() {
60 var e = this.getStartEntry_();
61 this.description_ = '';
62 if (!e)
63 return;
64
65 if (e.source.type == LogSourceType.NONE) {
66 // NONE is what we use for global events that aren't actually grouped
67 // by a "source ID", so we will just stringize the event's type.
68 this.description_ = getKeyWithValue(LogEventType, e.type);
69 return;
70 }
71
72 if (e.params == undefined) {
73 return;
74 }
75
76 switch (e.source.type) {
77 case LogSourceType.URL_REQUEST:
78 case LogSourceType.SOCKET_STREAM:
79 case LogSourceType.HTTP_STREAM_JOB:
80 this.description_ = e.params.url;
81 break;
82 case LogSourceType.CONNECT_JOB:
83 this.description_ = e.params.group_name;
84 break;
85 case LogSourceType.HOST_RESOLVER_IMPL_REQUEST:
86 case LogSourceType.HOST_RESOLVER_IMPL_JOB:
87 this.description_ = e.params.host;
88 break;
89 case LogSourceType.DISK_CACHE_ENTRY:
90 case LogSourceType.MEMORY_CACHE_ENTRY:
91 this.description_ = e.params.key;
92 break;
93 case LogSourceType.SPDY_SESSION:
94 if (e.params.host)
95 this.description_ = e.params.host + ' (' + e.params.proxy + ')';
96 break;
97 case LogSourceType.SOCKET:
98 if (e.params.source_dependency != undefined) {
99 var connectJobId = e.params.source_dependency.id;
100 var connectJob = g_browser.sourceTracker.getSourceEntry(connectJobId);
101 if (connectJob)
102 this.description_ = connectJob.getDescription();
103 }
104 break;
105 case LogSourceType.ASYNC_HOST_RESOLVER_REQUEST:
106 case LogSourceType.DNS_TRANSACTION:
107 this.description_ = e.params.hostname;
108 break;
109 }
110
111 if (this.description_ == undefined)
112 this.description_ = '';
113 };
114
115 /**
116 * Returns a description for this source log stream, which will be displayed
117 * in the list view. Most often this is a URL that identifies the request,
118 * or a hostname for a connect job, etc...
119 */
120 SourceEntry.prototype.getDescription = function() {
121 return this.description_;
122 };
123
124 /**
125 * Returns the starting entry for this source. Conceptually this is the
126 * first entry that was logged to this source. However, we skip over the
127 * TYPE_REQUEST_ALIVE entries which wrap TYPE_URL_REQUEST_START_JOB /
128 * TYPE_SOCKET_STREAM_CONNECT.
129 */
130 SourceEntry.prototype.getStartEntry_ = function() {
131 if (this.entries_.length < 1)
132 return undefined;
133 if (this.entries_.length >= 2) {
134 if (this.entries_[0].type == LogEventType.REQUEST_ALIVE ||
135 this.entries_[0].type == LogEventType.SOCKET_POOL_CONNECT_JOB)
136 return this.entries_[1];
137 }
138 return this.entries_[0];
139 };
140
141 SourceEntry.prototype.getLogEntries = function() {
142 return this.entries_;
143 };
144
145 SourceEntry.prototype.getSourceTypeString = function() {
146 return getKeyWithValue(LogSourceType, this.entries_[0].source.type);
147 };
148
149 SourceEntry.prototype.getSourceType = function() {
150 return this.entries_[0].source.type;
151 };
152
153 SourceEntry.prototype.getSourceId = function() {
154 return this.entries_[0].source.id;
155 };
156
157 /**
158 * Returns the largest source ID seen before this object was received.
159 * Used only for sorting SourceEntries without a source by source ID.
160 */
161 SourceEntry.prototype.getMaxPreviousEntrySourceId = function() {
162 return this.maxPreviousSourceId_;
163 };
164
165 SourceEntry.prototype.isInactive = function() {
166 return this.isInactive_;
167 };
168
169 SourceEntry.prototype.isError = function() {
170 return this.isError_;
171 };
172
173 /**
174 * Returns time of last event if inactive. Returns current time otherwise.
175 */
176 SourceEntry.prototype.getEndTime = function() {
177 if (!this.isInactive_) {
178 return (new Date()).getTime();
179 } else {
180 var endTicks = this.entries_[this.entries_.length - 1].time;
181 return convertTimeTicksToDate(endTicks).getTime();
182 }
183 };
184
185 /**
186 * Returns the time between the first and last events with a matching
187 * source ID. If source is still active, uses the current time for the
188 * last event.
189 */
190 SourceEntry.prototype.getDuration = function() {
191 var startTicks = this.entries_[0].time;
192 var startTime = convertTimeTicksToDate(startTicks).getTime();
193 var endTime = this.getEndTime();
194 return endTime - startTime;
195 };
196
197 SourceEntry.prototype.printAsText = function() {
198 return PrintSourceEntriesAsText(this.entries_);
199 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/net_internals/source_tracker.js ('k') | chrome/browser/resources/net_internals/sourcerow.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698