OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @constructor | 6 * @constructor |
7 * @implements {WebInspector.OutputStream} | 7 * @implements {WebInspector.OutputStream} |
8 * @implements {WebInspector.OutputStreamDelegate} | 8 * @implements {WebInspector.OutputStreamDelegate} |
9 * @param {!WebInspector.TracingModel} model | 9 * @param {!WebInspector.TracingModel} model |
10 * @param {!WebInspector.TimelineLifecycleDelegate} delegate | 10 * @param {!WebInspector.TimelineLifecycleDelegate} delegate |
11 */ | 11 */ |
12 WebInspector.TimelineLoader = function(model, delegate) | 12 WebInspector.TimelineLoader = function(model, delegate) |
13 { | 13 { |
14 this._model = model; | 14 this._model = model; |
15 this._delegate = delegate; | 15 this._delegate = delegate; |
16 | 16 |
17 /** @type {?function()} */ | 17 /** @type {?function()} */ |
18 this._canceledCallback = null; | 18 this._canceledCallback = null; |
19 | 19 |
20 this._state = WebInspector.TimelineLoader.State.Initial; | 20 this._state = WebInspector.TimelineLoader.State.Initial; |
21 this._buffer = ""; | 21 this._buffer = ""; |
22 this._firstChunk = true; | 22 this._firstChunk = true; |
23 | 23 |
24 this._loadedBytes = 0; | 24 this._loadedBytes = 0; |
25 /** @type {number} */ | 25 /** @type {number} */ |
26 this._totalSize; | 26 this._totalSize; |
27 this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this.
_writeBalancedJSON.bind(this), true); | 27 this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this.
_writeBalancedJSON.bind(this), true); |
28 } | 28 }; |
29 | 29 |
30 /** | 30 /** |
31 * @param {!WebInspector.TracingModel} model | 31 * @param {!WebInspector.TracingModel} model |
32 * @param {!File} file | 32 * @param {!File} file |
33 * @param {!WebInspector.TimelineLifecycleDelegate} delegate | 33 * @param {!WebInspector.TimelineLifecycleDelegate} delegate |
34 * @return {!WebInspector.TimelineLoader} | 34 * @return {!WebInspector.TimelineLoader} |
35 */ | 35 */ |
36 WebInspector.TimelineLoader.loadFromFile = function(model, file, delegate) | 36 WebInspector.TimelineLoader.loadFromFile = function(model, file, delegate) |
37 { | 37 { |
38 var loader = new WebInspector.TimelineLoader(model, delegate); | 38 var loader = new WebInspector.TimelineLoader(model, delegate); |
39 var fileReader = WebInspector.TimelineLoader._createFileReader(file, loader)
; | 39 var fileReader = WebInspector.TimelineLoader._createFileReader(file, loader)
; |
40 loader._canceledCallback = fileReader.cancel.bind(fileReader); | 40 loader._canceledCallback = fileReader.cancel.bind(fileReader); |
41 loader._totalSize = file.size; | 41 loader._totalSize = file.size; |
42 fileReader.start(loader); | 42 fileReader.start(loader); |
43 return loader; | 43 return loader; |
44 } | 44 }; |
45 | 45 |
46 /** | 46 /** |
47 * @param {!WebInspector.TracingModel} model | 47 * @param {!WebInspector.TracingModel} model |
48 * @param {string} url | 48 * @param {string} url |
49 * @param {!WebInspector.TimelineLifecycleDelegate} delegate | 49 * @param {!WebInspector.TimelineLifecycleDelegate} delegate |
50 * @return {!WebInspector.TimelineLoader} | 50 * @return {!WebInspector.TimelineLoader} |
51 */ | 51 */ |
52 WebInspector.TimelineLoader.loadFromURL = function(model, url, delegate) | 52 WebInspector.TimelineLoader.loadFromURL = function(model, url, delegate) |
53 { | 53 { |
54 var stream = new WebInspector.TimelineLoader(model, delegate); | 54 var stream = new WebInspector.TimelineLoader(model, delegate); |
55 WebInspector.ResourceLoader.loadAsStream(url, null, stream); | 55 WebInspector.ResourceLoader.loadAsStream(url, null, stream); |
56 return stream; | 56 return stream; |
57 } | 57 }; |
58 | 58 |
59 WebInspector.TimelineLoader.TransferChunkLengthBytes = 5000000; | 59 WebInspector.TimelineLoader.TransferChunkLengthBytes = 5000000; |
60 | 60 |
61 /** | 61 /** |
62 * @param {!File} file | 62 * @param {!File} file |
63 * @param {!WebInspector.OutputStreamDelegate} delegate | 63 * @param {!WebInspector.OutputStreamDelegate} delegate |
64 * @return {!WebInspector.ChunkedReader} | 64 * @return {!WebInspector.ChunkedReader} |
65 */ | 65 */ |
66 WebInspector.TimelineLoader._createFileReader = function(file, delegate) | 66 WebInspector.TimelineLoader._createFileReader = function(file, delegate) |
67 { | 67 { |
68 return new WebInspector.ChunkedFileReader(file, WebInspector.TimelineLoader.
TransferChunkLengthBytes, delegate); | 68 return new WebInspector.ChunkedFileReader(file, WebInspector.TimelineLoader.
TransferChunkLengthBytes, delegate); |
69 } | 69 }; |
70 | 70 |
71 /** | 71 /** |
72 * @enum {symbol} | 72 * @enum {symbol} |
73 */ | 73 */ |
74 WebInspector.TimelineLoader.State = { | 74 WebInspector.TimelineLoader.State = { |
75 Initial: Symbol("Initial"), | 75 Initial: Symbol("Initial"), |
76 LookingForEvents: Symbol("LookingForEvents"), | 76 LookingForEvents: Symbol("LookingForEvents"), |
77 ReadingEvents: Symbol("ReadingEvents"), | 77 ReadingEvents: Symbol("ReadingEvents"), |
78 SkippingTail: Symbol("SkippingTail") | 78 SkippingTail: Symbol("SkippingTail") |
79 } | 79 }; |
80 | 80 |
81 WebInspector.TimelineLoader.prototype = { | 81 WebInspector.TimelineLoader.prototype = { |
82 cancel: function() | 82 cancel: function() |
83 { | 83 { |
84 this._model.reset(); | 84 this._model.reset(); |
85 this._delegate.loadingComplete(false); | 85 this._delegate.loadingComplete(false); |
86 this._delegate = null; | 86 this._delegate = null; |
87 if (this._canceledCallback) | 87 if (this._canceledCallback) |
88 this._canceledCallback(); | 88 this._canceledCallback(); |
89 }, | 89 }, |
(...skipping 21 matching lines...) Expand all Loading... |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 if (this._state === WebInspector.TimelineLoader.State.LookingForEvents)
{ | 114 if (this._state === WebInspector.TimelineLoader.State.LookingForEvents)
{ |
115 var objectName = "\"traceEvents\":"; | 115 var objectName = "\"traceEvents\":"; |
116 var startPos = this._buffer.length - objectName.length; | 116 var startPos = this._buffer.length - objectName.length; |
117 this._buffer += chunk; | 117 this._buffer += chunk; |
118 var pos = this._buffer.indexOf(objectName, startPos); | 118 var pos = this._buffer.indexOf(objectName, startPos); |
119 if (pos === -1) | 119 if (pos === -1) |
120 return; | 120 return; |
121 chunk = this._buffer.slice(pos + objectName.length) | 121 chunk = this._buffer.slice(pos + objectName.length); |
122 this._state = WebInspector.TimelineLoader.State.ReadingEvents; | 122 this._state = WebInspector.TimelineLoader.State.ReadingEvents; |
123 } | 123 } |
124 | 124 |
125 if (this._state !== WebInspector.TimelineLoader.State.ReadingEvents) | 125 if (this._state !== WebInspector.TimelineLoader.State.ReadingEvents) |
126 return; | 126 return; |
127 if (this._jsonTokenizer.write(chunk)) | 127 if (this._jsonTokenizer.write(chunk)) |
128 return; | 128 return; |
129 this._state = WebInspector.TimelineLoader.State.SkippingTail; | 129 this._state = WebInspector.TimelineLoader.State.SkippingTail; |
130 if (this._firstChunk) { | 130 if (this._firstChunk) { |
131 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t
imeline input, wrong JSON brackets balance")); | 131 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t
imeline input, wrong JSON brackets balance")); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 break; | 232 break; |
233 case "NotReadableError": | 233 case "NotReadableError": |
234 this._reportErrorAndCancelLoading(WebInspector.UIString("File \"%s\"
is not readable", reader.fileName())); | 234 this._reportErrorAndCancelLoading(WebInspector.UIString("File \"%s\"
is not readable", reader.fileName())); |
235 break; | 235 break; |
236 case "AbortError": | 236 case "AbortError": |
237 break; | 237 break; |
238 default: | 238 default: |
239 this._reportErrorAndCancelLoading(WebInspector.UIString("An error oc
curred while reading the file \"%s\"", reader.fileName())); | 239 this._reportErrorAndCancelLoading(WebInspector.UIString("An error oc
curred while reading the file \"%s\"", reader.fileName())); |
240 } | 240 } |
241 } | 241 } |
242 } | 242 }; |
243 | 243 |
244 /** | 244 /** |
245 * @constructor | 245 * @constructor |
246 * @implements {WebInspector.OutputStreamDelegate} | 246 * @implements {WebInspector.OutputStreamDelegate} |
247 */ | 247 */ |
248 WebInspector.TracingTimelineSaver = function() | 248 WebInspector.TracingTimelineSaver = function() |
249 { | 249 { |
250 } | 250 }; |
251 | 251 |
252 WebInspector.TracingTimelineSaver.prototype = { | 252 WebInspector.TracingTimelineSaver.prototype = { |
253 /** | 253 /** |
254 * @override | 254 * @override |
255 */ | 255 */ |
256 onTransferStarted: function() { }, | 256 onTransferStarted: function() { }, |
257 | 257 |
258 /** | 258 /** |
259 * @override | 259 * @override |
260 */ | 260 */ |
261 onTransferFinished: function() { }, | 261 onTransferFinished: function() { }, |
262 | 262 |
263 /** | 263 /** |
264 * @override | 264 * @override |
265 * @param {!WebInspector.ChunkedReader} reader | 265 * @param {!WebInspector.ChunkedReader} reader |
266 */ | 266 */ |
267 onChunkTransferred: function(reader) { }, | 267 onChunkTransferred: function(reader) { }, |
268 | 268 |
269 /** | 269 /** |
270 * @override | 270 * @override |
271 * @param {!WebInspector.ChunkedReader} reader | 271 * @param {!WebInspector.ChunkedReader} reader |
272 * @param {!Event} event | 272 * @param {!Event} event |
273 */ | 273 */ |
274 onError: function(reader, event) | 274 onError: function(reader, event) |
275 { | 275 { |
276 var error = event.target.error; | 276 var error = event.target.error; |
277 WebInspector.console.error(WebInspector.UIString("Failed to save timelin
e: %s (%s, %s)", error.message, error.name, error.code)); | 277 WebInspector.console.error(WebInspector.UIString("Failed to save timelin
e: %s (%s, %s)", error.message, error.name, error.code)); |
278 } | 278 } |
279 } | 279 }; |
OLD | NEW |