OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_NET_NETWORK_QUALITY_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_NET_NETWORK_QUALITY_PROVIDER_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread_checker.h" |
| 15 #include "base/time/time.h" |
| 16 #include "net/base/network_change_notifier.h" |
| 17 |
| 18 // Native class that calls Java code exposed by |
| 19 // NetworkQualityProviderHelper.java. Provides network quality estimates as |
| 20 // provided by Android. Estimates are automatically updated on a network change |
| 21 // event. |
| 22 class NetworkQualityProvider |
| 23 : public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| 24 public: |
| 25 // Constructs and initializes the underlying provider. |
| 26 NetworkQualityProvider(); |
| 27 |
| 28 ~NetworkQualityProvider() override; |
| 29 |
| 30 // Returns true only if network quality estimate is available. |
| 31 bool IsEstimateAvailable(); |
| 32 |
| 33 // Returns true if the estimated RTT duration is available, and sets |rtt| to |
| 34 // the estimate. |
| 35 bool GetRTT(base::TimeDelta* rtt); |
| 36 |
| 37 // Returns true if the estimated downstream throughput (in Kbps -- Kilobits |
| 38 // per second) is available, and sets |downstream_throughput_kbps| to the |
| 39 // estimate. |
| 40 bool GetDownstreamThroughputKbps(int32_t* downstream_throughput_kbps); |
| 41 |
| 42 // Returns true if the estimated upstream throughput (in Kbps -- Kilobits per |
| 43 // second) is available, and sets |upstream_throughput_kbps| to the estimate. |
| 44 bool GetUpstreamThroughputKbps(int32_t* upstream_throughput_kbps); |
| 45 |
| 46 // Returns true if the time since network quality was last updated is |
| 47 // available, and sets |time_since_last_update| to that value. |
| 48 bool GetTimeSinceLastUpdate(base::TimeDelta* time_since_last_update); |
| 49 |
| 50 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| 51 void OnConnectionTypeChanged( |
| 52 net::NetworkChangeNotifier::ConnectionType type) override; |
| 53 |
| 54 private: |
| 55 // Places a requests to the provider to update the network quality. Returns |
| 56 // true if the request was placed successfully. |
| 57 void RequestUpdate(); |
| 58 |
| 59 // Value returned if valid value is unavailable. |
| 60 int32_t no_value_ = -1; |
| 61 |
| 62 base::android::ScopedJavaGlobalRef<jobject> j_network_quality_provider_; |
| 63 |
| 64 base::ThreadChecker thread_checker_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(NetworkQualityProvider); |
| 67 }; |
| 68 |
| 69 bool RegisterNetworkQualityProvider(JNIEnv* env); |
| 70 |
| 71 #endif // CHROME_BROWSER_ANDROID_NET_NETWORK_QUALITY_PROVIDER_H_ |
OLD | NEW |