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

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

Issue 1492583002: Add HttpUrlConnection backed implementation of CronetEngine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years 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 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 229 }
230 } 230 }
231 231
232 @Override 232 @Override
233 public void read(ByteBuffer buffer) { 233 public void read(ByteBuffer buffer) {
234 synchronized (mUrlRequestAdapterLock) { 234 synchronized (mUrlRequestAdapterLock) {
235 if (buffer.position() >= buffer.capacity()) { 235 if (buffer.position() >= buffer.capacity()) {
236 throw new IllegalArgumentException( 236 throw new IllegalArgumentException(
237 "ByteBuffer is already full."); 237 "ByteBuffer is already full.");
238 } 238 }
239 Preconditions.checkDirect(buffer);
239 240
240 if (!mWaitingOnRead) { 241 if (!mWaitingOnRead) {
241 throw new IllegalStateException("Unexpected read attempt."); 242 throw new IllegalStateException("Unexpected read attempt.");
242 } 243 }
243 mWaitingOnRead = false; 244 mWaitingOnRead = false;
244 mLegacyReadByteBufferAdjustment = true; 245 mLegacyReadByteBufferAdjustment = true;
245 246
246 if (isDone()) { 247 if (isDone()) {
247 return; 248 return;
248 } 249 }
249 250
250 // Indicate buffer has no new data. This is primarily to make it 251 // Indicate buffer has no new data. This is primarily to make it
251 // clear the buffer has no data in the failure and completion cases. 252 // clear the buffer has no data in the failure and completion cases.
252 buffer.limit(buffer.position()); 253 buffer.limit(buffer.position());
253 254
254 if (!nativeReadData(mUrlRequestAdapter, buffer, buffer.position(), 255 if (!nativeReadData(mUrlRequestAdapter, buffer, buffer.position(),
255 buffer.capacity())) { 256 buffer.capacity())) {
256 // Still waiting on read. This is just to have consistent 257 // Still waiting on read. This is just to have consistent
257 // behavior with the other error cases. 258 // behavior with the other error cases.
258 mWaitingOnRead = true; 259 mWaitingOnRead = true;
259 // Since accessing byteBuffer's memory failed, it's presumably 260 throw new IllegalArgumentException("Unable to call native read") ;
260 // not a direct ByteBuffer.
261 throw new IllegalArgumentException(
262 "byteBuffer must be a direct ByteBuffer.");
263 } 261 }
264 } 262 }
265 } 263 }
266 264
267 @Override 265 @Override
268 public void readNew(ByteBuffer buffer) { 266 public void readNew(ByteBuffer buffer) {
267 Preconditions.checkHasRemaining(buffer);
268 Preconditions.checkDirect(buffer);
269 synchronized (mUrlRequestAdapterLock) { 269 synchronized (mUrlRequestAdapterLock) {
270 if (!buffer.hasRemaining()) {
271 throw new IllegalArgumentException("ByteBuffer is already full." );
272 }
273
274 if (!mWaitingOnRead) { 270 if (!mWaitingOnRead) {
275 throw new IllegalStateException("Unexpected read attempt."); 271 throw new IllegalStateException("Unexpected read attempt.");
276 } 272 }
277 mWaitingOnRead = false; 273 mWaitingOnRead = false;
278 mLegacyReadByteBufferAdjustment = false; 274 mLegacyReadByteBufferAdjustment = false;
279 275
280 if (isDone()) { 276 if (isDone()) {
281 return; 277 return;
282 } 278 }
283 279
284 if (!nativeReadData(mUrlRequestAdapter, buffer, buffer.position(), b uffer.limit())) { 280 if (!nativeReadData(mUrlRequestAdapter, buffer, buffer.position(), b uffer.limit())) {
285 // Still waiting on read. This is just to have consistent 281 // Still waiting on read. This is just to have consistent
286 // behavior with the other error cases. 282 // behavior with the other error cases.
287 mWaitingOnRead = true; 283 mWaitingOnRead = true;
288 // Since accessing byteBuffer's memory failed, it's presumably 284 throw new IllegalArgumentException("Unable to call native read") ;
289 // not a direct ByteBuffer.
290 throw new IllegalArgumentException("byteBuffer must be a direct ByteBuffer.");
291 } 285 }
292 } 286 }
293 } 287 }
294 288
295 @Override 289 @Override
296 public void cancel() { 290 public void cancel() {
297 synchronized (mUrlRequestAdapterLock) { 291 synchronized (mUrlRequestAdapterLock) {
298 if (isDone() || !mStarted) { 292 if (isDone() || !mStarted) {
299 return; 293 return;
300 } 294 }
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 704
711 @NativeClassQualifiedName("CronetURLRequestAdapter") 705 @NativeClassQualifiedName("CronetURLRequestAdapter")
712 private native String nativeGetProxyServer(long nativePtr); 706 private native String nativeGetProxyServer(long nativePtr);
713 707
714 @NativeClassQualifiedName("CronetURLRequestAdapter") 708 @NativeClassQualifiedName("CronetURLRequestAdapter")
715 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener); 709 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener);
716 710
717 @NativeClassQualifiedName("CronetURLRequestAdapter") 711 @NativeClassQualifiedName("CronetURLRequestAdapter")
718 private native boolean nativeGetWasCached(long nativePtr); 712 private native boolean nativeGetWasCached(long nativePtr);
719 } 713 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698