| 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.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.support.annotation.IntDef; | 8 import android.support.annotation.IntDef; |
| 9 | 9 |
| 10 import java.lang.annotation.Retention; | 10 import java.lang.annotation.Retention; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 private final Executor mExecutor; | 41 private final Executor mExecutor; |
| 42 // List of request headers, stored as header field name and value pairs. | 42 // List of request headers, stored as header field name and value pairs. |
| 43 private final ArrayList<Map.Entry<String, String>> mRequestHeaders = | 43 private final ArrayList<Map.Entry<String, String>> mRequestHeaders = |
| 44 new ArrayList<Map.Entry<String, String>>(); | 44 new ArrayList<Map.Entry<String, String>>(); |
| 45 | 45 |
| 46 // HTTP method for the request. Default to POST. | 46 // HTTP method for the request. Default to POST. |
| 47 private String mHttpMethod = "POST"; | 47 private String mHttpMethod = "POST"; |
| 48 // Priority of the stream. Default is medium. | 48 // Priority of the stream. Default is medium. |
| 49 @StreamPriority private int mPriority = STREAM_PRIORITY_MEDIUM; | 49 @StreamPriority private int mPriority = STREAM_PRIORITY_MEDIUM; |
| 50 | 50 |
| 51 // TODO(xunjieli): Remove mDisableAutoFlush and make flush() required as
part of th API. | |
| 52 private boolean mDisableAutoFlush; | |
| 53 private boolean mDelayRequestHeadersUntilFirstFlush; | 51 private boolean mDelayRequestHeadersUntilFirstFlush; |
| 54 | 52 |
| 55 /** | 53 /** |
| 56 * Creates a builder for {@link BidirectionalStream} objects. All callba
cks for | 54 * Creates a builder for {@link BidirectionalStream} objects. All callba
cks for |
| 57 * generated {@code BidirectionalStream} objects will be invoked on | 55 * generated {@code BidirectionalStream} objects will be invoked on |
| 58 * {@code executor}. {@code executor} must not run tasks on the | 56 * {@code executor}. {@code executor} must not run tasks on the |
| 59 * current thread, otherwise the networking operations may block and exc
eptions | 57 * current thread, otherwise the networking operations may block and exc
eptions |
| 60 * may be thrown at shutdown time. | 58 * may be thrown at shutdown time. |
| 61 * | 59 * |
| 62 * @param url the URL for the generated stream | 60 * @param url the URL for the generated stream |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 * @param priority priority of the stream which should be one of the | 155 * @param priority priority of the stream which should be one of the |
| 158 * {@link #STREAM_PRIORITY_IDLE STREAM_PRIORITY_*} values. | 156 * {@link #STREAM_PRIORITY_IDLE STREAM_PRIORITY_*} values. |
| 159 * @return the builder to facilitate chaining. | 157 * @return the builder to facilitate chaining. |
| 160 */ | 158 */ |
| 161 public Builder setPriority(@StreamPriority int priority) { | 159 public Builder setPriority(@StreamPriority int priority) { |
| 162 mPriority = priority; | 160 mPriority = priority; |
| 163 return this; | 161 return this; |
| 164 } | 162 } |
| 165 | 163 |
| 166 /** | 164 /** |
| 167 * Disables or enables auto flush. By default, data is flushed after | |
| 168 * every {@link #write write()}. If the auto flush is disabled, the | |
| 169 * client should explicitly call {@link #flush flush()} to flush the dat
a. | |
| 170 * | |
| 171 * @param disableAutoFlush if true, auto flush will be disabled. | |
| 172 * @return the builder to facilitate chaining. | |
| 173 */ | |
| 174 public Builder disableAutoFlush(boolean disableAutoFlush) { | |
| 175 mDisableAutoFlush = disableAutoFlush; | |
| 176 return this; | |
| 177 } | |
| 178 | |
| 179 /** | |
| 180 * Delays sending request headers until {@link BidirectionalStream#flush
()} | 165 * Delays sending request headers until {@link BidirectionalStream#flush
()} |
| 181 * is called. This flag is currently only respected when QUIC is negotia
ted. | 166 * is called. This flag is currently only respected when QUIC is negotia
ted. |
| 182 * When true, QUIC will send request header frame along with data frame(
s) | 167 * When true, QUIC will send request header frame along with data frame(
s) |
| 183 * as a single packet when possible. | 168 * as a single packet when possible. |
| 184 * | 169 * |
| 185 * @param delayRequestHeadersUntilFirstFlush if true, sending request he
aders will | 170 * @param delayRequestHeadersUntilFirstFlush if true, sending request he
aders will |
| 186 * be delayed until flush() is called. | 171 * be delayed until flush() is called. |
| 187 * @return the builder to facilitate chaining. | 172 * @return the builder to facilitate chaining. |
| 188 */ | 173 */ |
| 189 public Builder delayRequestHeadersUntilFirstFlush( | 174 public Builder delayRequestHeadersUntilFirstFlush( |
| 190 boolean delayRequestHeadersUntilFirstFlush) { | 175 boolean delayRequestHeadersUntilFirstFlush) { |
| 191 mDelayRequestHeadersUntilFirstFlush = delayRequestHeadersUntilFirstF
lush; | 176 mDelayRequestHeadersUntilFirstFlush = delayRequestHeadersUntilFirstF
lush; |
| 192 return this; | 177 return this; |
| 193 } | 178 } |
| 194 | 179 |
| 195 /** | 180 /** |
| 196 * Creates a {@link BidirectionalStream} using configuration from this | 181 * Creates a {@link BidirectionalStream} using configuration from this |
| 197 * {@link Builder}. The returned {@code BidirectionalStream} can then be
started | 182 * {@link Builder}. The returned {@code BidirectionalStream} can then be
started |
| 198 * by calling {@link BidirectionalStream#start}. | 183 * by calling {@link BidirectionalStream#start}. |
| 199 * | 184 * |
| 200 * @return constructed {@link BidirectionalStream} using configuration f
rom | 185 * @return constructed {@link BidirectionalStream} using configuration f
rom |
| 201 * this {@link Builder} | 186 * this {@link Builder} |
| 202 */ | 187 */ |
| 203 @SuppressLint("WrongConstant") // TODO(jbudorick): Remove this after rol
ling to the N SDK. | 188 @SuppressLint("WrongConstant") // TODO(jbudorick): Remove this after rol
ling to the N SDK. |
| 204 public BidirectionalStream build() { | 189 public BidirectionalStream build() { |
| 205 return mCronetEngine.createBidirectionalStream(mUrl, mCallback, mExe
cutor, mHttpMethod, | 190 return mCronetEngine.createBidirectionalStream(mUrl, mCallback, mExe
cutor, mHttpMethod, |
| 206 mRequestHeaders, mPriority, mDisableAutoFlush, | 191 mRequestHeaders, mPriority, mDelayRequestHeadersUntilFirstFl
ush); |
| 207 mDelayRequestHeadersUntilFirstFlush); | |
| 208 } | 192 } |
| 209 } | 193 } |
| 210 | 194 |
| 211 /** | 195 /** |
| 212 * Callback class used to receive callbacks from a {@link BidirectionalStrea
m}. | 196 * Callback class used to receive callbacks from a {@link BidirectionalStrea
m}. |
| 213 */ | 197 */ |
| 214 public abstract static class Callback { | 198 public abstract static class Callback { |
| 215 /** | 199 /** |
| 216 * Invoked when the stream is ready for reading and writing. | 200 * Invoked when the stream is ready for reading and writing. |
| 217 * Consumer may call {@link BidirectionalStream#read read()} to start re
ading data. | 201 * Consumer may call {@link BidirectionalStream#read read()} to start re
ading data. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 /** | 385 /** |
| 402 * Returns {@code true} if the stream was successfully started and is now | 386 * Returns {@code true} if the stream was successfully started and is now |
| 403 * done (succeeded, canceled, or failed). | 387 * done (succeeded, canceled, or failed). |
| 404 * | 388 * |
| 405 * @return {@code true} if the stream was successfully started and is now | 389 * @return {@code true} if the stream was successfully started and is now |
| 406 * done (completed, canceled, or failed), otherwise returns {@code f
alse} | 390 * done (completed, canceled, or failed), otherwise returns {@code f
alse} |
| 407 * to indicate stream is not yet started or is in progress. | 391 * to indicate stream is not yet started or is in progress. |
| 408 */ | 392 */ |
| 409 public abstract boolean isDone(); | 393 public abstract boolean isDone(); |
| 410 } | 394 } |
| OLD | NEW |