package eh;

import android.os.Process;
import eh.b;
import java.util.concurrent.BlockingQueue;

/* loaded from: classes4.dex */
public class c extends Thread {

    /* renamed from: v, reason: collision with root package name */
    private static final boolean f17087v = v.f17151b;

    /* renamed from: p, reason: collision with root package name */
    private final BlockingQueue f17088p;

    /* renamed from: q, reason: collision with root package name */
    private final BlockingQueue f17089q;

    /* renamed from: r, reason: collision with root package name */
    private final b f17090r;

    /* renamed from: s, reason: collision with root package name */
    private final q f17091s;

    /* renamed from: t, reason: collision with root package name */
    private volatile boolean f17092t = false;

    /* renamed from: u, reason: collision with root package name */
    private final w f17093u;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public class a implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ n f17094p;

        a(n nVar) {
            this.f17094p = nVar;
        }

        @Override // java.lang.Runnable
        public void run() {
            try {
                c.this.f17089q.put(this.f17094p);
            } catch (InterruptedException unused) {
                Thread.currentThread().interrupt();
            }
        }
    }

    public c(BlockingQueue blockingQueue, BlockingQueue blockingQueue2, b bVar, q qVar) {
        this.f17088p = blockingQueue;
        this.f17089q = blockingQueue2;
        this.f17090r = bVar;
        this.f17091s = qVar;
        this.f17093u = new w(this, blockingQueue2, qVar);
    }

    private void b() throws InterruptedException {
        c((n) this.f17088p.take());
    }

    void c(n nVar) {
        nVar.e("cache-queue-take");
        nVar.S(1);
        try {
            if (nVar.M()) {
                nVar.u("cache-discard-canceled");
                return;
            }
            b.a aVar = this.f17090r.get(nVar.y());
            if (aVar == null) {
                nVar.e("cache-miss");
                if (!this.f17093u.c(nVar)) {
                    this.f17089q.put(nVar);
                }
                return;
            }
            long currentTimeMillis = System.currentTimeMillis();
            if (aVar.b(currentTimeMillis)) {
                nVar.e("cache-hit-expired");
                nVar.T(aVar);
                if (!this.f17093u.c(nVar)) {
                    this.f17089q.put(nVar);
                }
                return;
            }
            nVar.e("cache-hit");
            p R = nVar.R(new k(aVar.f17079a, aVar.f17085g));
            nVar.e("cache-hit-parsed");
            if (!R.b()) {
                nVar.e("cache-parsing-failed");
                this.f17090r.c(nVar.y(), true);
                nVar.T(null);
                if (!this.f17093u.c(nVar)) {
                    this.f17089q.put(nVar);
                }
                return;
            }
            if (aVar.c(currentTimeMillis)) {
                nVar.e("cache-hit-refresh-needed");
                nVar.T(aVar);
                R.f17147d = true;
                if (this.f17093u.c(nVar)) {
                    this.f17091s.b(nVar, R);
                } else {
                    this.f17091s.c(nVar, R, new a(nVar));
                }
            } else {
                this.f17091s.b(nVar, R);
            }
        } finally {
            nVar.S(2);
        }
    }

    public void d() {
        this.f17092t = true;
        interrupt();
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public void run() {
        if (f17087v) {
            v.e("start new dispatcher", new Object[0]);
        }
        Process.setThreadPriority(10);
        this.f17090r.b();
        while (true) {
            try {
                b();
            } catch (InterruptedException unused) {
                if (this.f17092t) {
                    Thread.currentThread().interrupt();
                    return;
                }
                v.c("Ignoring spurious interrupt of CacheDispatcher thread; use quit() to terminate it", new Object[0]);
            }
        }
    }
}
