Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProvider.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProvider.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c433237f149e0146f2c4c0b98a0488f2cfc8bac8 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProvider.java |
| @@ -0,0 +1,95 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// 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.qualityprovider; |
| + |
| +import android.content.Context; |
| + |
| +import org.chromium.chrome.browser.util.NonThreadSafe; |
| + |
| +/** |
| + * This class provides a base class implementation and may be overridden on operating systems that |
| + * provide more useful APIs. This class is not thread safe. |
| + */ |
| +public class NetworkQualityProvider { |
| + private static NetworkQualityProvider sInstance = null; |
| + private static NonThreadSafe sThreadCheck = null; |
| + |
| + /** |
| + * Value to return if a valid value is unavailable. |
| + */ |
| + protected static final int NO_VALUE = -1; |
| + |
| + /** |
| + * Returns an instance of singleton NetworkQualityProvider. |
| + */ |
| + public static NetworkQualityProvider getInstance() { |
| + if (sThreadCheck == null) sThreadCheck = new NonThreadSafe(); |
| + assert sThreadCheck.calledOnValidThread(); |
| + if (sInstance == null) sInstance = new NetworkQualityProvider(); |
| + return sInstance; |
| + } |
| + |
| + /** |
| + * Creates an instance of NetworkQualityProvider. |
| + */ |
| + protected NetworkQualityProvider() { |
| + assertCorrectness(); |
| + } |
| + |
| + /** |
| + * Initializes the provider with the context. |
| + */ |
| + public void initialize(Context context) { |
|
nyquist
2015/07/22 14:46:59
Why not pass this context in to the constructor in
tbansal1
2015/07/22 21:11:29
Done.
|
| + assertCorrectness(); |
| + } |
| + |
| + /** |
| + * Returns true if the network quality estimate is available. |
| + */ |
| + protected boolean isEstimateAvailable() { |
| + assertCorrectness(); |
| + return false; |
| + } |
| + |
| + /** |
| + * Returns the expected RTT duration in milliseconds. |
| + * Returns 0 if the estimate is unavailable. |
| + */ |
| + protected int getRTTMilliseconds() { |
| + assertCorrectness(); |
| + return NO_VALUE; |
| + } |
| + |
| + /** |
| + * Returns the expected downstream throughput in Kbps. |
| + * Returns 0 if the estimate is unavailable. |
| + */ |
| + protected long getDownstreamThroughputKbps() { |
| + assertCorrectness(); |
| + return NO_VALUE; |
| + } |
| + |
| + /** |
| + * Returns the expected upstream throughput in Kbps. |
| + * Returns 0 if the estimate is unavailable. |
| + */ |
| + protected long getUpstreamThroughputKbps() { |
| + assertCorrectness(); |
| + return NO_VALUE; |
| + } |
| + |
| + /** |
| + * Returns time (in seconds) since the network quality was last updated. |
| + */ |
| + protected long getTimeSinceLastUpdateSeconds() { |
| + assertCorrectness(); |
| + return NO_VALUE; |
| + } |
| + |
| + private void assertCorrectness() { |
|
nyquist
2015/07/22 14:46:59
static?
tbansal1
2015/07/22 21:11:29
Obsolete.
|
| + assert sThreadCheck.calledOnValidThread(); |
| + assert sInstance != null; |
| + } |
| +} |