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 * |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 parent.getDescription().length > 0) { | 125 parent.getDescription().length > 0) { |
126 this.description_ += ' [' + parent.getDescription() + ']'; | 126 this.description_ += ' [' + parent.getDescription() + ']'; |
127 } | 127 } |
128 } | 128 } |
129 } | 129 } |
130 break; | 130 break; |
131 case LogSourceType.ASYNC_HOST_RESOLVER_REQUEST: | 131 case LogSourceType.ASYNC_HOST_RESOLVER_REQUEST: |
132 case LogSourceType.DNS_TRANSACTION: | 132 case LogSourceType.DNS_TRANSACTION: |
133 this.description_ = e.params.hostname; | 133 this.description_ = e.params.hostname; |
134 break; | 134 break; |
| 135 case LogSourceType.DOWNLOAD: |
| 136 switch (e.type) { |
| 137 case LogEventType.DOWNLOAD_FILE_RENAMED: |
| 138 this.description_ = e.params.new_filename; |
| 139 break; |
| 140 case LogEventType.DOWNLOAD_FILE_OPENED: |
| 141 this.description_ = e.params.file_name; |
| 142 break; |
| 143 } |
| 144 break; |
135 case LogSourceType.FILESTREAM: | 145 case LogSourceType.FILESTREAM: |
136 this.description_ = e.params.file_name; | 146 this.description_ = e.params.file_name; |
137 break; | 147 break; |
138 } | 148 } |
139 | 149 |
140 if (this.description_ == undefined) | 150 if (this.description_ == undefined) |
141 this.description_ = ''; | 151 this.description_ = ''; |
142 }, | 152 }, |
143 | 153 |
144 /** | 154 /** |
(...skipping 12 matching lines...) Expand all Loading... |
157 * TYPE_SOCKET_STREAM_CONNECT. | 167 * TYPE_SOCKET_STREAM_CONNECT. |
158 */ | 168 */ |
159 getStartEntry_: function() { | 169 getStartEntry_: function() { |
160 if (this.entries_.length < 1) | 170 if (this.entries_.length < 1) |
161 return undefined; | 171 return undefined; |
162 if (this.entries_[0].source.type == LogSourceType.FILESTREAM) { | 172 if (this.entries_[0].source.type == LogSourceType.FILESTREAM) { |
163 var e = this.findLogEntryByType_(LogEventType.FILE_STREAM_OPEN); | 173 var e = this.findLogEntryByType_(LogEventType.FILE_STREAM_OPEN); |
164 if (e != undefined) | 174 if (e != undefined) |
165 return e; | 175 return e; |
166 } | 176 } |
| 177 if (this.entries_[0].source.type == LogSourceType.DOWNLOAD) { |
| 178 // If any rename occurred, use the last name |
| 179 e = this.findLastLogEntryStartByType_( |
| 180 LogEventType.DOWNLOAD_FILE_RENAMED); |
| 181 if (e != undefined) |
| 182 return e; |
| 183 // Otherwise, if the file was opened, use that name |
| 184 e = this.findLogEntryByType_(LogEventType.DOWNLOAD_FILE_OPENED); |
| 185 if (e != undefined) |
| 186 return e; |
| 187 } |
167 if (this.entries_.length >= 2) { | 188 if (this.entries_.length >= 2) { |
168 if (this.entries_[0].type == LogEventType.REQUEST_ALIVE || | 189 if (this.entries_[0].type == LogEventType.REQUEST_ALIVE || |
169 this.entries_[0].type == LogEventType.SOCKET_POOL_CONNECT_JOB || | 190 this.entries_[0].type == LogEventType.SOCKET_POOL_CONNECT_JOB || |
170 this.entries_[1].type == LogEventType.UDP_CONNECT) { | 191 this.entries_[1].type == LogEventType.UDP_CONNECT) { |
171 return this.entries_[1]; | 192 return this.entries_[1]; |
172 } | 193 } |
173 } | 194 } |
174 return this.entries_[0]; | 195 return this.entries_[0]; |
175 }, | 196 }, |
176 | 197 |
177 /** | 198 /** |
178 * Returns the first entry with the specified type, or undefined if not | 199 * Returns the first entry with the specified type, or undefined if not |
179 * found. | 200 * found. |
180 */ | 201 */ |
181 findLogEntryByType_: function(type) { | 202 findLogEntryByType_: function(type) { |
182 for (var i = 0; i < this.entries_.length; ++i) { | 203 for (var i = 0; i < this.entries_.length; ++i) { |
183 if (this.entries_[i].type == type) { | 204 if (this.entries_[i].type == type) { |
184 return this.entries_[i]; | 205 return this.entries_[i]; |
185 } | 206 } |
186 } | 207 } |
187 return undefined; | 208 return undefined; |
188 }, | 209 }, |
189 | 210 |
| 211 /** |
| 212 * Returns the last entry with the specified type, or undefined if not |
| 213 * found. |
| 214 */ |
| 215 findLastLogEntryStartByType_: function(type) { |
| 216 for (var i = this.entries_.length - 1; i >= 0; --i) { |
| 217 if (this.entries_[i].type == type) { |
| 218 if (this.entries_[i].phase == LogEventPhase.PHASE_BEGIN) |
| 219 return this.entries_[i]; |
| 220 } |
| 221 } |
| 222 return undefined; |
| 223 }, |
| 224 |
190 getLogEntries: function() { | 225 getLogEntries: function() { |
191 return this.entries_; | 226 return this.entries_; |
192 }, | 227 }, |
193 | 228 |
194 getSourceTypeString: function() { | 229 getSourceTypeString: function() { |
195 return getKeyWithValue(LogSourceType, this.entries_[0].source.type); | 230 return getKeyWithValue(LogSourceType, this.entries_[0].source.type); |
196 }, | 231 }, |
197 | 232 |
198 getSourceType: function() { | 233 getSourceType: function() { |
199 return this.entries_[0].source.type; | 234 return this.entries_[0].source.type; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 * Prints descriptive text about |entries_| to a new node added to the end | 282 * Prints descriptive text about |entries_| to a new node added to the end |
248 * of |parent|. | 283 * of |parent|. |
249 */ | 284 */ |
250 printAsText: function(parent) { | 285 printAsText: function(parent) { |
251 printLogEntriesAsText(this.entries_, parent); | 286 printLogEntriesAsText(this.entries_, parent); |
252 } | 287 } |
253 }; | 288 }; |
254 | 289 |
255 return SourceEntry; | 290 return SourceEntry; |
256 })(); | 291 })(); |
OLD | NEW |