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/compiler_specific.h"
10 #include "base/macros.h"
11 #include "net/android/network_change_notifier_delegate_android.h"
12 #include "net/base/network_change_notifier.h"
17 class NetworkChangeNotifierAndroidTest
;
18 class NetworkChangeNotifierFactoryAndroid
;
20 // NetworkChangeNotifierAndroid observes network events from the Android
21 // notification system and forwards them to observers.
23 // The implementation is complicated by the differing lifetime and thread
24 // affinity requirements of Android notifications and of NetworkChangeNotifier.
26 // High-level overview:
27 // NetworkChangeNotifier.java - Receives notifications from Android system, and
28 // notifies native code via JNI (on the main application thread).
29 // NetworkChangeNotifierDelegateAndroid ('Delegate') - Listens for notifications
30 // sent via JNI on the main application thread, and forwards them to observers
31 // on their threads. Owned by Factory, lives exclusively on main application
33 // NetworkChangeNotifierFactoryAndroid ('Factory') - Creates the Delegate on the
34 // main thread to receive JNI events, and vends Notifiers. Lives exclusively
35 // on main application thread, and outlives all other classes.
36 // NetworkChangeNotifierAndroid ('Notifier') - Receives event notifications from
37 // the Delegate. Processes and forwards these events to the
38 // NetworkChangeNotifier observers on their threads. May live on any thread
39 // and be called by any thread.
41 // For more details, see the implementation file.
42 class NET_EXPORT_PRIVATE NetworkChangeNotifierAndroid
43 : public NetworkChangeNotifier
,
44 public NetworkChangeNotifierDelegateAndroid::Observer
{
46 ~NetworkChangeNotifierAndroid() override
;
48 // NetworkChangeNotifier:
49 ConnectionType
GetCurrentConnectionType() const override
;
50 // Requires ACCESS_WIFI_STATE permission in order to provide precise WiFi link
52 double GetCurrentMaxBandwidth() const override
;
54 // NetworkChangeNotifierDelegateAndroid::Observer:
55 void OnConnectionTypeChanged() override
;
56 void OnMaxBandwidthChanged(double max_bandwidth_mbps
) override
;
58 static bool Register(JNIEnv
* env
);
60 // Promote GetMaxBandwidthForConnectionSubtype to public for the Android
62 using NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype
;
65 friend class NetworkChangeNotifierAndroidTest
;
66 friend class NetworkChangeNotifierFactoryAndroid
;
68 class DnsConfigServiceThread
;
70 NetworkChangeNotifierAndroid(NetworkChangeNotifierDelegateAndroid
* delegate
,
71 const DnsConfig
* dns_config_for_testing
);
73 static NetworkChangeCalculatorParams
NetworkChangeCalculatorParamsAndroid();
75 NetworkChangeNotifierDelegateAndroid
* const delegate_
;
76 scoped_ptr
<DnsConfigServiceThread
> dns_config_service_thread_
;
78 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierAndroid
);
83 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_