MessageLoop.smali

.class Laegon/chrome/net/urlconnection/MessageLoop;
.super Ljava/lang/Object;

# interfaces
.implements Ljava/util/concurrent/Executor;


# static fields
.field static final synthetic $assertionsDisabled:Z

.field private static final INVALID_THREAD_ID:J = -0x1L


# instance fields
.field private mLoopFailed:Z

.field private mLoopRunning:Z

.field private mPriorInterruptedIOException:Ljava/io/InterruptedIOException;

.field private mPriorRuntimeException:Ljava/lang/RuntimeException;

.field private final mQueue:Ljava/util/concurrent/BlockingQueue;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/concurrent/BlockingQueue",
            "<",
            "Ljava/lang/Runnable;",
            ">;"
        }
    .end annotation
.end field

.field private mThreadId:J


# direct methods
.method static constructor <clinit>()V
    .registers 1

    const-class v0, Laegon/chrome/net/urlconnection/MessageLoop;

    invoke-virtual {v0}, Ljava/lang/Class;->desiredAssertionStatus()Z

    move-result v0

    if-nez v0, :cond_c

    const/4 v0, 0x1

    :goto_9
    sput-boolean v0, Laegon/chrome/net/urlconnection/MessageLoop;->$assertionsDisabled:Z

    return-void

    :cond_c
    const/4 v0, 0x0

    goto :goto_9
.end method

.method constructor <init>()V
    .registers 3

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    const-wide/16 v0, -0x1

    iput-wide v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mThreadId:J

    new-instance v0, Ljava/util/concurrent/LinkedBlockingQueue;

    invoke-direct {v0}, Ljava/util/concurrent/LinkedBlockingQueue;-><init>()V

    iput-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mQueue:Ljava/util/concurrent/BlockingQueue;

    return-void
.end method

.method private calledOnValidThread()Z
    .registers 7

    const/4 v0, 0x1

    iget-wide v2, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mThreadId:J

    const-wide/16 v4, -0x1

    cmp-long v1, v2, v4

    if-nez v1, :cond_14

    invoke-static {}, Ljava/lang/Thread;->currentThread()Ljava/lang/Thread;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/Thread;->getId()J

    move-result-wide v2

    iput-wide v2, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mThreadId:J

    :cond_13
    :goto_13
    return v0

    :cond_14
    iget-wide v2, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mThreadId:J

    invoke-static {}, Ljava/lang/Thread;->currentThread()Ljava/lang/Thread;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/Thread;->getId()J

    move-result-wide v4

    cmp-long v1, v2, v4

    if-eqz v1, :cond_13

    const/4 v0, 0x0

    goto :goto_13
.end method

