OLD | NEW |
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 "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 // Observer interface implemented by NetworkChangeNotifierAndroid which | 27 // Observer interface implemented by NetworkChangeNotifierAndroid which |
28 // subscribes to network change notifications fired by the delegate (and | 28 // subscribes to network change notifications fired by the delegate (and |
29 // initiated by the Java side). | 29 // initiated by the Java side). |
30 class Observer { | 30 class Observer { |
31 public: | 31 public: |
32 virtual ~Observer() {} | 32 virtual ~Observer() {} |
33 | 33 |
34 // Updates the current connection type. | 34 // Updates the current connection type. |
35 virtual void OnConnectionTypeChanged() = 0; | 35 virtual void OnConnectionTypeChanged() = 0; |
| 36 |
| 37 // Updates the current max bandwidth. |
| 38 virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) = 0; |
36 }; | 39 }; |
37 | 40 |
38 NetworkChangeNotifierDelegateAndroid(); | 41 NetworkChangeNotifierDelegateAndroid(); |
39 ~NetworkChangeNotifierDelegateAndroid(); | 42 ~NetworkChangeNotifierDelegateAndroid(); |
40 | 43 |
41 // Called from NetworkChangeNotifierAndroid.java on the JNI thread whenever | 44 // Called from NetworkChangeNotifierAndroid.java on the JNI thread whenever |
42 // the connection type changes. This updates the current connection type seen | 45 // the connection type changes. This updates the current connection type seen |
43 // by this class and forwards the notification to the observers that | 46 // by this class and forwards the notification to the observers that |
44 // subscribed through AddObserver(). | 47 // subscribed through AddObserver(). |
45 void NotifyConnectionTypeChanged(JNIEnv* env, | 48 void NotifyConnectionTypeChanged(JNIEnv* env, |
46 jobject obj, | 49 jobject obj, |
47 jint new_connection_type); | 50 jint new_connection_type); |
48 jint GetConnectionType(JNIEnv* env, jobject obj) const; | 51 jint GetConnectionType(JNIEnv* env, jobject obj) const; |
49 | 52 |
| 53 // Called from NetworkChangeNotifierAndroid.java on the JNI thread whenever |
| 54 // the maximum bandwidth of the connection changes. This updates the current |
| 55 // max bandwidth seen by this class and forwards the notification to the |
| 56 // observers that subscribed through AddObserver(). |
| 57 void NotifyMaxBandwidthChanged(JNIEnv* env, |
| 58 jobject obj, |
| 59 jdouble new_max_bandwidth); |
| 60 |
50 // These methods can be called on any thread. Note that the provided observer | 61 // These methods can be called on any thread. Note that the provided observer |
51 // will be notified on the thread AddObserver() is called on. | 62 // will be notified on the thread AddObserver() is called on. |
52 void AddObserver(Observer* observer); | 63 void AddObserver(Observer* observer); |
53 void RemoveObserver(Observer* observer); | 64 void RemoveObserver(Observer* observer); |
54 | 65 |
55 // Can be called from any thread. | 66 // Can be called from any thread. |
56 ConnectionType GetCurrentConnectionType() const; | 67 ConnectionType GetCurrentConnectionType() const; |
57 | 68 |
58 // Can be called from any thread. | 69 // Can be called from any thread. |
59 double GetCurrentMaxBandwidth() const; | 70 double GetCurrentMaxBandwidth() const; |
(...skipping 18 matching lines...) Expand all Loading... |
78 mutable base::Lock connection_lock_; // Protects the state below. | 89 mutable base::Lock connection_lock_; // Protects the state below. |
79 ConnectionType connection_type_; | 90 ConnectionType connection_type_; |
80 double connection_max_bandwidth_; | 91 double connection_max_bandwidth_; |
81 | 92 |
82 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid); | 93 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid); |
83 }; | 94 }; |
84 | 95 |
85 } // namespace net | 96 } // namespace net |
86 | 97 |
87 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_H_ | 98 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_H_ |
OLD | NEW |