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 | 39 |
40 // net::ExternalEstimateProvider implementation. | 40 // net::ExternalEstimateProvider implementation: |
41 bool GetDownstreamThroughputKbps( | 41 bool GetDownstreamThroughputKbps( |
42 int32_t* downstream_throughput_kbps) const override; | 42 int32_t* downstream_throughput_kbps) const override; |
43 | 43 |
44 // net::ExternalEstimateProvider implementation. | 44 // net::ExternalEstimateProvider implementation: |
45 bool GetUpstreamThroughputKbps( | 45 bool GetUpstreamThroughputKbps( |
46 int32_t* upstream_throughput_kbps) const override; | 46 int32_t* upstream_throughput_kbps) const override; |
47 | 47 |
48 // net::ExternalEstimateProvider implementation. | 48 // net::ExternalEstimateProvider implementation: |
49 bool GetTimeSinceLastUpdate( | 49 bool GetTimeSinceLastUpdate( |
50 base::TimeDelta* time_since_last_update) const override; | 50 base::TimeDelta* time_since_last_update) const override; |
51 | 51 |
52 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 52 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
53 void OnConnectionTypeChanged( | 53 void OnConnectionTypeChanged( |
54 net::NetworkChangeNotifier::ConnectionType type) override; | 54 net::NetworkChangeNotifier::ConnectionType type) override; |
55 | 55 |
56 // net::ExternalEstimateProvider implementation. | 56 // net::ExternalEstimateProvider implementation: |
bengr
2015/09/08 18:14:23
I'm ok with you adding this comment only to the fi
tbansal1
2015/09/08 21:25:55
Thanks, this made it much cleaner. Done.
| |
57 void SetUpdatedEstimateDelegate( | 57 void SetUpdatedEstimateDelegate( |
58 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate) | 58 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate) |
59 override; | 59 override; |
60 | 60 |
61 // 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. |
62 // This may be called on a thread different from |task_runner_|. | 62 // This may be called on a thread different from |task_runner_|. |
63 void NotifyExternalEstimateProviderAndroidUpdate(JNIEnv* env, jobject obj); | 63 void NotifyExternalEstimateProviderAndroidUpdate(JNIEnv* env, jobject obj); |
64 | 64 |
65 // net::ExternalEstimateProvider implementation: | |
66 void RequestUpdate() const override; | |
bengr
2015/09/08 18:14:23
I would move this up with the other overrides.
tbansal1
2015/09/08 21:25:55
Done.
| |
67 | |
65 protected: | 68 protected: |
66 // Notifies the delegate that a new update to external estimate is available. | 69 // Notifies the delegate that a new update to external estimate is available. |
67 // Protected for testing. | 70 // Protected for testing. |
68 void NotifyUpdatedEstimateAvailable() const; | 71 void NotifyUpdatedEstimateAvailable() const; |
69 | 72 |
70 private: | 73 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 | |
75 // Value returned if valid value is unavailable. | 74 // Value returned if valid value is unavailable. |
76 int32_t no_value_ = -1; | 75 int32_t no_value_ = -1; |
77 | 76 |
78 base::android::ScopedJavaGlobalRef<jobject> j_external_estimate_provider_; | 77 base::android::ScopedJavaGlobalRef<jobject> j_external_estimate_provider_; |
79 | 78 |
80 // Task runner that accesses ExternalEstimateProviderAndroid members. | 79 // Task runner that accesses ExternalEstimateProviderAndroid members. |
81 scoped_refptr<base::TaskRunner> task_runner_; | 80 scoped_refptr<base::TaskRunner> task_runner_; |
82 | 81 |
83 // Notified every time there is an update available from the network quality | 82 // Notified every time there is an update available from the network quality |
84 // provider. | 83 // provider. |
85 // TODO(tbansal): Add the function that is called by Java side when an update | 84 // TODO(tbansal): Add the function that is called by Java side when an update |
86 // is available. | 85 // is available. |
87 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate_; | 86 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate_; |
88 | 87 |
89 base::ThreadChecker thread_checker_; | 88 base::ThreadChecker thread_checker_; |
90 | 89 |
91 // Used for posting tasks. | 90 // Used for posting tasks. |
92 base::WeakPtrFactory<ExternalEstimateProviderAndroid> weak_factory_; | 91 base::WeakPtrFactory<ExternalEstimateProviderAndroid> weak_factory_; |
93 | 92 |
94 DISALLOW_COPY_AND_ASSIGN(ExternalEstimateProviderAndroid); | 93 DISALLOW_COPY_AND_ASSIGN(ExternalEstimateProviderAndroid); |
95 }; | 94 }; |
96 | 95 |
97 bool RegisterExternalEstimateProviderAndroid(JNIEnv* env); | 96 bool RegisterExternalEstimateProviderAndroid(JNIEnv* env); |
98 | 97 |
99 } // namespace android | 98 } // namespace android |
100 } // namespace chrome | 99 } // namespace chrome |
101 | 100 |
102 #endif // CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_ | 101 #endif // CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_ |
OLD | NEW |