OLD | NEW |
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 var SourceEntry = (function() { | 5 var SourceEntry = (function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * A SourceEntry gathers all log entries with the same source. | 9 * A SourceEntry gathers all log entries with the same source. |
10 * | 10 * |
11 * @constructor | 11 * @constructor |
12 */ | 12 */ |
13 function SourceEntry(logEntry, maxPreviousSourceId) { | 13 function SourceEntry(logEntry, maxPreviousSourceId) { |
14 this.maxPreviousSourceId_ = maxPreviousSourceId; | 14 this.maxPreviousSourceId_ = maxPreviousSourceId; |
15 this.entries_ = []; | 15 this.entries_ = []; |
16 this.description_ = ''; | 16 this.description_ = ''; |
17 | 17 |
18 // Set to true on most net errors. | 18 // Set to true on most net errors. |
19 this.isError_ = false; | 19 this.isError_ = false; |
20 | 20 |
21 // If the first entry is a BEGIN_PHASE, set to false. | 21 // If the first entry is a BEGIN_PHASE, set to false. |
22 // Set to true when an END_PHASE matching the first entry is encountered. | 22 // Set to true when an END_PHASE matching the first entry is encountered. |
23 this.isInactive_ = true; | 23 this.isInactive_ = true; |
24 | 24 |
25 if (logEntry.phase == LogEventPhase.PHASE_BEGIN) | 25 if (logEntry.phase == EventPhase.PHASE_BEGIN) |
26 this.isInactive_ = false; | 26 this.isInactive_ = false; |
27 | 27 |
28 this.update(logEntry); | 28 this.update(logEntry); |
29 } | 29 } |
30 | 30 |
31 SourceEntry.prototype = { | 31 SourceEntry.prototype = { |
32 update: function(logEntry) { | 32 update: function(logEntry) { |
33 // Only the last event should have the same type first event, | 33 // Only the last event should have the same type first event, |
34 if (!this.isInactive_ && | 34 if (!this.isInactive_ && |
35 logEntry.phase == LogEventPhase.PHASE_END && | 35 logEntry.phase == EventPhase.PHASE_END && |
36 logEntry.type == this.entries_[0].type) { | 36 logEntry.type == this.entries_[0].type) { |
37 this.isInactive_ = true; | 37 this.isInactive_ = true; |
38 } | 38 } |
39 | 39 |
40 // If we have a net error code, update |this.isError_| if apporpriate. | 40 // If we have a net error code, update |this.isError_| if apporpriate. |
41 if (logEntry.params) { | 41 if (logEntry.params) { |
42 var netErrorCode = logEntry.params.net_error; | 42 var netErrorCode = logEntry.params.net_error; |
43 // Skip both cases where netErrorCode is undefined, and cases where it | 43 // Skip both cases where netErrorCode is undefined, and cases where it |
44 // is 0, indicating no actual error occurred. | 44 // is 0, indicating no actual error occurred. |
45 if (netErrorCode) { | 45 if (netErrorCode) { |
46 // Ignore error code caused by not finding an entry in the cache. | 46 // Ignore error code caused by not finding an entry in the cache. |
47 if (logEntry.type != LogEventType.HTTP_CACHE_OPEN_ENTRY || | 47 if (logEntry.type != EventType.HTTP_CACHE_OPEN_ENTRY || |
48 netErrorCode != NetError.FAILED) { | 48 netErrorCode != NetError.FAILED) { |
49 this.isError_ = true; | 49 this.isError_ = true; |
50 } | 50 } |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 var prevStartEntry = this.getStartEntry_(); | 54 var prevStartEntry = this.getStartEntry_(); |
55 this.entries_.push(logEntry); | 55 this.entries_.push(logEntry); |
56 var curStartEntry = this.getStartEntry_(); | 56 var curStartEntry = this.getStartEntry_(); |
57 | 57 |
58 // If we just got the first entry for this source. | 58 // If we just got the first entry for this source. |
59 if (prevStartEntry != curStartEntry) | 59 if (prevStartEntry != curStartEntry) |
60 this.updateDescription_(); | 60 this.updateDescription_(); |
61 }, | 61 }, |
62 | 62 |
63 updateDescription_: function() { | 63 updateDescription_: function() { |
64 var e = this.getStartEntry_(); | 64 var e = this.getStartEntry_(); |
65 this.description_ = ''; | 65 this.description_ = ''; |
66 if (!e) | 66 if (!e) |
67 return; | 67 return; |
68 | 68 |
69 if (e.source.type == LogSourceType.NONE) { | 69 if (e.source.type == EventSourceType.NONE) { |
70 // NONE is what we use for global events that aren't actually grouped | 70 // NONE is what we use for global events that aren't actually grouped |
71 // by a "source ID", so we will just stringize the event's type. | 71 // by a "source ID", so we will just stringize the event's type. |
72 this.description_ = LogEventTypeNames[e.type]; | 72 this.description_ = EventTypeNames[e.type]; |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
76 if (e.params == undefined) { | 76 if (e.params == undefined) { |
77 return; | 77 return; |
78 } | 78 } |
79 | 79 |
80 switch (e.source.type) { | 80 switch (e.source.type) { |
81 case LogSourceType.URL_REQUEST: | 81 case EventSourceType.URL_REQUEST: |
82 case LogSourceType.SOCKET_STREAM: | 82 case EventSourceType.SOCKET_STREAM: |
83 case LogSourceType.HTTP_STREAM_JOB: | 83 case EventSourceType.HTTP_STREAM_JOB: |
84 this.description_ = e.params.url; | 84 this.description_ = e.params.url; |
85 break; | 85 break; |
86 case LogSourceType.CONNECT_JOB: | 86 case EventSourceType.CONNECT_JOB: |
87 this.description_ = e.params.group_name; | 87 this.description_ = e.params.group_name; |
88 break; | 88 break; |
89 case LogSourceType.HOST_RESOLVER_IMPL_REQUEST: | 89 case EventSourceType.HOST_RESOLVER_IMPL_REQUEST: |
90 case LogSourceType.HOST_RESOLVER_IMPL_JOB: | 90 case EventSourceType.HOST_RESOLVER_IMPL_JOB: |
91 case LogSourceType.HOST_RESOLVER_IMPL_PROC_TASK: | 91 case EventSourceType.HOST_RESOLVER_IMPL_PROC_TASK: |
92 this.description_ = e.params.host; | 92 this.description_ = e.params.host; |
93 break; | 93 break; |
94 case LogSourceType.DISK_CACHE_ENTRY: | 94 case EventSourceType.DISK_CACHE_ENTRY: |
95 case LogSourceType.MEMORY_CACHE_ENTRY: | 95 case EventSourceType.MEMORY_CACHE_ENTRY: |
96 this.description_ = e.params.key; | 96 this.description_ = e.params.key; |
97 break; | 97 break; |
98 case LogSourceType.SPDY_SESSION: | 98 case EventSourceType.SPDY_SESSION: |
99 if (e.params.host) | 99 if (e.params.host) |
100 this.description_ = e.params.host + ' (' + e.params.proxy + ')'; | 100 this.description_ = e.params.host + ' (' + e.params.proxy + ')'; |
101 break; | 101 break; |
102 case LogSourceType.HTTP_PIPELINED_CONNECTION: | 102 case EventSourceType.HTTP_PIPELINED_CONNECTION: |
103 if (e.params.host_and_port) | 103 if (e.params.host_and_port) |
104 this.description_ = e.params.host_and_port; | 104 this.description_ = e.params.host_and_port; |
105 break; | 105 break; |
106 case LogSourceType.SOCKET: | 106 case EventSourceType.SOCKET: |
107 // Use description of parent source, if any. | 107 // Use description of parent source, if any. |
108 if (e.params.source_dependency != undefined) { | 108 if (e.params.source_dependency != undefined) { |
109 var parentId = e.params.source_dependency.id; | 109 var parentId = e.params.source_dependency.id; |
110 this.description_ = | 110 this.description_ = |
111 SourceTracker.getInstance().getDescription(parentId); | 111 SourceTracker.getInstance().getDescription(parentId); |
112 } | 112 } |
113 break; | 113 break; |
114 case LogSourceType.UDP_SOCKET: | 114 case EventSourceType.UDP_SOCKET: |
115 if (e.params.address != undefined) { | 115 if (e.params.address != undefined) { |
116 this.description_ = e.params.address; | 116 this.description_ = e.params.address; |
117 // If the parent of |this| is a HOST_RESOLVER_IMPL_JOB, use | 117 // If the parent of |this| is a HOST_RESOLVER_IMPL_JOB, use |
118 // '<DNS Server IP> [<host we're resolving>]'. | 118 // '<DNS Server IP> [<host we're resolving>]'. |
119 if (this.entries_[0].type == LogEventType.SOCKET_ALIVE && | 119 if (this.entries_[0].type == EventType.SOCKET_ALIVE && |
120 this.entries_[0].params.source_dependency != undefined) { | 120 this.entries_[0].params.source_dependency != undefined) { |
121 var parentId = this.entries_[0].params.source_dependency.id; | 121 var parentId = this.entries_[0].params.source_dependency.id; |
122 var parent = SourceTracker.getInstance().getSourceEntry(parentId); | 122 var parent = SourceTracker.getInstance().getSourceEntry(parentId); |
123 if (parent && | 123 if (parent && |
124 parent.getSourceType() == | 124 parent.getSourceType() == |
125 LogSourceType.HOST_RESOLVER_IMPL_JOB && | 125 EventSourceType.HOST_RESOLVER_IMPL_JOB && |
126 parent.getDescription().length > 0) { | 126 parent.getDescription().length > 0) { |
127 this.description_ += ' [' + parent.getDescription() + ']'; | 127 this.description_ += ' [' + parent.getDescription() + ']'; |
128 } | 128 } |
129 } | 129 } |
130 } | 130 } |
131 break; | 131 break; |
132 case LogSourceType.ASYNC_HOST_RESOLVER_REQUEST: | 132 case EventSourceType.ASYNC_HOST_RESOLVER_REQUEST: |
133 case LogSourceType.DNS_TRANSACTION: | 133 case EventSourceType.DNS_TRANSACTION: |
134 this.description_ = e.params.hostname; | 134 this.description_ = e.params.hostname; |
135 break; | 135 break; |
136 case LogSourceType.DOWNLOAD: | 136 case EventSourceType.DOWNLOAD: |
137 switch (e.type) { | 137 switch (e.type) { |
138 case LogEventType.DOWNLOAD_FILE_RENAMED: | 138 case EventType.DOWNLOAD_FILE_RENAMED: |
139 this.description_ = e.params.new_filename; | 139 this.description_ = e.params.new_filename; |
140 break; | 140 break; |
141 case LogEventType.DOWNLOAD_FILE_OPENED: | 141 case EventType.DOWNLOAD_FILE_OPENED: |
142 this.description_ = e.params.file_name; | 142 this.description_ = e.params.file_name; |
143 break; | 143 break; |
144 case LogEventType.DOWNLOAD_ITEM_ACTIVE: | 144 case EventType.DOWNLOAD_ITEM_ACTIVE: |
145 this.description_ = e.params.file_name; | 145 this.description_ = e.params.file_name; |
146 break; | 146 break; |
147 } | 147 } |
148 break; | 148 break; |
149 case LogSourceType.FILESTREAM: | 149 case EventSourceType.FILESTREAM: |
150 this.description_ = e.params.file_name; | 150 this.description_ = e.params.file_name; |
151 break; | 151 break; |
152 } | 152 } |
153 | 153 |
154 if (this.description_ == undefined) | 154 if (this.description_ == undefined) |
155 this.description_ = ''; | 155 this.description_ = ''; |
156 }, | 156 }, |
157 | 157 |
158 /** | 158 /** |
159 * Returns a description for this source log stream, which will be displayed | 159 * Returns a description for this source log stream, which will be displayed |
160 * in the list view. Most often this is a URL that identifies the request, | 160 * in the list view. Most often this is a URL that identifies the request, |
161 * or a hostname for a connect job, etc... | 161 * or a hostname for a connect job, etc... |
162 */ | 162 */ |
163 getDescription: function() { | 163 getDescription: function() { |
164 return this.description_; | 164 return this.description_; |
165 }, | 165 }, |
166 | 166 |
167 /** | 167 /** |
168 * Returns the starting entry for this source. Conceptually this is the | 168 * Returns the starting entry for this source. Conceptually this is the |
169 * first entry that was logged to this source. However, we skip over the | 169 * first entry that was logged to this source. However, we skip over the |
170 * TYPE_REQUEST_ALIVE entries which wrap TYPE_URL_REQUEST_START_JOB / | 170 * TYPE_REQUEST_ALIVE entries which wrap TYPE_URL_REQUEST_START_JOB / |
171 * TYPE_SOCKET_STREAM_CONNECT. | 171 * TYPE_SOCKET_STREAM_CONNECT. |
172 */ | 172 */ |
173 getStartEntry_: function() { | 173 getStartEntry_: function() { |
174 if (this.entries_.length < 1) | 174 if (this.entries_.length < 1) |
175 return undefined; | 175 return undefined; |
176 if (this.entries_[0].source.type == LogSourceType.FILESTREAM) { | 176 if (this.entries_[0].source.type == EventSourceType.FILESTREAM) { |
177 var e = this.findLogEntryByType_(LogEventType.FILE_STREAM_OPEN); | 177 var e = this.findLogEntryByType_(EventType.FILE_STREAM_OPEN); |
178 if (e != undefined) | 178 if (e != undefined) |
179 return e; | 179 return e; |
180 } | 180 } |
181 if (this.entries_[0].source.type == LogSourceType.DOWNLOAD) { | 181 if (this.entries_[0].source.type == EventSourceType.DOWNLOAD) { |
182 // If any rename occurred, use the last name | 182 // If any rename occurred, use the last name |
183 e = this.findLastLogEntryStartByType_( | 183 e = this.findLastLogEntryStartByType_( |
184 LogEventType.DOWNLOAD_FILE_RENAMED); | 184 EventType.DOWNLOAD_FILE_RENAMED); |
185 if (e != undefined) | 185 if (e != undefined) |
186 return e; | 186 return e; |
187 // Otherwise, if the file was opened, use that name | 187 // Otherwise, if the file was opened, use that name |
188 e = this.findLogEntryByType_(LogEventType.DOWNLOAD_FILE_OPENED); | 188 e = this.findLogEntryByType_(EventType.DOWNLOAD_FILE_OPENED); |
189 if (e != undefined) | 189 if (e != undefined) |
190 return e; | 190 return e; |
191 // History items are never opened, so use the activation info | 191 // History items are never opened, so use the activation info |
192 e = this.findLogEntryByType_(LogEventType.DOWNLOAD_ITEM_ACTIVE); | 192 e = this.findLogEntryByType_(EventType.DOWNLOAD_ITEM_ACTIVE); |
193 if (e != undefined) | 193 if (e != undefined) |
194 return e; | 194 return e; |
195 } | 195 } |
196 if (this.entries_.length >= 2) { | 196 if (this.entries_.length >= 2) { |
197 if (this.entries_[0].type == LogEventType.SOCKET_POOL_CONNECT_JOB || | 197 if (this.entries_[0].type == EventType.SOCKET_POOL_CONNECT_JOB || |
198 this.entries_[1].type == LogEventType.UDP_CONNECT) { | 198 this.entries_[1].type == EventType.UDP_CONNECT) { |
199 return this.entries_[1]; | 199 return this.entries_[1]; |
200 } | 200 } |
201 if (this.entries_[0].type == LogEventType.REQUEST_ALIVE) { | 201 if (this.entries_[0].type == EventType.REQUEST_ALIVE) { |
202 var start_index = 1; | 202 var start_index = 1; |
203 // Skip over URL_REQUEST_BLOCKED_ON_DELEGATE events for URL_REQUESTs. | 203 // Skip over URL_REQUEST_BLOCKED_ON_DELEGATE events for URL_REQUESTs. |
204 while (start_index + 1 < this.entries_.length && | 204 while (start_index + 1 < this.entries_.length && |
205 this.entries_[start_index].type == | 205 this.entries_[start_index].type == |
206 LogEventType.URL_REQUEST_BLOCKED_ON_DELEGATE) { | 206 EventType.URL_REQUEST_BLOCKED_ON_DELEGATE) { |
207 ++start_index; | 207 ++start_index; |
208 } | 208 } |
209 return this.entries_[start_index]; | 209 return this.entries_[start_index]; |
210 } | 210 } |
211 } | 211 } |
212 return this.entries_[0]; | 212 return this.entries_[0]; |
213 }, | 213 }, |
214 | 214 |
215 /** | 215 /** |
216 * Returns the first entry with the specified type, or undefined if not | 216 * Returns the first entry with the specified type, or undefined if not |
217 * found. | 217 * found. |
218 */ | 218 */ |
219 findLogEntryByType_: function(type) { | 219 findLogEntryByType_: function(type) { |
220 for (var i = 0; i < this.entries_.length; ++i) { | 220 for (var i = 0; i < this.entries_.length; ++i) { |
221 if (this.entries_[i].type == type) { | 221 if (this.entries_[i].type == type) { |
222 return this.entries_[i]; | 222 return this.entries_[i]; |
223 } | 223 } |
224 } | 224 } |
225 return undefined; | 225 return undefined; |
226 }, | 226 }, |
227 | 227 |
228 /** | 228 /** |
229 * Returns the beginning of the last entry with the specified type, or | 229 * Returns the beginning of the last entry with the specified type, or |
230 * undefined if not found. | 230 * undefined if not found. |
231 */ | 231 */ |
232 findLastLogEntryStartByType_: function(type) { | 232 findLastLogEntryStartByType_: function(type) { |
233 for (var i = this.entries_.length - 1; i >= 0; --i) { | 233 for (var i = this.entries_.length - 1; i >= 0; --i) { |
234 if (this.entries_[i].type == type) { | 234 if (this.entries_[i].type == type) { |
235 if (this.entries_[i].phase != LogEventPhase.PHASE_END) | 235 if (this.entries_[i].phase != EventPhase.PHASE_END) |
236 return this.entries_[i]; | 236 return this.entries_[i]; |
237 } | 237 } |
238 } | 238 } |
239 return undefined; | 239 return undefined; |
240 }, | 240 }, |
241 | 241 |
242 getLogEntries: function() { | 242 getLogEntries: function() { |
243 return this.entries_; | 243 return this.entries_; |
244 }, | 244 }, |
245 | 245 |
246 getSourceTypeString: function() { | 246 getSourceTypeString: function() { |
247 return LogSourceTypeNames[this.entries_[0].source.type]; | 247 return EventSourceTypeNames[this.entries_[0].source.type]; |
248 }, | 248 }, |
249 | 249 |
250 getSourceType: function() { | 250 getSourceType: function() { |
251 return this.entries_[0].source.type; | 251 return this.entries_[0].source.type; |
252 }, | 252 }, |
253 | 253 |
254 getSourceId: function() { | 254 getSourceId: function() { |
255 return this.entries_[0].source.id; | 255 return this.entries_[0].source.id; |
256 }, | 256 }, |
257 | 257 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 * of |parent|. | 300 * of |parent|. |
301 */ | 301 */ |
302 printAsText: function(parent) { | 302 printAsText: function(parent) { |
303 printLogEntriesAsText(this.entries_, parent, | 303 printLogEntriesAsText(this.entries_, parent, |
304 SourceTracker.getInstance().getSecurityStripping()); | 304 SourceTracker.getInstance().getSecurityStripping()); |
305 } | 305 } |
306 }; | 306 }; |
307 | 307 |
308 return SourceEntry; | 308 return SourceEntry; |
309 })(); | 309 })(); |
OLD | NEW |