Safari storage migration: code review

This commit is contained in:
Chris 2015-05-11 16:15:53 -06:00
parent 3ca6daac73
commit 63b846cf5f
1 changed files with 45 additions and 43 deletions

View File

@ -223,49 +223,6 @@
};
/******************************************************************************/
if(!safari.extension.settings.migratedStorage) {
var migrationMap = {
"cached_asset_content://assets/user/filters.txt": "userFilters"
};
var delayed = [];
vAPI.storage.preferences = {
get: function(a, b) {
delayed.push(settingsStorage.get.bind(settingsStorage, a, b));
},
set: function(a, b) {
delayed.push(settingsStorage.set.bind(settingsStorage, a, b));
},
remove: function(a, b) {
delayed.push(settingsStorage.remove.bind(settingsStorage, a, b));
},
clear: function() {
delayed.push(settingsStorage.clear.bind(settingsStorage));
},
};
localforage.iterate(function(value, key) {
if(migrationMap[key]) {
safari.extension.settings[migrationMap[key]] = value;
return;
}
if(key.lastIndexOf("cached_asset", 0) === 0) {
return;
}
safari.extension.settings[key] = value;
localforage.removeItem(key);
}, function() {
var func;
while(func = delayed.pop()) {
func();
}
delayed = null;
vAPI.storage.preferences = settingsStorage;
});
safari.extension.settings.migratedStorage = true;
}
var settingsStorage = {
_storage: safari.extension.settings,
get: function(keys, callback) {
@ -340,6 +297,51 @@
}
};
vAPI.storage.preferences = settingsStorage;
if(!safari.extension.settings.migratedStorage) { // if we haven't already migrated
var migrationMap = {
"cached_asset_content://assets/user/filters.txt": "userFilters"
};
var delayed = [];
vAPI.storage.preferences = {
get: function(a, b) {
delayed.push(settingsStorage.get.bind(settingsStorage, a, b));
},
set: function(a, b) {
delayed.push(settingsStorage.set.bind(settingsStorage, a, b));
},
remove: function(a, b) {
delayed.push(settingsStorage.remove.bind(settingsStorage, a, b));
},
clear: function() {
delayed.push(settingsStorage.clear.bind(settingsStorage));
},
};
localforage.iterate(function(value, key) {
if(migrationMap[key]) {
safari.extension.settings[migrationMap[key]] = value;
return;
}
if(key.lastIndexOf("cached_asset", 0) === 0) {
return;
}
safari.extension.settings[key] = value;
localforage.removeItem(key);
}, function() {
var func;
while(func = delayed.pop()) {
func();
}
delayed = null;
vAPI.storage.preferences = settingsStorage;
});
safari.extension.settings.migratedStorage = true;
}
/******************************************************************************/
vAPI.tabs = {