OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_ |
6 #define CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_ | 6 #define CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 // network change event. | 27 // network change event. |
28 class ExternalEstimateProviderAndroid | 28 class ExternalEstimateProviderAndroid |
29 : public net::NetworkChangeNotifier::ConnectionTypeObserver, | 29 : public net::NetworkChangeNotifier::ConnectionTypeObserver, |
30 public net::ExternalEstimateProvider { | 30 public net::ExternalEstimateProvider { |
31 public: | 31 public: |
32 // Constructs and initializes the underlying provider. | 32 // Constructs and initializes the underlying provider. |
33 ExternalEstimateProviderAndroid(); | 33 ExternalEstimateProviderAndroid(); |
34 | 34 |
35 ~ExternalEstimateProviderAndroid() override; | 35 ~ExternalEstimateProviderAndroid() override; |
36 | 36 |
37 // net::ExternalEstimateProvider implementation: | 37 // net::ExternalEstimateProvider implementation. |
38 bool GetRTT(base::TimeDelta* rtt) const override; | 38 bool GetRTT(base::TimeDelta* rtt) const override; |
| 39 |
| 40 // net::ExternalEstimateProvider implementation. |
39 bool GetDownstreamThroughputKbps( | 41 bool GetDownstreamThroughputKbps( |
40 int32_t* downstream_throughput_kbps) const override; | 42 int32_t* downstream_throughput_kbps) const override; |
| 43 |
| 44 // net::ExternalEstimateProvider implementation. |
41 bool GetUpstreamThroughputKbps( | 45 bool GetUpstreamThroughputKbps( |
42 int32_t* upstream_throughput_kbps) const override; | 46 int32_t* upstream_throughput_kbps) const override; |
| 47 |
| 48 // net::ExternalEstimateProvider implementation. |
43 bool GetTimeSinceLastUpdate( | 49 bool GetTimeSinceLastUpdate( |
44 base::TimeDelta* time_since_last_update) const override; | 50 base::TimeDelta* time_since_last_update) const override; |
45 void SetUpdatedEstimateDelegate( | |
46 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate) | |
47 override; | |
48 void Update() const override; | |
49 | 51 |
50 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 52 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
51 void OnConnectionTypeChanged( | 53 void OnConnectionTypeChanged( |
52 net::NetworkChangeNotifier::ConnectionType type) override; | 54 net::NetworkChangeNotifier::ConnectionType type) override; |
53 | 55 |
| 56 // net::ExternalEstimateProvider implementation. |
| 57 void SetUpdatedEstimateDelegate( |
| 58 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate) |
| 59 override; |
| 60 |
54 // Called by Java when the external estimate provider has an updated value. | 61 // Called by Java when the external estimate provider has an updated value. |
55 // This may be called on a thread different from |task_runner_|. | 62 // This may be called on a thread different from |task_runner_|. |
56 void NotifyExternalEstimateProviderAndroidUpdate(JNIEnv* env, jobject obj); | 63 void NotifyExternalEstimateProviderAndroidUpdate(JNIEnv* env, jobject obj); |
57 | 64 |
58 protected: | 65 protected: |
59 // Notifies the delegate that a new update to external estimate is available. | 66 // Notifies the delegate that a new update to external estimate is available. |
60 // Protected for testing. | 67 // Protected for testing. |
61 void NotifyUpdatedEstimateAvailable() const; | 68 void NotifyUpdatedEstimateAvailable() const; |
62 | 69 |
63 private: | 70 private: |
| 71 // Places a requests to the provider to update the network quality. Returns |
| 72 // true if the request was placed successfully. |
| 73 void RequestUpdate() const; |
| 74 |
64 // Value returned if valid value is unavailable. | 75 // Value returned if valid value is unavailable. |
65 int32_t no_value_ = -1; | 76 int32_t no_value_ = -1; |
66 | 77 |
67 base::android::ScopedJavaGlobalRef<jobject> j_external_estimate_provider_; | 78 base::android::ScopedJavaGlobalRef<jobject> j_external_estimate_provider_; |
68 | 79 |
69 // Task runner that accesses ExternalEstimateProviderAndroid members. | 80 // Task runner that accesses ExternalEstimateProviderAndroid members. |
70 scoped_refptr<base::TaskRunner> task_runner_; | 81 scoped_refptr<base::TaskRunner> task_runner_; |
71 | 82 |
72 // Notified every time there is an update available from the network quality | 83 // Notified every time there is an update available from the network quality |
73 // provider. | 84 // provider. |
74 // TODO(tbansal): Add the function that is called by Java side when an update | 85 // TODO(tbansal): Add the function that is called by Java side when an update |
75 // is available. | 86 // is available. |
76 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate_; | 87 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate_; |
77 | 88 |
78 base::ThreadChecker thread_checker_; | 89 base::ThreadChecker thread_checker_; |
79 | 90 |
80 // Used for posting tasks. | 91 // Used for posting tasks. |
81 base::WeakPtrFactory<ExternalEstimateProviderAndroid> weak_factory_; | 92 base::WeakPtrFactory<ExternalEstimateProviderAndroid> weak_factory_; |
82 | 93 |
83 DISALLOW_COPY_AND_ASSIGN(ExternalEstimateProviderAndroid); | 94 DISALLOW_COPY_AND_ASSIGN(ExternalEstimateProviderAndroid); |
84 }; | 95 }; |
85 | 96 |
86 bool RegisterExternalEstimateProviderAndroid(JNIEnv* env); | 97 bool RegisterExternalEstimateProviderAndroid(JNIEnv* env); |
87 | 98 |
88 } // namespace android | 99 } // namespace android |
89 } // namespace chrome | 100 } // namespace chrome |
90 | 101 |
91 #endif // CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_ | 102 #endif // CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_ |
OLD | NEW |