Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / android / net / external_estimate_provider_android.h
blobad787e1680d292d6c97498b87ff7829eb65efa2d
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.
5 #ifndef CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_
6 #define CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_
8 #include <jni.h>
9 #include <stdint.h>
11 #include "base/android/scoped_java_ref.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/thread_task_runner_handle.h"
16 #include "base/threading/thread_checker.h"
17 #include "base/time/time.h"
18 #include "net/base/external_estimate_provider.h"
19 #include "net/base/network_change_notifier.h"
21 namespace chrome {
22 namespace android {
24 // Native class that calls Java code exposed by
25 // ExternalEstimateProviderAndroidHelper.java. Provides network quality
26 // estimates as provided by Android. Estimates are automatically updated on a
27 // network change event.
28 class ExternalEstimateProviderAndroid
29 : public net::NetworkChangeNotifier::ConnectionTypeObserver,
30 public net::ExternalEstimateProvider {
31 public:
32 // Constructs and initializes the underlying provider.
33 ExternalEstimateProviderAndroid();
35 ~ExternalEstimateProviderAndroid() override;
37 // net::ExternalEstimateProvider implementation.
38 bool GetRTT(base::TimeDelta* rtt) const override;
40 // net::ExternalEstimateProvider implementation.
41 bool GetDownstreamThroughputKbps(
42 int32_t* downstream_throughput_kbps) const override;
44 // net::ExternalEstimateProvider implementation.
45 bool GetUpstreamThroughputKbps(
46 int32_t* upstream_throughput_kbps) const override;
48 // net::ExternalEstimateProvider implementation.
49 bool GetTimeSinceLastUpdate(
50 base::TimeDelta* time_since_last_update) const override;
52 // NetworkChangeNotifier::ConnectionTypeObserver implementation.
53 void OnConnectionTypeChanged(
54 net::NetworkChangeNotifier::ConnectionType type) override;
56 // net::ExternalEstimateProvider implementation.
57 void SetUpdatedEstimateDelegate(
58 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate)
59 override;
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_|.
63 void NotifyExternalEstimateProviderAndroidUpdate(JNIEnv* env, jobject obj);
65 protected:
66 // Notifies the delegate that a new update to external estimate is available.
67 // Protected for testing.
68 void NotifyUpdatedEstimateAvailable() const;
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;
75 // Value returned if valid value is unavailable.
76 int32_t no_value_ = -1;
78 base::android::ScopedJavaGlobalRef<jobject> j_external_estimate_provider_;
80 // Task runner that accesses ExternalEstimateProviderAndroid members.
81 scoped_refptr<base::TaskRunner> task_runner_;
83 // Notified every time there is an update available from the network quality
84 // provider.
85 // TODO(tbansal): Add the function that is called by Java side when an update
86 // is available.
87 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate_;
89 base::ThreadChecker thread_checker_;
91 // Used for posting tasks.
92 base::WeakPtrFactory<ExternalEstimateProviderAndroid> weak_factory_;
94 DISALLOW_COPY_AND_ASSIGN(ExternalEstimateProviderAndroid);
97 bool RegisterExternalEstimateProviderAndroid(JNIEnv* env);
99 } // namespace android
100 } // namespace chrome
102 #endif // CHROME_BROWSER_ANDROID_NET_EXTERNAL_ESTIMATE_PROVIDER_ANDROID_H_