| 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 | 8 |
| 9 import org.chromium.base.VisibleForTesting; | 9 import org.chromium.base.VisibleForTesting; |
| 10 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // Since accessing byteBuffer's memory failed, it's presumably | 259 // Since accessing byteBuffer's memory failed, it's presumably |
| 260 // not a direct ByteBuffer. | 260 // not a direct ByteBuffer. |
| 261 throw new IllegalArgumentException( | 261 throw new IllegalArgumentException( |
| 262 "byteBuffer must be a direct ByteBuffer."); | 262 "byteBuffer must be a direct ByteBuffer."); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 @Override | 267 @Override |
| 268 public void readNew(ByteBuffer buffer) { | 268 public void readNew(ByteBuffer buffer) { |
| 269 Preconditions.checkHasRemaining(buffer); |
| 270 Preconditions.checkDirect(buffer); |
| 269 synchronized (mUrlRequestAdapterLock) { | 271 synchronized (mUrlRequestAdapterLock) { |
| 270 if (!buffer.hasRemaining()) { | |
| 271 throw new IllegalArgumentException("ByteBuffer is already full."
); | |
| 272 } | |
| 273 | |
| 274 if (!mWaitingOnRead) { | 272 if (!mWaitingOnRead) { |
| 275 throw new IllegalStateException("Unexpected read attempt."); | 273 throw new IllegalStateException("Unexpected read attempt."); |
| 276 } | 274 } |
| 277 mWaitingOnRead = false; | 275 mWaitingOnRead = false; |
| 278 mLegacyReadByteBufferAdjustment = false; | 276 mLegacyReadByteBufferAdjustment = false; |
| 279 | 277 |
| 280 if (isDone()) { | 278 if (isDone()) { |
| 281 return; | 279 return; |
| 282 } | 280 } |
| 283 | 281 |
| 284 if (!nativeReadData(mUrlRequestAdapter, buffer, buffer.position(), b
uffer.limit())) { | 282 if (!nativeReadData(mUrlRequestAdapter, buffer, buffer.position(), b
uffer.limit())) { |
| 285 // Still waiting on read. This is just to have consistent | 283 // Still waiting on read. This is just to have consistent |
| 286 // behavior with the other error cases. | 284 // behavior with the other error cases. |
| 287 mWaitingOnRead = true; | 285 mWaitingOnRead = true; |
| 288 // Since accessing byteBuffer's memory failed, it's presumably | 286 // Since accessing byteBuffer's memory failed, it's presumably |
| 289 // not a direct ByteBuffer. | 287 // not a direct ByteBuffer. |
| 290 throw new IllegalArgumentException("byteBuffer must be a direct
ByteBuffer."); | 288 throw new IllegalArgumentException("Unable to call native read")
; |
| 291 } | 289 } |
| 292 } | 290 } |
| 293 } | 291 } |
| 294 | 292 |
| 295 @Override | 293 @Override |
| 296 public void cancel() { | 294 public void cancel() { |
| 297 synchronized (mUrlRequestAdapterLock) { | 295 synchronized (mUrlRequestAdapterLock) { |
| 298 if (isDone() || !mStarted) { | 296 if (isDone() || !mStarted) { |
| 299 return; | 297 return; |
| 300 } | 298 } |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 | 708 |
| 711 @NativeClassQualifiedName("CronetURLRequestAdapter") | 709 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 712 private native String nativeGetProxyServer(long nativePtr); | 710 private native String nativeGetProxyServer(long nativePtr); |
| 713 | 711 |
| 714 @NativeClassQualifiedName("CronetURLRequestAdapter") | 712 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 715 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); | 713 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); |
| 716 | 714 |
| 717 @NativeClassQualifiedName("CronetURLRequestAdapter") | 715 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 718 private native boolean nativeGetWasCached(long nativePtr); | 716 private native boolean nativeGetWasCached(long nativePtr); |
| 719 } | 717 } |
| OLD | NEW |