Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java

Issue 10912172: [Android] Upstream ChromeBrowserProvider, the Android port ContentProvider implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: temporarily removing tests until we can compile and run them (soon) Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java
new file mode 100644
index 0000000000000000000000000000000000000000..a1a2de652507c9406b8a2f295ce1ba9825a00850
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java
@@ -0,0 +1,132 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser;
+
+import android.app.SearchManager;
+import android.content.Intent;
+import android.database.AbstractCursor;
+import android.database.Cursor;
+import android.provider.BaseColumns;
+import android.provider.Browser.BookmarkColumns;
+
+import org.chromium.content.app.AppResource;
+
+/**
+ * For bookmarks/history suggestions, wrap the cursor returned in one that can feed
+ * the data back to global search in the format it wants.
+ */
+class ChromeBrowserProviderSuggestionsCursor extends AbstractCursor {
+
+ private static final String[] COLS = new String [] {
+ BaseColumns._ID,
+ SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
+ SearchManager.SUGGEST_COLUMN_INTENT_DATA,
+ SearchManager.SUGGEST_COLUMN_TEXT_1,
+ SearchManager.SUGGEST_COLUMN_TEXT_2,
+ SearchManager.SUGGEST_COLUMN_TEXT_2_URL,
+ SearchManager.SUGGEST_COLUMN_ICON_1,
+ SearchManager.SUGGEST_COLUMN_LAST_ACCESS_HINT
+ };
+
+ private static final int COLUMN_ID = 0;
+ private static final int COLUMN_SUGGEST_INTENT_ACTION = 1;
+ private static final int COLUMN_SUGGEST_INTENT_DATA = 2;
+ private static final int COLUMN_SUGGEST_TEXT_1 = 3;
+ private static final int COLUMN_SUGGEST_TEXT_2 = 4;
+ private static final int COLUMN_SUGGEST_TEXT_2_URL = 5;
+ private static final int COLUMN_SUGGEST_ICON_1 = 6;
+ private static final int COLUMN_SUGGEST_LAST_ACCESS_HINT = 7;
+
+ private Cursor mCursor;
+
+ public ChromeBrowserProviderSuggestionsCursor(Cursor c) {
+ mCursor = c;
+ }
+
+ @Override
+ public String[] getColumnNames() {
+ return COLS;
+ }
+
+ @Override
+ public int getCount() {
+ return mCursor.getCount();
+ }
+
+ @Override
+ public String getString(int column) {
+ switch (column) {
+ case COLUMN_ID:
+ return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns._ID));
+ case COLUMN_SUGGEST_INTENT_ACTION:
+ return Intent.ACTION_VIEW;
+ case COLUMN_SUGGEST_INTENT_DATA:
+ return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL));
+ case COLUMN_SUGGEST_TEXT_1:
+ return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.TITLE));
+ case COLUMN_SUGGEST_TEXT_2:
+ case COLUMN_SUGGEST_TEXT_2_URL:
+ return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL));
+ case COLUMN_SUGGEST_ICON_1:
+ // This is the icon displayed to the left of the result in QSB.
+ assert AppResource.DRAWABLE_ICON_APP_ICON != 0;
+ return Integer.toString(AppResource.DRAWABLE_ICON_APP_ICON);
+ case COLUMN_SUGGEST_LAST_ACCESS_HINT:
+ // After clearing history, the Chrome bookmarks database will have a last
+ // access time of 0 for all bookmarks. In the Android provider, this will
+ // yield a negative last access time. A negative last access time will
+ // cause global search to discard the result, so fix it up before
+ // we return it.
+ long lastAccess = mCursor.getLong(
+ mCursor.getColumnIndex(BookmarkColumns.DATE));
+ return lastAccess < 0 ? "0" : "" + lastAccess;
+ default:
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public boolean isNull(int c) {
+ return mCursor.isNull(c);
+ }
+
+ @Override
+ public long getLong(int c) {
+ switch (c) {
+ case 7:
+ // See comments above in getString() re. negative last access times.
+ long lastAccess = mCursor.getLong(
+ mCursor.getColumnIndex(BookmarkColumns.DATE));
+ return lastAccess < 0 ? 0 : lastAccess;
+ default:
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public short getShort(int c) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public double getDouble(int c) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getInt(int c) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public float getFloat(int c) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean onMove(int oldPosition, int newPosition) {
+ return mCursor.moveToPosition(newPosition);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698