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

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

Issue 997623002: [Cronet] Respect user agent string from config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass user agent string directly Created 5 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.content.Context; 7 import android.content.Context;
8 import android.text.TextUtils; 8 import android.text.TextUtils;
9 9
10 import org.apache.http.HttpStatus; 10 import org.apache.http.HttpStatus;
(...skipping 23 matching lines...) Expand all
34 class HttpUrlConnectionUrlRequest implements HttpUrlRequest { 34 class HttpUrlConnectionUrlRequest implements HttpUrlRequest {
35 35
36 private static final int MAX_CHUNK_SIZE = 8192; 36 private static final int MAX_CHUNK_SIZE = 8192;
37 37
38 private static final int CONNECT_TIMEOUT = 3000; 38 private static final int CONNECT_TIMEOUT = 3000;
39 39
40 private static final int READ_TIMEOUT = 90000; 40 private static final int READ_TIMEOUT = 90000;
41 41
42 private final Context mContext; 42 private final Context mContext;
43 43
44 private final String mDefaultUserAgent;
45
44 private final String mUrl; 46 private final String mUrl;
45 47
46 private final Map<String, String> mHeaders; 48 private final Map<String, String> mHeaders;
47 49
48 private final WritableByteChannel mSink; 50 private final WritableByteChannel mSink;
49 51
50 private final HttpUrlRequestListener mListener; 52 private final HttpUrlRequestListener mListener;
51 53
52 private IOException mException; 54 private IOException mException;
53 55
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 private String mMethod; 90 private String mMethod;
89 91
90 private InputStream mResponseStream; 92 private InputStream mResponseStream;
91 93
92 private final Object mLock; 94 private final Object mLock;
93 95
94 private static ExecutorService sExecutorService; 96 private static ExecutorService sExecutorService;
95 97
96 private static final Object sExecutorServiceLock = new Object(); 98 private static final Object sExecutorServiceLock = new Object();
97 99
98 HttpUrlConnectionUrlRequest(Context context, String url, 100 HttpUrlConnectionUrlRequest(Context context, String defaultUserAgent,
99 int requestPriority, Map<String, String> headers, 101 String url, int requestPriority, Map<String, String> headers,
100 HttpUrlRequestListener listener) { 102 HttpUrlRequestListener listener) {
101 this(context, url, requestPriority, headers, 103 this(context, defaultUserAgent, url, requestPriority, headers,
102 new ChunkedWritableByteChannel(), listener); 104 new ChunkedWritableByteChannel(), listener);
103 } 105 }
104 106
105 HttpUrlConnectionUrlRequest(Context context, String url, 107 HttpUrlConnectionUrlRequest(Context context, String defaultUserAgent,
106 int requestPriority, Map<String, String> headers, 108 String url, int requestPriority, Map<String, String> headers,
107 WritableByteChannel sink, HttpUrlRequestListener listener) { 109 WritableByteChannel sink, HttpUrlRequestListener listener) {
108 if (context == null) { 110 if (context == null) {
109 throw new NullPointerException("Context is required"); 111 throw new NullPointerException("Context is required");
110 } 112 }
111 if (url == null) { 113 if (url == null) {
112 throw new NullPointerException("URL is required"); 114 throw new NullPointerException("URL is required");
113 } 115 }
114 mContext = context; 116 mContext = context;
117 mDefaultUserAgent = defaultUserAgent;
115 mUrl = url; 118 mUrl = url;
116 mHeaders = headers; 119 mHeaders = headers;
117 mSink = sink; 120 mSink = sink;
118 mListener = listener; 121 mListener = listener;
119 mLock = new Object(); 122 mLock = new Object();
120 } 123 }
121 124
122 private static ExecutorService getExecutor() { 125 private static ExecutorService getExecutor() {
123 synchronized (sExecutorServiceLock) { 126 synchronized (sExecutorServiceLock) {
124 if (sExecutorService == null) { 127 if (sExecutorService == null) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 header.getValue()); 236 header.getValue());
234 } 237 }
235 } 238 }
236 239
237 if (mOffset != 0) { 240 if (mOffset != 0) {
238 mConnection.setRequestProperty("Range", 241 mConnection.setRequestProperty("Range",
239 "bytes=" + mOffset + "-"); 242 "bytes=" + mOffset + "-");
240 } 243 }
241 244
242 if (mConnection.getRequestProperty("User-Agent") == null) { 245 if (mConnection.getRequestProperty("User-Agent") == null) {
243 mConnection.setRequestProperty("User-Agent", 246 mConnection.setRequestProperty("User-Agent", mDefaultUserAgent);
244 UserAgent.from(mContext));
245 } 247 }
246 248
247 if (mPostData != null || mPostDataChannel != null) { 249 if (mPostData != null || mPostDataChannel != null) {
248 uploadData(); 250 uploadData();
249 } 251 }
250 252
251 InputStream stream = null; 253 InputStream stream = null;
252 try { 254 try {
253 // We need to open the stream before asking for the response 255 // We need to open the stream before asking for the response
254 // code. 256 // code.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 515 }
514 return mConnection.getHeaderFields(); 516 return mConnection.getHeaderFields();
515 } 517 }
516 518
517 private void validateNotStarted() { 519 private void validateNotStarted() {
518 if (mStarted) { 520 if (mStarted) {
519 throw new IllegalStateException("Request already started"); 521 throw new IllegalStateException("Request already started");
520 } 522 }
521 } 523 }
522 } 524 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698