| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.net.spdyproxy; | 5 package org.chromium.chrome.browser.net.spdyproxy; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.net.Uri; | 8 import android.net.Uri; |
| 9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
| 10 import android.webkit.URLUtil; | 10 import android.webkit.URLUtil; |
| 11 | 11 |
| 12 import org.chromium.base.ContextUtils; | 12 import org.chromium.base.ContextUtils; |
| 13 import org.chromium.base.ThreadUtils; | 13 import org.chromium.base.ThreadUtils; |
| 14 import org.chromium.base.VisibleForTesting; | 14 import org.chromium.base.VisibleForTesting; |
| 15 import org.chromium.base.annotations.CalledByNative; | 15 import org.chromium.base.annotations.CalledByNative; |
| 16 import org.chromium.chrome.browser.UrlConstants; |
| 16 | 17 |
| 17 import java.text.NumberFormat; | 18 import java.text.NumberFormat; |
| 18 import java.util.HashMap; | 19 import java.util.HashMap; |
| 19 import java.util.Locale; | 20 import java.util.Locale; |
| 20 import java.util.Map; | 21 import java.util.Map; |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * Entry point to manage all data reduction proxy configuration details. | 24 * Entry point to manage all data reduction proxy configuration details. |
| 24 */ | 25 */ |
| 25 public class DataReductionProxySettings { | 26 public class DataReductionProxySettings { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 /** Returns true if the SPDY proxy is allowed to be used. */ | 129 /** Returns true if the SPDY proxy is allowed to be used. */ |
| 129 public boolean isDataReductionProxyAllowed() { | 130 public boolean isDataReductionProxyAllowed() { |
| 130 return nativeIsDataReductionProxyAllowed(mNativeDataReductionProxySettin
gs); | 131 return nativeIsDataReductionProxyAllowed(mNativeDataReductionProxySettin
gs); |
| 131 } | 132 } |
| 132 | 133 |
| 133 /** Returns true if the SPDY proxy promo is allowed to be shown. */ | 134 /** Returns true if the SPDY proxy promo is allowed to be shown. */ |
| 134 public boolean isDataReductionProxyPromoAllowed() { | 135 public boolean isDataReductionProxyPromoAllowed() { |
| 135 return nativeIsDataReductionProxyPromoAllowed(mNativeDataReductionProxyS
ettings); | 136 return nativeIsDataReductionProxyPromoAllowed(mNativeDataReductionProxyS
ettings); |
| 136 } | 137 } |
| 137 | 138 |
| 139 /** Returns true if the snackbar promo is allowed to be shown. */ |
| 140 public boolean isSnackbarPromoAllowed(String url) { |
| 141 return url.startsWith(UrlConstants.HTTP_SCHEME) && isDataReductionProxyE
nabled() |
| 142 && isDataReductionProxyPromoAllowed(); |
| 143 } |
| 144 |
| 138 /** | 145 /** |
| 139 * Sets the preference on whether to enable/disable the SPDY proxy. This wil
l zero out the | 146 * Sets the preference on whether to enable/disable the SPDY proxy. This wil
l zero out the |
| 140 * data reduction statistics if this is the first time the SPDY proxy has be
en enabled. | 147 * data reduction statistics if this is the first time the SPDY proxy has be
en enabled. |
| 141 */ | 148 */ |
| 142 public void setDataReductionProxyEnabled(Context context, boolean enabled) { | 149 public void setDataReductionProxyEnabled(Context context, boolean enabled) { |
| 143 ContextUtils.getAppSharedPreferences().edit() | 150 ContextUtils.getAppSharedPreferences().edit() |
| 144 .putBoolean(DATA_REDUCTION_ENABLED_PREF, enabled).apply(); | 151 .putBoolean(DATA_REDUCTION_ENABLED_PREF, enabled).apply(); |
| 145 nativeSetDataReductionProxyEnabled(mNativeDataReductionProxySettings, en
abled); | 152 nativeSetDataReductionProxyEnabled(mNativeDataReductionProxySettings, en
abled); |
| 146 } | 153 } |
| 147 | 154 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 204 |
| 198 /** | 205 /** |
| 199 * Returns aggregate original and received content lengths. | 206 * Returns aggregate original and received content lengths. |
| 200 * @return The content lengths. | 207 * @return The content lengths. |
| 201 */ | 208 */ |
| 202 public ContentLengths getContentLengths() { | 209 public ContentLengths getContentLengths() { |
| 203 return nativeGetContentLengths(mNativeDataReductionProxySettings); | 210 return nativeGetContentLengths(mNativeDataReductionProxySettings); |
| 204 } | 211 } |
| 205 | 212 |
| 206 /** | 213 /** |
| 214 * Returns the total HTTP content length saved. |
| 215 * @return The HTTP content length saved. |
| 216 */ |
| 217 public long getTotalHttpContentLengthSaved() { |
| 218 return nativeGetTotalHttpContentLengthSaved(mNativeDataReductionProxySet
tings); |
| 219 } |
| 220 |
| 221 /** |
| 207 * Retrieves the history of daily totals of bytes that would have been | 222 * Retrieves the history of daily totals of bytes that would have been |
| 208 * received if no data reducing mechanism had been applied. | 223 * received if no data reducing mechanism had been applied. |
| 209 * @return The history of daily totals | 224 * @return The history of daily totals |
| 210 */ | 225 */ |
| 211 public long[] getOriginalNetworkStatsHistory() { | 226 public long[] getOriginalNetworkStatsHistory() { |
| 212 return nativeGetDailyOriginalContentLengths(mNativeDataReductionProxySet
tings); | 227 return nativeGetDailyOriginalContentLengths(mNativeDataReductionProxySet
tings); |
| 213 } | 228 } |
| 214 | 229 |
| 215 /** | 230 /** |
| 216 * Retrieves the history of daily totals of bytes that were received after | 231 * Retrieves the history of daily totals of bytes that were received after |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 private native void nativeSetLoFiLoadImageRequested( | 317 private native void nativeSetLoFiLoadImageRequested( |
| 303 long nativeDataReductionProxySettingsAndroid); | 318 long nativeDataReductionProxySettingsAndroid); |
| 304 private native boolean nativeIsDataReductionProxyManaged( | 319 private native boolean nativeIsDataReductionProxyManaged( |
| 305 long nativeDataReductionProxySettingsAndroid); | 320 long nativeDataReductionProxySettingsAndroid); |
| 306 private native void nativeSetDataReductionProxyEnabled( | 321 private native void nativeSetDataReductionProxyEnabled( |
| 307 long nativeDataReductionProxySettingsAndroid, boolean enabled); | 322 long nativeDataReductionProxySettingsAndroid, boolean enabled); |
| 308 private native long nativeGetDataReductionLastUpdateTime( | 323 private native long nativeGetDataReductionLastUpdateTime( |
| 309 long nativeDataReductionProxySettingsAndroid); | 324 long nativeDataReductionProxySettingsAndroid); |
| 310 private native ContentLengths nativeGetContentLengths( | 325 private native ContentLengths nativeGetContentLengths( |
| 311 long nativeDataReductionProxySettingsAndroid); | 326 long nativeDataReductionProxySettingsAndroid); |
| 327 private native long nativeGetTotalHttpContentLengthSaved( |
| 328 long nativeDataReductionProxySettingsAndroid); |
| 312 private native long[] nativeGetDailyOriginalContentLengths( | 329 private native long[] nativeGetDailyOriginalContentLengths( |
| 313 long nativeDataReductionProxySettingsAndroid); | 330 long nativeDataReductionProxySettingsAndroid); |
| 314 private native long[] nativeGetDailyReceivedContentLengths( | 331 private native long[] nativeGetDailyReceivedContentLengths( |
| 315 long nativeDataReductionProxySettingsAndroid); | 332 long nativeDataReductionProxySettingsAndroid); |
| 316 private native boolean nativeIsDataReductionProxyUnreachable( | 333 private native boolean nativeIsDataReductionProxyUnreachable( |
| 317 long nativeDataReductionProxySettingsAndroid); | 334 long nativeDataReductionProxySettingsAndroid); |
| 318 private native boolean nativeAreLoFiPreviewsEnabled( | 335 private native boolean nativeAreLoFiPreviewsEnabled( |
| 319 long nativeDataReductionProxySettingsAndroid); | 336 long nativeDataReductionProxySettingsAndroid); |
| 320 private native String nativeGetHttpProxyList(long nativeDataReductionProxySe
ttingsAndroid); | 337 private native String nativeGetHttpProxyList(long nativeDataReductionProxySe
ttingsAndroid); |
| 321 private native String nativeGetLastBypassEvent(long nativeDataReductionProxy
SettingsAndroid); | 338 private native String nativeGetLastBypassEvent(long nativeDataReductionProxy
SettingsAndroid); |
| 322 } | 339 } |
| OLD | NEW |