| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.util.Log; | 7 import android.util.Log; |
| 8 import android.util.Pair; | 8 import android.util.Pair; |
| 9 | 9 |
| 10 import org.chromium.base.CalledByNative; | 10 import org.chromium.base.CalledByNative; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * native tasks to native network thread. Because Cancel could be called from | 27 * native tasks to native network thread. Because Cancel could be called from |
| 28 * any thread it is protected by mUrlRequestAdapterLock. | 28 * any thread it is protected by mUrlRequestAdapterLock. |
| 29 */ | 29 */ |
| 30 @JNINamespace("cronet") | 30 @JNINamespace("cronet") |
| 31 final class CronetUrlRequest implements UrlRequest { | 31 final class CronetUrlRequest implements UrlRequest { |
| 32 /* Native adapter object, owned by UrlRequest. */ | 32 /* Native adapter object, owned by UrlRequest. */ |
| 33 private long mUrlRequestAdapter; | 33 private long mUrlRequestAdapter; |
| 34 private boolean mStarted = false; | 34 private boolean mStarted = false; |
| 35 private boolean mCanceled = false; | 35 private boolean mCanceled = false; |
| 36 private boolean mInOnDataReceived = false; | 36 private boolean mInOnDataReceived = false; |
| 37 private boolean mBypassCache = false; |
| 37 | 38 |
| 38 /* | 39 /* |
| 39 * Synchronize access to mUrlRequestAdapter, mStarted, mCanceled and | 40 * Synchronize access to mUrlRequestAdapter, mStarted, mCanceled and |
| 40 * mDestroyAfterReading. | 41 * mDestroyAfterReading. |
| 41 */ | 42 */ |
| 42 private final Object mUrlRequestAdapterLock = new Object(); | 43 private final Object mUrlRequestAdapterLock = new Object(); |
| 43 private final CronetUrlRequestContext mRequestContext; | 44 private final CronetUrlRequestContext mRequestContext; |
| 44 private final Executor mExecutor; | 45 private final Executor mExecutor; |
| 45 | 46 |
| 46 /* | 47 /* |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 264 } |
| 264 } | 265 } |
| 265 for (Pair<String, String> header : mRequestHeaders) { | 266 for (Pair<String, String> header : mRequestHeaders) { |
| 266 if (!nativeAddHeader(mUrlRequestAdapter, header.first, | 267 if (!nativeAddHeader(mUrlRequestAdapter, header.first, |
| 267 header.second)) { | 268 header.second)) { |
| 268 destroyRequestAdapter(); | 269 destroyRequestAdapter(); |
| 269 throw new IllegalArgumentException("Invalid header " | 270 throw new IllegalArgumentException("Invalid header " |
| 270 + header.first + "=" + header.second); | 271 + header.first + "=" + header.second); |
| 271 } | 272 } |
| 272 } | 273 } |
| 274 if (mBypassCache) { |
| 275 nativeBypassCache(mUrlRequestAdapter); |
| 276 } |
| 273 mStarted = true; | 277 mStarted = true; |
| 274 nativeStart(mUrlRequestAdapter); | 278 nativeStart(mUrlRequestAdapter); |
| 275 } | 279 } |
| 276 } | 280 } |
| 277 | 281 |
| 278 @Override | 282 @Override |
| 279 public void cancel() { | 283 public void cancel() { |
| 280 synchronized (mUrlRequestAdapterLock) { | 284 synchronized (mUrlRequestAdapterLock) { |
| 281 if (mCanceled || !mStarted) { | 285 if (mCanceled || !mStarted) { |
| 282 return; | 286 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 305 @Override | 309 @Override |
| 306 public boolean isPaused() { | 310 public boolean isPaused() { |
| 307 return false; | 311 return false; |
| 308 } | 312 } |
| 309 | 313 |
| 310 @Override | 314 @Override |
| 311 public void resume() { | 315 public void resume() { |
| 312 throw new UnsupportedOperationException("Not implemented yet"); | 316 throw new UnsupportedOperationException("Not implemented yet"); |
| 313 } | 317 } |
| 314 | 318 |
| 319 @Override |
| 320 public void bypassCache() { |
| 321 checkNotStarted(); |
| 322 mBypassCache = true; |
| 323 } |
| 324 |
| 315 /** | 325 /** |
| 316 * Post task to application Executor. Used for Listener callbacks | 326 * Post task to application Executor. Used for Listener callbacks |
| 317 * and other tasks that should not be executed on network thread. | 327 * and other tasks that should not be executed on network thread. |
| 318 */ | 328 */ |
| 319 private void postTaskToExecutor(Runnable task) { | 329 private void postTaskToExecutor(Runnable task) { |
| 320 mExecutor.execute(task); | 330 mExecutor.execute(task); |
| 321 } | 331 } |
| 322 | 332 |
| 323 private static int convertRequestPriority(int priority) { | 333 private static int convertRequestPriority(int priority) { |
| 324 switch (priority) { | 334 switch (priority) { |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 private native void nativePopulateResponseHeaders(long urlRequestAdapter, | 613 private native void nativePopulateResponseHeaders(long urlRequestAdapter, |
| 604 HeadersList headers); | 614 HeadersList headers); |
| 605 | 615 |
| 606 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter); | 616 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter); |
| 607 | 617 |
| 608 private native String nativeGetHttpStatusText(long urlRequestAdapter); | 618 private native String nativeGetHttpStatusText(long urlRequestAdapter); |
| 609 | 619 |
| 610 private native boolean nativeGetWasCached(long urlRequestAdapter); | 620 private native boolean nativeGetWasCached(long urlRequestAdapter); |
| 611 | 621 |
| 612 private native long nativeGetTotalReceivedBytes(long urlRequestAdapter); | 622 private native long nativeGetTotalReceivedBytes(long urlRequestAdapter); |
| 623 |
| 624 private native void nativeBypassCache(long urlRequestAdapter); |
| 613 } | 625 } |
| OLD | NEW |