mobile/android/base/db/BrowserDB.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 package org.mozilla.gecko.db;
michael@0 7
michael@0 8 import java.util.List;
michael@0 9
michael@0 10 import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
michael@0 11 import org.mozilla.gecko.favicons.decoders.LoadFaviconResult;
michael@0 12 import org.mozilla.gecko.mozglue.RobocopTarget;
michael@0 13
michael@0 14 import android.content.ContentResolver;
michael@0 15 import android.content.ContentValues;
michael@0 16 import android.database.ContentObserver;
michael@0 17 import android.database.Cursor;
michael@0 18 import android.graphics.drawable.BitmapDrawable;
michael@0 19
michael@0 20 public class BrowserDB {
michael@0 21 private static boolean sAreContentProvidersEnabled = true;
michael@0 22
michael@0 23 public static interface URLColumns {
michael@0 24 public static String URL = "url";
michael@0 25 public static String TITLE = "title";
michael@0 26 public static String FAVICON = "favicon";
michael@0 27 public static String THUMBNAIL = "thumbnail";
michael@0 28 public static String DATE_LAST_VISITED = "date-last-visited";
michael@0 29 public static String VISITS = "visits";
michael@0 30 public static String KEYWORD = "keyword";
michael@0 31 }
michael@0 32
michael@0 33 private static BrowserDBIface sDb = null;
michael@0 34
michael@0 35 public interface BrowserDBIface {
michael@0 36 public void invalidateCachedState();
michael@0 37
michael@0 38 @RobocopTarget
michael@0 39 public Cursor filter(ContentResolver cr, CharSequence constraint, int limit);
michael@0 40
michael@0 41 // This should only return frecent sites. BrowserDB.getTopSites will do the
michael@0 42 // work to combine that list with the pinned sites list.
michael@0 43 public Cursor getTopSites(ContentResolver cr, int limit);
michael@0 44
michael@0 45 public void updateVisitedHistory(ContentResolver cr, String uri);
michael@0 46
michael@0 47 public void updateHistoryTitle(ContentResolver cr, String uri, String title);
michael@0 48
michael@0 49 public void updateHistoryEntry(ContentResolver cr, String uri, String title,
michael@0 50 long date, int visits);
michael@0 51
michael@0 52 @RobocopTarget
michael@0 53 public Cursor getAllVisitedHistory(ContentResolver cr);
michael@0 54
michael@0 55 public Cursor getRecentHistory(ContentResolver cr, int limit);
michael@0 56
michael@0 57 public void expireHistory(ContentResolver cr, ExpirePriority priority);
michael@0 58
michael@0 59 public void removeHistoryEntry(ContentResolver cr, int id);
michael@0 60
michael@0 61 @RobocopTarget
michael@0 62 public void removeHistoryEntry(ContentResolver cr, String url);
michael@0 63
michael@0 64 public void clearHistory(ContentResolver cr);
michael@0 65
michael@0 66 @RobocopTarget
michael@0 67 public Cursor getBookmarksInFolder(ContentResolver cr, long folderId);
michael@0 68
michael@0 69 public Cursor getReadingList(ContentResolver cr);
michael@0 70
michael@0 71 public boolean isVisited(ContentResolver cr, String uri);
michael@0 72
michael@0 73 public int getReadingListCount(ContentResolver cr);
michael@0 74
michael@0 75 @RobocopTarget
michael@0 76 public boolean isBookmark(ContentResolver cr, String uri);
michael@0 77
michael@0 78 public boolean isReadingListItem(ContentResolver cr, String uri);
michael@0 79
michael@0 80 /**
michael@0 81 * Return a combination of fields about the provided URI
michael@0 82 * in a single hit on the DB.
michael@0 83 */
michael@0 84 public int getItemFlags(ContentResolver cr, String uri);
michael@0 85
michael@0 86 public String getUrlForKeyword(ContentResolver cr, String keyword);
michael@0 87
michael@0 88 @RobocopTarget
michael@0 89 public void addBookmark(ContentResolver cr, String title, String uri);
michael@0 90
michael@0 91 public void removeBookmark(ContentResolver cr, int id);
michael@0 92
michael@0 93 @RobocopTarget
michael@0 94 public void removeBookmarksWithURL(ContentResolver cr, String uri);
michael@0 95
michael@0 96 @RobocopTarget
michael@0 97 public void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword);
michael@0 98
michael@0 99 public void addReadingListItem(ContentResolver cr, ContentValues values);
michael@0 100
michael@0 101 public void removeReadingListItemWithURL(ContentResolver cr, String uri);
michael@0 102
michael@0 103 public void removeReadingListItem(ContentResolver cr, int id);
michael@0 104
michael@0 105 public LoadFaviconResult getFaviconForUrl(ContentResolver cr, String uri);
michael@0 106
michael@0 107 public String getFaviconUrlForHistoryUrl(ContentResolver cr, String url);
michael@0 108
michael@0 109 public void updateFaviconForUrl(ContentResolver cr, String pageUri, byte[] encodedFavicon, String faviconUri);
michael@0 110
michael@0 111 public void updateThumbnailForUrl(ContentResolver cr, String uri, BitmapDrawable thumbnail);
michael@0 112
michael@0 113 @RobocopTarget
michael@0 114 public byte[] getThumbnailForUrl(ContentResolver cr, String uri);
michael@0 115
michael@0 116 public Cursor getThumbnailsForUrls(ContentResolver cr, List<String> urls);
michael@0 117
michael@0 118 @RobocopTarget
michael@0 119 public void removeThumbnails(ContentResolver cr);
michael@0 120
michael@0 121 public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer);
michael@0 122
michael@0 123 public void registerHistoryObserver(ContentResolver cr, ContentObserver observer);
michael@0 124
michael@0 125 public int getCount(ContentResolver cr, String database);
michael@0 126
michael@0 127 public void pinSite(ContentResolver cr, String url, String title, int position);
michael@0 128
michael@0 129 public void unpinSite(ContentResolver cr, int position);
michael@0 130
michael@0 131 public void unpinAllSites(ContentResolver cr);
michael@0 132
michael@0 133 public Cursor getPinnedSites(ContentResolver cr, int limit);
michael@0 134
michael@0 135 @RobocopTarget
michael@0 136 public Cursor getBookmarkForUrl(ContentResolver cr, String url);
michael@0 137 }
michael@0 138
michael@0 139 static {
michael@0 140 // Forcing local DB no option to switch to Android DB for now
michael@0 141 sDb = null;
michael@0 142 }
michael@0 143
michael@0 144 public static void initialize(String profile) {
michael@0 145 sDb = new LocalBrowserDB(profile);
michael@0 146 }
michael@0 147
michael@0 148 public static void invalidateCachedState() {
michael@0 149 sDb.invalidateCachedState();
michael@0 150 }
michael@0 151
michael@0 152 @RobocopTarget
michael@0 153 public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
michael@0 154 return sDb.filter(cr, constraint, limit);
michael@0 155 }
michael@0 156
michael@0 157 public static Cursor getTopSites(ContentResolver cr, int minLimit, int maxLimit) {
michael@0 158 // Note this is not a single query anymore, but actually returns a mixture
michael@0 159 // of two queries, one for topSites and one for pinned sites.
michael@0 160 Cursor pinnedSites = sDb.getPinnedSites(cr, minLimit);
michael@0 161 Cursor topSites = sDb.getTopSites(cr, maxLimit - pinnedSites.getCount());
michael@0 162 return new TopSitesCursorWrapper(pinnedSites, topSites, minLimit);
michael@0 163 }
michael@0 164
michael@0 165 public static void updateVisitedHistory(ContentResolver cr, String uri) {
michael@0 166 if (sAreContentProvidersEnabled) {
michael@0 167 sDb.updateVisitedHistory(cr, uri);
michael@0 168 }
michael@0 169 }
michael@0 170
michael@0 171 public static void updateHistoryTitle(ContentResolver cr, String uri, String title) {
michael@0 172 if (sAreContentProvidersEnabled) {
michael@0 173 sDb.updateHistoryTitle(cr, uri, title);
michael@0 174 }
michael@0 175 }
michael@0 176
michael@0 177 public static void updateHistoryEntry(ContentResolver cr, String uri, String title,
michael@0 178 long date, int visits) {
michael@0 179 if (sAreContentProvidersEnabled) {
michael@0 180 sDb.updateHistoryEntry(cr, uri, title, date, visits);
michael@0 181 }
michael@0 182 }
michael@0 183
michael@0 184 @RobocopTarget
michael@0 185 public static Cursor getAllVisitedHistory(ContentResolver cr) {
michael@0 186 return (sAreContentProvidersEnabled ? sDb.getAllVisitedHistory(cr) : null);
michael@0 187 }
michael@0 188
michael@0 189 public static Cursor getRecentHistory(ContentResolver cr, int limit) {
michael@0 190 return sDb.getRecentHistory(cr, limit);
michael@0 191 }
michael@0 192
michael@0 193 public static void expireHistory(ContentResolver cr, ExpirePriority priority) {
michael@0 194 if (sDb == null)
michael@0 195 return;
michael@0 196
michael@0 197 if (priority == null)
michael@0 198 priority = ExpirePriority.NORMAL;
michael@0 199 sDb.expireHistory(cr, priority);
michael@0 200 }
michael@0 201
michael@0 202 public static void removeHistoryEntry(ContentResolver cr, int id) {
michael@0 203 sDb.removeHistoryEntry(cr, id);
michael@0 204 }
michael@0 205
michael@0 206 @RobocopTarget
michael@0 207 public static void removeHistoryEntry(ContentResolver cr, String url) {
michael@0 208 sDb.removeHistoryEntry(cr, url);
michael@0 209 }
michael@0 210
michael@0 211 @RobocopTarget
michael@0 212 public static void clearHistory(ContentResolver cr) {
michael@0 213 sDb.clearHistory(cr);
michael@0 214 }
michael@0 215
michael@0 216 @RobocopTarget
michael@0 217 public static Cursor getBookmarksInFolder(ContentResolver cr, long folderId) {
michael@0 218 return sDb.getBookmarksInFolder(cr, folderId);
michael@0 219 }
michael@0 220
michael@0 221 @RobocopTarget
michael@0 222 public static Cursor getReadingList(ContentResolver cr) {
michael@0 223 return sDb.getReadingList(cr);
michael@0 224 }
michael@0 225
michael@0 226 public static String getUrlForKeyword(ContentResolver cr, String keyword) {
michael@0 227 return sDb.getUrlForKeyword(cr, keyword);
michael@0 228 }
michael@0 229
michael@0 230 public static boolean isVisited(ContentResolver cr, String uri) {
michael@0 231 return sDb.isVisited(cr, uri);
michael@0 232 }
michael@0 233
michael@0 234 public static int getReadingListCount(ContentResolver cr) {
michael@0 235 return sDb.getReadingListCount(cr);
michael@0 236 }
michael@0 237
michael@0 238 @RobocopTarget
michael@0 239 public static boolean isBookmark(ContentResolver cr, String uri) {
michael@0 240 return (sAreContentProvidersEnabled && sDb.isBookmark(cr, uri));
michael@0 241 }
michael@0 242
michael@0 243 public static boolean isReadingListItem(ContentResolver cr, String uri) {
michael@0 244 return (sAreContentProvidersEnabled && sDb.isReadingListItem(cr, uri));
michael@0 245 }
michael@0 246
michael@0 247 public static int getItemFlags(ContentResolver cr, String uri) {
michael@0 248 if (!sAreContentProvidersEnabled) {
michael@0 249 return 0;
michael@0 250 }
michael@0 251 return sDb.getItemFlags(cr, uri);
michael@0 252 }
michael@0 253
michael@0 254 public static void addBookmark(ContentResolver cr, String title, String uri) {
michael@0 255 sDb.addBookmark(cr, title, uri);
michael@0 256 }
michael@0 257
michael@0 258 public static void removeBookmark(ContentResolver cr, int id) {
michael@0 259 sDb.removeBookmark(cr, id);
michael@0 260 }
michael@0 261
michael@0 262 @RobocopTarget
michael@0 263 public static void removeBookmarksWithURL(ContentResolver cr, String uri) {
michael@0 264 sDb.removeBookmarksWithURL(cr, uri);
michael@0 265 }
michael@0 266
michael@0 267 @RobocopTarget
michael@0 268 public static void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword) {
michael@0 269 sDb.updateBookmark(cr, id, uri, title, keyword);
michael@0 270 }
michael@0 271
michael@0 272 public static void addReadingListItem(ContentResolver cr, ContentValues values) {
michael@0 273 sDb.addReadingListItem(cr, values);
michael@0 274 }
michael@0 275
michael@0 276 public static void removeReadingListItemWithURL(ContentResolver cr, String uri) {
michael@0 277 sDb.removeReadingListItemWithURL(cr, uri);
michael@0 278 }
michael@0 279
michael@0 280 public static void removeReadingListItem(ContentResolver cr, int id) {
michael@0 281 sDb.removeReadingListItem(cr, id);
michael@0 282 }
michael@0 283
michael@0 284 public static LoadFaviconResult getFaviconForFaviconUrl(ContentResolver cr, String faviconURL) {
michael@0 285 return sDb.getFaviconForUrl(cr, faviconURL);
michael@0 286 }
michael@0 287
michael@0 288 public static String getFaviconUrlForHistoryUrl(ContentResolver cr, String url) {
michael@0 289 return sDb.getFaviconUrlForHistoryUrl(cr, url);
michael@0 290 }
michael@0 291
michael@0 292 public static void updateFaviconForUrl(ContentResolver cr, String pageUri, byte[] encodedFavicon, String faviconUri) {
michael@0 293 sDb.updateFaviconForUrl(cr, pageUri, encodedFavicon, faviconUri);
michael@0 294 }
michael@0 295
michael@0 296 public static void updateThumbnailForUrl(ContentResolver cr, String uri, BitmapDrawable thumbnail) {
michael@0 297 sDb.updateThumbnailForUrl(cr, uri, thumbnail);
michael@0 298 }
michael@0 299
michael@0 300 @RobocopTarget
michael@0 301 public static byte[] getThumbnailForUrl(ContentResolver cr, String uri) {
michael@0 302 return sDb.getThumbnailForUrl(cr, uri);
michael@0 303 }
michael@0 304
michael@0 305 public static Cursor getThumbnailsForUrls(ContentResolver cr, List<String> urls) {
michael@0 306 return sDb.getThumbnailsForUrls(cr, urls);
michael@0 307 }
michael@0 308
michael@0 309 @RobocopTarget
michael@0 310 public static void removeThumbnails(ContentResolver cr) {
michael@0 311 sDb.removeThumbnails(cr);
michael@0 312 }
michael@0 313
michael@0 314 public static void registerBookmarkObserver(ContentResolver cr, ContentObserver observer) {
michael@0 315 sDb.registerBookmarkObserver(cr, observer);
michael@0 316 }
michael@0 317
michael@0 318 public static void registerHistoryObserver(ContentResolver cr, ContentObserver observer) {
michael@0 319 sDb.registerHistoryObserver(cr, observer);
michael@0 320 }
michael@0 321
michael@0 322 public static void unregisterContentObserver(ContentResolver cr, ContentObserver observer) {
michael@0 323 cr.unregisterContentObserver(observer);
michael@0 324 }
michael@0 325
michael@0 326 public static int getCount(ContentResolver cr, String database) {
michael@0 327 return sDb.getCount(cr, database);
michael@0 328 }
michael@0 329
michael@0 330 public static void pinSite(ContentResolver cr, String url, String title, int position) {
michael@0 331 sDb.pinSite(cr, url, title, position);
michael@0 332 }
michael@0 333
michael@0 334 public static void unpinSite(ContentResolver cr, int position) {
michael@0 335 sDb.unpinSite(cr, position);
michael@0 336 }
michael@0 337
michael@0 338 public static void unpinAllSites(ContentResolver cr) {
michael@0 339 sDb.unpinAllSites(cr);
michael@0 340 }
michael@0 341
michael@0 342 public static Cursor getPinnedSites(ContentResolver cr, int limit) {
michael@0 343 return sDb.getPinnedSites(cr, limit);
michael@0 344 }
michael@0 345
michael@0 346 @RobocopTarget
michael@0 347 public static Cursor getBookmarkForUrl(ContentResolver cr, String url) {
michael@0 348 return sDb.getBookmarkForUrl(cr, url);
michael@0 349 }
michael@0 350
michael@0 351 public static boolean areContentProvidersDisabled() {
michael@0 352 return sAreContentProvidersEnabled;
michael@0 353 }
michael@0 354
michael@0 355 public static void setEnableContentProviders(boolean enableContentProviders) {
michael@0 356 sAreContentProvidersEnabled = enableContentProviders;
michael@0 357 }
michael@0 358 }

mercurial