package com.parse;

import p137.C2739;
import p137.C2742;
import p137.InterfaceC2741;

/* JADX INFO: loaded from: classes.dex */
public class CachedCurrentInstallationController implements ParseCurrentInstallationController {
    public ParseInstallation currentInstallation;
    public final InstallationId installationId;
    public final ParseObjectStore<ParseInstallation> store;
    public final Object mutex = new Object();
    public final TaskQueue taskQueue = new TaskQueue();

    /* JADX INFO: renamed from: com.parse.CachedCurrentInstallationController$2, reason: invalid class name */
    public class AnonymousClass2 implements InterfaceC2741<Void, C2742<ParseInstallation>> {
        public AnonymousClass2() {
        }

        @Override // p137.InterfaceC2741
        public C2742<ParseInstallation> then(C2742<Void> c2742) {
            return c2742.m4815(new InterfaceC2741<Void, C2742<ParseInstallation>>() { // from class: com.parse.CachedCurrentInstallationController.2.1
                @Override // p137.InterfaceC2741
                public /* bridge */ /* synthetic */ C2742<ParseInstallation> then(C2742<Void> c27422) {
                    return then();
                }

                public C2742 then() {
                    synchronized (CachedCurrentInstallationController.this.mutex) {
                        if (CachedCurrentInstallationController.this.currentInstallation == null) {
                            return CachedCurrentInstallationController.this.store.getAsync().m4809(new InterfaceC2741<ParseInstallation, ParseInstallation>() { // from class: com.parse.CachedCurrentInstallationController.2.1.1
                                /* JADX WARN: Can't rename method to resolve collision */
                                @Override // p137.InterfaceC2741
                                public ParseInstallation then(C2742<ParseInstallation> c27422) {
                                    ParseInstallation parseInstallationM4812 = c27422.m4812();
                                    if (parseInstallationM4812 == null) {
                                        parseInstallationM4812 = (ParseInstallation) ParseObject.create(ParseInstallation.class);
                                        parseInstallationM4812.updateDeviceInfo(CachedCurrentInstallationController.this.installationId);
                                    } else {
                                        CachedCurrentInstallationController.this.installationId.set(parseInstallationM4812.getString("installationId"));
                                        PLog.log(2, "com.parse.CachedCurrentInstallationController", "Successfully deserialized Installation object", null);
                                    }
                                    synchronized (CachedCurrentInstallationController.this.mutex) {
                                        CachedCurrentInstallationController.this.currentInstallation = parseInstallationM4812;
                                    }
                                    return parseInstallationM4812;
                                }
                            }, ParseExecutors.io(), (C2739) null);
                        }
                        return C2742.m4805(CachedCurrentInstallationController.this.currentInstallation);
                    }
                }
            }, C2742.f8455, null);
        }
    }

    public CachedCurrentInstallationController(ParseObjectStore<ParseInstallation> parseObjectStore, InstallationId installationId) {
        this.store = parseObjectStore;
        this.installationId = installationId;
    }

    @Override // com.parse.ParseObjectCurrentController
    public void clearFromMemory() {
        synchronized (this.mutex) {
            this.currentInstallation = null;
        }
    }

    @Override // com.parse.ParseObjectCurrentController
    public C2742<ParseInstallation> getAsync() {
        synchronized (this.mutex) {
            if (this.currentInstallation == null) {
                return this.taskQueue.enqueue(new AnonymousClass2());
            }
            return C2742.m4805(this.currentInstallation);
        }
    }

    @Override // com.parse.ParseObjectCurrentController
    public boolean isCurrent(ParseInstallation parseInstallation) {
        boolean z;
        synchronized (this.mutex) {
            z = this.currentInstallation == parseInstallation;
        }
        return z;
    }

    @Override // com.parse.ParseObjectCurrentController
    public C2742 setAsync(ParseObject parseObject) {
        final ParseInstallation parseInstallation = (ParseInstallation) parseObject;
        return !isCurrent(parseInstallation) ? C2742.m4805((Object) null) : this.taskQueue.enqueue(new InterfaceC2741<Void, C2742<Void>>() { // from class: com.parse.CachedCurrentInstallationController.1
            @Override // p137.InterfaceC2741
            public C2742<Void> then(C2742<Void> c2742) {
                return c2742.m4815(new InterfaceC2741<Void, C2742<Void>>() { // from class: com.parse.CachedCurrentInstallationController.1.2
                    @Override // p137.InterfaceC2741
                    public C2742<Void> then(C2742<Void> c27422) {
                        AnonymousClass1 anonymousClass1 = AnonymousClass1.this;
                        return CachedCurrentInstallationController.this.store.setAsync(parseInstallation);
                    }
                }, C2742.f8455, null).m4815(new InterfaceC2741<Void, C2742<Void>>() { // from class: com.parse.CachedCurrentInstallationController.1.1
                    @Override // p137.InterfaceC2741
                    public C2742<Void> then(C2742<Void> c27422) {
                        AnonymousClass1 anonymousClass1 = AnonymousClass1.this;
                        CachedCurrentInstallationController.this.installationId.set(parseInstallation.getString("installationId"));
                        return c27422;
                    }
                }, ParseExecutors.io(), null);
            }
        });
    }
}
