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

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

Issue 1849753002: [Cronet] Separate Cronet implementation and API by package name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 4 years, 5 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 builder.append("; "); 50 builder.append("; ");
51 builder.append(model); 51 builder.append(model);
52 } 52 }
53 53
54 String id = Build.ID; 54 String id = Build.ID;
55 if (id.length() > 0) { 55 if (id.length() > 0) {
56 builder.append("; Build/"); 56 builder.append("; Build/");
57 builder.append(id); 57 builder.append(id);
58 } 58 }
59 59
60 builder.append("; Cronet/"); 60 builder.append(";");
61 builder.append(Version.CRONET_VERSION); 61 appendCronetVersion(builder);
62 62
63 builder.append(')'); 63 builder.append(')');
64 64
65 return builder.toString(); 65 return builder.toString();
66 } 66 }
67 67
68 /** 68 /**
69 * Constructs default QUIC User Agent Id string including application name 69 * Constructs default QUIC User Agent Id string including application name
70 * and Cronet version. 70 * and Cronet version.
71 * @param context the context to fetch the application name from. 71 * @param context the context to fetch the application name from.
72 * @return User-Agent string. 72 * @return User-Agent string.
73 */ 73 */
74 static String getQuicUserAgentIdFrom(Context context) { 74 static String getQuicUserAgentIdFrom(Context context) {
75 StringBuilder builder = new StringBuilder(); 75 StringBuilder builder = new StringBuilder();
76 76
77 // Application name and cronet version. 77 // Application name and cronet version.
78 builder.append(context.getPackageName()); 78 builder.append(context.getPackageName());
79 builder.append(" Cronet/"); 79 appendCronetVersion(builder);
80 builder.append(Version.CRONET_VERSION);
81 80
82 return builder.toString(); 81 return builder.toString();
83 } 82 }
84 83
85 private static int versionFromContext(Context context) { 84 private static int versionFromContext(Context context) {
86 synchronized (sLock) { 85 synchronized (sLock) {
87 if (sVersionCode == VERSION_CODE_UNINITIALIZED) { 86 if (sVersionCode == VERSION_CODE_UNINITIALIZED) {
88 PackageManager packageManager = context.getPackageManager(); 87 PackageManager packageManager = context.getPackageManager();
89 String packageName = context.getPackageName(); 88 String packageName = context.getPackageName();
90 try { 89 try {
91 PackageInfo packageInfo = packageManager.getPackageInfo( 90 PackageInfo packageInfo = packageManager.getPackageInfo(
92 packageName, 0); 91 packageName, 0);
93 sVersionCode = packageInfo.versionCode; 92 sVersionCode = packageInfo.versionCode;
94 } catch (NameNotFoundException e) { 93 } catch (NameNotFoundException e) {
95 throw new IllegalStateException( 94 throw new IllegalStateException(
96 "Cannot determine package version"); 95 "Cannot determine package version");
97 } 96 }
98 } 97 }
99 return sVersionCode; 98 return sVersionCode;
100 } 99 }
101 } 100 }
101
102 private static void appendCronetVersion(StringBuilder builder) {
103 builder.append(" Cronet/");
104 // TODO(pauljensen): This is the API version not the implementation
105 // version. The implementation version may be more appropriate for the
106 // UserAgent but is not available until after the CronetEngine is
107 // instantiated. Down the road, if the implementation is loaded via
108 // other means, this should be replaced with the implementation version.
109 builder.append(ApiVersion.CRONET_VERSION);
110 }
102 } 111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698