@@ -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)

@@ -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());

}

});

@@ -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.

*/