commit 1387995d6a8764a730deac5a6d50a1f2ffa3ca0e Author: Rob Wu rob@robwu.nl Date: Thu Jun 21 15:36:56 2018 +0200
Bug 1448305 - Fall back to the memory cache when a shortcut is created. r=JanH --- .../mozilla/gecko/icons/TestIconRequestBuilder.java | 21 +++++++++++++++++++++ .../java/org/mozilla/gecko/GeckoApplication.java | 16 ++++++++++++++-- .../org/mozilla/gecko/icons/IconRequestBuilder.java | 10 ++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/mobile/android/app/src/test/java/org/mozilla/gecko/icons/TestIconRequestBuilder.java b/mobile/android/app/src/test/java/org/mozilla/gecko/icons/TestIconRequestBuilder.java index 066febaf2b93..2d80ad7ae5f6 100644 --- a/mobile/android/app/src/test/java/org/mozilla/gecko/icons/TestIconRequestBuilder.java +++ b/mobile/android/app/src/test/java/org/mozilla/gecko/icons/TestIconRequestBuilder.java @@ -172,6 +172,27 @@ public class TestIconRequestBuilder { }
@Test + public void testSkipMemoryIf() { + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertFalse(request.shouldSkipMemory()); + + request.modify() + .skipMemoryIf(true) + .deferBuild(); + + Assert.assertTrue(request.shouldSkipMemory()); + + request.modify() + .skipMemoryIf(false) + .deferBuild(); + + Assert.assertFalse(request.shouldSkipMemory()); + } + + @Test public void testExecutionOnBackgroundThread() { IconRequest request = Icons.with(RuntimeEnvironment.application) .pageUrl(TEST_PAGE_URL_1) diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java index 9a5e89dc1579..e896134e0af9 100644 --- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java +++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java @@ -613,15 +613,27 @@ public class GeckoApplication extends Application }
public static void createBrowserShortcut(final String title, final String url) { - Icons.with(GeckoAppShell.getApplicationContext()) + createBrowserShortcut(title, url, true); + } + + private static void createBrowserShortcut(final String title, final String url, final boolean skipMemoryCache) { + // Try to fetch the icon from the disk cache. The memory cache is + // initially skipped to avoid the use of downsized icons. + Icons.with(GeckoAppShell.getApplicationContext()) .pageUrl(url) .skipNetwork() - .skipMemory() + .skipMemoryIf(skipMemoryCache) .forLauncherIcon() .build() .execute(new IconCallback() { @Override public void onIconResponse(final IconResponse response) { + if (response.isGenerated() && skipMemoryCache) { + // The icon was not found in the disk cache. + // Fall back to the memory cache. + createBrowserShortcut(title, url, false); + return; + } createShortcutWithIcon(title, url, response.getBitmap()); } }); diff --git a/mobile/android/base/java/org/mozilla/gecko/icons/IconRequestBuilder.java b/mobile/android/base/java/org/mozilla/gecko/icons/IconRequestBuilder.java index b2fb46e3a39f..7e3ac5ce1395 100644 --- a/mobile/android/base/java/org/mozilla/gecko/icons/IconRequestBuilder.java +++ b/mobile/android/base/java/org/mozilla/gecko/icons/IconRequestBuilder.java @@ -107,6 +107,16 @@ public class IconRequestBuilder { }
/** + * If shouldSkipMemory is true then skip the memory cache and do not return + * a previously loaded icon. + */ + @CheckResult + public IconRequestBuilder skipMemoryIf(boolean shouldSkipMemory) { + internal.skipMemory = shouldSkipMemory; + return this; + } + + /** * The icon will be used as (Android) launcher icon. The loaded icon will be scaled to the * preferred Android launcher icon size. */
tbb-commits@lists.torproject.org