Bug 725052 - Check if a password is in the deleted database before inserting it. r=rnewman
authorWes Johnston <wjohnston@mozilla.com>
Thu, 08 Mar 2012 10:25:44 -0800
changeset 88561 b295c8825acd15c76dc25bf62caad1691fa0c94b
parent 88560 d0c82cb6eb28a8a4e67b00817ef358d98ed6b960
child 88562 d4433c487dc8272fea12b1f3ab13a84560498f39
push id22208
push usermak77@bonardo.net
push dateFri, 09 Mar 2012 12:34:50 +0000
treeherdermozilla-central@ead9016b4102 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs725052
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 725052 - Check if a password is in the deleted database before inserting it. r=rnewman
mobile/android/base/db/FormHistoryProvider.java.in
mobile/android/base/db/GeckoProvider.java.in
mobile/android/base/db/PasswordsProvider.java.in
--- a/mobile/android/base/db/FormHistoryProvider.java.in
+++ b/mobile/android/base/db/FormHistoryProvider.java.in
@@ -139,14 +139,33 @@ public class FormHistoryProvider extends
                 throw new UnsupportedOperationException("Unknown insert URI " + uri);
         }
     }
 
     public void initGecko() {
         GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FormHistory:Init", null));
     }
 
-    public void onPreInsert(ContentValues values, Uri uri) { }
+    @Override
+    public void onPreInsert(ContentValues values, Uri uri, SQLiteBridge db) {
+        if (!values.containsKey(FormHistory.GUID)) {
+            return;
+        }
+        String guid = values.getAsString(FormHistory.GUID);
+        String where = BrowserContract.DeletedFormHistory.GUID + " = ?";
+        String[] args = new String[] { guid };
+        if (guid == null) {
+            where = BrowserContract.DeletedFormHistory.GUID + " IS NULL";
+            args = null;
+        }
+        try {
+            db.delete(TABLE_DELETED_FORM_HISTORY, where, args);
+        } catch(SQLiteBridgeException ex) {
+            Log.w(getLogTag(), "Error removing entry with GUID " + guid, ex);
+        }
+     }
 
-    public void onPreUpdate(ContentValues values, Uri uri) { }
+    @Override
+    public void onPreUpdate(ContentValues values, Uri uri, SQLiteBridge db) { }
 
-    public void onPostQuery(Cursor cursor, Uri uri) { }
+    @Override
+    public void onPostQuery(Cursor cursor, Uri uri, SQLiteBridge db) { }
 }
--- a/mobile/android/base/db/GeckoProvider.java.in
+++ b/mobile/android/base/db/GeckoProvider.java.in
@@ -217,17 +217,17 @@ public abstract class GeckoProvider exte
         // If we can not get a SQLiteBridge instance, its likely that the database
         // has not been set up and Gecko is not running. We return null and expect
         // callers to try again later
         if (db == null)
             return null;
 
         setupDefaults(uri, values);
 
-        onPreInsert(values, uri);
+        onPreInsert(values, uri, db);
 
         try {
             id = db.insert(getTable(uri), null, values);
         } catch(SQLiteBridgeException ex) {
             Log.e(mLogTag, "Error inserting in db", ex);
         }
 
         return ContentUris.withAppendedId(uri, id);
@@ -240,17 +240,17 @@ public abstract class GeckoProvider exte
         final SQLiteBridge db = getDatabase(uri);
 
         // If we can not get a SQLiteBridge instance, its likely that the database
         // has not been set up and Gecko is not running. We return null and expect
         // callers to try again later
         if (db == null)
             return updated;
 
-        onPreUpdate(values, uri);
+        onPreUpdate(values, uri, db);
 
         try {
             updated = db.update(getTable(uri), values, selection, selectionArgs);
         } catch(SQLiteBridgeException ex) {
             Log.e(mLogTag, "Error updating table", ex);
         }
 
         return updated;
