Commit 5801fd5c authored by Rob Wu's avatar Rob Wu Committed by Georg Koppen
Browse files

Bug 1448305 - Avoid disk cache for icons of private tabs. r=JanH

parent 51022a4f
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -84,6 +84,27 @@ public class TestIconRequestBuilder {
        Assert.assertEquals(2, request.getIconCount());
    }

    @Test
    public void testPrivateMode() {
        IconRequest request = Icons.with(RuntimeEnvironment.application)
                .pageUrl(TEST_PAGE_URL_1)
                .build();

        Assert.assertFalse(request.isPrivateMode());

        request.modify()
                .setPrivateMode(true)
                .deferBuild();

        Assert.assertTrue(request.isPrivateMode());

        request.modify()
                .setPrivateMode(false)
                .deferBuild();

        Assert.assertFalse(request.isPrivateMode());
    }

    @Test
    public void testSkipNetwork() {
        IconRequest request = Icons.with(RuntimeEnvironment.application)
+1 −0
Original line number Diff line number Diff line
@@ -443,6 +443,7 @@ public class Tab {
        }

        mRunningIconRequest = mIconRequestBuilder
                .setPrivateMode(isPrivate())
                .build()
                .execute(new IconCallback() {
                    @Override
+9 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ public class IconRequest {
    // Those values are written by the IconRequestBuilder class.
    /* package-private */ String pageUrl;
    /* package-private */ boolean privileged;
    /* package-private */ boolean isPrivate;
    /* package-private */ TreeSet<IconDescriptor> icons;
    /* package-private */ boolean skipNetwork;
    /* package-private */ boolean backgroundThread;
@@ -40,6 +41,7 @@ public class IconRequest {

        // Setting some sensible defaults.
        this.privileged = false;
        this.isPrivate = false;
        this.skipMemory = false;
        this.skipDisk = false;
        this.skipNetwork = false;
@@ -96,6 +98,13 @@ public class IconRequest {
        return privileged;
    }

    /**
     * Is this request initiated from a tab in private browsing mode?
     */
    public boolean isPrivateMode() {
        return isPrivate;
    }

    /**
     * Get the number of icon descriptors associated with this request.
     */
+10 −0
Original line number Diff line number Diff line
@@ -61,6 +61,15 @@ public class IconRequestBuilder {
        return this;
    }

    /**
     * Set the private mode to avoid saving the result to the disk.
     */
    @CheckResult
    public IconRequestBuilder setPrivateMode(boolean isPrivate) {
        internal.isPrivate = isPrivate;
        return this;
    }

    /**
     * Skip the network and do not load an icon from a network connection.
     */
@@ -165,6 +174,7 @@ public class IconRequestBuilder {
        IconRequest request = new IconRequest(internal.getContext());
        request.pageUrl = internal.pageUrl;
        request.privileged = internal.privileged;
        request.isPrivate = internal.isPrivate;
        request.icons = new TreeSet<>(internal.icons);
        request.skipNetwork = internal.skipNetwork;
        request.backgroundThread = internal.backgroundThread;
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import org.mozilla.gecko.util.StringUtils;
public class DiskProcessor implements Processor {
    @Override
    public void process(IconRequest request, IconResponse response) {
        if (request.shouldSkipDisk()) {
        if (request.shouldSkipDisk() || request.isPrivateMode()) {
            return;
        }