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

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

Issue 1777333002: [Cronet] Fix race in UploadDataStream.attachToRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months 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.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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 mUrlRequestAdapter, header.getKey(), header.getV alue())) { 203 mUrlRequestAdapter, header.getKey(), header.getV alue())) {
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 mUploadDataStream.postTaskToExecutor(new Runnable() {
mef 2016/03/10 17:10:39 This was also a problem as 'isDone' is looking at
xunjieli 2016/03/10 17:29:53 But if start() is called a second time before the
mef 2016/03/10 17:44:05 Ah, excellent point! Done.
214 mUploadDataStream.attachToRequest(this, mUrlRequestAdapter, new Runnable() {
215 @Override 214 @Override
216 public void run() { 215 public void run() {
217 synchronized (mUrlRequestAdapterLock) { 216 synchronized (mUrlRequestAdapterLock) {
218 startInternalLocked(); 217 startInternalLocked();
219 } 218 }
220 } 219 }
221 }); 220 });
222 return; 221 return;
223 } 222 }
224 } catch (RuntimeException e) { 223 } catch (RuntimeException e) {
225 // If there's an exception, cleanup and then throw the 224 // If there's an exception, cleanup and then throw the
226 // exception to the caller. 225 // exception to the caller.
227 destroyRequestAdapter(false); 226 destroyRequestAdapter(false);
228 throw e; 227 throw e;
229 } 228 }
230 mStarted = true;
231 startInternalLocked(); 229 startInternalLocked();
232 } 230 }
233 } 231 }
234 232
235 @GuardedBy("mUrlRequestAdapterLock") 233 @GuardedBy("mUrlRequestAdapterLock")
236 private void startInternalLocked() { 234 private void startInternalLocked() {
235 if (mUrlRequestAdapter == 0) {
236 return;
237 }
238 if (mUploadDataStream != null) {
239 mUploadDataStream.attachToRequest(this, mUrlRequestAdapter);
mef 2016/03/10 17:10:39 attach only if request is still valid.
240 }
237 if (mDisableCache) { 241 if (mDisableCache) {
238 nativeDisableCache(mUrlRequestAdapter); 242 nativeDisableCache(mUrlRequestAdapter);
239 } 243 }
240 if (mRequestMetricsAccumulator != null) { 244 if (mRequestMetricsAccumulator != null) {
241 mRequestMetricsAccumulator.onRequestStarted(); 245 mRequestMetricsAccumulator.onRequestStarted();
242 } 246 }
247 mStarted = true;
243 nativeStart(mUrlRequestAdapter); 248 nativeStart(mUrlRequestAdapter);
244 } 249 }
245 250
246 @Override 251 @Override
247 public void followRedirect() { 252 public void followRedirect() {
248 synchronized (mUrlRequestAdapterLock) { 253 synchronized (mUrlRequestAdapterLock) {
249 if (!mWaitingOnRedirect) { 254 if (!mWaitingOnRedirect) {
250 throw new IllegalStateException("No redirect to follow."); 255 throw new IllegalStateException("No redirect to follow.");
251 } 256 }
252 mWaitingOnRedirect = false; 257 mWaitingOnRedirect = false;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 @NativeClassQualifiedName("CronetURLRequestAdapter") 741 @NativeClassQualifiedName("CronetURLRequestAdapter")
737 private native boolean nativeReadData(long nativePtr, ByteBuffer byteBuffer, 742 private native boolean nativeReadData(long nativePtr, ByteBuffer byteBuffer,
738 int position, int capacity); 743 int position, int capacity);
739 744
740 @NativeClassQualifiedName("CronetURLRequestAdapter") 745 @NativeClassQualifiedName("CronetURLRequestAdapter")
741 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); 746 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled);
742 747
743 @NativeClassQualifiedName("CronetURLRequestAdapter") 748 @NativeClassQualifiedName("CronetURLRequestAdapter")
744 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener); 749 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener);
745 } 750 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698