@@ -267,30 +267,30 @@ public abstract class GeckoProvider exte
         // callers to try again later
         if (db == null)
             return cursor;
 
         sortOrder = getSortOrder(uri, sortOrder);
 
         try {
             cursor = db.query(getTable(uri), projection, selection, selectionArgs, null, null, sortOrder, null);
-            onPostQuery(cursor, uri);
+            onPostQuery(cursor, uri, db);
         } catch (SQLiteBridgeException ex) {
             Log.e(mLogTag, "Error querying database", ex);
         }
 
         return cursor;
     }
 
     public abstract String getTable(Uri uri);
 
     public abstract String getSortOrder(Uri uri, String aRequested);
 
     public abstract void setupDefaults(Uri uri, ContentValues values);
 
     public abstract void initGecko();
 
-    public abstract void onPreInsert(ContentValues values, Uri uri);
+    public abstract void onPreInsert(ContentValues values, Uri uri, SQLiteBridge db);
 
-    public abstract void onPreUpdate(ContentValues values, Uri uri);
+    public abstract void onPreUpdate(ContentValues values, Uri uri, SQLiteBridge db);
 
-    public abstract void onPostQuery(Cursor cursor, Uri uri);
+    public abstract void onPostQuery(Cursor cursor, Uri uri, SQLiteBridge db);
 }
--- a/mobile/android/base/db/PasswordsProvider.java.in
+++ b/mobile/android/base/db/PasswordsProvider.java.in
@@ -205,41 +205,60 @@ public class PasswordsProvider extends G
           else result = NSSBridge.encrypt(mContext, initialValue);
         } else {
           if (profilePath != null) result = NSSBridge.decrypt(mContext, profilePath, initialValue);
           else result = NSSBridge.decrypt(mContext, initialValue);            
         }
         return result;
     }
 
-    public void onPreInsert(ContentValues values, Uri uri) {
-        if (values.containsKey(Passwords.ENCRYPTED_PASSWORD)) {
-            String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_PASSWORD), uri, true);
-            values.put(Passwords.ENCRYPTED_PASSWORD, res);
+    @Override
+    public void onPreInsert(ContentValues values, Uri uri, SQLiteBridge db) {
+        if (values.containsKey(Passwords.GUID)) {
+            String guid = values.getAsString(Passwords.GUID);
+            String where = BrowserContract.DeletedPasswords.GUID + " = ?";
+            String[] args = new String[] { guid };
+            if (guid == null) {
+                where = BrowserContract.DeletedPasswords.GUID + " IS NULL";
+                args = null;
+            }
+    
+            try {
+                db.delete(TABLE_DELETED_PASSWORDS, where, args);
+            } catch(SQLiteBridgeException ex) {
+                Log.w(getLogTag(), "Error removing entry with GUID " + guid, ex);
+            }
         }
 
-        if (values.containsKey(Passwords.ENCRYPTED_USERNAME)) {
-            String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_USERNAME), uri, true);
-            values.put(Passwords.ENCRYPTED_USERNAME, res);
-        }
-    }
- 
-    public void onPreUpdate(ContentValues values, Uri uri) {
         if (values.containsKey(Passwords.ENCRYPTED_PASSWORD)) {
             String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_PASSWORD), uri, true);
             values.put(Passwords.ENCRYPTED_PASSWORD, res);
         }
 
         if (values.containsKey(Passwords.ENCRYPTED_USERNAME)) {
             String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_USERNAME), uri, true);
             values.put(Passwords.ENCRYPTED_USERNAME, res);
         }
     }
 
-    public void onPostQuery(Cursor cursor, Uri uri) {
+    @Override
+    public void onPreUpdate(ContentValues values, Uri uri, SQLiteBridge db) {
+        if (values.containsKey(Passwords.ENCRYPTED_PASSWORD)) {
+            String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_PASSWORD), uri, true);
+            values.put(Passwords.ENCRYPTED_PASSWORD, res);
+        }
+
+        if (values.containsKey(Passwords.ENCRYPTED_USERNAME)) {
+            String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_USERNAME), uri, true);
+            values.put(Passwords.ENCRYPTED_USERNAME, res);
+        }
+    }
+
+    @Override
+    public void onPostQuery(Cursor cursor, Uri uri, SQLiteBridge db) {
         int passwordIndex = -1;
         int usernameIndex = -1;
         String profilePath = null;
 
         try {
             passwordIndex = cursor.getColumnIndexOrThrow(Passwords.ENCRYPTED_PASSWORD);
         } catch(Exception ex) { }
         try {