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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/android/scoped_java_ref.h" | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
12 #include "net/base/network_change_notifier.h" | 10 #include "net/base/network_change_notifier.h" |
13 | 11 |
14 namespace net { | 12 namespace net { |
15 namespace android { | 13 namespace android { |
16 | 14 |
| 15 // On Android this is provided as a 'loop back' implementation, where the |
| 16 // embedder chooses how and when to update the current network connection |
| 17 // state. Embedders must push the current state down via setConnected(). |
| 18 // |
| 19 // This is a singleton object and the singleton property is enforced by |
| 20 // a private constructor here and the friend NetworkChangeNotifierFactory |
| 21 // class. |
17 class NetworkChangeNotifier : public net::NetworkChangeNotifier { | 22 class NetworkChangeNotifier : public net::NetworkChangeNotifier { |
18 public: | 23 public: |
| 24 // The embedder must call through to this method to notify the network |
| 25 // stack of the current connection state. |
| 26 void setConnected(bool network_up); |
| 27 |
| 28 private: |
19 NetworkChangeNotifier(); | 29 NetworkChangeNotifier(); |
20 virtual ~NetworkChangeNotifier(); | 30 virtual ~NetworkChangeNotifier(); |
21 | 31 |
22 void NotifyObservers(JNIEnv* env, jobject obj); | |
23 | |
24 static bool Register(JNIEnv* env); | |
25 | |
26 private: | |
27 void CreateJavaObject(JNIEnv* env); | |
28 | |
29 // NetworkChangeNotifier: | 32 // NetworkChangeNotifier: |
30 virtual net::NetworkChangeNotifier::ConnectionType | 33 virtual net::NetworkChangeNotifier::ConnectionType |
31 GetCurrentConnectionType() const OVERRIDE; | 34 GetCurrentConnectionType() const OVERRIDE; |
32 | 35 |
33 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_; | 36 bool is_connected_; |
| 37 |
| 38 friend class NetworkChangeNotifierFactory; |
34 | 39 |
35 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); | 40 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
36 }; | 41 }; |
37 | 42 |
38 } // namespace android | 43 } // namespace android |
39 } // namespace net | 44 } // namespace net |
40 | 45 |
41 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ | 46 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ |
OLD | NEW |