Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.impl; | 5 package org.chromium.net.impl; |
| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 | 301 |
| 302 /** | 302 /** |
| 303 * Initializes upload length by getting it from data provider. Always called | 303 * Initializes upload length by getting it from data provider. Always called |
| 304 * on executor thread to allow getLength() to block and/or report errors. | 304 * on executor thread to allow getLength() to block and/or report errors. |
| 305 * If data provider throws an exception, then it is reported to the request. | 305 * If data provider throws an exception, then it is reported to the request. |
| 306 * No native calls to urlRequest are allowed as this is done before request | 306 * No native calls to urlRequest are allowed as this is done before request |
| 307 * start, so native object may not exist. | 307 * start, so native object may not exist. |
| 308 */ | 308 */ |
| 309 void initializeWithRequest(final CronetUrlRequest urlRequest) { | 309 void initializeWithRequest(final CronetUrlRequest urlRequest, final Runnable callback) { |
| 310 synchronized (mLock) { | 310 synchronized (mLock) { |
| 311 mRequest = urlRequest; | 311 mRequest = urlRequest; |
| 312 mInWhichUserCallback = UserCallback.GET_LENGTH; | |
| 313 } | 312 } |
| 314 try { | 313 postTaskToExecutor(new Runnable() { |
|
mef
2016/08/30 16:29:45
this is already on executor thread, why do you nee
Charles
2016/08/30 20:11:06
It's not on the executor thread any more.
mef
2016/08/31 17:26:52
Acknowledged. Please update comment.
Charles
2016/08/31 19:08:36
Done.
| |
| 315 mLength = mDataProvider.getLength(); | 314 @Override |
| 316 mRemainingLength = mLength; | 315 public void run() { |
| 317 } catch (Throwable t) { | 316 synchronized (mLock) { |
| 318 onError(t); | 317 mInWhichUserCallback = UserCallback.GET_LENGTH; |
| 319 } | 318 } |
| 320 synchronized (mLock) { | 319 try { |
| 321 mInWhichUserCallback = UserCallback.NOT_IN_CALLBACK; | 320 mLength = mDataProvider.getLength(); |
| 322 } | 321 mRemainingLength = mLength; |
| 322 } catch (Throwable t) { | |
| 323 onError(t); | |
| 324 } | |
| 325 synchronized (mLock) { | |
| 326 mInWhichUserCallback = UserCallback.NOT_IN_CALLBACK; | |
| 327 } | |
| 328 callback.run(); | |
| 329 } | |
| 330 }); | |
| 323 } | 331 } |
| 324 | 332 |
| 325 /** | 333 /** |
| 326 * Creates native objects and attaches them to the underlying request | 334 * Creates native objects and attaches them to the underlying request |
| 327 * adapter object. Always called on executor thread. | 335 * adapter object. Always called on executor thread. |
| 328 */ | 336 */ |
| 329 void attachNativeAdapterToRequest(final long requestAdapter) { | 337 void attachNativeAdapterToRequest(final long requestAdapter) { |
| 330 synchronized (mLock) { | 338 synchronized (mLock) { |
| 331 mUploadDataStreamAdapter = nativeAttachUploadDataToRequest(requestAd apter, mLength); | 339 mUploadDataStreamAdapter = nativeAttachUploadDataToRequest(requestAd apter, mLength); |
| 332 } | 340 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 362 | 370 |
| 363 @NativeClassQualifiedName("CronetUploadDataStreamAdapter") | 371 @NativeClassQualifiedName("CronetUploadDataStreamAdapter") |
| 364 private native void nativeOnReadSucceeded(long nativePtr, int bytesRead, boo lean finalChunk); | 372 private native void nativeOnReadSucceeded(long nativePtr, int bytesRead, boo lean finalChunk); |
| 365 | 373 |
| 366 @NativeClassQualifiedName("CronetUploadDataStreamAdapter") | 374 @NativeClassQualifiedName("CronetUploadDataStreamAdapter") |
| 367 private native void nativeOnRewindSucceeded(long nativePtr); | 375 private native void nativeOnRewindSucceeded(long nativePtr); |
| 368 | 376 |
| 369 @NativeClassQualifiedName("CronetUploadDataStreamAdapter") | 377 @NativeClassQualifiedName("CronetUploadDataStreamAdapter") |
| 370 private static native void nativeDestroy(long nativePtr); | 378 private static native void nativeDestroy(long nativePtr); |
| 371 } | 379 } |
| OLD | NEW |