Bug 1212297 - improve error handling in Chrome bookmarks migration code, r=MattN

--HG--
extra : commitid : BEgGX9o3KPB
extra : rebase_source : e6c4de4e72db8aab771864d453409b02cdcc067e
This commit is contained in:
Gijs Kruitbosch 2015-10-07 13:24:50 +01:00
Родитель e046a644c8
Коммит 2352be03b3
1 изменённых файлов: 18 добавлений и 5 удалений

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

@ -52,11 +52,18 @@ function chromeTimeToDate(aTime)
* GUID of the folder where items will be inserted
* @param items
* bookmark items to be inserted
* @param errorAccumulator
* function that gets called with any errors thrown so we don't drop them on the floor.
*/
function* insertBookmarkItems(parentGuid, items) {
function* insertBookmarkItems(parentGuid, items, errorAccumulator) {
for (let item of items) {
try {
if (item.type == "url") {
if (item.url.trim().startsWith("chrome:")) {
// Skip invalid chrome URIs. Creating an actual URI always reports
// messages to the console, so we avoid doing that.
continue;
}
yield PlacesUtils.bookmarks.insert({
parentGuid, url: item.url, title: item.name
});
@ -65,10 +72,11 @@ function* insertBookmarkItems(parentGuid, items) {
parentGuid, type: PlacesUtils.bookmarks.TYPE_FOLDER, title: item.name
})).guid;
yield insertBookmarkItems(newFolderGuid, item.children);
yield insertBookmarkItems(newFolderGuid, item.children, errorAccumulator);
}
} catch (e) {
Cu.reportError(e);
errorAccumulator(e);
}
}
}
@ -202,6 +210,8 @@ function GetBookmarksResource(aProfileFolder) {
migrate: function(aCallback) {
return Task.spawn(function* () {
let gotErrors = false;
let errorGatherer = () => gotErrors = true;
let jsonStream = yield new Promise(resolve =>
NetUtil.asyncFetch({ uri: NetUtil.newURI(bookmarksFile),
loadUsingSystemPrincipal: true
@ -230,7 +240,7 @@ function GetBookmarksResource(aProfileFolder) {
parentGuid =
yield MigrationUtils.createImportedBookmarksFolder("Chrome", parentGuid);
}
yield insertBookmarkItems(parentGuid, roots.bookmark_bar.children);
yield insertBookmarkItems(parentGuid, roots.bookmark_bar.children, errorGatherer);
}
// Importing bookmark menu items
@ -242,10 +252,13 @@ function GetBookmarksResource(aProfileFolder) {
parentGuid =
yield MigrationUtils.createImportedBookmarksFolder("Chrome", parentGuid);
}
yield insertBookmarkItems(parentGuid, roots.other.children);
yield insertBookmarkItems(parentGuid, roots.other.children, errorGatherer);
}
if (gotErrors) {
throw "The migration included errors.";
}
}.bind(this)).then(() => aCallback(true),
e => { Cu.reportError(e); aCallback(false) });
e => aCallback(false));
}
};
}