Index: Source/devtools/front_end/timeline/TimelineModel.js |
diff --git a/Source/devtools/front_end/timeline/TimelineModel.js b/Source/devtools/front_end/timeline/TimelineModel.js |
index 5a89c30ce9720acb3016b4e2ea07a8c84a1fb9ce..f8f490222601aa7dfb6f3372ebd80229381dc103 100644 |
--- a/Source/devtools/front_end/timeline/TimelineModel.js |
+++ b/Source/devtools/front_end/timeline/TimelineModel.js |
@@ -1196,7 +1196,7 @@ WebInspector.TimelineModel.prototype = { |
{ |
var delegate = new WebInspector.TimelineModelLoadFromFileDelegate(this, progress); |
var fileReader = this._createFileReader(file, delegate); |
- var loader = this.createLoader(fileReader, progress); |
+ var loader = new WebInspector.TracingModelLoader(this, new WebInspector.ProgressStub(), fileReader.cancel.bind(fileReader)); |
fileReader.start(loader); |
}, |
@@ -1282,16 +1282,6 @@ WebInspector.TimelineModel.prototype = { |
}, |
/** |
- * @param {!WebInspector.ChunkedFileReader} fileReader |
- * @param {!WebInspector.Progress} progress |
- * @return {!WebInspector.OutputStream} |
- */ |
- createLoader: function(fileReader, progress) |
- { |
- return new WebInspector.TracingModelLoader(this, fileReader, progress); |
- }, |
- |
- /** |
* @return {boolean} |
*/ |
isEmpty: function() |
@@ -1539,17 +1529,24 @@ WebInspector.ExclusiveTraceEventNameFilter.prototype = { |
* @constructor |
* @implements {WebInspector.OutputStream} |
* @param {!WebInspector.TimelineModel} model |
- * @param {!{cancel: function()}} reader |
* @param {!WebInspector.Progress} progress |
+ * @param {function()=} canceledCallback |
*/ |
-WebInspector.TracingModelLoader = function(model, reader, progress) |
+WebInspector.TracingModelLoader = function(model, progress, canceledCallback) |
{ |
this._model = model; |
- this._reader = reader; |
+ this._loader = new WebInspector.TracingModel.Loader(model._tracingModel); |
+ |
+ this._canceledCallback = canceledCallback; |
this._progress = progress; |
- this._buffer = ""; |
+ this._progress.setTitle(WebInspector.UIString("Loading")); |
+ this._progress.setTotalWork(100000); // Unknown, will loop the values. |
alph
2015/03/01 11:30:14
mind to a define a const for it plz.
pfeldman
2015/03/01 12:18:53
Done.
|
+ |
this._firstChunk = true; |
- this._loader = new WebInspector.TracingModel.Loader(model._tracingModel); |
+ this._wasCanceledOnce = false; |
+ |
+ this._loadedBytes = 0; |
+ this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this._writeBalancedJSON.bind(this), true); |
} |
WebInspector.TracingModelLoader.prototype = { |
@@ -1559,19 +1556,22 @@ WebInspector.TracingModelLoader.prototype = { |
*/ |
write: function(chunk) |
{ |
- var data = this._buffer + chunk; |
- var lastIndex = 0; |
- var index; |
- do { |
- index = lastIndex; |
- lastIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(data, index); |
- } while (lastIndex !== -1); |
- |
- var json = data.slice(0, index) + "]"; |
- this._buffer = data.slice(index); |
- |
- if (!index) |
+ this._loadedBytes += chunk.length; |
+ if (this._progress.isCanceled() && !this._wasCanceledOnce) { |
+ this._wasCanceled = true; |
+ this._reportErrorAndCancelLoading(); |
return; |
+ } |
+ this._progress.setWorked(this._loadedBytes % 100000, WebInspector.UIString("Loaded %s bytes", Number.bytesToString(this._loadedBytes))); |
alph
2015/03/01 11:30:14
Drop extra "bytes" word.
pfeldman
2015/03/01 12:18:54
Done.
|
+ this._jsonTokenizer.write(chunk); |
+ }, |
+ |
+ /** |
+ * @param {string} data |
+ */ |
+ _writeBalancedJSON: function(data) |
+ { |
+ var json = data + "]"; |
if (this._firstChunk) { |
this._model._startCollectingTraceEvents(true); |
@@ -1586,14 +1586,14 @@ WebInspector.TracingModelLoader.prototype = { |
try { |
items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload>} */ (JSON.parse(json)); |
} catch (e) { |
- this._reportErrorAndCancelLoading("Malformed timeline data: " + e); |
+ this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed timeline data: " + e)); |
return; |
} |
if (this._firstChunk) { |
this._firstChunk = false; |
if (this._looksLikeAppVersion(items[0])) { |
- this._reportErrorAndCancelLoading("Old Timeline format is not supported."); |
+ this._reportErrorAndCancelLoading(WebInspector.UIString("Legacy Timeline format is not supported.")); |
return; |
} |
} |
@@ -1601,17 +1601,22 @@ WebInspector.TracingModelLoader.prototype = { |
try { |
this._loader.loadNextChunk(items); |
} catch(e) { |
- this._reportErrorAndCancelLoading("Malformed timeline data: " + e); |
+ this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed timeline data: " + e)); |
return; |
} |
}, |
+ /** |
+ * @param {string=} messsage |
+ */ |
_reportErrorAndCancelLoading: function(messsage) |
{ |
- WebInspector.console.error(messsage); |
+ if (messsage) |
alph
2015/03/01 11:30:14
two 's'-es should be enough
pfeldman
2015/03/01 12:18:53
Done.
|
+ WebInspector.console.error(messsage); |
this._model.tracingComplete(); |
this._model.reset(); |
- this._reader.cancel(); |
+ if (this._canceledCallback) |
+ this._canceledCallback(); |
this._progress.done(); |
}, |
@@ -1627,6 +1632,8 @@ WebInspector.TracingModelLoader.prototype = { |
{ |
this._loader.finish(); |
this._model.tracingComplete(); |
+ if (this._progress) |
+ this._progress.done(); |
} |
} |