package com.google.android.gms.internal.ads;

import android.os.Process;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;

/* JADX INFO: loaded from: classes2.dex */
public final class ac extends Thread {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final boolean f8618g = oc.f15004a;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final BlockingQueue f8619a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final BlockingQueue f8620b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final zb f8621c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public volatile boolean f8622d = false;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final pc f8623e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final ru f8624f;

    public ac(PriorityBlockingQueue priorityBlockingQueue, PriorityBlockingQueue priorityBlockingQueue2, zb zbVar, ru ruVar) {
        this.f8619a = priorityBlockingQueue;
        this.f8620b = priorityBlockingQueue2;
        this.f8621c = zbVar;
        this.f8624f = ruVar;
        this.f8623e = new pc(this, priorityBlockingQueue2, ruVar);
    }

    public final void a() {
        gc gcVar = (gc) this.f8619a.take();
        gcVar.a("cache-queue-take");
        gcVar.c(1);
        try {
            synchronized (gcVar.f11699e) {
            }
            vc vcVar = (vc) this.f8621c;
            yb ybVarZza = vcVar.zza(gcVar.d());
            if (ybVarZza == null) {
                gcVar.a("cache-miss");
                if (!this.f8623e.b(gcVar)) {
                    this.f8620b.put(gcVar);
                }
            } else {
                long jCurrentTimeMillis = System.currentTimeMillis();
                if (ybVarZza.f18783e < jCurrentTimeMillis) {
                    gcVar.a("cache-hit-expired");
                    gcVar.e(ybVarZza);
                    if (!this.f8623e.b(gcVar)) {
                        this.f8620b.put(gcVar);
                    }
                } else {
                    gcVar.a("cache-hit");
                    lc lcVarI = gcVar.i(new fc(ybVarZza.f18779a, ybVarZza.f18785g));
                    gcVar.a("cache-hit-parsed");
                    if (!(lcVarI.zzc == null)) {
                        gcVar.a("cache-parsing-failed");
                        String strD = gcVar.d();
                        synchronized (vcVar) {
                            try {
                                yb ybVarZza2 = vcVar.zza(strD);
                                if (ybVarZza2 != null) {
                                    ybVarZza2.f18784f = 0L;
                                    ybVarZza2.f18783e = 0L;
                                    vcVar.a(strD, ybVarZza2);
                                }
                            } finally {
                            }
                        }
                        gcVar.e(null);
                        if (!this.f8623e.b(gcVar)) {
                            this.f8620b.put(gcVar);
                        }
                    } else if (ybVarZza.f18784f < jCurrentTimeMillis) {
                        gcVar.a("cache-hit-refresh-needed");
                        gcVar.e(ybVarZza);
                        lcVarI.f13618a = true;
                        if (this.f8623e.b(gcVar)) {
                            this.f8624f.g(gcVar, lcVarI, null);
                        } else {
                            this.f8624f.g(gcVar, lcVarI, new bv(this, gcVar));
                        }
                    } else {
                        this.f8624f.g(gcVar, lcVarI, null);
                    }
                }
            }
            gcVar.c(2);
        } catch (Throwable th) {
            gcVar.c(2);
            throw th;
        }
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public final void run() {
        if (f8618g) {
            oc.a("start new dispatcher", new Object[0]);
        }
        Process.setThreadPriority(10);
        ((vc) this.f8621c).b();
        while (true) {
            try {
                a();
            } catch (InterruptedException unused) {
                if (this.f8622d) {
                    Thread.currentThread().interrupt();
                    return;
                }
                oc.b("Ignoring spurious interrupt of CacheDispatcher thread; use quit() to terminate it", new Object[0]);
            }
        }
    }
}
