Move android_app_version_* into an inner variables dict.
[chromium-blink-merge.git] / net / android / network_change_notifier_android.h
blobf6d43d011298e7247d452a89ad63f497f71c6a3c
1 // Copyright (c) 2012 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 NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_
6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_
8 #include "base/android/jni_android.h"
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "net/android/network_change_notifier_delegate_android.h"
12 #include "net/base/network_change_notifier.h"
14 namespace net {
16 class NetworkChangeNotifierAndroidTest;
17 class NetworkChangeNotifierFactoryAndroid;
19 // NetworkChangeNotifierAndroid observes network events from the Android
20 // notification system and forwards them to observers.
22 // The implementation is complicated by the differing lifetime and thread
23 // affinity requirements of Android notifications and of NetworkChangeNotifier.
25 // High-level overview:
26 // NetworkChangeNotifier.java - Receives notifications from Android system, and
27 // notifies native code via JNI (on the main application thread).
28 // NetworkChangeNotifierDelegateAndroid ('Delegate') - Listens for notifications
29 // sent via JNI on the main application thread, and forwards them to observers
30 // on their threads. Owned by Factory, lives exclusively on main application
31 // thread.
32 // NetworkChangeNotifierFactoryAndroid ('Factory') - Creates the Delegate on the
33 // main thread to receive JNI events, and vends Notifiers. Lives exclusively
34 // on main application thread, and outlives all other classes.
35 // NetworkChangeNotifierAndroid ('Notifier') - Receives event notifications from
36 // the Delegate. Processes and forwards these events to the
37 // NetworkChangeNotifier observers on their threads. May live on any thread
38 // and be called by any thread.
40 // For more details, see the implementation file.
41 class NET_EXPORT_PRIVATE NetworkChangeNotifierAndroid
42 : public NetworkChangeNotifier,
43 public NetworkChangeNotifierDelegateAndroid::Observer {
44 public:
45 ~NetworkChangeNotifierAndroid() override;
47 // NetworkChangeNotifier:
48 ConnectionType GetCurrentConnectionType() const override;
49 // Requires ACCESS_WIFI_STATE permission in order to provide precise WiFi link
50 // speed.
51 double GetCurrentMaxBandwidth() const override;
53 // NetworkChangeNotifierDelegateAndroid::Observer:
54 void OnConnectionTypeChanged() override;
55 void OnMaxBandwidthChanged(double max_bandwidth_mbps) override;
57 static bool Register(JNIEnv* env);
59 // Promote GetMaxBandwidthForConnectionSubtype to public for the Android
60 // delegate class.
61 using NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype;
63 private:
64 friend class NetworkChangeNotifierAndroidTest;
65 friend class NetworkChangeNotifierFactoryAndroid;
67 class DnsConfigServiceThread;
69 explicit NetworkChangeNotifierAndroid(
70 NetworkChangeNotifierDelegateAndroid* delegate);
72 static NetworkChangeCalculatorParams NetworkChangeCalculatorParamsAndroid();
74 NetworkChangeNotifierDelegateAndroid* const delegate_;
75 scoped_ptr<DnsConfigServiceThread> dns_config_service_thread_;
77 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierAndroid);
80 } // namespace net
82 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_