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..9e0a77be23bcd7e2a4721ef5c1dc3352d2874f15 |
--- /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); |
+ |
+ // 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() { |
jkarlin
2015/08/28 01:19:48
Since this is empty, prefer = default in the heade
iclelland
2015/08/31 16:00:52
Done.
|
+} |
+ |
+void BackgroundSyncNetworkObserverAndroid::NotifyConnectionTypeChanged( |
+ JNIEnv* env, |
+ jobject jcaller, |
+ jint new_connection_type) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ OnNetworkChanged(static_cast<net::NetworkChangeNotifier::ConnectionType>( |
+ new_connection_type)); |
+} |
+ |
+} // namespace content |