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

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

Issue 2339223002: Cronet API Refactoring (Closed)
Patch Set: Javadoc + rebase Created 4 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 package org.chromium.net.impl;
5
6 import android.support.annotation.IntDef;
7
8 import org.chromium.net.ExperimentalUrlRequest;
9 import org.chromium.net.UploadDataProvider;
10 import org.chromium.net.UrlRequest;
11
12 import java.lang.annotation.Retention;
13 import java.lang.annotation.RetentionPolicy;
14 import java.util.concurrent.Executor;
15
16 /**
17 * Base class for classes that implement {@link UrlRequest} including experiment al
18 * features. {@link CronetUrlRequest} and {@link JavaUrlRequest} extends this cl ass.
19 */
20 public abstract class UrlRequestBase extends ExperimentalUrlRequest {
pauljensen 2016/09/20 19:01:37 can this be an interface?
kapishnikov 2016/09/22 21:32:03 It could be an interface but I think we should kee
21 /**
22 * Sets the HTTP method verb to use for this request. Must be done before
23 * request has started.
24 *
25 * <p>The default when this method is not called is "GET" if the request has
26 * no body or "POST" if it does.
27 *
28 * @param method "GET", "HEAD", "DELETE", "POST" or "PUT".
29 */
30 public abstract void setHttpMethod(String method);
31
32 /**
33 * Adds a request header. Must be done before request has started.
34 *
35 * @param header header name.
36 * @param value header value.
37 */
38 public abstract void addHeader(String header, String value);
39
40 /**
41 * Sets upload data provider. Must be done before request has started. May o nly be
42 * invoked once per request. Switches method to "POST" if not explicitly
43 * set. Starting the request will throw an exception if a Content-Type
44 * header is not set.
45 *
46 * @param uploadDataProvider responsible for providing the upload data.
47 * @param executor All {@code uploadDataProvider} methods will be invoked
48 * using this {@code Executor}. May optionally be the same
49 * {@code Executor} the request itself is using.
50 */
51 protected abstract void setUploadDataProvider(
52 UploadDataProvider uploadDataProvider, Executor executor);
53
54 /**
55 * Possible URL Request statuses.
56 */
57 public static class Status extends UrlRequest.Status {
58 @IntDef({
59 INVALID, IDLE, WAITING_FOR_STALLED_SOCKET_POOL, WAITING_FOR_AVAI LABLE_SOCKET,
60 WAITING_FOR_DELEGATE, WAITING_FOR_CACHE, DOWNLOADING_PROXY_SCRIP T,
61 RESOLVING_PROXY_FOR_URL, RESOLVING_HOST_IN_PROXY_SCRIPT, ESTABLI SHING_PROXY_TUNNEL,
62 RESOLVING_HOST, CONNECTING, SSL_HANDSHAKE, SENDING_REQUEST, WAIT ING_FOR_RESPONSE,
63 READING_RESPONSE,
64 })
65 @Retention(RetentionPolicy.SOURCE)
66 public @interface StatusValues {}
67
68 /**
69 * Convert a LoadState int to one of values listed above.
70 * @param loadState a LoadState to convert.
71 * @return static int Status.
72 */
73 @StatusValues
74 public static int convertLoadState(int loadState) {
75 assert loadState >= LoadState.IDLE && loadState <= LoadState.READING _RESPONSE;
76 switch (loadState) {
77 case (LoadState.IDLE):
78 return IDLE;
79
80 case (LoadState.WAITING_FOR_STALLED_SOCKET_POOL):
81 return WAITING_FOR_STALLED_SOCKET_POOL;
82
83 case (LoadState.WAITING_FOR_AVAILABLE_SOCKET):
84 return WAITING_FOR_AVAILABLE_SOCKET;
85
86 case (LoadState.WAITING_FOR_DELEGATE):
87 return WAITING_FOR_DELEGATE;
88
89 case (LoadState.WAITING_FOR_CACHE):
90 return WAITING_FOR_CACHE;
91
92 case (LoadState.DOWNLOADING_PROXY_SCRIPT):
93 return DOWNLOADING_PROXY_SCRIPT;
94
95 case (LoadState.RESOLVING_PROXY_FOR_URL):
96 return RESOLVING_PROXY_FOR_URL;
97
98 case (LoadState.RESOLVING_HOST_IN_PROXY_SCRIPT):
99 return RESOLVING_HOST_IN_PROXY_SCRIPT;
100
101 case (LoadState.ESTABLISHING_PROXY_TUNNEL):
102 return ESTABLISHING_PROXY_TUNNEL;
103
104 case (LoadState.RESOLVING_HOST):
105 return RESOLVING_HOST;
106
107 case (LoadState.CONNECTING):
108 return CONNECTING;
109
110 case (LoadState.SSL_HANDSHAKE):
111 return SSL_HANDSHAKE;
112
113 case (LoadState.SENDING_REQUEST):
114 return SENDING_REQUEST;
115
116 case (LoadState.WAITING_FOR_RESPONSE):
117 return WAITING_FOR_RESPONSE;
118
119 case (LoadState.READING_RESPONSE):
120 return READING_RESPONSE;
121
122 default:
123 // A load state is retrieved but there is no corresponding
124 // request status. This most likely means that the mapping i s
125 // incorrect.
126 throw new IllegalArgumentException("No request status found. ");
127 }
128 }
129 }
130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698