Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / android / network_change_notifier_android.h
blobe82b852f0fb79ab0b8f521d8272f914f458bba5c
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 virtual ~NetworkChangeNotifierAndroid();
47 // NetworkChangeNotifier:
48 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE;
50 // NetworkChangeNotifierDelegateAndroid::Observer:
51 virtual void OnConnectionTypeChanged() OVERRIDE;
53 static bool Register(JNIEnv* env);
55 private:
56 friend class NetworkChangeNotifierAndroidTest;
57 friend class NetworkChangeNotifierFactoryAndroid;
59 class DnsConfigServiceThread;
61 explicit NetworkChangeNotifierAndroid(
62 NetworkChangeNotifierDelegateAndroid* delegate);
64 static NetworkChangeCalculatorParams NetworkChangeCalculatorParamsAndroid();
66 NetworkChangeNotifierDelegateAndroid* const delegate_;
67 scoped_ptr<DnsConfigServiceThread> dns_config_service_thread_;
69 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierAndroid);
72 } // namespace net
74 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_