summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/icons/processing/DiskProcessor.java
blob: 150aa503b83e1bf7b2aafeb3dda836d0603619eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.mozilla.gecko.icons.processing;

import org.mozilla.gecko.icons.IconRequest;
import org.mozilla.gecko.icons.IconResponse;
import org.mozilla.gecko.icons.storage.DiskStorage;
import org.mozilla.gecko.util.StringUtils;

public class DiskProcessor implements Processor {
    @Override
    public void process(IconRequest request, IconResponse response) {
        if (request.shouldSkipDisk()) {
            return;
        }

        if (!response.hasUrl() || !StringUtils.isHttpOrHttps(response.getUrl())) {
            // If the response does not contain an URL from which the icon was loaded or if this is
            // not a http(s) URL then we cannot store this or do not need to (because it's already
            // stored somewhere else, like for URLs pointing inside the omni.ja).
            return;
        }

        final DiskStorage storage = DiskStorage.get(request.getContext());

        if (response.isFromNetwork()) {
            // The icon has been loaded from the network. Store it on the disk now.
            storage.putIcon(response);
        }

        if (response.isFromMemory() || response.isFromDisk() || response.isFromNetwork()) {
            // Remember mapping between page URL and storage URL. Even when this icon has been loaded
            // from memory or disk this does not mean that we stored this mapping already: We could
            // have loaded this icon for a different page URL previously.
            storage.putMapping(request, response.getUrl());
        }
    }
}