Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.support.annotation.IntDef; | 7 import android.support.annotation.IntDef; |
| 8 | 8 |
| 9 import java.lang.annotation.Retention; | 9 import java.lang.annotation.Retention; |
| 10 import java.lang.annotation.RetentionPolicy; | 10 import java.lang.annotation.RetentionPolicy; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 private final Executor mExecutor; | 40 private final Executor mExecutor; |
| 41 // List of request headers, stored as header field name and value pairs. | 41 // List of request headers, stored as header field name and value pairs. |
| 42 private final ArrayList<Map.Entry<String, String>> mRequestHeaders = | 42 private final ArrayList<Map.Entry<String, String>> mRequestHeaders = |
| 43 new ArrayList<Map.Entry<String, String>>(); | 43 new ArrayList<Map.Entry<String, String>>(); |
| 44 | 44 |
| 45 // HTTP method for the request. Default to POST. | 45 // HTTP method for the request. Default to POST. |
| 46 private String mHttpMethod = "POST"; | 46 private String mHttpMethod = "POST"; |
| 47 // Priority of the stream. Default is medium. | 47 // Priority of the stream. Default is medium. |
| 48 @StreamPriority private int mPriority = STREAM_PRIORITY_MEDIUM; | 48 @StreamPriority private int mPriority = STREAM_PRIORITY_MEDIUM; |
| 49 | 49 |
| 50 // TODO(xunjieli): Remove mDisableAutoFlush and make flush() required as part of th API. | |
| 50 private boolean mDisableAutoFlush; | 51 private boolean mDisableAutoFlush; |
| 52 private boolean mDelayRequestHeadersUntilNextFlush; | |
| 51 | 53 |
| 52 /** | 54 /** |
| 53 * Creates a builder for {@link BidirectionalStream} objects. All callba cks for | 55 * Creates a builder for {@link BidirectionalStream} objects. All callba cks for |
| 54 * generated {@code BidirectionalStream} objects will be invoked on | 56 * generated {@code BidirectionalStream} objects will be invoked on |
| 55 * {@code executor}. {@code executor} must not run tasks on the | 57 * {@code executor}. {@code executor} must not run tasks on the |
| 56 * current thread, otherwise the networking operations may block and exc eptions | 58 * current thread, otherwise the networking operations may block and exc eptions |
| 57 * may be thrown at shutdown time. | 59 * may be thrown at shutdown time. |
| 58 * | 60 * |
| 59 * @param url the URL for the generated stream | 61 * @param url the URL for the generated stream |
| 60 * @param callback the {@link Callback} object that gets invoked upon di fferent events | 62 * @param callback the {@link Callback} object that gets invoked upon di fferent events |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 * | 169 * |
| 168 * @param disableAutoFlush if true, auto flush will be disabled. | 170 * @param disableAutoFlush if true, auto flush will be disabled. |
| 169 * @return the builder to facilitate chaining. | 171 * @return the builder to facilitate chaining. |
| 170 */ | 172 */ |
| 171 public Builder disableAutoFlush(boolean disableAutoFlush) { | 173 public Builder disableAutoFlush(boolean disableAutoFlush) { |
| 172 mDisableAutoFlush = disableAutoFlush; | 174 mDisableAutoFlush = disableAutoFlush; |
| 173 return this; | 175 return this; |
| 174 } | 176 } |
| 175 | 177 |
| 176 /** | 178 /** |
| 179 * Delays sending request headers until the next {@link BidirectionalStr eam#flush()} | |
| 180 * is called. This flag is currently only respected when QUIC is negotia ted. | |
| 181 * When true, QUIC will send request header frame along with data frame( s) | |
| 182 * as a single packet when possible. | |
| 183 * | |
| 184 * @param delayRequestHeadersUntilNextFlush if true, sending request hea ders will | |
| 185 * be delayed until the next flush() is called. | |
| 186 * @return the builder to facilitate chaining. | |
| 187 */ | |
| 188 public Builder delayRequestHeadersUntilNextFlush( | |
| 189 boolean delayRequestHeadersUntilNextFlush) { | |
| 190 mDelayRequestHeadersUntilNextFlush = delayRequestHeadersUntilNextFlu sh; | |
| 191 return this; | |
| 192 } | |
| 193 | |
| 194 /** | |
| 177 * Creates a {@link BidirectionalStream} using configuration from this | 195 * Creates a {@link BidirectionalStream} using configuration from this |
| 178 * {@link Builder}. The returned {@code BidirectionalStream} can then be started | 196 * {@link Builder}. The returned {@code BidirectionalStream} can then be started |
| 179 * by calling {@link BidirectionalStream#start}. | 197 * by calling {@link BidirectionalStream#start}. |
| 180 * | 198 * |
| 181 * @return constructed {@link BidirectionalStream} using configuration f rom | 199 * @return constructed {@link BidirectionalStream} using configuration f rom |
| 182 * this {@link Builder} | 200 * this {@link Builder} |
| 183 */ | 201 */ |
| 184 public BidirectionalStream build() { | 202 public BidirectionalStream build() { |
| 185 return mCronetEngine.createBidirectionalStream(mUrl, mCallback, mExe cutor, mHttpMethod, | 203 return mCronetEngine.createBidirectionalStream(mUrl, mCallback, mExe cutor, mHttpMethod, |
| 186 mRequestHeaders, mPriority, mDisableAutoFlush); | 204 mRequestHeaders, mPriority, mDisableAutoFlush, |
| 205 mDelayRequestHeadersUntilNextFlush); | |
| 187 } | 206 } |
| 188 } | 207 } |
| 189 | 208 |
| 190 /** | 209 /** |
| 191 * Callback class used to receive callbacks from a {@link BidirectionalStrea m}. | 210 * Callback class used to receive callbacks from a {@link BidirectionalStrea m}. |
| 192 */ | 211 */ |
| 193 public abstract static class Callback { | 212 public abstract static class Callback { |
| 194 /** | 213 /** |
| 195 * Invoked when the stream is ready for reading and writing. | 214 * Invoked when the stream is ready for reading and writing. |
| 196 * Consumer may call {@link BidirectionalStream#read read()} to start re ading data. | 215 * Consumer may call {@link BidirectionalStream#read read()} to start re ading data. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 * {@link Callback#onWriteCompleted onWriteCompleted()}, {@link Callback #onCanceled | 390 * {@link Callback#onWriteCompleted onWriteCompleted()}, {@link Callback #onCanceled |
| 372 * onCanceled()}, or {@link Callback#onFailed onFailed()} are invoked. C an be empty | 391 * onCanceled()}, or {@link Callback#onFailed onFailed()} are invoked. C an be empty |
| 373 * when {@code endOfStream} is {@code true}. | 392 * when {@code endOfStream} is {@code true}. |
| 374 * @param endOfStream if {@code true}, then {@code buffer} is the last buffe r to be written, | 393 * @param endOfStream if {@code true}, then {@code buffer} is the last buffe r to be written, |
| 375 * and once written, stream is closed from the client side, resulting in half-closed | 394 * and once written, stream is closed from the client side, resulting in half-closed |
| 376 * stream or a fully closed stream if the remote side has already closed . | 395 * stream or a fully closed stream if the remote side has already closed . |
| 377 */ | 396 */ |
| 378 public abstract void write(ByteBuffer buffer, boolean endOfStream); | 397 public abstract void write(ByteBuffer buffer, boolean endOfStream); |
| 379 | 398 |
| 380 /** | 399 /** |
| 381 * Flushes pending writes. This method should only be invoked when auto | 400 * Flushes pending writes. This method should not be invoked before {@link |
|
mef
2016/06/01 21:33:20
I think this deserves more verbose comment, explai
xunjieli
2016/06/01 22:27:16
Done.
| |
| 382 * flush is disabled through {@link Builder#disableAutoFlush}. | 401 * Callback#onStreamReady onStreamReady()}. |
| 383 */ | 402 */ |
| 384 public abstract void flush(); | 403 public abstract void flush(); |
| 385 | 404 |
| 386 /** | 405 /** |
| 387 * Pings remote end-point. {@code callback} methods will be invoked on {@cod e executor}. | 406 * Pings remote end-point. {@code callback} methods will be invoked on {@cod e executor}. |
| 388 * | 407 * |
| 389 * @param callback the callback that will be invoked when ping succeeds or f ails | 408 * @param callback the callback that will be invoked when ping succeeds or f ails |
| 390 * @param executor the executor on which the callback will be invoked | 409 * @param executor the executor on which the callback will be invoked |
| 391 */ | 410 */ |
| 392 // TODO(mef): May be last thing to be implemented on Android. | 411 // TODO(mef): May be last thing to be implemented on Android. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 417 /** | 436 /** |
| 418 * Returns {@code true} if the stream was successfully started and is now | 437 * Returns {@code true} if the stream was successfully started and is now |
| 419 * done (succeeded, canceled, or failed). | 438 * done (succeeded, canceled, or failed). |
| 420 * | 439 * |
| 421 * @return {@code true} if the stream was successfully started and is now | 440 * @return {@code true} if the stream was successfully started and is now |
| 422 * done (completed, canceled, or failed), otherwise returns {@code f alse} | 441 * done (completed, canceled, or failed), otherwise returns {@code f alse} |
| 423 * to indicate stream is not yet started or is in progress. | 442 * to indicate stream is not yet started or is in progress. |
| 424 */ | 443 */ |
| 425 public abstract boolean isDone(); | 444 public abstract boolean isDone(); |
| 426 } | 445 } |
| OLD | NEW |