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

Side by Side Diff: net/android/network_change_notifier.cc

Issue 10073024: Add NetworkChangeNotifier for Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(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
10 using net::android::NetworkChangeNotifier;
11 #include "jni/network_change_notifier_jni.h"
12
13 namespace net {
14 namespace android {
15
16 NetworkChangeNotifier::NetworkChangeNotifier() {
17 JNIEnv* env = base::android::AttachCurrentThread();
18 CreateJavaObject(env);
19 }
20
21 NetworkChangeNotifier::~NetworkChangeNotifier() {
22 JNIEnv* env = base::android::AttachCurrentThread();
23 Java_NetworkChangeNotifier_unregisterReceiver(
24 env, java_network_change_notifier_.obj());
25 }
26
27 void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) {
28 java_network_change_notifier_.Reset(
29 Java_NetworkChangeNotifier_create(
30 env,
31 base::android::GetApplicationContext(),
32 reinterpret_cast<jint>(this)));
33 }
34
35 void NetworkChangeNotifier::NotifyObservers(JNIEnv* env, jobject obj) {
36 NotifyObserversOfOnlineStateChange();
37 }
38
39 bool NetworkChangeNotifier::IsCurrentlyOffline() const {
40 JNIEnv* env = base::android::AttachCurrentThread();
41 return !Java_NetworkChangeNotifier_isConnected(
42 env, java_network_change_notifier_.obj());
43 }
44
45 // static
46 bool NetworkChangeNotifier::Register(JNIEnv* env) {
47 return RegisterNativesImpl(env);
48 }
49
50 } // namespace android
51 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698