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 synchronized (mUrlRequestAdapterLock) { | 217 synchronized (mUrlRequestAdapterLock) { |
| 218 startInternalLocked(); | 218 startInternalLocked(); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 }); | 221 }); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 } catch (RuntimeException e) { | 224 } catch (RuntimeException e) { |
| 225 // If there's an exception, cleanup and then throw the | 225 // If there's an exception, cleanup and then throw the |
| 226 // exception to the caller. | 226 // exception to the caller. |
| 227 destroyRequestAdapter(false); | 227 destroyRequestAdapter(false); |
| 228 throw e; | 228 throw e; |
| 229 } | 229 } |
| 230 mStarted = true; | 230 mStarted = true; |
| 231 startInternalLocked(); | 231 startInternalLocked(); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 @GuardedBy("mUrlRequestAdapterLock") | 235 @GuardedBy("mUrlRequestAdapterLock") |
| 236 private void startInternalLocked() { | 236 private void startInternalLocked() { |
| 237 if (isDoneLocked()) { | |
|
xunjieli
2016/03/10 18:14:19
use isDone() instead? since startInternalLocked sh
mef
2016/03/10 19:00:54
Right, isDoneLocked() expects that lock is already
| |
| 238 return; | |
| 239 } | |
| 240 if (mUploadDataStream != null) { | |
| 241 mUploadDataStream.attachToRequest(this, mUrlRequestAdapter); | |
| 242 } | |
| 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 |