Bug 943515 - Refactor favicon accessors for naming and usage consistency. r=mcomella
authorJoshua Dover <jdover@mozilla.com>
Wed, 08 Jan 2014 13:42:45 -0800
changeset 162810 a95bf9dca67099323532f9f712d2284551a6dad6
parent 162809 ed22a1ba0e138dfe1b79ceeebf7f838b4b103910
child 162811 ad1fec1c3678105164cac37481187a943bc1af1b
push id25971
push userkwierso@gmail.com
push dateFri, 10 Jan 2014 00:50:13 +0000
treeherdermozilla-central@37516445a0b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs943515
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 943515 - Refactor favicon accessors for naming and usage consistency. r=mcomella
mobile/android/base/BrowserApp.java
mobile/android/base/Tabs.java
mobile/android/base/db/BrowserProvider.java
mobile/android/base/favicons/Favicons.java
mobile/android/base/favicons/LoadFaviconTask.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -781,21 +781,21 @@ abstract public class BrowserApp extends
 
             final String url = tab.getURL();
             final String title = tab.getDisplayTitle();
             if (url == null || title == null) {
                 return true;
             }
 
             final OnFaviconLoadedListener listener = new GeckoAppShell.CreateShortcutFaviconLoadedListener(url, title);
-            Favicons.getFaviconForSize(url,
-                                       tab.getFaviconURL(),
-                                       Integer.MAX_VALUE,
-                                       LoadFaviconTask.FLAG_PERSIST,
-                                       listener);
+            Favicons.getSizedFavicon(url,
+                                     tab.getFaviconURL(),
+                                     Integer.MAX_VALUE,
+                                     LoadFaviconTask.FLAG_PERSIST,
+                                     listener);
             return true;
         }
 
         return false;
     }
 
     @Override
     public void setAccessibilityEnabled(boolean enabled) {
@@ -1408,17 +1408,17 @@ abstract public class BrowserApp extends
     };
 
     private void loadFavicon(final Tab tab) {
         maybeCancelFaviconLoad(tab);
 
         final int tabFaviconSize = getResources().getDimensionPixelSize(R.dimen.browser_toolbar_favicon_size);
 
         int flags = (tab.isPrivate() || tab.getErrorType() != Tab.ErrorType.NONE) ? 0 : LoadFaviconTask.FLAG_PERSIST;
-        int id = Favicons.getFaviconForSize(tab.getURL(), tab.getFaviconURL(), tabFaviconSize, flags, sFaviconLoadedListener);
+        int id = Favicons.getSizedFavicon(tab.getURL(), tab.getFaviconURL(), tabFaviconSize, flags, sFaviconLoadedListener);
 
         tab.setFaviconLoadId(id);
 
         final Tabs tabs = Tabs.getInstance();
         if (id != Favicons.LOADED && tabs.isSelectedTab(tab)) {
             // We're loading the current tab's favicon from somewhere
             // other than the cache. Display the globe favicon until then.
             tab.updateFavicon(Favicons.sDefaultFavicon);
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -761,17 +761,17 @@ public class Tabs implements GeckoEventL
     /**
      * These favicons are only used for the URL bar, so
      * we fetch with that size.
      *
      * This method completes on the calling thread.
      */
     private Bitmap getAboutPageFavicon(final String url) {
         int faviconSize = Math.round(mAppContext.getResources().getDimension(R.dimen.browser_toolbar_favicon_size));
-        return Favicons.getCachedFaviconForSize(url, faviconSize);
+        return Favicons.getSizedFaviconForPageFromCache(url, faviconSize);
     }
 
     /**
      * Open the url as a new tab, and mark the selected tab as its "parent".
      *
      * If the url is already open in a tab, the existing tab is selected.
      * Use this for tabs opened by the browser chrome, so users can press the
      * "Back" button to return to the previous tab.
--- a/mobile/android/base/db/BrowserProvider.java
+++ b/mobile/android/base/db/BrowserProvider.java
@@ -2969,17 +2969,17 @@ public class BrowserProvider extends Con
         // Extract the page URL from the ContentValues
         if (values.containsKey(Favicons.PAGE_URL)) {
             pageUrl = values.getAsString(Favicons.PAGE_URL);
             values.remove(Favicons.PAGE_URL);
         }
 
         // If no URL is provided, insert using the default one.
         if (TextUtils.isEmpty(faviconUrl) && !TextUtils.isEmpty(pageUrl)) {
-            values.put(Favicons.URL, org.mozilla.gecko.favicons.Favicons.guessDefaultFaviconURL(pageUrl));
+            values.put(Favicons.URL, org.mozilla.gecko.favicons.Favicons.guessDefaultFaviconUrl(pageUrl));
         }
 
         long now = System.currentTimeMillis();
         values.put(Favicons.DATE_CREATED, now);
         values.put(Favicons.DATE_MODIFIED, now);
         faviconId = db.insertOrThrow(TABLE_FAVICONS, null, values);
 
         if (pageUrl != null) {
--- a/mobile/android/base/favicons/Favicons.java
+++ b/mobile/android/base/favicons/Favicons.java
@@ -60,25 +60,25 @@ public class Favicons {
     public static int sDefaultFaviconSize;
 
     private static final Map<Integer, LoadFaviconTask> sLoadTasks = Collections.synchronizedMap(new HashMap<Integer, LoadFaviconTask>());
 
     // Cache to hold mappings between page URLs and Favicon URLs. Used to avoid going to the DB when
     // doing so is not necessary.
     private static final NonEvictingLruCache<String, String> sPageURLMappings = new NonEvictingLruCache<String, String>(NUM_PAGE_URL_MAPPINGS_TO_STORE);
 
-    public static String getFaviconURLForPageURLFromCache(String pageURL) {
+    public static String getFaviconUrlForPageUrlFromCache(String pageURL) {
         return sPageURLMappings.get(pageURL);
     }
 
     /**
      * Insert the given pageUrl->faviconUrl mapping into the memory cache of such mappings.
      * Useful for short-circuiting local database access.
      */
-    public static void putFaviconURLForPageURLInCache(String pageURL, String faviconURL) {
+    public static void putFaviconUrlForPageUrlInCache(String pageURL, String faviconURL) {
         sPageURLMappings.put(pageURL, faviconURL);
     }
 
     private static FaviconCache sFaviconsCache;
 
     /**
      * Returns either NOT_LOADING, or LOADED if the onFaviconLoaded call could
      * be made on the main thread.
@@ -106,17 +106,17 @@ public class Favicons {
     }
 
     /**
      * Only returns a non-null Bitmap if the entire path is cached -- the
      * page URL to favicon URL, and the favicon URL to in-memory bitmaps.
      *
      * Returns null otherwise.
      */
-    public static Bitmap getCachedFaviconForSize(final String pageURL, int targetSize) {
+    public static Bitmap getSizedFaviconForPageFromCache(final String pageURL, int targetSize) {
         final String faviconURL = sPageURLMappings.get(pageURL);
         if (faviconURL == null) {
             return null;
         }
         return getSizedFaviconFromCache(faviconURL, targetSize);
     }
 
     /**
@@ -129,26 +129,26 @@ public class Favicons {
      * @param faviconURL URL of the Favicon to be downloaded, if known. If none provided, an educated
      *                    guess is made by the system.
      * @param targetSize Target size of the returned Favicon
      * @param listener Listener to call with the result of the load operation, if the result is not
      *                  immediately available.
      * @return The id of the asynchronous task created, NOT_LOADING if none is created, or
      *         LOADED if the value could be dispatched on the current thread.
      */
-    public static int getFaviconForSize(String pageURL, String faviconURL, int targetSize, int flags, OnFaviconLoadedListener listener) {
+    public static int getSizedFavicon(String pageURL, String faviconURL, int targetSize, int flags, OnFaviconLoadedListener listener) {
         // Do we know the favicon URL for this page already?
         String cacheURL = faviconURL;
         if (cacheURL == null) {
             cacheURL = sPageURLMappings.get(pageURL);
         }
 
         // If there's no favicon URL given, try and hit the cache with the default one.
         if (cacheURL == null)  {
-            cacheURL = guessDefaultFaviconURL(pageURL);
+            cacheURL = guessDefaultFaviconUrl(pageURL);
         }
 
         // If it's something we can't even figure out a default URL for, just give up.
         if (cacheURL == null) {
             return dispatchResult(pageURL, null, sDefaultFavicon, listener);
         }
 
         Bitmap cachedIcon = getSizedFaviconFromCache(cacheURL, targetSize);
@@ -217,16 +217,17 @@ public class Favicons {
         sLoadTasks.put(taskId, task);
         task.execute();
         return taskId;
     }
 
     public static int getSizedFaviconForPageFromLocal(final String pageURL, final OnFaviconLoadedListener callback) {
         return getSizedFaviconForPageFromLocal(pageURL, sDefaultFaviconSize, callback);
     }
+
     /**
      * Helper method to determine the URL of the Favicon image for a given page URL by querying the
      * history database. Should only be called from the background thread - does database access.
      *
      * @param pageURL The URL of a webpage with a Favicon.
      * @return The URL of the Favicon used by that webpage, according to either the History database
      *         or a somewhat educated guess.
      */
@@ -240,17 +241,17 @@ public class Favicons {
             if (targetURL != null) {
                 return targetURL;
             }
         }
 
         targetURL = BrowserDB.getFaviconUrlForHistoryUrl(sContext.getContentResolver(), pageURL);
         if (targetURL == null) {
             // Nothing in the history database. Fall back to the default URL and hope for the best.
-            targetURL = guessDefaultFaviconURL(pageURL);
+            targetURL = guessDefaultFaviconUrl(pageURL);
         }
         return targetURL;
     }
 
     /**
      * Helper function to create an async job to load a Favicon which does not exist in the memcache.
      * Contains logic to prevent the repeated loading of Favicons which have previously failed.
      * There is no support for recovery from transient failures.
@@ -401,17 +402,17 @@ public class Favicons {
     }
 
     /**
      * Helper method to get the default Favicon URL for a given pageURL. Generally: somewhere.com/favicon.ico
      *
      * @param pageURL Page URL for which a default Favicon URL is requested
      * @return The default Favicon URL.
      */
-    public static String guessDefaultFaviconURL(String pageURL) {
+    public static String guessDefaultFaviconUrl(String pageURL) {
         // Special-casing for about: pages. The favicon for about:pages which don't provide a link tag
         // is bundled in the database, keyed only by page URL, hence the need to return the page URL
         // here. If the database ever migrates to stop being silly in this way, this can plausibly
         // be removed.
         if (AboutPages.isAboutPage(pageURL) || pageURL.startsWith("jar:")) {
             return pageURL;
         }
 
--- a/mobile/android/base/favicons/LoadFaviconTask.java
+++ b/mobile/android/base/favicons/LoadFaviconTask.java
@@ -235,33 +235,33 @@ public class LoadFaviconTask extends UiA
 
         String storedFaviconUrl;
         boolean isUsingDefaultURL = false;
 
         // Handle the case of malformed favicon URL.
         // If favicon is empty, fall back to the stored one.
         if (TextUtils.isEmpty(mFaviconUrl)) {
             // Try to get the favicon URL from the memory cache.
-            storedFaviconUrl = Favicons.getFaviconURLForPageURLFromCache(mPageUrl);
+            storedFaviconUrl = Favicons.getFaviconUrlForPageUrlFromCache(mPageUrl);
 
             // If that failed, try to get the URL from the database.
             if (storedFaviconUrl == null) {
                 storedFaviconUrl = Favicons.getFaviconUrlForPageUrl(mPageUrl);
                 if (storedFaviconUrl != null) {
                     // If that succeeded, cache the URL loaded from the database in memory.
-                    Favicons.putFaviconURLForPageURLInCache(mPageUrl, storedFaviconUrl);
+                    Favicons.putFaviconUrlForPageUrlInCache(mPageUrl, storedFaviconUrl);
                 }
             }
 
             // If we found a faviconURL - use it.
             if (storedFaviconUrl != null) {
                 mFaviconUrl = storedFaviconUrl;
             } else {
                 // If we don't have a stored one, fall back to the default.
-                mFaviconUrl = Favicons.guessDefaultFaviconURL(mPageUrl);
+                mFaviconUrl = Favicons.guessDefaultFaviconUrl(mPageUrl);
 
                 if (TextUtils.isEmpty(mFaviconUrl)) {
                     return null;
                 }
                 isUsingDefaultURL = true;
             }
         }
 
@@ -330,17 +330,17 @@ public class LoadFaviconTask extends UiA
         }
 
         if (isUsingDefaultURL) {
             Favicons.putFaviconInFailedCache(mFaviconUrl);
             return null;
         }
 
         // If we're not already trying the default URL, try it now.
-        final String guessed = Favicons.guessDefaultFaviconURL(mPageUrl);
+        final String guessed = Favicons.guessDefaultFaviconUrl(mPageUrl);
         if (guessed == null) {
             Favicons.putFaviconInFailedCache(mFaviconUrl);
             return null;
         }
 
         image = fetchJARFavicon(guessed);
         if (imageIsValid(image)) {
             // We don't want to put this into the DB.