summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/provider
diff options
context:
space:
mode:
authorJeff Hamilton <jham@android.com>2010-08-20 15:49:09 -0500
committerJeff Hamilton <jham@android.com>2010-08-20 15:51:16 -0500
commit56d7ac214b2fb5f14d6997ae0f97e681f824e589 (patch)
tree4819990cc6cec05d00d56c55e0e41efb969f6dd3 /src/com/android/browser/provider
parent9af72b71354aff4408acb557c858216ffa868738 (diff)
downloadpackages_apps_Browser-56d7ac214b2fb5f14d6997ae0f97e681f824e589.zip
packages_apps_Browser-56d7ac214b2fb5f14d6997ae0f97e681f824e589.tar.gz
packages_apps_Browser-56d7ac214b2fb5f14d6997ae0f97e681f824e589.tar.bz2
Properly update the local version when updating bookmarks.
Change-Id: I22c1ba9eed960ba773ecb949edc0b4b2b54fa287
Diffstat (limited to 'src/com/android/browser/provider')
-rw-r--r--src/com/android/browser/provider/BrowserProvider2.java41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java
index 973d0f7..5825525 100644
--- a/src/com/android/browser/provider/BrowserProvider2.java
+++ b/src/com/android/browser/provider/BrowserProvider2.java
@@ -51,8 +51,8 @@ public class BrowserProvider2 extends SQLiteContentProvider {
static final String TABLE_SEARCHES = "searches";
static final String TABLE_SYNC_STATE = "syncstate";
- static final String DEFAULT_HISTORY_SORT = History.DATE_LAST_VISITED + " DESC";
-
+ static final String DEFAULT_SORT_HISTORY = History.DATE_LAST_VISITED + " DESC";
+
static final int BOOKMARKS = 1000;
static final int BOOKMARKS_ID = 1001;
static final int BOOKMARKS_FOLDER = 1002;
@@ -77,9 +77,9 @@ public class BrowserProvider2 extends SQLiteContentProvider {
static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
static final HashMap<String, String> BOOKMARKS_PROJECTION_MAP = new HashMap<String, String>();
- static final HashMap<String, String> OTHER_BOOKMARKS_PROJECTION_MAP = new HashMap<String, String>();
+ static final HashMap<String, String> OTHER_BOOKMARKS_PROJECTION_MAP =
+ new HashMap<String, String>();
static final HashMap<String, String> HISTORY_PROJECTION_MAP = new HashMap<String, String>();
- static final HashMap<String, String> SEARCHES_PROJECTION_MAP = new HashMap<String, String>();
static final HashMap<String, String> SYNC_STATE_PROJECTION_MAP = new HashMap<String, String>();
static {
@@ -493,7 +493,7 @@ public class BrowserProvider2 extends SQLiteContentProvider {
}
case HISTORY: {
if (sortOrder == null) {
- sortOrder = DEFAULT_HISTORY_SORT;
+ sortOrder = DEFAULT_SORT_HISTORY;
}
qb.setProjectionMap(HISTORY_PROJECTION_MAP);
qb.setTables(TABLE_HISTORY);
@@ -511,7 +511,7 @@ public class BrowserProvider2 extends SQLiteContentProvider {
+ (selection == null ? "" : " AND (" + selection + ")");
return mSyncHelper.query(db, projection, selectionWithId, selectionArgs, sortOrder);
}
-
+
default: {
throw new UnsupportedOperationException("Unknown URL " + uri.toString());
}
@@ -643,24 +643,15 @@ public class BrowserProvider2 extends SQLiteContentProvider {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
switch (match) {
case BOOKMARKS_ID: {
- // Mark the bookmark dirty if the caller isn't a sync adapter
- if (!callerIsSyncAdapter) {
- values = new ContentValues(values);
- values.put(Bookmarks.DIRTY, 1);
- }
selection = DatabaseUtils.concatenateWhere(selection,
TABLE_BOOKMARKS + "._id=?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
- return db.update(TABLE_BOOKMARKS, values, selection, selectionArgs);
+ // fall through
}
-
case BOOKMARKS: {
- if (!callerIsSyncAdapter) {
- values = new ContentValues(values);
- values.put(Bookmarks.DIRTY, 1);
- }
- return updateBookmarksInTransaction(values, selection, selectionArgs);
+ return updateBookmarksInTransaction(values, selection, selectionArgs,
+ callerIsSyncAdapter);
}
case HISTORY_ID: {
@@ -704,15 +695,25 @@ public class BrowserProvider2 extends SQLiteContentProvider {
* Does a query to find the matching bookmarks and updates each one with the provided values.
*/
private int updateBookmarksInTransaction(ContentValues values, String selection,
- String[] selectionArgs) {
+ String[] selectionArgs, boolean callerIsSyncAdapter) {
int count = 0;
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- Cursor cursor = query(Bookmarks.CONTENT_URI, new String[] { Bookmarks._ID },
+ Cursor cursor = query(Bookmarks.CONTENT_URI,
+ new String[] { Bookmarks._ID, Bookmarks.VERSION },
selection, selectionArgs, null);
try {
String[] args = new String[1];
+ // Mark the bookmark dirty if the caller isn't a sync adapter
+ if (!callerIsSyncAdapter) {
+ values = new ContentValues(values);
+ values.put(Bookmarks.DIRTY, 1);
+ }
while (cursor.moveToNext()) {
args[0] = cursor.getString(0);
+ if (!callerIsSyncAdapter) {
+ // increase the local version for non-sync changes
+ values.put(Bookmarks.VERSION, cursor.getLong(1) + 1);
+ }
count += db.update(TABLE_BOOKMARKS, values, "_id=?", args);
}
} finally {