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_ANDROID_H_ | 5 #ifndef NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ |
6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ | 6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ |
7 | 7 |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/synchronization/lock.h" |
11 #include "net/base/network_change_notifier.h" | 12 #include "net/base/network_change_notifier.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 class NetworkChangeNotifierAndroidTest; | 16 class NetworkChangeNotifierAndroidTest; |
16 | 17 |
17 class NetworkChangeNotifierAndroid : public NetworkChangeNotifier { | 18 class NetworkChangeNotifierAndroid : public NetworkChangeNotifier { |
18 public: | 19 public: |
19 NetworkChangeNotifierAndroid(); | |
20 virtual ~NetworkChangeNotifierAndroid(); | 20 virtual ~NetworkChangeNotifierAndroid(); |
21 | 21 |
22 void NotifyObserversOfConnectionTypeChange(JNIEnv* env, jobject obj); | 22 // Called from Java on the UI thread. |
| 23 void NotifyObserversOfConnectionTypeChange( |
| 24 JNIEnv* env, jobject obj, jint new_connection_type); |
| 25 jint GetConnectionType(JNIEnv* env, jobject obj); |
23 | 26 |
24 static bool Register(JNIEnv* env); | 27 static bool Register(JNIEnv* env); |
25 | 28 |
26 private: | 29 private: |
27 friend class NetworkChangeNotifierAndroidTest; | 30 friend class NetworkChangeNotifierAndroidTest; |
| 31 friend class NetworkChangeNotifierFactoryAndroid; |
28 | 32 |
29 // NetworkChangeNotifier: | 33 NetworkChangeNotifierAndroid(); |
30 virtual NetworkChangeNotifier::ConnectionType | 34 |
31 GetCurrentConnectionType() const OVERRIDE; | 35 void SetConnectionType(int connection_type); |
32 | 36 |
33 void ForceConnectivityState(bool state); | 37 void ForceConnectivityState(bool state); |
34 | 38 |
| 39 // NetworkChangeNotifier: |
| 40 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE; |
| 41 |
35 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_; | 42 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_; |
| 43 // TODO(pliard): http://crbug.com/150867. Use an atomic integer for the |
| 44 // connection type without the lock once a non-subtle atomic integer is |
| 45 // available under base/. That might never happen though. |
| 46 mutable base::Lock lock_; // Protects the state below. |
| 47 // Written from the UI thread, read from any thread. |
| 48 int connection_type_; |
36 | 49 |
37 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierAndroid); | 50 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierAndroid); |
38 }; | 51 }; |
39 | 52 |
40 } // namespace net | 53 } // namespace net |
41 | 54 |
42 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ | 55 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ |
OLD | NEW |