Bug 1649616, remove OS.File usages from ContextualIdentityService.jsm r=barret

Differential Revision: https://phabricator.services.mozilla.com/D97054
This commit is contained in:
Emma Malysz 2020-11-19 01:48:07 +00:00
Родитель 47c56b553d
Коммит 73a40153e2
2 изменённых файлов: 10 добавлений и 18 удалений

Просмотреть файл

@ -34,7 +34,6 @@ ChromeUtils.defineModuleGetter(
"AsyncShutdown",
"resource://gre/modules/AsyncShutdown.jsm"
);
ChromeUtils.defineModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
ChromeUtils.defineModuleGetter(
this,
"DeferredTask",
@ -170,7 +169,7 @@ _ContextualIdentityService.prototype = {
},
load() {
return OS.File.read(this._path).then(
return IOUtils.read(this._path).then(
bytes => {
// If synchronous loading happened in the meantime, exit now.
if (this._dataReady) {
@ -217,14 +216,7 @@ _ContextualIdentityService.prototype = {
},
loadError(error) {
if (
error != null &&
!(error instanceof OS.File.Error && error.becauseNoSuchFile) &&
!(
error instanceof Components.Exception &&
error.result == Cr.NS_ERROR_FILE_NOT_FOUND
)
) {
if (error != null && error.name != "NotFoundError") {
// Let's report the error.
Cu.reportError(error);
}
@ -266,7 +258,7 @@ _ContextualIdentityService.prototype = {
};
let bytes = gTextEncoder.encode(JSON.stringify(object));
return OS.File.writeAtomic(this._path, bytes, {
return IOUtils.writeAtomic(this._path, bytes, {
tmpPath: this._path + ".tmp",
});
},
@ -653,5 +645,8 @@ _ContextualIdentityService.prototype = {
},
};
let path = OS.Path.join(OS.Constants.Path.profileDir, "containers.json");
let path = PathUtils.join(
Services.dirsvc.get("ProfD", Ci.nsIFile).path,
"containers.json"
);
var ContextualIdentityService = new _ContextualIdentityService(path);

Просмотреть файл

@ -6,9 +6,8 @@ const { ContextualIdentityService } = ChromeUtils.import(
"resource://gre/modules/ContextualIdentityService.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const TEST_STORE_FILE_PATH = OS.Path.join(
const TEST_STORE_FILE_PATH = PathUtils.join(
profileDir.path,
"test-containers.json"
);
@ -91,7 +90,7 @@ add_task(async function corruptedFile() {
);
// Let's create a corrupted file.
await OS.File.writeAtomic(TEST_STORE_FILE_PATH, "{ vers", {
await IOUtils.writeAtomicUTF8(TEST_STORE_FILE_PATH, "{ vers", {
tmpPath: TEST_STORE_FILE_PATH + ".tmp",
});
@ -157,9 +156,7 @@ add_task(async function corruptedFile() {
// Verify the version of the newly created containers.json file.
cis.save();
const stateFileText = await OS.File.read(TEST_STORE_FILE_PATH, {
encoding: "utf-8",
});
const stateFileText = await IOUtils.readUTF8(TEST_STORE_FILE_PATH);
equal(
JSON.parse(stateFileText).version,
cis.LAST_CONTAINERS_JSON_VERSION,