A bunch of updates to BrowserProvider2.

The images are now shared between the history
and bookmarks tables so updates to one are
reflected in the other.

Added a parameter for specifying a limit when
calling query().

Added a combined view of history and bookmarks.

Added a way to get a distinct list of the
accounts providing bookmarks.

Added the ability to find the server unique
IDs for parent and insert_after when doing
a query for a row.

Change-Id: I9afa15bcf7ca68468793c49fbec701e516e4540e
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index e1e1e18..9dd801d 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -69,6 +69,7 @@
 import android.provider.Browser;
 import android.provider.BrowserContract;
 import android.provider.ContactsContract;
+import android.provider.BrowserContract.Images;
 import android.provider.ContactsContract.Intents.Insert;
 import android.provider.Downloads;
 import android.provider.MediaStore;
@@ -2449,29 +2450,25 @@
         new AsyncTask<Void, Void, Void>() {
             @Override
             protected Void doInBackground(Void... unused) {
-                Cursor c = null;
+                Cursor cursor = null;
                 try {
-                    c = Bookmarks.queryBookmarksForUrl(
-                            cr, originalUrl, url);
-                    if (c != null) {
-                        if (c.moveToFirst()) {
-                            ContentValues values = new ContentValues();
-                            final ByteArrayOutputStream os
-                                    = new ByteArrayOutputStream();
-                            bm.compress(Bitmap.CompressFormat.PNG, 100, os);
-                            values.put(BrowserContract.Bookmarks.THUMBNAIL,
-                                    os.toByteArray());
-                            do {
-                                cr.update(ContentUris.withAppendedId(
-                                        BrowserContract.Bookmarks.CONTENT_URI, c.getLong(0)),
-                                        values, null, null);
-                            } while (c.moveToNext());
-                        }
+                    cursor = Bookmarks.queryCombinedForUrl(cr, originalUrl, url);
+                    if (cursor != null && cursor.moveToFirst()) {
+                        final ByteArrayOutputStream os = new ByteArrayOutputStream();
+                        bm.compress(Bitmap.CompressFormat.PNG, 100, os);
+
+                        ContentValues values = new ContentValues();
+                        values.put(Images.THUMBNAIL, os.toByteArray());
+                        values.put(Images.URL, cursor.getString(0));
+
+                        do {
+                            cr.update(Images.CONTENT_URI, values, null, null);
+                        } while (cursor.moveToNext());
                     }
                 } catch (IllegalStateException e) {
                     // Ignore
                 } finally {
-                    if (c != null) c.close();
+                    if (cursor != null) cursor.close();
                 }
                 return null;
             }