зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1671274 - Convert SearchSettings.jsm and SearchService.jsm to no longer use OS.File r=barret
Differential Revision: https://phabricator.services.mozilla.com/D97205
This commit is contained in:
Родитель
497409d76e
Коммит
5391deaa4c
|
@ -16,7 +16,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
AddonManager: "resource://gre/modules/AddonManager.jsm",
|
||||
IgnoreLists: "resource://gre/modules/IgnoreLists.jsm",
|
||||
OpenSearchEngine: "resource://gre/modules/OpenSearchEngine.jsm",
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
Region: "resource://gre/modules/Region.jsm",
|
||||
RemoteSettings: "resource://services-settings/remote-settings.js",
|
||||
SearchEngine: "resource://gre/modules/SearchEngine.jsm",
|
||||
|
@ -2777,7 +2776,7 @@ SearchService.prototype = {
|
|||
stack: undefined,
|
||||
},
|
||||
};
|
||||
OS.File.profileBeforeChange.addBlocker(
|
||||
IOUtils.profileBeforeChange.addBlocker(
|
||||
"Search service: shutting down",
|
||||
() =>
|
||||
(async () => {
|
||||
|
|
|
@ -10,7 +10,6 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
DeferredTask: "resource://gre/modules/DeferredTask.jsm",
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
SearchUtils: "resource://gre/modules/SearchUtils.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
});
|
||||
|
@ -22,11 +21,6 @@ XPCOMUtils.defineLazyGetter(this, "logConsole", () => {
|
|||
});
|
||||
});
|
||||
|
||||
// A text encoder to UTF8, used whenever we commit the settings to disk.
|
||||
XPCOMUtils.defineLazyGetter(this, "gEncoder", function() {
|
||||
return new TextEncoder();
|
||||
});
|
||||
|
||||
const SETTINGS_FILENAME = "search.json.mozlz4";
|
||||
|
||||
/**
|
||||
|
@ -102,12 +96,11 @@ class SearchSettings {
|
|||
let json;
|
||||
await this._ensurePendingWritesCompleted(origin);
|
||||
try {
|
||||
let settingsFilePath = OS.Path.join(
|
||||
OS.Constants.Path.profileDir,
|
||||
let settingsFilePath = PathUtils.join(
|
||||
await PathUtils.getProfileDir(),
|
||||
SETTINGS_FILENAME
|
||||
);
|
||||
let bytes = await OS.File.read(settingsFilePath, { compression: "lz4" });
|
||||
json = JSON.parse(new TextDecoder().decode(bytes));
|
||||
json = await IOUtils.readJSON(settingsFilePath, { decompress: true });
|
||||
if (!json.engines || !json.engines.length) {
|
||||
throw new Error("no engine in the file");
|
||||
}
|
||||
|
@ -224,12 +217,11 @@ class SearchSettings {
|
|||
}
|
||||
|
||||
logConsole.debug("_write: Writing to settings file.");
|
||||
let path = OS.Path.join(OS.Constants.Path.profileDir, SETTINGS_FILENAME);
|
||||
let data = gEncoder.encode(JSON.stringify(settings));
|
||||
await OS.File.writeAtomic(path, data, {
|
||||
compression: "lz4",
|
||||
tmpPath: path + ".tmp",
|
||||
});
|
||||
let path = PathUtils.join(
|
||||
await PathUtils.getProfileDir(),
|
||||
SETTINGS_FILENAME
|
||||
);
|
||||
await IOUtils.writeJSON(path, settings, { compress: true });
|
||||
logConsole.debug("_write: settings file written to disk.");
|
||||
Services.obs.notifyObservers(
|
||||
null,
|
||||
|
|
|
@ -90,10 +90,10 @@ add_task(async function setup() {
|
|||
enginesSettings.buildID = appInfo.platformBuildID;
|
||||
enginesSettings.appVersion = appInfo.version;
|
||||
|
||||
await OS.File.writeAtomic(
|
||||
OS.Path.join(OS.Constants.Path.profileDir, SETTINGS_FILENAME),
|
||||
new TextEncoder().encode(JSON.stringify(enginesSettings)),
|
||||
{ compression: "lz4" }
|
||||
await IOUtils.writeJSON(
|
||||
PathUtils.join(await PathUtils.getProfileDir(), SETTINGS_FILENAME),
|
||||
enginesSettings,
|
||||
{ compress: true }
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -68,10 +68,10 @@ add_task(async function setup() {
|
|||
enginesSettings.buildID = appInfo.platformBuildID;
|
||||
enginesSettings.appVersion = appInfo.version;
|
||||
|
||||
await OS.File.writeAtomic(
|
||||
OS.Path.join(OS.Constants.Path.profileDir, SETTINGS_FILENAME),
|
||||
new TextEncoder().encode(JSON.stringify(enginesSettings)),
|
||||
{ compression: "lz4" }
|
||||
await IOUtils.writeJSON(
|
||||
PathUtils.join(await PathUtils.getProfileDir(), SETTINGS_FILENAME),
|
||||
enginesSettings,
|
||||
{ compress: true }
|
||||
);
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче