Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettingsAndroid.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettingsAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettingsAndroid.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2dace66fe2628bb07258f28ac9e91c2abfd73427 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettingsAndroid.java |
| @@ -0,0 +1,173 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
|
nyquist
2013/09/04 02:20:15
Nit: Nowadays, there should be no (c), but the yea
bengr
2013/09/05 02:03:49
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.net.spdyproxy; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.ThreadUtils; |
| + |
| +public class DataReductionProxySettingsAndroid { |
| + |
| + public static class ContentLengths { |
| + private final long mOriginal; |
| + private final long mReceived; |
| + |
| + @CalledByNative("ContentLengths") |
| + public static ContentLengths create(long original, long received) { |
| + return new ContentLengths(original, received); |
| + } |
| + |
| + public ContentLengths(long original, long received) { |
|
nyquist
2013/09/04 02:20:15
private
bengr
2013/09/05 02:03:49
Done.
|
| + mOriginal = original; |
| + mReceived = received; |
| + } |
| + |
| + public long getOriginal() { |
| + return mOriginal; |
| + } |
| + |
| + public long getReceived() { |
| + return mReceived; |
| + } |
| + } |
| + |
| + private static DataReductionProxySettingsAndroid sConfig; |
|
nyquist
2013/09/04 02:20:15
sSettings? At least something that is part of the
bengr
2013/09/05 02:03:49
Done.
|
| + |
| + public static DataReductionProxySettingsAndroid getInstance() { |
| + ThreadUtils.assertOnUiThread(); |
| + if (sConfig == null) { |
| + sConfig = new DataReductionProxySettingsAndroid(); |
| + } |
| + return sConfig; |
| + } |
| + |
| + private final int mNativeDataReductionProxySettingsAndroid; |
| + |
| + private DataReductionProxySettingsAndroid() { |
| + // Note that this technically leaks the native object, however, |
| + // DataReductionProxySettingsAndroid is a singleton that lives forever and there's no clean |
| + // shutdown of Chrome on Android |
| + mNativeDataReductionProxySettingsAndroid = nativeInit(); |
| + initDataReductionProxySettings(); |
| + } |
| + |
| + /** |
| + * Initializes the data reduction proxy at Chrome startup. |
| + */ |
| + public void initDataReductionProxySettings() { |
| + nativeInitDataReductionProxySettings(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + |
| + /** Returns true if the SPDY proxy is meant to be available. */ |
| + public boolean isDataReductionProxyAvailable() { |
| + return nativeIsDataReductionProxyAvailable(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /** Returns true if the SPDY proxy promo is meant to be available. */ |
| + public boolean isDataReductionProxyPromoAvailable() { |
| + return nativeIsDataReductionProxyPromoAvailable(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /** |
| + * Returns the current SPDY proxy origin. |
| + */ |
| + public String getDataReductionProxyOrigin() { |
| + return nativeGetDataReductionProxyOrigin(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /* |
| + * Returns the current SPDY proxy property. |
| + */ |
| + public String getDataReductionProxyValue() { |
| + return nativeGetDataReductionProxyValue(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /** |
| + * Sets the preference on whether to enable/disable the SPDY proxy. This will zero out the |
| + * data reduction statistics if this is the first time the SPDY proxy has been enabled. |
| + */ |
| + public void setDataReductionProxyEnabled(boolean enabled) { |
| + nativeSetDataReductionProxyEnabled(mNativeDataReductionProxySettingsAndroid, enabled); |
| + } |
| + |
| + /** Returns true if the SPDY proxy is enabled. */ |
| + public boolean isDataReductionProxyEnabled() { |
| + return nativeIsDataReductionProxyEnabled(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /** |
| + * Returns the time that the data reduction statistics were last updated. |
| + * @return The last update time in milliseconds since the epoch. |
| + */ |
| + public long getDataReductionLastUpdateTime() { |
| + return nativeGetDataReductionLastUpdateTime(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /** |
| + * Returns aggregate original and received content lengths. |
| + * @return The content lengths. |
| + */ |
| + public ContentLengths getContentLengths() { |
| + return nativeGetContentLengths(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /** |
| + * Retrieves the history of daily totals of bytes that would have been |
| + * received if no data reducing mechanism had been applied. |
| + * @param days The number of days of history to get |
| + * @return The history of daily totals |
| + */ |
| + public long[] getOriginalNetworkStatsHistory(int days) { |
|
nyquist
2013/09/04 02:20:15
|days| is unused. something that will be used soon
bengr
2013/09/05 02:03:49
Done.
|
| + return nativeGetDailyOriginalContentLengths(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /** |
| + * Retrieves the history of daily totals of bytes that were received after |
| + * applying a data reducing mechanism. |
| + * @param days The number of days of history to get |
| + * @return The history of daily totals |
| + */ |
| + public long[] getReceivedNetworkStatsHistory(int days) { |
|
nyquist
2013/09/04 02:20:15
|days| is unused.
bengr
2013/09/05 02:03:49
Done.
|
| + return nativeGetDailyReceivedContentLengths(mNativeDataReductionProxySettingsAndroid); |
| + } |
| + |
| + /** |
| + * @return The data reduction settings as a string percentage. |
| + */ |
| + public String getContentLengthPercentSavings() { |
| + ContentLengths length = getContentLengths(); |
| + String percent = "0%"; |
| + if (length.getOriginal() > 0L && length.getOriginal() > length.getReceived()) { |
| + percent = String.format( |
| + "%.0f%%", 100.0 * |
| + (length.getOriginal() - length.getReceived()) / length.getOriginal()); |
| + } |
| + return percent; |
| + } |
| + |
| + private native int nativeInit(); |
| + private native void nativeInitDataReductionProxySettings( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native boolean nativeIsDataReductionProxyAvailable( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native boolean nativeIsDataReductionProxyPromoAvailable( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native String nativeGetDataReductionProxyOrigin( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native String nativeGetDataReductionProxyValue( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native boolean nativeIsDataReductionProxyEnabled( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native void nativeSetDataReductionProxyEnabled( |
| + int nativeDataReductionProxySettingsAndroid, boolean enabled); |
| + private native long nativeGetDataReductionLastUpdateTime( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native ContentLengths nativeGetContentLengths( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native long[] nativeGetDailyOriginalContentLengths( |
| + int nativeDataReductionProxySettingsAndroid); |
| + private native long[] nativeGetDailyReceivedContentLengths( |
| + int nativeDataReductionProxySettingsAndroid); |
| +} |