Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/CronetUrlRequest.java

Issue 860893002: [Cronet] Allow UrlRequest bypass cache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 mDisableCache = 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 274 }
274 } 275 }
275 for (Pair<String, String> header : mRequestHeaders) { 276 for (Pair<String, String> header : mRequestHeaders) {
276 if (!nativeAddHeader(mUrlRequestAdapter, header.first, 277 if (!nativeAddHeader(mUrlRequestAdapter, header.first,
277 header.second)) { 278 header.second)) {
278 destroyRequestAdapter(); 279 destroyRequestAdapter();
279 throw new IllegalArgumentException("Invalid header " 280 throw new IllegalArgumentException("Invalid header "
280 + header.first + "=" + header.second); 281 + header.first + "=" + header.second);
281 } 282 }
282 } 283 }
284 if (mDisableCache) {
285 nativeDisableCache(mUrlRequestAdapter);
286 }
283 mStarted = true; 287 mStarted = true;
284 nativeStart(mUrlRequestAdapter); 288 nativeStart(mUrlRequestAdapter);
285 } 289 }
286 } 290 }
287 291
288 @Override 292 @Override
289 public void cancel() { 293 public void cancel() {
290 synchronized (mUrlRequestAdapterLock) { 294 synchronized (mUrlRequestAdapterLock) {
291 if (mCanceled || !mStarted) { 295 if (mCanceled || !mStarted) {
292 return; 296 return;
(...skipping 22 matching lines...) Expand all
315 @Override 319 @Override
316 public boolean isPaused() { 320 public boolean isPaused() {
317 return false; 321 return false;
318 } 322 }
319 323
320 @Override 324 @Override
321 public void resume() { 325 public void resume() {
322 throw new UnsupportedOperationException("Not implemented yet"); 326 throw new UnsupportedOperationException("Not implemented yet");
323 } 327 }
324 328
329 @Override
330 public void disableCache() {
331 checkNotStarted();
332 mDisableCache = true;
333 }
334
325 /** 335 /**
326 * Post task to application Executor. Used for Listener callbacks 336 * Post task to application Executor. Used for Listener callbacks
327 * and other tasks that should not be executed on network thread. 337 * and other tasks that should not be executed on network thread.
328 */ 338 */
329 private void postTaskToExecutor(Runnable task) { 339 private void postTaskToExecutor(Runnable task) {
330 mExecutor.execute(task); 340 mExecutor.execute(task);
331 } 341 }
332 342
333 private static int convertRequestPriority(int priority) { 343 private static int convertRequestPriority(int priority) {
334 switch (priority) { 344 switch (priority) {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 private native void nativePopulateResponseHeaders(long urlRequestAdapter, 623 private native void nativePopulateResponseHeaders(long urlRequestAdapter,
614 HeadersList headers); 624 HeadersList headers);
615 625
616 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter); 626 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter);
617 627
618 private native String nativeGetHttpStatusText(long urlRequestAdapter); 628 private native String nativeGetHttpStatusText(long urlRequestAdapter);
619 629
620 private native boolean nativeGetWasCached(long urlRequestAdapter); 630 private native boolean nativeGetWasCached(long urlRequestAdapter);
621 631
622 private native long nativeGetTotalReceivedBytes(long urlRequestAdapter); 632 private native long nativeGetTotalReceivedBytes(long urlRequestAdapter);
633
634 private native void nativeDisableCache(long urlRequestAdapter);
623 } 635 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698