Bug 889442 - Remove newTab page migration for chromeappsstore.sqlite

t=ttaubert
This commit is contained in:
Marco Bonardo 2013-07-03 23:41:28 +02:00
parent 30168113bb
commit 89118248d1
3 changed files with 10 additions and 142 deletions

View File

@ -19,9 +19,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
XPCOMUtils.defineLazyModuleGetter(this, "PageThumbs",
"resource://gre/modules/PageThumbs.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyGetter(this, "gPrincipal", function () {
let uri = Services.io.newURI("about:newtab", null, null);
return Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
@ -79,7 +76,9 @@ function LinksStorage() {
if (this._storedVersion < this._version) {
// This is either an upgrade, or version information is missing.
if (this._storedVersion < 1) {
this._migrateToV1();
// Version 1 moved data from DOM Storage to prefs. Since migrating from
// version 0 is no more supported, we just reportError a dataloss later.
throw new Error("Unsupported newTab storage version");
}
// Add further migration steps here.
}
@ -117,7 +116,13 @@ LinksStorage.prototype = {
this.__storedVersion =
Services.prefs.getIntPref("browser.newtabpage.storageVersion");
} catch (ex) {
this.__storedVersion = 0;
// The storage version is unknown, so either:
// - it's a new profile
// - it's a profile where versioning information got lost
// In this case we still run through all of the valid migrations,
// starting from 1, as if it was a downgrade. As previously stated the
// migrations should already support running on an updated store.
this.__storedVersion = 1;
}
}
return this.__storedVersion;
@ -128,44 +133,6 @@ LinksStorage.prototype = {
return aValue;
},
/**
* V1 changes storage from chromeappsstore.sqlite to prefs.
*/
_migrateToV1: function Storage__migrateToV1() {
// Import data from the old chromeappsstore.sqlite file, if exists.
let file = FileUtils.getFile("ProfD", ["chromeappsstore.sqlite"]);
if (!file.exists())
return;
let db = Services.storage.openUnsharedDatabase(file);
let stmt = db.createStatement(
"SELECT key, value FROM webappsstore2 WHERE scope = 'batwen.:about'");
try {
while (stmt.executeStep()) {
let key = stmt.row.key;
let value = JSON.parse(stmt.row.value);
switch (key) {
case "pinnedLinks":
this.set(key, value);
break;
case "blockedLinks":
// Convert urls to hashes.
let hashes = {};
for (let url in value) {
hashes[toHash(url)] = 1;
}
this.set(key, hashes);
break;
default:
// Ignore unknown keys.
break;
}
}
} finally {
stmt.finalize();
db.close();
}
},
/**
* Gets the value for a given key from the storage.
* @param aKey The storage key (a string).

View File

@ -1,98 +0,0 @@
/* 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/. */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://gre/modules/NewTabUtils.jsm");
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
Cu.import("resource://gre/modules/Services.jsm");
/**
* Asynchronously load test data from chromeappstore.sqlite.
*
* @param aDBFile
* the database file to load
* @return {Promise} resolved when the load is complete
*/
function promiseLoadChromeAppsStore(aDBFile) {
let deferred = Promise.defer();
let pinnedLinks = [];
let blockedLinks = [];
let db = Services.storage.openUnsharedDatabase(aDBFile);
let stmt = db.createAsyncStatement(
"SELECT key, value FROM webappsstore2 WHERE scope = 'batwen.:about'");
try {
stmt.executeAsync({
handleResult: function(aResultSet) {
for (let row = aResultSet.getNextRow(); row;
row = aResultSet.getNextRow()) {
let value = JSON.parse(row.getResultByName("value"));
if (row.getResultByName("key") == "pinnedLinks") {
pinnedLinks = value;
} else {
for (let url of Object.keys(value)) {
blockedLinks.push({ url: url, title: "" });
}
}
}
},
handleError: function(aError) {
deferred.reject(new Components.Exception("Error", Cr.NS_ERROR_FAILURE));
},
handleCompletion: function(aReason) {
if (aReason === Ci.mozIStorageStatementCallback.REASON_FINISHED) {
deferred.resolve([pinnedLinks, blockedLinks]);
}
}
});
} finally {
stmt.finalize();
db.asyncClose();
}
return deferred.promise;
}
function run_test() {
do_test_pending();
// First of all copy the chromeappsstore.sqlite file to the profile folder.
let dbFile = do_get_file("chromeappsstore.sqlite");
let profileDBFile = do_get_profile();
dbFile.copyTo(profileDBFile, "chromeappsstore.sqlite");
profileDBFile.append("chromeappsstore.sqlite");
do_check_true(profileDBFile.exists());
// Load test data from the database.
promiseLoadChromeAppsStore(dbFile).then(function success(aResults) {
let [pinnedLinks, blockedLinks] = aResults;
do_check_true(pinnedLinks.length > 0);
do_check_eq(pinnedLinks.length, NewTabUtils.pinnedLinks.links.length);
do_check_true(pinnedLinks.every(
function(aLink) NewTabUtils.pinnedLinks.isPinned(aLink)
));
do_check_true(blockedLinks.length > 0);
do_check_eq(blockedLinks.length,
Object.keys(NewTabUtils.blockedLinks.links).length);
do_check_true(blockedLinks.every(
function(aLink) NewTabUtils.blockedLinks.isBlocked(aLink)
));
try {
profileDBFile.remove(true);
} catch (ex) {
// May fail due to OS file locking, not a blocking error though.
do_print("Unable to remove chromeappsstore.sqlite file.");
}
do_test_finished();
}, do_report_unexpected_exception);
}

View File

@ -4,7 +4,6 @@ tail =
[test_dict.js]
[test_FileUtils.js]
[test_newtab-migrate-v1.js]
[test_Preferences.js]
[test_Promise.js]
[test_propertyListsUtils.js]