| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; |
| 7 import android.content.Context; | 8 import android.content.Context; |
| 8 | 9 |
| 9 import org.chromium.base.ObserverList; | 10 import org.chromium.base.ObserverList; |
| 10 import org.chromium.base.VisibleForTesting; | 11 import org.chromium.base.VisibleForTesting; |
| 11 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
| 12 import org.chromium.base.annotations.JNINamespace; | 13 import org.chromium.base.annotations.JNINamespace; |
| 13 import org.chromium.base.annotations.NativeClassQualifiedName; | 14 import org.chromium.base.annotations.NativeClassQualifiedName; |
| 14 | 15 |
| 15 import java.util.ArrayList; | 16 import java.util.ArrayList; |
| 16 | 17 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 34 public void onConnectionTypeChanged(int connectionType); | 35 public void onConnectionTypeChanged(int connectionType); |
| 35 } | 36 } |
| 36 | 37 |
| 37 private final ArrayList<Long> mNativeChangeNotifiers; | 38 private final ArrayList<Long> mNativeChangeNotifiers; |
| 38 private final ObserverList<ConnectionTypeObserver> mConnectionTypeObservers; | 39 private final ObserverList<ConnectionTypeObserver> mConnectionTypeObservers; |
| 39 private NetworkChangeNotifierAutoDetect mAutoDetector; | 40 private NetworkChangeNotifierAutoDetect mAutoDetector; |
| 40 private int mCurrentConnectionType = ConnectionType.CONNECTION_UNKNOWN; | 41 private int mCurrentConnectionType = ConnectionType.CONNECTION_UNKNOWN; |
| 41 private double mCurrentMaxBandwidth = Double.POSITIVE_INFINITY; | 42 private double mCurrentMaxBandwidth = Double.POSITIVE_INFINITY; |
| 42 private int mMaxBandwidthConnectionType = mCurrentConnectionType; | 43 private int mMaxBandwidthConnectionType = mCurrentConnectionType; |
| 43 | 44 |
| 45 @SuppressLint("StaticFieldLeak") |
| 44 private static NetworkChangeNotifier sInstance; | 46 private static NetworkChangeNotifier sInstance; |
| 45 | 47 |
| 46 @VisibleForTesting | 48 @VisibleForTesting |
| 47 protected NetworkChangeNotifier() { | 49 protected NetworkChangeNotifier() { |
| 48 mNativeChangeNotifiers = new ArrayList<Long>(); | 50 mNativeChangeNotifiers = new ArrayList<Long>(); |
| 49 mConnectionTypeObservers = new ObserverList<ConnectionTypeObserver>(); | 51 mConnectionTypeObservers = new ObserverList<ConnectionTypeObserver>(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 // TODO(wnwen): Remove after downstream no longer depends on this. | 54 // TODO(wnwen): Remove after downstream no longer depends on this. |
| 53 public static NetworkChangeNotifier init(Context context) { | 55 public static NetworkChangeNotifier init(Context context) { |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 425 } |
| 424 | 426 |
| 425 /** | 427 /** |
| 426 * Checks if there currently is connectivity. | 428 * Checks if there currently is connectivity. |
| 427 */ | 429 */ |
| 428 public static boolean isOnline() { | 430 public static boolean isOnline() { |
| 429 int connectionType = getInstance().getCurrentConnectionType(); | 431 int connectionType = getInstance().getCurrentConnectionType(); |
| 430 return connectionType != ConnectionType.CONNECTION_NONE; | 432 return connectionType != ConnectionType.CONNECTION_NONE; |
| 431 } | 433 } |
| 432 } | 434 } |
| OLD | NEW |