.method private take(ZJ)Ljava/lang/Runnable;
    .registers 6

    if-nez p1, :cond_12

    :try_start_2
    iget-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mQueue:Ljava/util/concurrent/BlockingQueue;

    invoke-interface {v0}, Ljava/util/concurrent/BlockingQueue;->take()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Runnable;
    :try_end_a
    .catch Ljava/lang/InterruptedException; {:try_start_2 .. :try_end_a} :catch_1d

    :goto_a
    if-nez v0, :cond_27

    new-instance v0, Ljava/net/SocketTimeoutException;

    invoke-direct {v0}, Ljava/net/SocketTimeoutException;-><init>()V

    throw v0

    :cond_12
    :try_start_12
    iget-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mQueue:Ljava/util/concurrent/BlockingQueue;

    sget-object v1, Ljava/util/concurrent/TimeUnit;->NANOSECONDS:Ljava/util/concurrent/TimeUnit;

    invoke-interface {v0, p2, p3, v1}, Ljava/util/concurrent/BlockingQueue;->poll(JLjava/util/concurrent/TimeUnit;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Runnable;
    :try_end_1c
    .catch Ljava/lang/InterruptedException; {:try_start_12 .. :try_end_1c} :catch_1d

    goto :goto_a

    :catch_1d
    move-exception v0

    new-instance v1, Ljava/io/InterruptedIOException;

    invoke-direct {v1}, Ljava/io/InterruptedIOException;-><init>()V

    invoke-virtual {v1, v0}, Ljava/io/InterruptedIOException;->initCause(Ljava/lang/Throwable;)Ljava/lang/Throwable;

    throw v1

    :cond_27
    return-object v0
.end method


# virtual methods
.method public execute(Ljava/lang/Runnable;)V
    .registers 4

    if-nez p1, :cond_8

    new-instance v0, Ljava/lang/IllegalArgumentException;

    invoke-direct {v0}, Ljava/lang/IllegalArgumentException;-><init>()V

    throw v0

    :cond_8
    :try_start_8
    iget-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mQueue:Ljava/util/concurrent/BlockingQueue;

    invoke-interface {v0, p1}, Ljava/util/concurrent/BlockingQueue;->put(Ljava/lang/Object;)V
    :try_end_d
    .catch Ljava/lang/InterruptedException; {:try_start_8 .. :try_end_d} :catch_e

    return-void

    :catch_e
    move-exception v0

    new-instance v1, Ljava/util/concurrent/RejectedExecutionException;

    invoke-direct {v1, v0}, Ljava/util/concurrent/RejectedExecutionException;-><init>(Ljava/lang/Throwable;)V

    throw v1
.end method

.method public hasLoopFailed()Z
    .registers 2

    iget-boolean v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopFailed:Z

    return v0
.end method

.method public isRunning()Z
    .registers 2

    iget-boolean v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopRunning:Z

    return v0
.end method

.method public loop()V
    .registers 2

    const/4 v0, 0x0

    invoke-virtual {p0, v0}, Laegon/chrome/net/urlconnection/MessageLoop;->loop(I)V

    return-void
.end method

.method public loop(I)V
    .registers 12

    const/4 v9, 0x0

    const/4 v8, 0x1

    sget-boolean v0, Laegon/chrome/net/urlconnection/MessageLoop;->$assertionsDisabled:Z

    if-nez v0, :cond_12

    invoke-direct {p0}, Laegon/chrome/net/urlconnection/MessageLoop;->calledOnValidThread()Z

    move-result v0

    if-nez v0, :cond_12

    new-instance v0, Ljava/lang/AssertionError;

    invoke-direct {v0}, Ljava/lang/AssertionError;-><init>()V

    throw v0

    :cond_12
    invoke-static {}, Ljava/lang/System;->nanoTime()J

    move-result-wide v0

    sget-object v2, Ljava/util/concurrent/TimeUnit;->NANOSECONDS:Ljava/util/concurrent/TimeUnit;

    int-to-long v4, p1

    sget-object v3, Ljava/util/concurrent/TimeUnit;->MILLISECONDS:Ljava/util/concurrent/TimeUnit;

    invoke-virtual {v2, v4, v5, v3}, Ljava/util/concurrent/TimeUnit;->convert(JLjava/util/concurrent/TimeUnit;)J

    move-result-wide v2

    iget-boolean v4, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopFailed:Z

    if-eqz v4, :cond_2d

    iget-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mPriorInterruptedIOException:Ljava/io/InterruptedIOException;

    if-eqz v0, :cond_2a

    iget-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mPriorInterruptedIOException:Ljava/io/InterruptedIOException;

    throw v0

    :cond_2a
    iget-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mPriorRuntimeException:Ljava/lang/RuntimeException;

    throw v0

    :cond_2d
    iget-boolean v4, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopRunning:Z

    if-eqz v4, :cond_39

    new-instance v0, Ljava/lang/IllegalStateException;

    const-string v1, "Cannot run loop when it is already running."

    invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V

    throw v0

    :cond_39
    iput-boolean v8, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopRunning:Z

    :goto_3b
    iget-boolean v4, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopRunning:Z

    if-eqz v4, :cond_6c

    if-nez p1, :cond_54

    const/4 v4, 0x0

    const-wide/16 v6, 0x0

    :try_start_44
    invoke-direct {p0, v4, v6, v7}, Laegon/chrome/net/urlconnection/MessageLoop;->take(ZJ)Ljava/lang/Runnable;

    move-result-object v4

    invoke-interface {v4}, Ljava/lang/Runnable;->run()V
    :try_end_4b
    .catch Ljava/io/InterruptedIOException; {:try_start_44 .. :try_end_4b} :catch_4c
    .catch Ljava/lang/RuntimeException; {:try_start_44 .. :try_end_4b} :catch_64

    goto :goto_3b

    :catch_4c
    move-exception v0

    iput-boolean v9, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopRunning:Z

    iput-boolean v8, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopFailed:Z

    iput-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mPriorInterruptedIOException:Ljava/io/InterruptedIOException;

    throw v0

    :cond_54
    const/4 v4, 0x1

    :try_start_55
    invoke-static {}, Ljava/lang/System;->nanoTime()J

    move-result-wide v6

    sub-long v6, v2, v6

    add-long/2addr v6, v0

    invoke-direct {p0, v4, v6, v7}, Laegon/chrome/net/urlconnection/MessageLoop;->take(ZJ)Ljava/lang/Runnable;

    move-result-object v4

    invoke-interface {v4}, Ljava/lang/Runnable;->run()V
    :try_end_63
    .catch Ljava/io/InterruptedIOException; {:try_start_55 .. :try_end_63} :catch_4c
    .catch Ljava/lang/RuntimeException; {:try_start_55 .. :try_end_63} :catch_64

    goto :goto_3b

    :catch_64
    move-exception v0

    iput-boolean v9, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopRunning:Z

    iput-boolean v8, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopFailed:Z

    iput-object v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mPriorRuntimeException:Ljava/lang/RuntimeException;

    throw v0

    :cond_6c
    return-void
.end method

.method public quit()V
    .registers 2

    sget-boolean v0, Laegon/chrome/net/urlconnection/MessageLoop;->$assertionsDisabled:Z

    if-nez v0, :cond_10

    invoke-direct {p0}, Laegon/chrome/net/urlconnection/MessageLoop;->calledOnValidThread()Z

    move-result v0

    if-nez v0, :cond_10

    new-instance v0, Ljava/lang/AssertionError;

    invoke-direct {v0}, Ljava/lang/AssertionError;-><init>()V

    throw v0

    :cond_10
    const/4 v0, 0x0

    iput-boolean v0, p0, Laegon/chrome/net/urlconnection/MessageLoop;->mLoopRunning:Z

    return-void
.end method