зеркало из https://github.com/mozilla/gecko-dev.git
Bug 987101 - Switch the CrashMonitor to native OS.File.read(). r=Yoric
This commit is contained in:
Родитель
e579502249
Коммит
c8bfdc8364
|
@ -41,8 +41,6 @@ Cu.import("resource://gre/modules/osfile.jsm");
|
||||||
Cu.import("resource://gre/modules/Promise.jsm");
|
Cu.import("resource://gre/modules/Promise.jsm");
|
||||||
Cu.import("resource://gre/modules/Task.jsm");
|
Cu.import("resource://gre/modules/Task.jsm");
|
||||||
Cu.import("resource://gre/modules/AsyncShutdown.jsm");
|
Cu.import("resource://gre/modules/AsyncShutdown.jsm");
|
||||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
|
||||||
Cu.import("resource://gre/modules/FileUtils.jsm");
|
|
||||||
|
|
||||||
const NOTIFICATIONS = [
|
const NOTIFICATIONS = [
|
||||||
"final-ui-startup",
|
"final-ui-startup",
|
||||||
|
@ -100,42 +98,30 @@ let CrashMonitorInternal = {
|
||||||
* @return {Promise} A promise that resolves/rejects once loading is complete
|
* @return {Promise} A promise that resolves/rejects once loading is complete
|
||||||
*/
|
*/
|
||||||
loadPreviousCheckpoints: function () {
|
loadPreviousCheckpoints: function () {
|
||||||
let deferred = Promise.defer();
|
this.previousCheckpoints = Task.spawn(function*() {
|
||||||
CrashMonitorInternal.previousCheckpoints = deferred.promise;
|
let data;
|
||||||
|
try {
|
||||||
let file = FileUtils.File(CrashMonitorInternal.path);
|
data = yield OS.File.read(CrashMonitorInternal.path, { encoding: "utf-8" });
|
||||||
NetUtil.asyncFetch(file, function(inputStream, status) {
|
} catch (ex if ex instanceof OS.File.Error) {
|
||||||
if (!Components.isSuccessCode(status)) {
|
if (!ex.becauseNoSuchFile) {
|
||||||
if (status != Cr.NS_ERROR_FILE_NOT_FOUND) {
|
Cu.reportError("Error while loading crash monitor data: " + ex.toString());
|
||||||
Cu.reportError("Error while loading crash monitor data: " + status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deferred.resolve(null);
|
return null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = NetUtil.readInputStreamToString(inputStream,
|
let notifications;
|
||||||
inputStream.available(), { charset: "UTF-8" });
|
|
||||||
|
|
||||||
let notifications = null;
|
|
||||||
try {
|
try {
|
||||||
notifications = JSON.parse(data);
|
notifications = JSON.parse(data);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Cu.reportError("Error while parsing crash monitor data: " + ex);
|
Cu.reportError("Error while parsing crash monitor data: " + ex);
|
||||||
deferred.resolve(null);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return Object.freeze(notifications);
|
||||||
deferred.resolve(Object.freeze(notifications));
|
|
||||||
} catch (ex) {
|
|
||||||
// The only exception we reject from is if notifications is not
|
|
||||||
// an object. This happens when the checkpoints file contained
|
|
||||||
// just a numeric string.
|
|
||||||
deferred.reject(ex);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return deferred.promise;
|
return this.previousCheckpoints;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test with sessionCheckpoints.json containing invalid JSON data
|
||||||
|
*/
|
||||||
|
add_task(function test_invalid_file() {
|
||||||
|
// Write bogus data to checkpoint file
|
||||||
|
let data = "[}";
|
||||||
|
yield OS.File.writeAtomic(sessionCheckpointsPath, data,
|
||||||
|
{tmpPath: sessionCheckpointsPath + ".tmp"});
|
||||||
|
|
||||||
|
CrashMonitor.init();
|
||||||
|
let checkpoints = yield CrashMonitor.previousCheckpoints;
|
||||||
|
do_check_eq(checkpoints, null);
|
||||||
|
});
|
|
@ -5,5 +5,6 @@ tail =
|
||||||
[test_init.js]
|
[test_init.js]
|
||||||
[test_valid_file.js]
|
[test_valid_file.js]
|
||||||
[test_invalid_file.js]
|
[test_invalid_file.js]
|
||||||
|
[test_invalid_json.js]
|
||||||
[test_missing_file.js]
|
[test_missing_file.js]
|
||||||
[test_register.js]
|
[test_register.js]
|
||||||
|
|
Загрузка…
Ссылка в новой задаче