--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -685,17 +685,17 @@ public class BrowserApp extends GeckoApp
// Distribution being initialized. If you move this initialization, ensure it plays well with telemetry.
final Distribution distribution = Distribution.init(this);
distribution.addOnDistributionReadyCallback(new DistributionStoreCallback(this, profile.getName()));
mSearchEngineManager = new SearchEngineManager(this, distribution);
// Init suggested sites engine in BrowserDB.
final SuggestedSites suggestedSites = new SuggestedSites(appContext, distribution);
- final BrowserDB db = profile.getDB();
+ final BrowserDB db = GeckoApplication.getDB(profile);
db.setSuggestedSites(suggestedSites);
JavaAddonManager.getInstance().init(appContext);
mSharedPreferencesHelper = new SharedPreferencesHelper(appContext);
mOrderedBroadcastHelper = new OrderedBroadcastHelper(appContext);
mReadingListHelper = new ReadingListHelper(appContext, profile);
mAccountsHelper = new AccountsHelper(appContext, profile);
@@ -1470,17 +1470,17 @@ public class BrowserApp extends GeckoApp
public void onDoorHangerHide() {
final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 0);
alphaAnimator.setDuration(200);
alphaAnimator.start();
}
private void handleClearHistory(final boolean clearSearchHistory) {
- final BrowserDB db = getProfile().getDB();
+ final BrowserDB db = GeckoApplication.getDB(getProfile());
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
db.clearHistory(getContentResolver(), clearSearchHistory);
}
});
}
@@ -1734,17 +1734,17 @@ public class BrowserApp extends GeckoApp
// Don't use a transition to settings if we're on a device where that
// would look bad.
if (HardwareUtils.IS_KINDLE_DEVICE) {
overridePendingTransition(0, 0);
}
} else if ("Telemetry:Gather".equals(event)) {
- final BrowserDB db = getProfile().getDB();
+ final BrowserDB db = GeckoApplication.getDB(getProfile());
final ContentResolver cr = getContentResolver();
Telemetry.addToHistogram("PLACES_PAGES_COUNT", db.getCount(cr, "history"));
Telemetry.addToHistogram("FENNEC_BOOKMARKS_COUNT", db.getCount(cr, "bookmarks"));
Telemetry.addToHistogram("BROWSER_IS_USER_DEFAULT", (isDefaultBrowser(Intent.ACTION_VIEW) ? 1 : 0));
Telemetry.addToHistogram("FENNEC_CUSTOM_HOMEPAGE", (TextUtils.isEmpty(getHomepage()) ? 0 : 1));
final SharedPreferences prefs = GeckoSharedPrefs.forProfile(getContext());
final boolean hasCustomHomepanels = prefs.contains(HomeConfigPrefsBackend.PREFS_CONFIG_KEY) || prefs.contains(HomeConfigPrefsBackend.PREFS_CONFIG_KEY_OLD);
Telemetry.addToHistogram("FENNEC_HOMEPANELS_CUSTOM", hasCustomHomepanels ? 1 : 0);
@@ -2380,17 +2380,17 @@ public class BrowserApp extends GeckoApp
if (!StringUtils.isSearchQuery(url, true)) {
Tabs.getInstance().loadUrl(url, Tabs.LOADURL_USER_ENTERED);
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.ACTIONBAR, "user");
return;
}
// Otherwise, check for a bookmark keyword.
final SharedPreferences sharedPrefs = GeckoSharedPrefs.forProfile(this);
- final BrowserDB db = getProfile().getDB();
+ final BrowserDB db = GeckoApplication.getDB(getProfile());
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
final String keyword;
final String keywordSearch;
final int index = url.indexOf(" ");
if (index == -1) {
@@ -2455,17 +2455,17 @@ public class BrowserApp extends GeckoApp
}
final GeckoProfile profile = getProfile();
// Don't bother storing search queries in guest mode
if (profile.inGuestMode()) {
return;
}
- final BrowserDB db = profile.getDB();
+ final BrowserDB db = GeckoApplication.getDB(profile);
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
db.getSearches().insert(getContentResolver(), query);
}
});
}
--- a/mobile/android/base/java/org/mozilla/gecko/EditBookmarkDialog.java
+++ b/mobile/android/base/java/org/mozilla/gecko/EditBookmarkDialog.java
@@ -18,16 +18,18 @@ import android.content.DialogInterface;
import android.database.Cursor;
import android.support.design.widget.Snackbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
+import static org.mozilla.gecko.GeckoProfile.get;
+
/**
* A dialog that allows editing a bookmarks url, title, or keywords
* <p>
* Invoked by calling one of the {@link org.mozilla.gecko.EditBookmarkDialog#show(String)}
* methods.
*/
public class EditBookmarkDialog {
private final Context mContext;
@@ -137,17 +139,17 @@ public class EditBookmarkDialog {
*
* @param url The url of the bookmark to edit. The dialog will look up other information like the id,
* current title, or keywords associated with this url. If the url isn't bookmarked, the
* dialog will fail silently. If the url is bookmarked multiple times, this will only show
* information about the first it finds.
*/
public void show(final String url) {
final ContentResolver cr = mContext.getContentResolver();
- final BrowserDB db = GeckoProfile.get(mContext).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(mContext));
(new UIAsyncTask.WithoutParams<Bookmark>(ThreadUtils.getBackgroundHandler()) {
@Override
public Bookmark doInBackground() {
final Cursor cursor = db.getBookmarkForUrl(cr, url);
if (cursor == null) {
return null;
}
@@ -196,17 +198,17 @@ public class EditBookmarkDialog {
final EditText nameText = ((EditText) editView.findViewById(R.id.edit_bookmark_name));
final EditText locationText = ((EditText) editView.findViewById(R.id.edit_bookmark_location));
final EditText keywordText = ((EditText) editView.findViewById(R.id.edit_bookmark_keyword));
nameText.setText(title);
locationText.setText(url);
keywordText.setText(keyword);
- final BrowserDB db = GeckoProfile.get(mContext).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(mContext));
editPrompt.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
(new UIAsyncTask.WithoutParams<Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground() {
String newUrl = locationText.getText().toString().trim();
String newKeyword = keywordText.getText().toString().trim();
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -119,16 +119,18 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import static org.mozilla.gecko.GeckoProfile.get;
+
public abstract class GeckoApp
extends GeckoActivity
implements
ContextGetter,
GeckoAppShell.GeckoInterface,
GeckoEventListener,
GeckoMenu.Callback,
GeckoMenu.MenuPresenter,
@@ -562,17 +564,17 @@ public abstract class GeckoApp
final EventCallback callback) {
if ("Accessibility:Ready".equals(event)) {
GeckoAccessibility.updateAccessibilitySettings(this);
} else if ("Bookmark:Insert".equals(event)) {
final String url = message.getString("url");
final String title = message.getString("title");
final Context context = this;
- final BrowserDB db = getProfile().getDB();
+ final BrowserDB db = GeckoApplication.getDB(getProfile());
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
final boolean bookmarkAdded = db.addBookmark(getContentResolver(), title, url);
final int resId = bookmarkAdded ? R.string.bookmark_added : R.string.bookmark_already_added;
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
@@ -1929,17 +1931,18 @@ public abstract class GeckoApp
// Do not allow duplicate items.
intent.putExtra("duplicate", false);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
// Remember interaction
- final UrlAnnotations urlAnnotations = GeckoProfile.get(getApplicationContext()).getDB().getUrlAnnotations();
+ final UrlAnnotations urlAnnotations = GeckoApplication.getDB(GeckoProfile.get
+ (getApplicationContext())).getUrlAnnotations();
urlAnnotations.insertHomeScreenShortcut(getContentResolver(), aURI, true);
}
private void processAlertCallback(SafeIntent intent) {
String alertName = "";
String alertCookie = "";
Uri data = intent.getData();
if (data != null) {
@@ -2842,29 +2845,29 @@ public abstract class GeckoApp
@Override
public void checkUriVisited(String uri) {
GlobalHistory.getInstance().checkUriVisited(uri);
}
@Override
public void markUriVisited(final String uri) {
final Context context = getApplicationContext();
- final BrowserDB db = GeckoProfile.get(context).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(context));
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GlobalHistory.getInstance().add(context, db, uri);
}
});
}
@Override
public void setUriTitle(final String uri, final String title) {
final Context context = getApplicationContext();
- final BrowserDB db = GeckoProfile.get(context).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(context));
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GlobalHistory.getInstance().update(context.getContentResolver(), db, uri, title);
}
});
}
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -9,16 +9,17 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.SystemClock;
import android.util.Log;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
+import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.LocalBrowserDB;
import org.mozilla.gecko.dlc.DownloadContentService;
import org.mozilla.gecko.home.HomePanelsManager;
import org.mozilla.gecko.lwt.LightweightTheme;
import org.mozilla.gecko.mdns.MulticastDNSManager;
import org.mozilla.gecko.util.Clipboard;
@@ -109,17 +110,17 @@ public class GeckoApplication extends Ap
// Notify Gecko that we are pausing; the cache service will be
// shutdown, closing the disk cache cleanly. If the android
// low memory killer subsequently kills us, the disk cache will
// be left in a consistent state, avoiding costly cleanup and
// re-creation.
GeckoThread.onPause();
mPausedGecko = true;
- final BrowserDB db = GeckoProfile.get(this).getDB();
+ final BrowserDB db = GeckoApplication.getDB(GeckoProfile.get(this));
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
db.expireHistory(getContentResolver(), BrowserContract.ExpirePriority.NORMAL);
}
});
}
GeckoNetworkManager.getInstance().stop();
@@ -211,9 +212,14 @@ public class GeckoApplication extends Ap
public LightweightTheme getLightweightTheme() {
return mLightweightTheme;
}
public void prepareLightweightTheme() {
mLightweightTheme = new LightweightTheme(this);
}
+
+ @RobocopTarget
+ public static BrowserDB getDB(GeckoProfile profile) {
+ return profile.getDB();
+ }
}
--- a/mobile/android/base/java/org/mozilla/gecko/GlobalHistory.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GlobalHistory.java
@@ -17,16 +17,18 @@ import org.mozilla.gecko.util.ThreadUtil
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
+import static org.mozilla.gecko.GeckoProfile.get;
+
class GlobalHistory {
private static final String LOGTAG = "GeckoGlobalHistory";
private static final String TELEMETRY_HISTOGRAM_ADD = "FENNEC_GLOBALHISTORY_ADD_MS";
private static final String TELEMETRY_HISTOGRAM_UPDATE = "FENNEC_GLOBALHISTORY_UPDATE_MS";
private static final String TELEMETRY_HISTOGRAM_BUILD_VISITED_LINK = "FENNEC_GLOBALHISTORY_VISITED_BUILD_MS";
private static final GlobalHistory sInstance = new GlobalHistory();
@@ -48,17 +50,17 @@ class GlobalHistory {
boolean mProcessing; // = false // whether or not the runnable is queued/working
private class NotifierRunnable implements Runnable {
private final ContentResolver mContentResolver;
private final BrowserDB mDB;
public NotifierRunnable(final Context context) {
mContentResolver = context.getContentResolver();
- mDB = GeckoProfile.get(context).getDB();
+ mDB = GeckoApplication.getDB(get(context));
}
@Override
public void run() {
Set<String> visitedSet = mVisitedCache.get();
if (visitedSet == null) {
// The cache was wiped. Repopulate it.
Log.w(LOGTAG, "Rebuilding visited link set...");
--- a/mobile/android/base/java/org/mozilla/gecko/MemoryMonitor.java
+++ b/mobile/android/base/java/org/mozilla/gecko/MemoryMonitor.java
@@ -238,17 +238,17 @@ class MemoryMonitor extends BroadcastRec
// Since this may be called while Fennec is in the background, we don't want to risk accidentally
// using the wrong context. If the profile we get is a guest profile, use the default profile instead.
GeckoProfile profile = GeckoProfile.get(mContext);
if (profile.inGuestMode()) {
// If it was the guest profile, switch to the default one.
profile = GeckoProfile.get(mContext, GeckoProfile.DEFAULT_PROFILE);
}
- mDB = profile.getDB();
+ mDB = GeckoApplication.getDB(profile);
}
@Override
public void run() {
// this might get run right on startup, if so wait 10 seconds and try again
if (!GeckoThread.isRunning()) {
ThreadUtils.getBackgroundHandler().postDelayed(this, 10000);
return;
--- a/mobile/android/base/java/org/mozilla/gecko/Tab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tab.java
@@ -37,16 +37,18 @@ import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import org.mozilla.gecko.widget.SiteLogins;
+import static org.mozilla.gecko.GeckoProfile.get;
+
public class Tab {
private static final String LOGTAG = "GeckoTab";
private static Pattern sColorPattern;
private final int mId;
private final BrowserDB mDB;
private long mLastUsed;
private String mUrl;
@@ -119,17 +121,17 @@ public class Tab {
CERT_ERROR, // Pages with certificate problems
BLOCKED, // Pages blocked for phishing or malware warnings
NET_ERROR, // All other types of error
NONE // Non error pages
}
public Tab(Context context, int id, String url, boolean external, int parentId, String title) {
mAppContext = context.getApplicationContext();
- mDB = GeckoProfile.get(context).getDB();
+ mDB = GeckoApplication.getDB(get(context));
mId = id;
mUrl = url;
mBaseDomain = "";
mUserRequested = "";
mExternal = external;
mParentId = parentId;
mTitle = title == null ? "" : title;
mSiteIdentity = new SiteIdentity();
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -34,16 +34,18 @@ import android.content.Context;
import android.database.ContentObserver;
import android.database.sqlite.SQLiteException;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.provider.Browser;
import android.util.Log;
+import static org.mozilla.gecko.GeckoProfile.get;
+
public class Tabs implements GeckoEventListener {
private static final String LOGTAG = "GeckoTabs";
// mOrder and mTabs are always of the same cardinality, and contain the same values.
private final CopyOnWriteArrayList<Tab> mOrder = new CopyOnWriteArrayList<Tab>();
// All writes to mSelectedTab must be synchronized on the Tabs instance.
// In general, it's preferred to always use selectTab()).
@@ -81,17 +83,17 @@ public class Tabs implements GeckoEventL
private static class PersistTabsRunnable implements Runnable {
private final BrowserDB db;
private final Context context;
private final Iterable<Tab> tabs;
public PersistTabsRunnable(final Context context, Iterable<Tab> tabsInOrder) {
this.context = context;
- this.db = GeckoProfile.get(context).getDB();
+ this.db = GeckoApplication.getDB(get(context));
this.tabs = tabsInOrder;
}
@Override
public void run() {
try {
db.getTabsAccessor().persistLocalTabs(context.getContentResolver(), tabs);
} catch (SQLiteException e) {
@@ -145,17 +147,17 @@ public class Tabs implements GeckoEventL
};
// The listener will run on the background thread (see 2nd argument).
mAccountManager.addOnAccountsUpdatedListener(mAccountListener, ThreadUtils.getBackgroundHandler(), false);
if (mBookmarksContentObserver != null) {
// It's safe to use the db here since we aren't doing any I/O.
final GeckoProfile profile = GeckoProfile.get(context);
- profile.getDB().registerBookmarkObserver(getContentResolver(), mBookmarksContentObserver);
+ GeckoApplication.getDB(profile).registerBookmarkObserver(getContentResolver(), mBookmarksContentObserver);
}
}
/**
* Gets the tab count corresponding to the private state of the selected
* tab.
*
* If the selected tab is a non-private tab, this will return the number of
@@ -195,17 +197,17 @@ public class Tabs implements GeckoEventL
for (Tab tab : mOrder) {
tab.updateBookmark();
}
}
};
// It's safe to use the db here since we aren't doing any I/O.
final GeckoProfile profile = GeckoProfile.get(mAppContext);
- profile.getDB().registerBookmarkObserver(getContentResolver(), mBookmarksContentObserver);
+ GeckoApplication.getDB(profile).registerBookmarkObserver(getContentResolver(), mBookmarksContentObserver);
}
}
private Tab addTab(int id, String url, boolean external, int parentId, String title, boolean isPrivate, int tabIndex) {
final Tab tab = isPrivate ? new PrivateTab(mAppContext, id, url, external, parentId, title) :
new Tab(mAppContext, id, url, external, parentId, title);
synchronized (this) {
lazyRegisterBookmarkObserver();
@@ -557,17 +559,17 @@ public class Tabs implements GeckoEventL
}
} catch (Exception e) {
Log.w(LOGTAG, "handleMessage threw for " + event, e);
}
}
public void refreshThumbnails() {
- final BrowserDB db = GeckoProfile.get(mAppContext).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(mAppContext));
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
for (final Tab tab : mOrder) {
if (tab.getThumbnail() == null) {
tab.loadThumbnailFromDB(db);
}
}
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -7,16 +7,17 @@ package org.mozilla.gecko.db;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mozilla.gecko.AboutPages;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserContract.FaviconColumns;
import org.mozilla.gecko.db.BrowserContract.Favicons;
import org.mozilla.gecko.db.BrowserContract.History;
import org.mozilla.gecko.db.BrowserContract.Visits;
@@ -40,16 +41,18 @@ import android.database.MatrixCursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
+import static org.mozilla.gecko.db.BrowserContract.PARAM_PROFILE;
+
public class BrowserProvider extends SharedBrowserDatabaseProvider {
private static final String LOGTAG = "GeckoBrowserProvider";
// How many records to reposition in a single query.
// This should be less than the SQLite maximum number of query variables
// (currently 999) divided by the number of variables used per positioning
// query (currently 3).
static final int MAX_POSITION_UPDATES_PER_QUERY = 100;
@@ -812,17 +815,18 @@ public class BrowserProvider extends Sha
"(" + Combined.URL + " NOT LIKE ?)";
final String[] ignoreForTopSitesArgs = new String[] {
AboutPages.URL_FILTER
};
// Stuff the suggested sites into SQL: this allows us to filter pinned and topsites out of the suggested
// sites list as part of the final query (as opposed to walking cursors in java)
- final SuggestedSites suggestedSites = GeckoProfile.get(getContext(), uri.getQueryParameter(BrowserContract.PARAM_PROFILE)).getDB().getSuggestedSites();
+ final SuggestedSites suggestedSites = GeckoApplication.getDB(GeckoProfile.get(getContext
+ (), uri.getQueryParameter(PARAM_PROFILE))).getSuggestedSites();
StringBuilder suggestedSitesBuilder = new StringBuilder();
// We could access the underlying data here, however SuggestedSites also performs filtering on the suggested
// sites list, which means we'd need to process the lists within SuggestedSites in any case. If we're doing
// that processing, there is little real between us using a MatrixCursor, or a Map (or List) instead of the
// MatrixCursor.
final Cursor suggestedSitesCursor = suggestedSites.get(suggestedGridLimit);
--- a/mobile/android/base/java/org/mozilla/gecko/delegates/ScreenshotDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/delegates/ScreenshotDelegate.java
@@ -7,27 +7,30 @@ package org.mozilla.gecko.delegates;
import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.util.Log;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.BrowserApp;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.ScreenshotObserver;
import org.mozilla.gecko.SnackbarHelper;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import java.lang.ref.WeakReference;
+import static org.mozilla.gecko.GeckoProfile.get;
+
/**
* Delegate for observing screenshots being taken.
*/
public class ScreenshotDelegate extends BrowserAppDelegateWithReference implements ScreenshotObserver.OnScreenshotListener {
private static final String LOGTAG = "GeckoScreenshotDelegate";
private final ScreenshotObserver mScreenshotObserver = new ScreenshotObserver();
@@ -53,17 +56,17 @@ public class ScreenshotDelegate extends
return;
}
final Activity activity = getBrowserApp();
if (activity == null) {
return;
}
- GeckoProfile.get(activity).getDB().getUrlAnnotations().insertScreenshot(
+ GeckoApplication.getDB(get(activity)).getUrlAnnotations().insertScreenshot(
activity.getContentResolver(), selectedTab.getURL(), screenshotPath);
SnackbarHelper.showSnackbar(activity,
activity.getResources().getString(R.string.screenshot_added_to_bookmarks), Snackbar.LENGTH_SHORT);
}
@Override
public void onResume(BrowserApp browserApp) {
--- a/mobile/android/base/java/org/mozilla/gecko/favicons/Favicons.java
+++ b/mobile/android/base/java/org/mozilla/gecko/favicons/Favicons.java
@@ -3,16 +3,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.favicons;
import android.graphics.drawable.Drawable;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.URLMetadataTable;
import org.mozilla.gecko.favicons.cache.FaviconCache;
import org.mozilla.gecko.util.GeckoJarReader;
@@ -36,16 +37,18 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
+import static org.mozilla.gecko.GeckoProfile.get;
+
public class Favicons {
private static final String LOGTAG = "GeckoFavicons";
public enum LoadType {
PRIVILEGED,
UNPRIVILEGED
}
@@ -623,17 +626,17 @@ public class Favicons {
* the best available favicon.
*
* This implementation sidesteps the cache and will load the icon from the database or the
* internet. See getPreferredSizeFaviconForPage().
*/
public static void getPreferredIconForHomeScreenShortcut(Context context, String url, OnFaviconLoadedListener onFaviconLoadedListener) {
ThreadUtils.assertOnBackgroundThread();
- final BrowserDB db = GeckoProfile.get(context).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(context));
final String metadataQueryURL = StringUtils.stripRef(url);
final ContentResolver cr = context.getContentResolver();
final Map<String, Map<String, Object>> metadata = db.getURLMetadata().getForURLs(cr,
Collections.singletonList(metadataQueryURL),
Collections.singletonList(URLMetadataTable.TOUCH_ICON_COLUMN)
);
--- a/mobile/android/base/java/org/mozilla/gecko/favicons/LoadFaviconTask.java
+++ b/mobile/android/base/java/org/mozilla/gecko/favicons/LoadFaviconTask.java
@@ -5,16 +5,17 @@
package org.mozilla.gecko.favicons;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.util.Log;
import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.favicons.decoders.FaviconDecoder;
import org.mozilla.gecko.favicons.decoders.LoadFaviconResult;
import org.mozilla.gecko.util.GeckoJarReader;
import org.mozilla.gecko.util.IOUtils;
import org.mozilla.gecko.util.ProxySelector;
import org.mozilla.gecko.util.ThreadUtils;
@@ -28,16 +29,17 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
+import static org.mozilla.gecko.GeckoProfile.get;
import static org.mozilla.gecko.util.IOUtils.ConsumedInputStream;
/**
* Class representing the asynchronous task to load a Favicon which is not currently in the in-memory
* cache.
* The implementation initially tries to get the Favicon from the database. Upon failure, the icon
* is loaded from the internet.
*/
@@ -89,17 +91,17 @@ public class LoadFaviconTask {
}
}
public LoadFaviconTask(Context context, String pageURL, String faviconURL, int flags, OnFaviconLoadedListener listener,
int targetWidth, boolean onlyFromLocal) {
id = nextFaviconLoadId.incrementAndGet();
this.context = context;
- db = GeckoProfile.get(context).getDB();
+ db = GeckoApplication.getDB(get(context));
this.pageUrl = pageURL;
this.faviconURL = faviconURL;
this.listener = listener;
this.flags = flags;
this.targetWidthAndHeight = targetWidth;
this.onlyFromLocal = onlyFromLocal;
}
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/FeedService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/FeedService.java
@@ -12,28 +12,31 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.annotation.Nullable;
import android.support.v4.net.ConnectivityManagerCompat;
import android.util.Log;
import com.keepsafe.switchboard.SwitchBoard;
import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.feeds.action.FeedAction;
import org.mozilla.gecko.feeds.action.CheckForUpdatesAction;
import org.mozilla.gecko.feeds.action.EnrollSubscriptionsAction;
import org.mozilla.gecko.feeds.action.SetupAlarmsAction;
import org.mozilla.gecko.feeds.action.SubscribeToFeedAction;
import org.mozilla.gecko.feeds.action.WithdrawSubscriptionsAction;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.util.Experiments;
+import static org.mozilla.gecko.GeckoProfile.get;
+
/**
* Background service for subscribing to and checking website feeds to notify the user about updates.
*/
public class FeedService extends IntentService {
private static final String LOGTAG = "GeckoFeedService";
public static final String ACTION_SETUP = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.SETUP";
public static final String ACTION_SUBSCRIBE = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.SUBSCRIBE";
@@ -59,17 +62,17 @@ public class FeedService extends IntentS
}
private BrowserDB browserDB;
@Override
public void onCreate() {
super.onCreate();
- browserDB = GeckoProfile.get(this).getDB();
+ browserDB = GeckoApplication.getDB(get(this));
}
@Override
protected void onHandleIntent(Intent intent) {
try {
if (intent == null) {
return;
}
--- a/mobile/android/base/java/org/mozilla/gecko/home/BookmarkFolderView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BookmarkFolderView.java
@@ -1,15 +1,16 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UIAsyncTask;
import android.content.Context;
@@ -21,16 +22,18 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
+import static org.mozilla.gecko.GeckoProfile.get;
+
public class BookmarkFolderView extends LinearLayout {
private static final Set<Integer> FOLDERS_WITH_COUNT;
static {
final Set<Integer> folders = new TreeSet<>();
folders.add(BrowserContract.Bookmarks.FAKE_READINGLIST_SMARTFOLDER_ID);
FOLDERS_WITH_COUNT = Collections.unmodifiableSet(folders);
@@ -102,17 +105,17 @@ public class BookmarkFolderView extends
@Override
protected Integer doInBackground() {
final TextView textView = mTextViewReference.get();
if (textView == null) {
return null;
}
- final BrowserDB db = GeckoProfile.get(textView.getContext()).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(textView.getContext()));
return db.getBookmarkCountForFolder(textView.getContext().getContentResolver(), mFolderID);
}
@Override
protected void onPostExecute(Integer count) {
final TextView textView = mTextViewReference.get();
if (textView == null) {
--- a/mobile/android/base/java/org/mozilla/gecko/home/BookmarksPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BookmarksPanel.java
@@ -4,16 +4,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.home.BookmarksListAdapter.FolderInfo;
import org.mozilla.gecko.home.BookmarksListAdapter.OnRefreshFolderListener;
import org.mozilla.gecko.home.BookmarksListAdapter.RefreshType;
import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
@@ -30,16 +31,18 @@ import android.support.v4.app.LoaderMana
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.ImageView;
import android.widget.TextView;
+import static org.mozilla.gecko.GeckoProfile.get;
+
/**
* A page in about:home that displays a ListView of bookmarks.
*/
public class BookmarksPanel extends HomeFragment {
public static final String LOGTAG = "GeckoBookmarksPanel";
// Cursor loader ID for list of bookmarks.
private static final int LOADER_ID_BOOKMARKS_LIST = 0;
@@ -210,17 +213,17 @@ public class BookmarksPanel extends Home
new FolderInfo(Bookmarks.FIXED_ROOT_ID, context.getResources().getString(R.string.bookmarks_title)),
RefreshType.CHILD);
}
public BookmarksLoader(Context context, FolderInfo folderInfo, RefreshType refreshType) {
super(context);
mFolderInfo = folderInfo;
mRefreshType = refreshType;
- mDB = GeckoProfile.get(context).getDB();
+ mDB = GeckoApplication.getDB(get(context));
}
@Override
public Cursor loadCursor() {
return mDB.getBookmarksInFolder(getContext().getContentResolver(), mFolderInfo.id);
}
@Override
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -33,16 +33,17 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.RemoteClientsDialogFragment;
import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.SyncStatusListener;
import org.mozilla.gecko.home.CombinedHistoryPanel.OnPanelLevelChangeListener.PanelLevel;
import org.mozilla.gecko.restrictions.Restrictions;
@@ -52,16 +53,18 @@ import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.RemoteClient;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.widget.DividerItemDecoration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import static org.mozilla.gecko.GeckoProfile.get;
+
public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsDialogFragment.RemoteClientsListener {
private static final String LOGTAG = "GeckoCombinedHistoryPnl";
private static final String[] STAGES_TO_SYNC_ON_REFRESH = new String[] { "clients", "tabs" };
private final int LOADER_ID_HISTORY = 0;
private final int LOADER_ID_REMOTE = 1;
// String placeholders to mark formatting.
@@ -272,44 +275,44 @@ public class CombinedHistoryPanel extend
public RemoteTabsCursorLoader(Context context) {
super(context);
mProfile = GeckoProfile.get(context);
}
@Override
public Cursor loadCursor() {
- return mProfile.getDB().getTabsAccessor().getRemoteTabsCursor(getContext());
+ return GeckoApplication.getDB(mProfile).getTabsAccessor().getRemoteTabsCursor(getContext());
}
}
private static class HistoryCursorLoader extends SimpleCursorLoader {
// Max number of history results
public static final int HISTORY_LIMIT = 100;
private final BrowserDB mDB;
public HistoryCursorLoader(Context context) {
super(context);
- mDB = GeckoProfile.get(context).getDB();
+ mDB = GeckoApplication.getDB(get(context));
}
@Override
public Cursor loadCursor() {
final ContentResolver cr = getContext().getContentResolver();
return mDB.getRecentHistory(cr, HISTORY_LIMIT);
}
}
private class CursorLoaderCallbacks implements LoaderManager.LoaderCallbacks<Cursor> {
private BrowserDB mDB; // Pseudo-final: set in onCreateLoader.
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
if (mDB == null) {
- mDB = GeckoProfile.get(getActivity()).getDB();
+ mDB = GeckoApplication.getDB(get(getActivity()));
}
switch (id) {
case LOADER_ID_HISTORY:
return new HistoryCursorLoader(getContext());
case LOADER_ID_REMOTE:
return new RemoteTabsCursorLoader(getContext());
default:
--- a/mobile/android/base/java/org/mozilla/gecko/home/HomeFragment.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/HomeFragment.java
@@ -42,16 +42,18 @@ import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import static org.mozilla.gecko.GeckoProfile.get;
+
/**
* HomeFragment is an empty fragment that can be added to the HomePager.
* Subclasses can add their own views.
* <p>
* The containing activity <b>must</b> implement {@link OnUrlOpenListener}.
*/
public abstract class HomeFragment extends Fragment {
// Log Tag.
@@ -383,17 +385,17 @@ public abstract class HomeFragment exten
*/
public RemoveItemByUrlTask(Context context, String url, RemoveItemType type, int position) {
super(ThreadUtils.getBackgroundHandler());
mContext = context;
mUrl = url;
mType = type;
mPosition = position;
- mDB = GeckoProfile.get(context).getDB();
+ mDB = GeckoApplication.getDB(get(context));
}
@Override
public Void doInBackground() {
ContentResolver cr = mContext.getContentResolver();
if (mPosition > -1) {
mDB.unpinSite(cr, mPosition);
--- a/mobile/android/base/java/org/mozilla/gecko/home/SearchLoader.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/SearchLoader.java
@@ -2,16 +2,17 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home;
import java.util.EnumSet;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.db.BrowserDB.FilterFlags;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.os.SystemClock;
@@ -93,17 +94,17 @@ class SearchLoader {
mSearchTerm = searchTerm;
mFlags = flags;
mProfile = GeckoProfile.get(context);
}
@Override
public Cursor loadCursor() {
final long start = SystemClock.uptimeMillis();
- final Cursor cursor = mProfile.getDB().filter(getContext().getContentResolver(), mSearchTerm, SEARCH_LIMIT, mFlags);
+ final Cursor cursor = GeckoApplication.getDB(mProfile).filter(getContext().getContentResolver(), mSearchTerm, SEARCH_LIMIT, mFlags);
final long end = SystemClock.uptimeMillis();
final long took = end - start;
Telemetry.addToHistogram(TELEMETRY_HISTOGRAM_LOAD_CURSOR, (int) Math.min(took, Integer.MAX_VALUE));
return cursor;
}
public String getSearchTerm() {
return mSearchTerm;
--- a/mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
@@ -1,25 +1,27 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home;
+import static org.mozilla.gecko.GeckoProfile.get;
import static org.mozilla.gecko.db.URLMetadataTable.TILE_COLOR_COLUMN;
import static org.mozilla.gecko.db.URLMetadataTable.TILE_IMAGE_URL_COLUMN;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.db.BrowserContract.Thumbnails;
import org.mozilla.gecko.db.BrowserContract.TopSites;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.favicons.Favicons;
@@ -369,17 +371,17 @@ public class TopSitesPanel extends HomeF
if (!(menuInfo instanceof TopSitesGridContextMenuInfo)) {
return false;
}
TopSitesGridContextMenuInfo info = (TopSitesGridContextMenuInfo) menuInfo;
final int itemId = item.getItemId();
- final BrowserDB db = GeckoProfile.get(getActivity()).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(getActivity()));
if (itemId == R.id.top_sites_pin) {
final String url = info.url;
final String title = info.title;
final int position = info.position;
final Context context = getActivity().getApplicationContext();
ThreadUtils.postToBackgroundThread(new Runnable() {
@@ -458,17 +460,17 @@ public class TopSitesPanel extends HomeF
dialog.show(manager, TAG_PIN_SITE);
}
}
@Override
public void onSiteSelected(final String url, final String title) {
final int position = mPosition;
final Context context = getActivity().getApplicationContext();
- final BrowserDB db = GeckoProfile.get(getActivity()).getDB();
+ final BrowserDB db = GeckoApplication.getDB(get(getActivity()));
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
db.pinSite(context.getContentResolver(), url, title, position);
}
});
}
}
@@ -492,17 +494,17 @@ public class TopSitesPanel extends HomeF
private static final int SEARCH_LIMIT = 30;
private static final String TELEMETRY_HISTOGRAM_LOAD_CURSOR = "FENNEC_TOPSITES_LOADER_TIME_MS";
private final BrowserDB mDB;
private final int mMaxGridEntries;
public TopSitesLoader(Context context) {
super(context);
mMaxGridEntries = context.getResources().getInteger(R.integer.number_of_top_sites);
- mDB = GeckoProfile.get(context).getDB();
+ mDB = GeckoApplication.getDB(get(context));
}
@Override
public Cursor loadCursor() {
final long start = SystemClock.uptimeMillis();
final Cursor cursor = mDB.getTopSites(getContext().getContentResolver(), mMaxGridEntries, SEARCH_LIMIT);
final long end = SystemClock.uptimeMillis();
final long took = end - start;
@@ -544,17 +546,17 @@ public class TopSitesPanel extends HomeF
public class TopSitesGridAdapter extends CursorAdapter {
private final BrowserDB mDB;
// Cache to store the thumbnails.
// Ensure that this is only accessed from the UI thread.
private Map<String, ThumbnailInfo> mThumbnailInfos;
public TopSitesGridAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
- mDB = GeckoProfile.get(context).getDB();
+ mDB = GeckoApplication.getDB(get(context));
}
@Override
public int getCount() {
return Math.min(mMaxGridEntries, super.getCount());
}
@Override
@@ -727,17 +729,17 @@ public class TopSitesPanel extends HomeF
final ArrayList<String> urls = new ArrayList<String>();
int i = 1;
do {
final String url = c.getString(col);
// Only try to fetch thumbnails for non-empty URLs that
// don't have an associated suggested image URL.
final GeckoProfile profile = GeckoProfile.get(getActivity());
- if (TextUtils.isEmpty(url) || profile.getDB().hasSuggestedImageUrl(url)) {
+ if (TextUtils.isEmpty(url) || GeckoApplication.getDB(profile).hasSuggestedImageUrl(url)) {
continue;
}
urls.add(url);
} while (i++ < mMaxGridEntries && c.moveToNext());
if (urls.isEmpty()) {
// Short-circuit empty results to the UI.
@@ -814,17 +816,17 @@ public class TopSitesPanel extends HomeF
tempColumns.add(TILE_IMAGE_URL_COLUMN);
tempColumns.add(TILE_COLOR_COLUMN);
COLUMNS = Collections.unmodifiableList(tempColumns);
}
public ThumbnailsLoader(Context context, ArrayList<String> urls) {
super(context);
mUrls = urls;
- mDB = GeckoProfile.get(context).getDB();
+ mDB = GeckoApplication.getDB(get(context));
}
@Override
public Map<String, ThumbnailInfo> loadInBackground() {
final Map<String, ThumbnailInfo> thumbnails = new HashMap<String, ThumbnailInfo>();
if (mUrls == null || mUrls.size() == 0) {
return thumbnails;
}
--- a/mobile/android/base/java/org/mozilla/gecko/overlays/service/sharemethods/SendTab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/overlays/service/sharemethods/SendTab.java
@@ -10,16 +10,17 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.RemoteClient;
import org.mozilla.gecko.db.TabsAccessor;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import org.mozilla.gecko.fxa.login.State;
import org.mozilla.gecko.overlays.OverlayConstants;
@@ -31,16 +32,18 @@ import org.mozilla.gecko.sync.SyncConfig
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import static org.mozilla.gecko.GeckoProfile.get;
+
/**
* ShareMethod implementation to handle Sync's "Send tab to device" mechanism.
* See OverlayConstants for documentation of OverlayIntentHandler service intent API (which is how
* this class is chiefly interacted with).
*/
public class SendTab extends ShareMethod {
private static final String LOGTAG = "GeckoSendTab";
@@ -233,17 +236,17 @@ public class SendTab extends ShareMethod
* @return A collection of unique remote clients sorted by most recently used.
*/
protected Collection<RemoteClient> getOtherClients(final TabSender sender) {
if (sender == null) {
Log.w(LOGTAG, "No tab sender when fetching other client IDs.");
return Collections.emptyList();
}
- final BrowserDB browserDB = GeckoProfile.get(context).getDB();
+ final BrowserDB browserDB = GeckoApplication.getDB(get(context));
final TabsAccessor tabsAccessor = browserDB.getTabsAccessor();
final Cursor remoteTabsCursor = tabsAccessor.getRemoteClientsByRecencyCursor(context);
try {
if (remoteTabsCursor.getCount() == 0) {
return Collections.emptyList();
}
return tabsAccessor.getClientsWithoutTabsByRecencyFromCursor(remoteTabsCursor);
} finally {
--- a/mobile/android/base/java/org/mozilla/gecko/promotion/AddToHomeScreenPromotion.java
+++ b/mobile/android/base/java/org/mozilla/gecko/promotion/AddToHomeScreenPromotion.java
@@ -12,16 +12,17 @@ import android.os.Bundle;
import android.util.Log;
import com.keepsafe.switchboard.SwitchBoard;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.BrowserApp;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.delegates.BrowserAppDelegate;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.UrlAnnotations;
import org.mozilla.gecko.tabs.TabsPanel;
@@ -214,23 +215,24 @@ public class AddToHomeScreenPromotion ex
// Let's not ask again for this url - We do not want to be annoying.
return false;
}
return true;
}
protected boolean hasAcceptedOrDeclinedHomeScreenShortcut(Context context, String url) {
- final UrlAnnotations urlAnnotations = GeckoProfile.get(context).getDB().getUrlAnnotations();
+ final UrlAnnotations urlAnnotations = GeckoApplication.getDB(GeckoProfile.get(context))
+ .getUrlAnnotations();
return urlAnnotations.hasAcceptedOrDeclinedHomeScreenShortcut(context.getContentResolver(), url);
}
protected URLHistory getHistoryForURL(Context context, String url) {
final GeckoProfile profile = GeckoProfile.get(context);
- final BrowserDB browserDB = profile.getDB();
+ final BrowserDB browserDB = GeckoApplication.getDB(profile);
Cursor cursor = null;
try {
cursor = browserDB.getHistoryForURL(context.getContentResolver(), url);
if (cursor.moveToFirst()) {
return new URLHistory(
cursor.getInt(cursor.getColumnIndex(BrowserContract.History.VISITS)),
--- a/mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
+++ b/mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
@@ -15,16 +15,17 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.db.UrlAnnotations;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
@@ -169,17 +170,18 @@ public class HomeScreenPrompt extends Lo
/**
* Remember that the user rejected creating a home screen shortcut for this URL.
*/
private void rememberRejection() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
- final UrlAnnotations urlAnnotations = GeckoProfile.get(HomeScreenPrompt.this).getDB().getUrlAnnotations();
+ final UrlAnnotations urlAnnotations = GeckoApplication.getDB(GeckoProfile.get
+ (HomeScreenPrompt.this)).getUrlAnnotations();
urlAnnotations.insertHomeScreenShortcut(getContentResolver(), url, false);
}
});
}
private void slideOut() {
if (isAnimating) {
return;
--- a/mobile/android/base/java/org/mozilla/gecko/push/PushService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/push/PushService.java
@@ -10,16 +10,17 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoService;
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.annotation.ReflectionTarget;
import org.mozilla.gecko.gcm.GcmTokenClient;
import org.mozilla.gecko.push.autopush.AutopushClientException;
@@ -380,17 +381,18 @@ public class PushService implements Bund
return;
}
final String prePath = message.getString("prePath");
if (prePath == null) {
callback.sendError("prePath must not be null in " + event);
return;
}
// We're on a background thread, so we can be synchronous.
- final long millis = geckoProfile.getDB().getPrePathLastVisitedTimeMilliseconds(
+ final long millis = GeckoApplication.getDB(geckoProfile)
+ .getPrePathLastVisitedTimeMilliseconds(
context.getContentResolver(), prePath);
callback.sendSuccess(millis);
return;
}
} catch (GcmTokenClient.NeedsGooglePlayServicesException e) {
// TODO: improve this. Can we find a point where the user is *definitely* interacting
// with the WebPush? Perhaps we can show a dialog when interacting with the Push
// permissions, and then be more aggressive showing this notification when we have
--- a/mobile/android/base/java/org/mozilla/gecko/reader/ReadingListHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/reader/ReadingListHelper.java
@@ -5,16 +5,17 @@
package org.mozilla.gecko.reader;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.NativeEventListener;
import org.mozilla.gecko.util.NativeJSObject;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UIAsyncTask;
@@ -25,17 +26,17 @@ import android.util.Log;
public final class ReadingListHelper implements NativeEventListener {
private static final String LOGTAG = "GeckoReadingListHelper";
protected final Context context;
private final BrowserDB db;
public ReadingListHelper(Context context, GeckoProfile profile) {
this.context = context;
- this.db = profile.getDB();
+ this.db = GeckoApplication.getDB(profile);
EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener) this,
"Reader:FaviconRequest", "Reader:AddedToCache");
}
public void uninit() {
EventDispatcher.getInstance().unregisterGeckoThreadListener((NativeEventListener) this,
"Reader:FaviconRequest", "Reader:AddedToCache");
--- a/mobile/android/base/java/org/mozilla/gecko/reader/SavedReaderViewHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/reader/SavedReaderViewHelper.java
@@ -6,16 +6,17 @@
package org.mozilla.gecko.reader;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.db.UrlAnnotations;
import org.mozilla.gecko.util.ThreadUtils;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
@@ -140,33 +141,35 @@ public class SavedReaderViewHelper {
Log.w(LOG_TAG, "Item insertion failed:", e);
// This should never happen, absent any errors in our own implementation
throw new IllegalStateException("Failure inserting into SavedReaderViewHelper json");
}
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
- UrlAnnotations annotations = GeckoProfile.get(mContext).getDB().getUrlAnnotations();
+ UrlAnnotations annotations = GeckoApplication.getDB(GeckoProfile.get(mContext))
+ .getUrlAnnotations();
annotations.insertReaderViewUrl(mContext.getContentResolver(), pageURL);
commit();
}
});
}
protected synchronized void remove(@NonNull final String pageURL) {
assertItemsLoaded();
mItems.remove(pageURL);
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
- UrlAnnotations annotations = GeckoProfile.get(mContext).getDB().getUrlAnnotations();
+ UrlAnnotations annotations = GeckoApplication.getDB(GeckoProfile.get(mContext))
+ .getUrlAnnotations();
annotations.deleteReaderViewUrl(mContext.getContentResolver(), pageURL);
commit();
}
});
}
@RobocopTarget
--- a/mobile/android/base/java/org/mozilla/gecko/widget/ActivityChooserModel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/ActivityChooserModel.java
@@ -19,16 +19,17 @@
*/
//package android.widget;
package org.mozilla.gecko.widget;
// Mozilla: New import
import android.accounts.Account;
import android.content.pm.PackageManager;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.TabsAccessor;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.fxa.SyncStatusListener;
import org.mozilla.gecko.overlays.ui.ShareDialog;
import org.mozilla.gecko.R;
@@ -1308,17 +1309,17 @@ public class ActivityChooserModel extend
*/
private boolean hasOtherSyncClients() {
// ClientsDatabaseAccessor returns stale data (bug 1145896) so we work around this by
// checking if we have accounts set up - if not, we can't have any clients.
if (!FirefoxAccounts.firefoxAccountsExist(mContext)) {
return false;
}
- final BrowserDB browserDB = GeckoProfile.get(mContext).getDB();
+ final BrowserDB browserDB = GeckoApplication.getDB(GeckoProfile.get(mContext));
final TabsAccessor tabsAccessor = browserDB.getTabsAccessor();
final Cursor remoteClientsCursor = tabsAccessor
.getRemoteClientsByRecencyCursor(mContext);
if (remoteClientsCursor == null) {
return false;
}
try {
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestTopSites.java
+++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestTopSites.java
@@ -1,14 +1,15 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.background.db;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.SuggestedSites;
import org.mozilla.gecko.sync.setup.Constants;
import android.app.Activity;
import android.content.ContentResolver;
@@ -32,22 +33,24 @@ public class TestTopSites extends Activi
}
@Override
public void setUp() {
mContext = getInstrumentation().getTargetContext();
mSuggestedSites = new SuggestedSites(mContext);
// By default we're using StubBrowserDB which has no suggested sites available.
- GeckoProfile.get(mContext, Constants.DEFAULT_PROFILE).getDB().setSuggestedSites(mSuggestedSites);
+ GeckoApplication.getDB(GeckoProfile.get(mContext, Constants.DEFAULT_PROFILE))
+ .setSuggestedSites(mSuggestedSites);
}
@Override
public void tearDown() {
- GeckoProfile.get(mContext, Constants.DEFAULT_PROFILE).getDB().setSuggestedSites(null);
+ GeckoApplication.getDB(GeckoProfile.get(mContext, Constants.DEFAULT_PROFILE))
+ .setSuggestedSites(null);
}
public void testGetTopSites() {
final int SUGGESTED_LIMIT = 6;
final int TOTAL_LIMIT = 50;
ContentResolver cr = mContext.getContentResolver();
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/DatabaseHelper.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/DatabaseHelper.java
@@ -7,24 +7,27 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.tests;
import java.util.ArrayList;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.Assert;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.db.BrowserDB;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
+import static org.mozilla.gecko.GeckoProfile.get;
+
class DatabaseHelper {
protected enum BrowserDataType {BOOKMARKS, HISTORY};
private final Activity mActivity;
private final Assert mAsserter;
public DatabaseHelper(Activity activity, Assert asserter) {
mActivity = activity;
mAsserter = asserter;
@@ -160,11 +163,11 @@ class DatabaseHelper {
return browserData;
} finally {
cursor.close();
}
}
protected BrowserDB getProfileDB() {
- return GeckoProfile.get(mActivity).getDB();
+ return GeckoApplication.getDB(get(mActivity));
}
}
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testBrowserProvider.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testBrowserProvider.java
@@ -2,16 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.tests;
import java.util.ArrayList;
import java.util.Random;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.background.db.CursorDumper;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.UrlAnnotations.SyncStatus;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentUris;
import android.content.ContentValues;
@@ -1462,17 +1463,17 @@ public class testBrowserProvider extends
}
private void testInsertionViaUrlAnnotations() throws Exception {
final String url = "http://hello.org";
final String key = "toTheUniverse";
final String value = "42a";
final long timeBeforeCreation = System.currentTimeMillis();
- getTestProfile().getDB().getUrlAnnotations().insertAnnotation(mResolver, url, key, value);
+ GeckoApplication.getDB(getTestProfile()).getUrlAnnotations().insertAnnotation(mResolver, url, key, value);
final Cursor c = getUrlAnnotationByUrl(url);
try {
mAsserter.is(c.moveToFirst(), true, "Inserted url annotation found");
assertKeyValueSync(c, key, value);
mAsserter.is(true, c.getLong(c.getColumnIndex(BrowserContract.UrlAnnotations.DATE_CREATED)) >= timeBeforeCreation,
"Inserted url annotation has date created greater than or equal to time saved before insertion");
mAsserter.is(true, c.getLong(c.getColumnIndex(BrowserContract.UrlAnnotations.DATE_MODIFIED)) >= timeBeforeCreation,