OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "net/android/network_change_notifier.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/android/jni_android.h" | |
9 #include "jni/network_change_notifier_jni.h" | |
10 | |
11 namespace net { | |
12 namespace android { | |
13 | |
14 NetworkChangeNotifier::NetworkChangeNotifier() { | |
15 JNIEnv* env = base::android::AttachCurrentThread(); | |
16 CreateJavaObject(env); | |
17 } | |
18 | |
19 NetworkChangeNotifier::~NetworkChangeNotifier() { | |
20 JNIEnv* env = base::android::AttachCurrentThread(); | |
21 Java_NetworkChangeNotifier_unregisterReceiver( | |
22 env, java_network_change_notifier_.obj()); | |
23 } | |
24 | |
25 void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) { | |
26 java_network_change_notifier_.Reset( | |
27 Java_NetworkChangeNotifier_create( | |
28 env, | |
29 base::android::GetApplicationContext(), | |
30 reinterpret_cast<jint>(this))); | |
31 } | |
32 | |
33 void NetworkChangeNotifier::NotifyObservers(JNIEnv* env, jobject obj) { | |
34 NotifyObserversOfOnlineStateChange(); | |
35 } | |
36 | |
37 bool NetworkChangeNotifier::IsCurrentlyOffline() const { | |
38 JNIEnv* env = base::android::AttachCurrentThread(); | |
39 return !Java_NetworkChangeNotifier_isConnected( | |
40 env, java_network_change_notifier_.obj()); | |
41 } | |
42 | |
43 // static | |
44 bool NetworkChangeNotifier::Register(JNIEnv* env) { | |
45 return RegisterNativesImpl(env); | |
46 } | |
47 | |
48 } // namespace android | |
49 } // namespace net | |
OLD | NEW |