| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
| 9 import android.provider.Settings; | 9 import android.provider.Settings; |
| 10 | 10 |
| 11 import org.chromium.base.ApplicationState; | 11 import org.chromium.base.ApplicationState; |
| 12 import org.chromium.base.ApplicationStatus; | 12 import org.chromium.base.ApplicationStatus; |
| 13 import org.chromium.base.ApplicationStatus.ApplicationStateListener; | 13 import org.chromium.base.ApplicationStatus.ApplicationStateListener; |
| 14 import org.chromium.base.ContextUtils; | 14 import org.chromium.base.ContextUtils; |
| 15 import org.chromium.base.LocaleUtils; |
| 15 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
| 16 import org.chromium.base.VisibleForTesting; | 17 import org.chromium.base.VisibleForTesting; |
| 17 import org.chromium.base.metrics.RecordHistogram; | 18 import org.chromium.base.metrics.RecordHistogram; |
| 18 import org.chromium.chrome.browser.accessibility.FontSizePrefs; | 19 import org.chromium.chrome.browser.accessibility.FontSizePrefs; |
| 19 import org.chromium.chrome.browser.browsing_data.BrowsingDataType; | 20 import org.chromium.chrome.browser.browsing_data.BrowsingDataType; |
| 20 import org.chromium.chrome.browser.browsing_data.TimePeriod; | 21 import org.chromium.chrome.browser.browsing_data.TimePeriod; |
| 21 import org.chromium.chrome.browser.metrics.UmaUtils; | 22 import org.chromium.chrome.browser.metrics.UmaUtils; |
| 22 import org.chromium.chrome.browser.metrics.VariationsSession; | 23 import org.chromium.chrome.browser.metrics.VariationsSession; |
| 23 import org.chromium.chrome.browser.notifications.NotificationPlatformBridge; | 24 import org.chromium.chrome.browser.notifications.NotificationPlatformBridge; |
| 24 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza
tions; | 25 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza
tions; |
| 25 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 26 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| 26 import org.chromium.chrome.browser.share.ShareHelper; | 27 import org.chromium.chrome.browser.share.ShareHelper; |
| 27 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 28 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 28 import org.chromium.chrome.browser.util.FeatureUtilities; | 29 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 29 import org.chromium.content.browser.ChildProcessLauncher; | 30 import org.chromium.content.browser.ChildProcessLauncher; |
| 30 | 31 |
| 31 import java.lang.ref.WeakReference; | 32 import java.lang.ref.WeakReference; |
| 32 import java.util.Locale; | |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Tracks the foreground session state for the Chrome activities. | 35 * Tracks the foreground session state for the Chrome activities. |
| 36 */ | 36 */ |
| 37 public class ChromeActivitySessionTracker { | 37 public class ChromeActivitySessionTracker { |
| 38 | 38 |
| 39 private static final String PREF_LOCALE = "locale"; | 39 private static final String PREF_LOCALE = "locale"; |
| 40 | 40 |
| 41 private static ChromeActivitySessionTracker sInstance; | 41 private static ChromeActivitySessionTracker sInstance; |
| 42 | 42 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 }; | 175 }; |
| 176 } | 176 } |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * Update the accept languages after changing Android locale setting. Doing
so kills the | 179 * Update the accept languages after changing Android locale setting. Doing
so kills the |
| 180 * Activities but it doesn't kill the Application, so this should be called
in | 180 * Activities but it doesn't kill the Application, so this should be called
in |
| 181 * {@link #onStart} instead of {@link #initialize}. | 181 * {@link #onStart} instead of {@link #initialize}. |
| 182 */ | 182 */ |
| 183 private void updateAcceptLanguages() { | 183 private void updateAcceptLanguages() { |
| 184 PrefServiceBridge instance = PrefServiceBridge.getInstance(); | 184 PrefServiceBridge instance = PrefServiceBridge.getInstance(); |
| 185 String localeString = Locale.getDefault().toString(); // ex) en_US, de_
DE, zh_CN_#Hans | 185 String localeString = LocaleUtils.getDefaultLocale(); |
| 186 if (hasLocaleChanged(localeString)) { | 186 if (hasLocaleChanged(localeString)) { |
| 187 instance.resetAcceptLanguages(localeString); | 187 instance.resetAcceptLanguages(localeString); |
| 188 // Clear cache so that accept-languages change can be applied immedi
ately. | 188 // Clear cache so that accept-languages change can be applied immedi
ately. |
| 189 // TODO(changwan): The underlying BrowsingDataRemover::Remove() is a
n asynchronous call. | 189 // TODO(changwan): The underlying BrowsingDataRemover::Remove() is a
n asynchronous call. |
| 190 // So cache-clearing may not be effective if URL rendering can happe
n before | 190 // So cache-clearing may not be effective if URL rendering can happe
n before |
| 191 // OnBrowsingDataRemoverDone() is called, in which case we may have
to reload as well. | 191 // OnBrowsingDataRemoverDone() is called, in which case we may have
to reload as well. |
| 192 // Check if it can happen. | 192 // Check if it can happen. |
| 193 instance.clearBrowsingData( | 193 instance.clearBrowsingData( |
| 194 null, new int[]{ BrowsingDataType.CACHE }, TimePeriod.ALL_TI
ME); | 194 null, new int[]{ BrowsingDataType.CACHE }, TimePeriod.ALL_TI
ME); |
| 195 } | 195 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 233 } |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * @return The PowerBroadcastReceiver for the browser process. | 236 * @return The PowerBroadcastReceiver for the browser process. |
| 237 */ | 237 */ |
| 238 @VisibleForTesting | 238 @VisibleForTesting |
| 239 public PowerBroadcastReceiver getPowerBroadcastReceiverForTesting() { | 239 public PowerBroadcastReceiver getPowerBroadcastReceiverForTesting() { |
| 240 return mPowerBroadcastReceiver; | 240 return mPowerBroadcastReceiver; |
| 241 } | 241 } |
| 242 } | 242 } |
| OLD | NEW |