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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PwsClientImpl.java

Issue 2721083002: Move PwsClientImplTest to junit (Closed)
Patch Set: Update commit message Created 3 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.chrome.browser.physicalweb; 5 package org.chromium.chrome.browser.physicalweb;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.os.AsyncTask; 9 import android.os.AsyncTask;
10 import android.os.Build; 10 import android.os.Build;
11 import android.text.TextUtils; 11 import android.text.TextUtils;
12 12
13 import org.json.JSONArray; 13 import org.json.JSONArray;
14 import org.json.JSONException; 14 import org.json.JSONException;
15 import org.json.JSONObject; 15 import org.json.JSONObject;
16 16
17 import org.chromium.base.ContextUtils;
17 import org.chromium.base.LocaleUtils; 18 import org.chromium.base.LocaleUtils;
18 import org.chromium.base.Log; 19 import org.chromium.base.Log;
19 import org.chromium.base.ThreadUtils; 20 import org.chromium.base.ThreadUtils;
20 import org.chromium.base.VisibleForTesting; 21 import org.chromium.base.VisibleForTesting;
21 import org.chromium.chrome.GoogleAPIKeys; 22 import org.chromium.chrome.GoogleAPIKeys;
22 import org.chromium.chrome.R; 23 import org.chromium.chrome.R;
23 import org.chromium.chrome.browser.ChromeVersionInfo; 24 import org.chromium.chrome.browser.ChromeVersionInfo;
24 import org.chromium.chrome.browser.physicalweb.PwsClient.FetchIconCallback; 25 import org.chromium.chrome.browser.physicalweb.PwsClient.FetchIconCallback;
25 import org.chromium.chrome.browser.physicalweb.PwsClient.ResolveScanCallback; 26 import org.chromium.chrome.browser.physicalweb.PwsClient.ResolveScanCallback;
26 27
(...skipping 22 matching lines...) Expand all
49 private static final String OS_INFO_FORMAT = "Linux; Android %s; %s Build/%s "; 50 private static final String OS_INFO_FORMAT = "Linux; Android %s; %s Build/%s ";
50 private static final String PRODUCT_FORMAT = "Chrome/%s Mobile"; 51 private static final String PRODUCT_FORMAT = "Chrome/%s Mobile";
51 52
52 // HTTP request header strings, lazily initialized. 53 // HTTP request header strings, lazily initialized.
53 private static String sUserAgent; 54 private static String sUserAgent;
54 private static String sAcceptLanguage; 55 private static String sAcceptLanguage;
55 56
56 // Cached locale string. When the default locale changes, recreate the Accep t-Language header. 57 // Cached locale string. When the default locale changes, recreate the Accep t-Language header.
57 private static String sDefaultLocale; 58 private static String sDefaultLocale;
58 59
59 // The context must be valid for as long as this client is in use, since it is used to recreate 60 public PwsClientImpl() {}
60 // the Accept-Language header when the locale changes.
61 private final Context mContext;
62
63 public PwsClientImpl(Context context) {
64 mContext = context;
65 }
66 61
67 private String getApiKey() { 62 private String getApiKey() {
68 if (ChromeVersionInfo.isStableBuild()) { 63 if (ChromeVersionInfo.isStableBuild()) {
69 return GoogleAPIKeys.GOOGLE_API_KEY; 64 return GoogleAPIKeys.GOOGLE_API_KEY;
70 } else { 65 } else {
71 return GoogleAPIKeys.GOOGLE_API_KEY_PHYSICAL_WEB_TEST; 66 return GoogleAPIKeys.GOOGLE_API_KEY_PHYSICAL_WEB_TEST;
72 } 67 }
73 } 68 }
74 69
75 private static JSONObject createResolveScanPayload(Collection<UrlInfo> urls) 70 private static JSONObject createResolveScanPayload(Collection<UrlInfo> urls)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 219
225 /** 220 /**
226 * Update an Accept-Language string based on the current default locales and make a string of 221 * Update an Accept-Language string based on the current default locales and make a string of
227 * an Accept-Language header with q-values. 222 * an Accept-Language header with q-values.
228 * @return An Accept-Language string made of an Accept-Language header with q-values. 223 * @return An Accept-Language string made of an Accept-Language header with q-values.
229 */ 224 */
230 @VisibleForTesting 225 @VisibleForTesting
231 String updateAcceptLanguage() { 226 String updateAcceptLanguage() {
232 String localeString = LocaleUtils.getDefaultLocaleListString(); 227 String localeString = LocaleUtils.getDefaultLocaleListString();
233 if (sDefaultLocale == null || !sDefaultLocale.equals(localeString)) { 228 if (sDefaultLocale == null || !sDefaultLocale.equals(localeString)) {
234 String acceptLanguages = mContext.getResources().getString(R.string. accept_languages); 229 Context context = ContextUtils.getApplicationContext();
230 String acceptLanguages = context.getResources().getString(R.string.a ccept_languages);
235 acceptLanguages = prependToAcceptLanguagesIfNecessary(localeString, acceptLanguages); 231 acceptLanguages = prependToAcceptLanguagesIfNecessary(localeString, acceptLanguages);
236 sAcceptLanguage = generateAcceptLanguageHeader(acceptLanguages); 232 sAcceptLanguage = generateAcceptLanguageHeader(acceptLanguages);
237 sDefaultLocale = localeString; 233 sDefaultLocale = localeString;
238 } 234 }
239 return sAcceptLanguage; 235 return sAcceptLanguage;
240 } 236 }
241 237
242 /** 238 /**
243 * Get the language code for the default locales and prepend it to the Accep t-Language string 239 * Get the language code for the default locales and prepend it to the Accep t-Language string
244 * if it isn't already present. The logic should match PrependToAcceptLangua gesIfNecessary in 240 * if it isn't already present. The logic should match PrependToAcceptLangua gesIfNecessary in
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 langListWithQ.format(",%s;q=0.%d", language, qvalue10); 305 langListWithQ.format(",%s;q=0.%d", language, qvalue10);
310 } 306 }
311 // It does not make sense to have 'q=0'. 307 // It does not make sense to have 'q=0'.
312 if (qvalue10 > kQvalueDecrement10) { 308 if (qvalue10 > kQvalueDecrement10) {
313 qvalue10 -= kQvalueDecrement10; 309 qvalue10 -= kQvalueDecrement10;
314 } 310 }
315 } 311 }
316 return langListWithQ.toString(); 312 return langListWithQ.toString();
317 } 313 }
318 } 314 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698