Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: net/android/network_change_notifier_delegate_android.h

Issue 2866253002: Refactor NetworkChangeNotifierAndroid (Closed)
Patch Set: Add test to make sure NCN doesn't call native functions during startup Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ 5 #ifndef NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_
6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ 6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/observer_list_threadsafe.h" 14 #include "base/observer_list_threadsafe.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
17 #include "net/base/net_export.h" 17 #include "net/base/net_export.h"
18 #include "net/base/network_change_notifier.h" 18 #include "net/base/network_change_notifier.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 // Delegate used to thread-safely notify NetworkChangeNotifierAndroid whenever a 22 // Delegate used to thread-safely notify NetworkChangeNotifierAndroid whenever a
23 // network connection change notification is signaled by the Java side (on the 23 // network connection change notification is signaled by the Java side (on the
24 // JNI thread). 24 // JNI thread).
25 // All the methods exposed below must be called exclusively on the JNI thread 25 // All the methods exposed below must be called exclusively on the JNI thread
26 // unless otherwise stated (e.g. AddObserver()/RemoveObserver()). 26 // unless otherwise stated (e.g. AddObserver()/RemoveObserver()).
27 class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid { 27 class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid {
28 public: 28 public:
29 typedef NetworkChangeNotifier::ConnectionType ConnectionType; 29 typedef NetworkChangeNotifier::ConnectionType ConnectionType;
30 typedef NetworkChangeNotifier::ConnectionSubtype ConnectionSubtype;
30 typedef NetworkChangeNotifier::NetworkHandle NetworkHandle; 31 typedef NetworkChangeNotifier::NetworkHandle NetworkHandle;
31 typedef NetworkChangeNotifier::NetworkList NetworkList; 32 typedef NetworkChangeNotifier::NetworkList NetworkList;
32 33
33 // Observer interface implemented by NetworkChangeNotifierAndroid which 34 // Observer interface implemented by NetworkChangeNotifierAndroid which
34 // subscribes to network change notifications fired by the delegate (and 35 // subscribes to network change notifications fired by the delegate (and
35 // initiated by the Java side). 36 // initiated by the Java side).
36 class Observer : public NetworkChangeNotifier::NetworkObserver { 37 class Observer : public NetworkChangeNotifier::NetworkObserver {
37 public: 38 public:
38 ~Observer() override {} 39 ~Observer() override {}
39 40
(...skipping 19 matching lines...) Expand all
59 jlong default_netid); 60 jlong default_netid);
60 jint GetConnectionType(JNIEnv* env, jobject obj) const; 61 jint GetConnectionType(JNIEnv* env, jobject obj) const;
61 62
62 // Called from NetworkChangeNotifier.java on the JNI thread whenever 63 // Called from NetworkChangeNotifier.java on the JNI thread whenever
63 // the maximum bandwidth of the connection changes. This updates the current 64 // the maximum bandwidth of the connection changes. This updates the current
64 // max bandwidth seen by this class and forwards the notification to the 65 // max bandwidth seen by this class and forwards the notification to the
65 // observers that subscribed through AddObserver(). 66 // observers that subscribed through AddObserver().
66 void NotifyMaxBandwidthChanged( 67 void NotifyMaxBandwidthChanged(
67 JNIEnv* env, 68 JNIEnv* env,
68 const base::android::JavaParamRef<jobject>& obj, 69 const base::android::JavaParamRef<jobject>& obj,
69 jdouble new_max_bandwidth); 70 jint subtype);
70 71
71 // Called from NetworkChangeNotifier.java on the JNI thread to push 72 // Called from NetworkChangeNotifier.java on the JNI thread to push
72 // down notifications of network connectivity events. These functions in 73 // down notifications of network connectivity events. These functions in
73 // turn: 74 // turn:
74 // 1) Update |network_map_| and |default_network_|. 75 // 1) Update |network_map_| and |default_network_|.
75 // 2) Push notifications to NetworkChangeNotifier which in turn pushes 76 // 2) Push notifications to NetworkChangeNotifier which in turn pushes
76 // notifications to its NetworkObservers. Note that these functions 77 // notifications to its NetworkObservers. Note that these functions
77 // perform valuable transformations on the signals like deduplicating. 78 // perform valuable transformations on the signals like deduplicating.
78 // For descriptions of what individual calls mean, see 79 // For descriptions of what individual calls mean, see
79 // NetworkChangeNotifierAutoDetect.Observer functions of the same names. 80 // NetworkChangeNotifierAutoDetect.Observer functions of the same names.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 void SetCurrentNetworksAndTypes(NetworkMap network_map); 135 void SetCurrentNetworksAndTypes(NetworkMap network_map);
135 136
136 // Methods calling the Java side exposed for testing. 137 // Methods calling the Java side exposed for testing.
137 void SetOnline(); 138 void SetOnline();
138 void SetOffline(); 139 void SetOffline();
139 void FakeNetworkConnected(NetworkHandle network, ConnectionType type); 140 void FakeNetworkConnected(NetworkHandle network, ConnectionType type);
140 void FakeNetworkSoonToBeDisconnected(NetworkHandle network); 141 void FakeNetworkSoonToBeDisconnected(NetworkHandle network);
141 void FakeNetworkDisconnected(NetworkHandle network); 142 void FakeNetworkDisconnected(NetworkHandle network);
142 void FakePurgeActiveNetworkList(NetworkList networks); 143 void FakePurgeActiveNetworkList(NetworkList networks);
143 void FakeDefaultNetwork(NetworkHandle network, ConnectionType type); 144 void FakeDefaultNetwork(NetworkHandle network, ConnectionType type);
144 void FakeMaxBandwidthChanged(double max_bandwidth_mbps); 145 void FakeConnectionSubtypeChanged(ConnectionSubtype subtype);
145 146
146 base::ThreadChecker thread_checker_; 147 base::ThreadChecker thread_checker_;
147 scoped_refptr<base::ObserverListThreadSafe<Observer>> observers_; 148 scoped_refptr<base::ObserverListThreadSafe<Observer>> observers_;
148 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_; 149 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_;
149 150
150 mutable base::Lock connection_lock_; // Protects the state below. 151 mutable base::Lock connection_lock_; // Protects the state below.
151 ConnectionType connection_type_; 152 ConnectionType connection_type_;
152 double connection_max_bandwidth_; 153 double connection_max_bandwidth_;
153 NetworkHandle default_network_; 154 NetworkHandle default_network_;
154 NetworkMap network_map_; 155 NetworkMap network_map_;
155 156
156 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid); 157 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid);
157 }; 158 };
158 159
159 } // namespace net 160 } // namespace net
160 161
161 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ 162 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698