OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "content/browser/android/background_sync_network_observer_android.h" | |
6 | |
7 #include "content/public/browser/browser_thread.h" | |
8 #include "jni/BackgroundSyncNetworkObserver_jni.h" | |
9 | |
10 namespace content { | |
11 | |
12 // static | |
13 bool BackgroundSyncNetworkObserverAndroid::RegisterNetworkObserver( | |
14 JNIEnv* env) { | |
15 return RegisterNativesImpl(env); | |
16 } | |
17 | |
18 BackgroundSyncNetworkObserverAndroid::BackgroundSyncNetworkObserverAndroid( | |
19 const base::Closure& network_changed_callback) | |
20 : BackgroundSyncNetworkObserver(network_changed_callback) { | |
21 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
22 | |
23 // Remove the observer attached by the NetworkObserver constructor | |
24 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | |
25 | |
26 // Attach a Java BackgroundSyncNetworkObserver object. Its lifetime will be | |
27 // scoped to the lifetime of this object. | |
28 JNIEnv* env = base::android::AttachCurrentThread(); | |
29 base::android::ScopedJavaLocalRef<jobject> obj = | |
30 Java_BackgroundSyncNetworkObserver_createObserver( | |
31 env, base::android::GetApplicationContext(), | |
32 reinterpret_cast<jlong>(this)); | |
33 observer_ = obj; | |
34 } | |
35 | |
36 BackgroundSyncNetworkObserverAndroid::~BackgroundSyncNetworkObserverAndroid() { | |
jkarlin
2015/08/28 01:19:48
Since this is empty, prefer = default in the heade
iclelland
2015/08/31 16:00:52
Done.
| |
37 } | |
38 | |
39 void BackgroundSyncNetworkObserverAndroid::NotifyConnectionTypeChanged( | |
40 JNIEnv* env, | |
41 jobject jcaller, | |
42 jint new_connection_type) { | |
43 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
44 OnNetworkChanged(static_cast<net::NetworkChangeNotifier::ConnectionType>( | |
45 new_connection_type)); | |
46 } | |
47 | |
48 } // namespace content | |
OLD | NEW |