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

import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;

/* JADX INFO: loaded from: classes2.dex */
public final class pc {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final HashMap f15363a = new HashMap();

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

    @Nullable
    private final ac zzb;

    @Nullable
    private final BlockingQueue zzc;

    public pc(ac acVar, PriorityBlockingQueue priorityBlockingQueue, ru ruVar) {
        this.f15364b = ruVar;
        this.zzb = acVar;
        this.zzc = priorityBlockingQueue;
    }

    public final synchronized void a(gc gcVar) {
        try {
            HashMap map = this.f15363a;
            String strD = gcVar.d();
            List list = (List) map.remove(strD);
            if (list == null || list.isEmpty()) {
                return;
            }
            if (oc.f15004a) {
                oc.a("%d waiting requests for cacheKey=%s; resend to network", Integer.valueOf(list.size()), strD);
            }
            gc gcVar2 = (gc) list.remove(0);
            map.put(strD, list);
            synchronized (gcVar2.f11699e) {
                gcVar2.f11703i = this;
            }
            try {
                this.zzc.put(gcVar2);
            } catch (InterruptedException e10) {
                oc.b("Couldn't add request to queue. %s", e10.toString());
                Thread.currentThread().interrupt();
                ac acVar = this.zzb;
                acVar.f8622d = true;
                acVar.interrupt();
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized boolean b(gc gcVar) {
        try {
            HashMap map = this.f15363a;
            String strD = gcVar.d();
            if (!map.containsKey(strD)) {
                map.put(strD, null);
                synchronized (gcVar.f11699e) {
                    gcVar.f11703i = this;
                }
                if (oc.f15004a) {
                    oc.b("new request, sending to network %s", strD);
                }
                return false;
            }
            List arrayList = (List) map.get(strD);
            if (arrayList == null) {
                arrayList = new ArrayList();
            }
            gcVar.a("waiting-for-response");
            arrayList.add(gcVar);
            map.put(strD, arrayList);
            if (oc.f15004a) {
                oc.b("Request for cacheKey=%s is in flight, putting on hold.", strD);
            }
            return true;
        } catch (Throwable th) {
            throw th;
        }
    }
}
