Chromium Code Reviews| 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.os.SystemClock; | 7 import android.os.SystemClock; |
| 8 import android.support.annotation.Nullable; | 8 import android.support.annotation.Nullable; |
| 9 import android.util.Log; | 9 import android.util.Log; |
| 10 | 10 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 throw new IllegalArgumentException( | 204 throw new IllegalArgumentException( |
| 205 "Invalid header " + header.getKey() + "=" + head er.getValue()); | 205 "Invalid header " + header.getKey() + "=" + head er.getValue()); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 if (mUploadDataStream != null) { | 208 if (mUploadDataStream != null) { |
| 209 if (!hasContentType) { | 209 if (!hasContentType) { |
| 210 throw new IllegalArgumentException( | 210 throw new IllegalArgumentException( |
| 211 "Requests with upload data must have a Content-T ype."); | 211 "Requests with upload data must have a Content-T ype."); |
| 212 } | 212 } |
| 213 mStarted = true; | 213 mStarted = true; |
| 214 mUploadDataStream.attachToRequest(this, mUrlRequestAdapter, new Runnable() { | 214 mUploadDataStream.postTaskToExecutor(new Runnable() { |
| 215 @Override | 215 @Override |
| 216 public void run() { | 216 public void run() { |
| 217 mUploadDataStream.initializeWithRequest(CronetUrlReq uest.this); | |
| 217 synchronized (mUrlRequestAdapterLock) { | 218 synchronized (mUrlRequestAdapterLock) { |
| 219 if (isDoneLocked()) { | |
| 220 return; | |
| 221 } | |
| 222 mUploadDataStream.attachNativeAdapterToRequest(m UrlRequestAdapter); | |
| 218 startInternalLocked(); | 223 startInternalLocked(); |
| 219 } | 224 } |
| 220 } | 225 } |
| 221 }); | 226 }); |
| 222 return; | 227 return; |
| 223 } | 228 } |
| 224 } catch (RuntimeException e) { | 229 } catch (RuntimeException e) { |
| 225 // If there's an exception, cleanup and then throw the | 230 // If there's an exception, cleanup and then throw the |
| 226 // exception to the caller. | 231 // exception to the caller. |
| 227 destroyRequestAdapter(false); | 232 destroyRequestAdapter(false); |
| 228 throw e; | 233 throw e; |
| 229 } | 234 } |
| 230 mStarted = true; | 235 mStarted = true; |
| 231 startInternalLocked(); | 236 startInternalLocked(); |
| 232 } | 237 } |
| 233 } | 238 } |
| 234 | 239 |
| 235 @GuardedBy("mUrlRequestAdapterLock") | 240 @GuardedBy("mUrlRequestAdapterLock") |
| 236 private void startInternalLocked() { | 241 private void startInternalLocked() { |
| 242 // Caller is expected to ensure that request isn't done and mUrlRequestA dapter is valid. | |
|
xunjieli
2016/03/10 22:40:54
nit: maybe make this comment to the method level (
mef
2016/03/11 15:43:06
Done. I wonder whether we should just put isDoneLo
xunjieli
2016/03/11 15:44:32
I am not sure. Your call :)
| |
| 237 if (mDisableCache) { | 243 if (mDisableCache) { |
| 238 nativeDisableCache(mUrlRequestAdapter); | 244 nativeDisableCache(mUrlRequestAdapter); |
| 239 } | 245 } |
| 240 if (mRequestMetricsAccumulator != null) { | 246 if (mRequestMetricsAccumulator != null) { |
| 241 mRequestMetricsAccumulator.onRequestStarted(); | 247 mRequestMetricsAccumulator.onRequestStarted(); |
| 242 } | 248 } |
| 243 nativeStart(mUrlRequestAdapter); | 249 nativeStart(mUrlRequestAdapter); |
| 244 } | 250 } |
| 245 | 251 |
| 246 @Override | 252 @Override |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 @NativeClassQualifiedName("CronetURLRequestAdapter") | 742 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 737 private native boolean nativeReadData(long nativePtr, ByteBuffer byteBuffer, | 743 private native boolean nativeReadData(long nativePtr, ByteBuffer byteBuffer, |
| 738 int position, int capacity); | 744 int position, int capacity); |
| 739 | 745 |
| 740 @NativeClassQualifiedName("CronetURLRequestAdapter") | 746 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 741 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 747 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 742 | 748 |
| 743 @NativeClassQualifiedName("CronetURLRequestAdapter") | 749 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 744 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener); | 750 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener); |
| 745 } | 751 } |
| OLD | NEW |