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

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

Issue 1665503002: [Cronet] Expose quic_user_agent_id and quic_prefer_aes config options. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Document QUIC UAID string usage, don't pass it down unless QUIC is enabled. Created 4 years, 10 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.content.pm.PackageInfo; 8 import android.content.pm.PackageInfo;
9 import android.content.pm.PackageManager; 9 import android.content.pm.PackageManager;
10 import android.content.pm.PackageManager.NameNotFoundException; 10 import android.content.pm.PackageManager.NameNotFoundException;
(...skipping 11 matching lines...) Expand all
22 public final class UserAgent { 22 public final class UserAgent {
23 private static final Object sLock = new Object(); 23 private static final Object sLock = new Object();
24 24
25 private static final int VERSION_CODE_UNINITIALIZED = 0; 25 private static final int VERSION_CODE_UNINITIALIZED = 0;
26 private static int sVersionCode = VERSION_CODE_UNINITIALIZED; 26 private static int sVersionCode = VERSION_CODE_UNINITIALIZED;
27 27
28 private UserAgent() { 28 private UserAgent() {
29 } 29 }
30 30
31 /** 31 /**
32 * Constructs a User-Agent string including Cronet version, and application 32 * Constructs a User-Agent string including application name and version,
33 * name and version. 33 * system build version, model and Id, and Cronet version.
34 * @param context the context to fetch the application name and version 34 * @param context the context to fetch the application name and version
35 * from. 35 * from.
36 * @return User-Agent string. 36 * @return User-Agent string.
37 */ 37 */
38 public static String from(Context context) { 38 public static String from(Context context) {
39 StringBuilder builder = new StringBuilder(); 39 StringBuilder builder = new StringBuilder();
40 40
41 // Our package name and version. 41 // Our package name and version.
42 builder.append(context.getPackageName()); 42 builder.append(context.getPackageName());
43 builder.append('/'); 43 builder.append('/');
(...skipping 18 matching lines...) Expand all
62 } 62 }
63 63
64 builder.append("; Cronet/"); 64 builder.append("; Cronet/");
65 builder.append(Version.CRONET_VERSION); 65 builder.append(Version.CRONET_VERSION);
66 66
67 builder.append(')'); 67 builder.append(')');
68 68
69 return builder.toString(); 69 return builder.toString();
70 } 70 }
71 71
72 /**
73 * Constructs default QUIC User Agent Id string including application name
74 * and Cronet version.
75 * @param context the context to fetch the application name from.
76 * @return User-Agent string.
77 */
78 static String getQuicUserAgentIdFrom(Context context) {
79 StringBuilder builder = new StringBuilder();
80
81 // Application name and cronet version.
82 builder.append(context.getPackageName());
83 builder.append(" Cronet/");
84 builder.append(Version.CRONET_VERSION);
85
86 return builder.toString();
87 }
88
72 private static int versionFromContext(Context context) { 89 private static int versionFromContext(Context context) {
73 synchronized (sLock) { 90 synchronized (sLock) {
74 if (sVersionCode == VERSION_CODE_UNINITIALIZED) { 91 if (sVersionCode == VERSION_CODE_UNINITIALIZED) {
75 PackageManager packageManager = context.getPackageManager(); 92 PackageManager packageManager = context.getPackageManager();
76 String packageName = context.getPackageName(); 93 String packageName = context.getPackageName();
77 try { 94 try {
78 PackageInfo packageInfo = packageManager.getPackageInfo( 95 PackageInfo packageInfo = packageManager.getPackageInfo(
79 packageName, 0); 96 packageName, 0);
80 sVersionCode = packageInfo.versionCode; 97 sVersionCode = packageInfo.versionCode;
81 } catch (NameNotFoundException e) { 98 } catch (NameNotFoundException e) {
82 throw new IllegalStateException( 99 throw new IllegalStateException(
83 "Cannot determine package version"); 100 "Cannot determine package version");
84 } 101 }
85 } 102 }
86 return sVersionCode; 103 return sVersionCode;
87 } 104 }
88 } 105 }
89 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698