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

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

Issue 526503002: SetUploadData now throws an exception if contentType is null. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comment. Created 6 years, 3 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
« no previous file with comments | « no previous file | components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleUrlTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.util.Log; 7 import android.util.Log;
8 8
9 import org.apache.http.conn.ConnectTimeoutException; 9 import org.apache.http.conn.ConnectTimeoutException;
10 import org.chromium.base.CalledByNative; 10 import org.chromium.base.CalledByNative;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 /** 207 /**
208 * Sets data to upload as part of a POST or PUT request. 208 * Sets data to upload as part of a POST or PUT request.
209 * 209 *
210 * @param contentType MIME type of the upload content or null if this is not 210 * @param contentType MIME type of the upload content or null if this is not
211 * an upload. 211 * an upload.
212 * @param data The content that needs to be uploaded. 212 * @param data The content that needs to be uploaded.
213 */ 213 */
214 public void setUploadData(String contentType, byte[] data) { 214 public void setUploadData(String contentType, byte[] data) {
215 synchronized (mLock) { 215 synchronized (mLock) {
216 validateNotStarted(); 216 validateNotStarted();
217 validateContentType(contentType);
217 mUploadContentType = contentType; 218 mUploadContentType = contentType;
218 mUploadData = data; 219 mUploadData = data;
219 mUploadChannel = null; 220 mUploadChannel = null;
220 mChunkedUpload = false; 221 mChunkedUpload = false;
221 } 222 }
222 } 223 }
223 224
224 /** 225 /**
225 * Sets a readable byte channel to upload as part of a POST or PUT request. 226 * Sets a readable byte channel to upload as part of a POST or PUT request.
226 * 227 *
227 * @param contentType MIME type of the upload content or null if this is not 228 * @param contentType MIME type of the upload content or null if this is not
228 * an upload request. 229 * an upload request.
229 * @param channel The channel to read to read upload data from if this is an 230 * @param channel The channel to read to read upload data from if this is an
230 * upload request. 231 * upload request.
231 * @param contentLength The length of data to upload. 232 * @param contentLength The length of data to upload.
232 */ 233 */
233 public void setUploadChannel(String contentType, 234 public void setUploadChannel(String contentType,
234 ReadableByteChannel channel, long contentLength) { 235 ReadableByteChannel channel, long contentLength) {
235 synchronized (mLock) { 236 synchronized (mLock) {
236 validateNotStarted(); 237 validateNotStarted();
238 validateContentType(contentType);
237 mUploadContentType = contentType; 239 mUploadContentType = contentType;
238 mUploadChannel = channel; 240 mUploadChannel = channel;
239 mUploadContentLength = contentLength; 241 mUploadContentLength = contentLength;
240 mUploadData = null; 242 mUploadData = null;
241 mChunkedUpload = false; 243 mChunkedUpload = false;
242 } 244 }
243 } 245 }
244 246
245 /** 247 /**
246 * Sets this request up for chunked uploading. To upload data call 248 * Sets this request up for chunked uploading. To upload data call
247 * {@link #appendChunk(ByteBuffer, boolean)} after {@link #start()}. 249 * {@link #appendChunk(ByteBuffer, boolean)} after {@link #start()}.
248 * 250 *
249 * @param contentType MIME type of the post content or null if this is not a 251 * @param contentType MIME type of the post content or null if this is not a
250 * POST request. 252 * POST request.
251 */ 253 */
252 public void setChunkedUpload(String contentType) { 254 public void setChunkedUpload(String contentType) {
253 synchronized (mLock) { 255 synchronized (mLock) {
254 validateNotStarted(); 256 validateNotStarted();
257 validateContentType(contentType);
255 mUploadContentType = contentType; 258 mUploadContentType = contentType;
256 mChunkedUpload = true; 259 mChunkedUpload = true;
257 mUploadData = null; 260 mUploadData = null;
258 mUploadChannel = null; 261 mUploadChannel = null;
259 } 262 }
260 } 263 }
261 264
262 /** 265 /**
263 * Uploads a new chunk. Must have called {@link #setChunkedUpload(String)} 266 * Uploads a new chunk. Must have called {@link #setChunkedUpload(String)}
264 * and {@link #start()}. 267 * and {@link #start()}.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 throw new IllegalStateException("Request already started"); 451 throw new IllegalStateException("Request already started");
449 } 452 }
450 } 453 }
451 454
452 private void validateHeadersAvailable() { 455 private void validateHeadersAvailable() {
453 if (!mHeadersAvailable) { 456 if (!mHeadersAvailable) {
454 throw new IllegalStateException("Response headers not available"); 457 throw new IllegalStateException("Response headers not available");
455 } 458 }
456 } 459 }
457 460
461 private void validateContentType(String contentType) {
462 if (contentType == null) {
463 throw new NullPointerException("contentType is required");
464 }
465 }
466
458 // Private methods called by native library. 467 // Private methods called by native library.
459 468
460 /** 469 /**
461 * If @CalledByNative method throws an exception, request gets cancelled 470 * If @CalledByNative method throws an exception, request gets cancelled
462 * and exception could be retrieved from request using getException(). 471 * and exception could be retrieved from request using getException().
463 */ 472 */
464 private void onCalledByNativeException(Exception e) { 473 private void onCalledByNativeException(Exception e) {
465 mSinkException = new IOException( 474 mSinkException = new IOException(
466 "CalledByNative method has thrown an exception", e); 475 "CalledByNative method has thrown an exception", e);
467 Log.e(ChromiumUrlRequestContext.LOG_TAG, 476 Log.e(ChromiumUrlRequestContext.LOG_TAG,
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 684
676 private native String nativeGetHeader(long urlRequestAdapter, String name); 685 private native String nativeGetHeader(long urlRequestAdapter, String name);
677 686
678 private native void nativeGetAllHeaders(long urlRequestAdapter, 687 private native void nativeGetAllHeaders(long urlRequestAdapter,
679 ResponseHeadersMap headers); 688 ResponseHeadersMap headers);
680 689
681 // Explicit class to work around JNI-generator generics confusion. 690 // Explicit class to work around JNI-generator generics confusion.
682 private class ResponseHeadersMap extends HashMap<String, List<String>> { 691 private class ResponseHeadersMap extends HashMap<String, List<String>> {
683 } 692 }
684 } 693 }
OLDNEW
« no previous file with comments | « no previous file | components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleUrlTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698