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

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

Issue 1801943002: [Cronet] Fix race in UploadDataStream.attachToRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
240 /*
241 * Starts fully configured request. Could execute on UploadDataProvider exec utor.
242 * Caller is expected to ensure that request isn't canceled and mUrlRequestA dapter is valid.
243 */
235 @GuardedBy("mUrlRequestAdapterLock") 244 @GuardedBy("mUrlRequestAdapterLock")
236 private void startInternalLocked() { 245 private void startInternalLocked() {
237 if (mDisableCache) { 246 if (mDisableCache) {
238 nativeDisableCache(mUrlRequestAdapter); 247 nativeDisableCache(mUrlRequestAdapter);
239 } 248 }
240 if (mRequestMetricsAccumulator != null) { 249 if (mRequestMetricsAccumulator != null) {
241 mRequestMetricsAccumulator.onRequestStarted(); 250 mRequestMetricsAccumulator.onRequestStarted();
242 } 251 }
243 nativeStart(mUrlRequestAdapter); 252 nativeStart(mUrlRequestAdapter);
244 } 253 }
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 @NativeClassQualifiedName("CronetURLRequestAdapter") 745 @NativeClassQualifiedName("CronetURLRequestAdapter")
737 private native boolean nativeReadData(long nativePtr, ByteBuffer byteBuffer, 746 private native boolean nativeReadData(long nativePtr, ByteBuffer byteBuffer,
738 int position, int capacity); 747 int position, int capacity);
739 748
740 @NativeClassQualifiedName("CronetURLRequestAdapter") 749 @NativeClassQualifiedName("CronetURLRequestAdapter")
741 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); 750 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled);
742 751
743 @NativeClassQualifiedName("CronetURLRequestAdapter") 752 @NativeClassQualifiedName("CronetURLRequestAdapter")
744 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener); 753 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener);
745 } 754 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698