Bug 1300543 - LegacyLoader: Skip loading from legacy storage if network download is permitted. r=ahunt

If we are allowed to load the icon from the network then skip loading from the legacy storage and just
load a fresh icon. This will avoid touching the legacy storage (disk) every time before downloading an
icon.

MozReview-Commit-ID: C9hYqISno6U

--HG--
extra : rebase_source : 6f19839c38d37916deb351b3e080e023e532a83f
This commit is contained in:
Sebastian Kaspari 2016-09-05 15:38:27 +02:00
Родитель 87a7500078
Коммит 80177742b4
2 изменённых файлов: 26 добавлений и 3 удалений

Просмотреть файл

@ -25,6 +25,12 @@ import org.mozilla.gecko.icons.IconResponse;
public class LegacyLoader implements IconLoader {
@Override
public IconResponse load(IconRequest request) {
if (!request.shouldSkipNetwork()) {
// If we are allowed to load from the network for this request then just ommit the legacy
// loader and fetch a fresh new icon.
return null;
}
if (request.shouldSkipDisk()) {
return null;
}
@ -41,7 +47,7 @@ public class LegacyLoader implements IconLoader {
/* package-private */ Bitmap loadBitmapFromDatabase(IconRequest request) {
final Context context = request.getContext();
final ContentResolver contentResolver = context.getContentResolver();
final BrowserDB db = GeckoProfile.get(request.getContext()).getDB();
final BrowserDB db = GeckoProfile.get(context).getDB();
// We ask the database for the favicon URL and ignore the icon URL in the request object:
// As we are not updating the database anymore the icon might be stored under a different URL.

Просмотреть файл

@ -27,7 +27,23 @@ public class TestLegacyLoader {
private static final String TEST_ICON_URL = "https://example.org/favicon.ico";
@Test
public void testDatabaseIsQueriesForNormalRequests() {
public void testDatabaseIsQueriesForNormalRequestsWithNetworkSkipped() {
final IconRequest request = Icons.with(RuntimeEnvironment.application)
.pageUrl(TEST_PAGE_URL)
.icon(IconDescriptor.createGenericIcon(TEST_ICON_URL))
.skipNetwork()
.build();
final LegacyLoader loader = spy(new LegacyLoader());
final IconResponse response = loader.load(request);
verify(loader).loadBitmapFromDatabase(request);
Assert.assertNull(response);
}
@Test
public void testNothingIsLoadedIfNetworkIsNotSkipped() {
final IconRequest request = Icons.with(RuntimeEnvironment.application)
.pageUrl(TEST_PAGE_URL)
.icon(IconDescriptor.createGenericIcon(TEST_ICON_URL))
@ -36,7 +52,7 @@ public class TestLegacyLoader {
final LegacyLoader loader = spy(new LegacyLoader());
final IconResponse response = loader.load(request);
verify(loader).loadBitmapFromDatabase(request);
verify(loader, never()).loadBitmapFromDatabase(request);
Assert.assertNull(response);
}
@ -62,6 +78,7 @@ public class TestLegacyLoader {
final IconRequest request = Icons.with(RuntimeEnvironment.application)
.pageUrl(TEST_PAGE_URL)
.icon(IconDescriptor.createGenericIcon(TEST_ICON_URL))
.skipNetwork()
.build();
final Bitmap bitmap = mock(Bitmap.class);