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

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/HttpUrlConnectionUrlRequestFactory.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 8
9 import java.io.IOException; 9 import java.io.IOException;
10 import java.io.PrintWriter; 10 import java.io.PrintWriter;
11 import java.nio.channels.WritableByteChannel; 11 import java.nio.channels.WritableByteChannel;
12 import java.util.Map; 12 import java.util.Map;
13 13
14 /** 14 /**
15 * Network request using {@link java.net.HttpURLConnection}. 15 * Network request using {@link java.net.HttpURLConnection}.
16 */ 16 */
17 class HttpUrlConnectionUrlRequestFactory extends HttpUrlRequestFactory { 17 class HttpUrlConnectionUrlRequestFactory extends HttpUrlRequestFactory {
18 18
19 private final Context mContext; 19 private final Context mContext;
20 private final String mDefaultUserAgent;
20 21
21 public HttpUrlConnectionUrlRequestFactory( 22 public HttpUrlConnectionUrlRequestFactory(
22 Context context, UrlRequestContextConfig config) { 23 Context context, UrlRequestContextConfig config) {
23 mContext = context; 24 mContext = context;
25 String userAgent = config.userAgent();
26 if (userAgent.isEmpty()) {
27 userAgent = UserAgent.from(mContext);
28 }
29 mDefaultUserAgent = userAgent;
24 } 30 }
25 31
26 @Override 32 @Override
27 public boolean isEnabled() { 33 public boolean isEnabled() {
28 return true; 34 return true;
29 } 35 }
30 36
31 @Override 37 @Override
32 public String getName() { 38 public String getName() {
33 return "HttpUrlConnection/" + Version.getVersion(); 39 return "HttpUrlConnection/" + Version.getVersion();
34 } 40 }
35 41
36 @Override 42 @Override
37 public HttpUrlRequest createRequest(String url, int requestPriority, 43 public HttpUrlRequest createRequest(String url, int requestPriority,
38 Map<String, String> headers, HttpUrlRequestListener listener) { 44 Map<String, String> headers, HttpUrlRequestListener listener) {
39 return new HttpUrlConnectionUrlRequest(mContext, url, requestPriority, 45 return new HttpUrlConnectionUrlRequest(mContext, mDefaultUserAgent, url,
40 headers, listener); 46 requestPriority, headers, listener);
41 } 47 }
42 48
43 @Override 49 @Override
44 public HttpUrlRequest createRequest(String url, int requestPriority, 50 public HttpUrlRequest createRequest(String url, int requestPriority,
45 Map<String, String> headers, WritableByteChannel channel, 51 Map<String, String> headers, WritableByteChannel channel,
46 HttpUrlRequestListener listener) { 52 HttpUrlRequestListener listener) {
47 return new HttpUrlConnectionUrlRequest(mContext, url, requestPriority, 53 return new HttpUrlConnectionUrlRequest(mContext, mDefaultUserAgent, url,
48 headers, channel, listener); 54 requestPriority, headers, channel, listener);
49 } 55 }
50 56
51 @Override 57 @Override
52 public void startNetLogToFile(String fileName) { 58 public void startNetLogToFile(String fileName) {
53 try { 59 try {
54 PrintWriter out = new PrintWriter(fileName); 60 PrintWriter out = new PrintWriter(fileName);
55 out.println("NetLog is not supported by " + getName()); 61 out.println("NetLog is not supported by " + getName());
56 out.close(); 62 out.close();
57 } catch (IOException e) { 63 } catch (IOException e) {
58 // Ignore any exceptions. 64 // Ignore any exceptions.
59 } 65 }
60 } 66 }
61 67
62 @Override 68 @Override
63 public void stopNetLog() { 69 public void stopNetLog() {
64 } 70 }
65 } 71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698