Chromium Code Reviews| Index: content/browser/android/background_sync_network_observer_android.cc |
| diff --git a/content/browser/android/background_sync_network_observer_android.cc b/content/browser/android/background_sync_network_observer_android.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..48e92573d34c14a9ed7291ae2083bf7fd82b85c5 |
| --- /dev/null |
| +++ b/content/browser/android/background_sync_network_observer_android.cc |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/android/background_sync_network_observer_android.h" |
| + |
| +#include "content/public/browser/browser_thread.h" |
| +#include "jni/BackgroundSyncNetworkObserver_jni.h" |
| + |
| +namespace content { |
| + |
| +// static |
| +bool BackgroundSyncNetworkObserverAndroid::RegisterNetworkObserver( |
| + JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +BackgroundSyncNetworkObserverAndroid::BackgroundSyncNetworkObserverAndroid( |
| + const base::Closure& network_changed_callback) |
| + : BackgroundSyncNetworkObserver(network_changed_callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
|
jkarlin
2015/09/11 00:05:23
I'm pretty tired so I may be wrong but I believe t
iclelland
2015/09/11 14:42:15
Well... JNI is usable from any thread, and this cl
jkarlin
2015/09/11 15:16:06
Good point. This class needs to be on the IO threa
jkarlin
2015/09/11 20:58:55
Sorry, I meant the class that talks to Java should
|
| + |
| + // Remove the observer attached by the NetworkObserver constructor |
| + net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| + |
| + // Attach a Java BackgroundSyncNetworkObserver object. Its lifetime will be |
| + // scoped to the lifetime of this object. |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + base::android::ScopedJavaLocalRef<jobject> obj = |
| + Java_BackgroundSyncNetworkObserver_createObserver( |
| + env, base::android::GetApplicationContext(), |
| + reinterpret_cast<jlong>(this)); |
| + observer_ = obj; |
| +} |
| + |
| +BackgroundSyncNetworkObserverAndroid::~BackgroundSyncNetworkObserverAndroid() { |
| +} |
| + |
| +void BackgroundSyncNetworkObserverAndroid::NotifyConnectionTypeChanged( |
| + JNIEnv* env, |
| + jobject jcaller, |
| + jint new_connection_type) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
|
jkarlin
2015/09/11 00:05:23
I believe this will be called on UI?
Probably exp
iclelland
2015/09/11 14:42:15
Apparently you weren't the only tired one. I fixed
|
| + OnNetworkChanged(static_cast<net::NetworkChangeNotifier::ConnectionType>( |
| + new_connection_type)); |
| +} |
| + |
| +} // namespace content |