OSDN Git Service

Do not insert duplicate urls into the browser database.
authorLeon Scroggins <scroggo@google.com>
Tue, 2 Mar 2010 21:01:49 +0000 (16:01 -0500)
committerLeon Scroggins <scroggo@google.com>
Tue, 2 Mar 2010 22:21:38 +0000 (17:21 -0500)
Move the logic for finding similar URLs to frameworks/base,
and use it in addBookmark.  In BrowserActivity, call smartUrlFilter
before calling updateVisitedHistory, so the '/' will be appended
before adding to the database.

Part of fix for http://b/issue?id=2442391

Depends on a change to frameworks/base

src/com/android/browser/Bookmarks.java
src/com/android/browser/BrowserActivity.java

index 8d98f89..2cbd851 100644 (file)
@@ -35,12 +35,6 @@ import java.util.Date;
  *  This class is purely to have a common place for adding/deleting bookmarks.
  */
 /* package */ class Bookmarks {
-    private static final String     WHERE_CLAUSE
-            = "url = ? OR url = ? OR url = ? OR url = ?";
-    private static final String     WHERE_CLAUSE_SECURE = "url = ? OR url = ?";
-
-    private static String[]         SELECTION_ARGS;
-
     // We only want the user to be able to bookmark content that
     // the browser can handle directly.
     private static final String acceptableBookmarkSchemes[] = {
@@ -71,38 +65,8 @@ import java.util.Date;
             Bitmap thumbnail, boolean retainIcon) {
         // Want to append to the beginning of the list
         long creationTime = new Date().getTime();
-        // First we check to see if the user has already visited this
-        // site.  They may have bookmarked it in a different way from
-        // how it's stored in the database, so allow different combos
-        // to map to the same url.
-        boolean secure = false;
-        String compareString = url;
-        if (compareString.startsWith("http://")) {
-            compareString = compareString.substring(7);
-        } else if (compareString.startsWith("https://")) {
-            compareString = compareString.substring(8);
-            secure = true;
-        }
-        if (compareString.startsWith("www.")) {
-            compareString = compareString.substring(4);
-        }
-        if (secure) {
-            SELECTION_ARGS = new String[2];
-            SELECTION_ARGS[0] = "https://" + compareString;
-            SELECTION_ARGS[1] = "https://www." + compareString;
-        } else {
-            SELECTION_ARGS = new String[4];
-            SELECTION_ARGS[0] = compareString;
-            SELECTION_ARGS[1] = "www." + compareString;
-            SELECTION_ARGS[2] = "http://" + compareString;
-            SELECTION_ARGS[3] = "http://" + SELECTION_ARGS[1];
-        }
-        Cursor cursor = cr.query(Browser.BOOKMARKS_URI,
-                Browser.HISTORY_PROJECTION,
-                secure ? WHERE_CLAUSE_SECURE : WHERE_CLAUSE,
-                SELECTION_ARGS,
-                null);
         ContentValues map = new ContentValues();
+        Cursor cursor = Browser.getVisitedLike(cr, url);
         if (cursor.moveToFirst() && cursor.getInt(
                 Browser.HISTORY_PROJECTION_BOOKMARK_INDEX) == 0) {
             // This means we have been to this site but not bookmarked
index 1d57f67..0bf370c 100644 (file)
@@ -722,11 +722,11 @@ public class BrowserActivity extends Activity
                 url = intent.getStringExtra(SearchManager.QUERY);
                 if (url != null) {
                     mLastEnteredUrl = url;
-                    Browser.updateVisitedHistory(mResolver, url, false);
                     // In general, we shouldn't modify URL from Intent.
                     // But currently, we get the user-typed URL from search box as well.
                     url = fixUrl(url);
                     url = smartUrlFilter(url);
+                    Browser.updateVisitedHistory(mResolver, url, false);
                     String searchSource = "&source=android-" + GOOGLE_SEARCH_SOURCE_SUGGEST + "&";
                     if (url.contains(searchSource)) {
                         String source = null;