Bug 938171 - Move browser app database file in gecko; r=fabrice

This commit is contained in:
Kyle Machulis 2014-08-25 13:30:07 -07:00
Родитель ad1eef9d2e
Коммит ce8680c513
5 изменённых файлов: 109 добавлений и 0 удалений

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

@ -0,0 +1,98 @@
/* 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/. */
'use strict';
function debug(s) {
dump("-*- B2GAppMigrator.js: " + s + "\n");
}
const DEBUG = false;
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const kMigrationMessageName = "webapps-before-update-merge";
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "appsService",
"@mozilla.org/AppsService;1",
"nsIAppsService");
function B2GAppMigrator() {
Services.obs.addObserver(this, kMigrationMessageName, false);
Services.obs.addObserver(this, "xpcom-shutdown", false);
}
B2GAppMigrator.prototype = {
classID: Components.ID('{7211ece0-b458-4635-9afc-f8d7f376ee95}'),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
executeBrowserMigration: function() {
// The browser db name is hashed the same way everywhere, so it
// should be the same on all systems. We should be able to just
// hardcode it.
let browserDBFileName = "2959517650brreosw.sqlite";
// Storage directories need to be prefixed with the local id of
// the app
let browserLocalAppId = appsService.getAppLocalIdByManifestURL("app://browser.gaiamobile.org/manifest.webapp");
let browserAppStorageDirName = browserLocalAppId + "+f+app+++browser.gaiamobile.org";
let browserDBFile = FileUtils.getFile("ProfD",
["storage",
"persistent",
browserAppStorageDirName,
"idb",
browserDBFileName], true);
if (!browserDBFile.exists()) {
if (DEBUG) debug("Browser DB file does not exist, nothing to copy");
return;
}
let systemLocalAppId = appsService.getAppLocalIdByManifestURL("app://system.gaiamobile.org/manifest.webapp");
let systemAppStorageDirName = systemLocalAppId + "+f+app+++system.gaiamobile.org";
let systemDBDir = FileUtils.getDir("ProfD",
["storage",
"persistent",
systemAppStorageDirName,
"idb"], false, true);
if (DEBUG) {
debug("Browser DB file exists, copying");
debug("Browser local id: " + browserLocalAppId + "");
debug("System local id: " + systemLocalAppId + "");
debug("Browser DB file path: " + browserDBFile.path + "");
debug("System DB directory path: " + systemDBDir.path + "");
}
try {
browserDBFile.copyTo(systemDBDir, browserDBFileName);
} catch (e) {
debug("File copy caused error! " + e.name);
}
if (DEBUG) debug("Browser DB copied successfully");
},
observe: function(subject, topic, data) {
switch (topic) {
case kMigrationMessageName:
this.executeBrowserMigration();
Services.obs.removeObserver(this, kMigrationMessageName);
break;
case "xpcom-shutdown":
Services.obs.removeObserver(this, kMigrationMessageName);
Services.obs.removeObserver(this, "xpcom-shutdown");
break;
default:
debug("Unhandled topic: " + topic);
break;
}
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([B2GAppMigrator]);

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

@ -101,3 +101,8 @@ category command-line-handler m-b2goop @mozilla.org/commandlinehandler/general-s
# MobileIdentityUIGlue.js
component {83dbe26a-81f3-4a75-9541-3d0b7ca496b5} MobileIdentityUIGlue.js
contract @mozilla.org/services/mobileid-ui-glue;1 {83dbe26a-81f3-4a75-9541-3d0b7ca496b5}
# B2GAppMigrator.js
component {7211ece0-b458-4635-9afc-f8d7f376ee95} B2GAppMigrator.js
contract @mozilla.org/b2g-app-migrator;1 {7211ece0-b458-4635-9afc-f8d7f376ee95}
category profile-after-change B2GAppMigrator @mozilla.org/b2g-app-migrator;1

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

@ -10,6 +10,7 @@ EXTRA_COMPONENTS += [
'ActivitiesGlue.js',
'AlertsService.js',
'B2GAboutRedirector.js',
'B2GAppMigrator.js',
'ContentPermissionPrompt.js',
'FilePicker.js',
'FxAccountsUIGlue.js',

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

@ -831,6 +831,7 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DLL_SUFFIX@
@BINPATH@/components/DownloadsUI.js
@BINPATH@/components/InterAppCommUIGlue.js
@BINPATH@/components/SystemMessageGlue.js
@BINPATH@/components/B2GAppMigrator.js
#ifndef MOZ_WIDGET_GONK
@BINPATH@/components/SimulatorScreen.js

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

@ -629,6 +629,10 @@ this.DOMApplicationRegistry = {
yield this.loadCurrentRegistry();
if (runUpdate) {
// Run migration before uninstall of core apps happens.
Services.obs.notifyObservers(null, "webapps-before-update-merge", null);
#ifdef MOZ_WIDGET_GONK
yield this.installSystemApps();
#endif