Bug 718817 - Create a deleted passwords table for sync. r=dolske
authorWes Johnston <wjohnston@mozilla.com>
Thu, 09 Feb 2012 09:56:03 -0800
changeset 86512 7a74c7738877595588ffb089efcb524a150342eb
parent 86511 1a01259eb5c8daa732b44db34cba0f6af07e22a2
child 86513 8fa903fa888740143d0537fb51abca5061c6e01e
push id5899
push userwjohnston@mozilla.com
push dateThu, 09 Feb 2012 17:56:39 +0000
treeherdermozilla-inbound@85346ae0ea99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs718817
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 718817 - Create a deleted passwords table for sync. r=dolske
toolkit/components/passwordmgr/Makefile.in
toolkit/components/passwordmgr/storage-mozStorage.js
--- a/toolkit/components/passwordmgr/Makefile.in
+++ b/toolkit/components/passwordmgr/Makefile.in
@@ -57,14 +57,17 @@ XPIDLSRCS = \
 
 EXTRA_COMPONENTS = \
   crypto-SDR.js \
   nsLoginInfo.js \
   nsLoginManager.js \
   nsLoginManagerPrompter.js \
   passwordmgr.manifest \
   storage-Legacy.js \
+  $(NULL)
+
+EXTRA_PP_COMPONENTS = \
   storage-mozStorage.js \
   $(NULL)
 
 TEST_DIRS += test
 
 include $(topsrcdir)/config/rules.mk
--- a/toolkit/components/passwordmgr/storage-mozStorage.js
+++ b/toolkit/components/passwordmgr/storage-mozStorage.js
@@ -39,17 +39,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 
-const DB_VERSION = 4; // The database schema version
+const DB_VERSION = 5; // The database schema version
 
 const ENCTYPE_BASE64 = 0;
 const ENCTYPE_SDR = 1;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 /**
@@ -147,16 +147,20 @@ LoginManagerStorage_mozStorage.prototype
                                 "timeLastUsed        INTEGER,"             +
                                 "timePasswordChanged INTEGER,"             +
                                 "timesUsed           INTEGER",
             // Changes must be reflected in this._dbAreExpectedColumnsPresent(),
             // this._searchLogins(), and this.modifyLogin().
 
             moz_disabledHosts:  "id                 INTEGER PRIMARY KEY," +
                                 "hostname           TEXT UNIQUE ON CONFLICT REPLACE",
+
+            moz_deleted_logins: "id                  INTEGER PRIMARY KEY," +
+                                "guid                TEXT,"                +
+                                "timeDeleted         INTEGER",
         },
         indices: {
           moz_logins_hostname_index: {
             table: "moz_logins",
             columns: ["hostname"]
           },
           moz_logins_hostname_formSubmitURL_index: {
             table: "moz_logins",
@@ -368,28 +372,31 @@ LoginManagerStorage_mozStorage.prototype
         let [idToDelete, storedLogin] = this._getIdForLogin(login);
         if (!idToDelete)
             throw "No matching logins";
 
         // Execute the statement & remove from DB
         let query  = "DELETE FROM moz_logins WHERE id = :id";
         let params = { id: idToDelete };
         let stmt;
+        let transaction = new Transaction(this._dbConnection);
         try {
             stmt = this._dbCreateStatement(query, params);
             stmt.execute();
+            this.storeDeletedLogin(storedLogin);
+            transaction.commit();
         } catch (e) {
             this.log("_removeLogin failed: " + e.name + " : " + e.message);
             throw "Couldn't write to database, login not removed.";
+            transaction.rollback();
         } finally {
             if (stmt) {
                 stmt.reset();
             }
         }
-
         this._sendNotification("removeLogin", storedLogin);
     },
 
 
     /*
      * modifyLogin
      *
      */
@@ -675,44 +682,78 @@ LoginManagerStorage_mozStorage.prototype
                 stmt.reset();
             }
         }
 
         this.log("_searchLogins: returning " + logins.length + " logins");
         return [logins, ids];
     },
 
+    /* storeDeletedLogin
+     *
+     * Moves a login to the deleted logins table
+     *
+     */
+     storeDeletedLogin : function(aLogin) {
+#ifdef ANDROID
+          let stmt = null; 
+          try {
+              this.log("Storing " + aLogin.guid + " in deleted passwords\n");
+              let query = "INSERT INTO moz_deleted_logins (guid, timeDeleted) VALUES (:guid, :timeDeleted)";
+              let params = { guid: aLogin.guid,
+                             timeDeleted: Date.now() };
+              let stmt = this._dbCreateStatement(query, params);
+              stmt.execute();
+          } catch(ex) {
+              throw ex;
+          } finally {
+              if (stmt)
+                  stmt.reset();
+          }		
+#endif
+     },
+
 
     /*
      * removeAllLogins
      *
      * Removes all logins from storage.
      */
     removeAllLogins : function () {
         this.log("Removing all logins");
+        let query;
+        let stmt;
+        let transaction = new Transaction(this._dbConnection);
+ 
         // Delete any old, unused files.
         this._removeOldSignonsFiles();
 
         // Disabled hosts kept, as one presumably doesn't want to erase those.
-        let query = "DELETE FROM moz_logins";
-        let stmt;
+        query = "DELETE FROM moz_logins";
         try {
+            let logins = this.getAllLogins();
+            for each (let login in logins) {
+                let [id, storedLogin] = this._getIdForLogin(login);
+                this.storeDeletedLogin(storedLogin);
+            }
             stmt = this._dbCreateStatement(query);
             stmt.execute();
+            transaction.commit();
         } catch (e) {
             this.log("_removeAllLogins failed: " + e.name + " : " + e.message);
+            transaction.rollback();
             throw "Couldn't write to database";
         } finally {
             if (stmt) {
                 stmt.reset();
             }
         }
 
         this._sendNotification("removeAllLogins", null);
-    },
+   },
 
 
     /*
      * getAllDisabledHosts
      *
      */
     getAllDisabledHosts : function (count) {
         let disabledHosts = this._queryDisabledHosts(null);
@@ -1558,16 +1599,27 @@ LoginManagerStorage_mozStorage.prototype
                     stmt.reset();
                 }
             }
         }
     },
 
 
     /*
+     * _dbMigrateToVersion5
+     *
+     * Version 5 adds the moz_deleted_logins table
+     */
+    _dbMigrateToVersion5 : function () {
+        if (!this._dbConnection.tableExists("moz_deleted_logins")) {
+          this._dbConnection.createTable("moz_deleted_logins", this._dbSchema.tables.moz_deleted_logins);
+        }
+    },
+
+    /*
      * _dbAreExpectedColumnsPresent
      *
      * Sanity check to ensure that the columns this version of the code expects
      * are present in the DB we're using.
      */
     _dbAreExpectedColumnsPresent : function () {
         let query = "SELECT " +
                        "id, " +