Index: content/public/android/java/src/org/chromium/content/browser/BackgroundSyncNetworkObserver.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncNetworkObserver.java b/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncNetworkObserver.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7dc74279f326d10a57e440dd06a9268db8c4e1d6 |
--- /dev/null |
+++ b/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncNetworkObserver.java |
@@ -0,0 +1,58 @@ |
+// 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. |
+ |
+package org.chromium.content.browser; |
+ |
+import android.content.Context; |
+ |
+import org.chromium.base.ThreadUtils; |
+import org.chromium.base.annotations.CalledByNative; |
+import org.chromium.base.annotations.JNINamespace; |
+import org.chromium.base.annotations.NativeClassQualifiedName; |
+import org.chromium.net.NetworkChangeNotifierAutoDetect; |
+ |
+/** |
+ * Contains the Java code used by the BackgroundSyncNetworkObserverAndroid C++ class. |
+ * |
+ * The purpose of this class is to listen for and forward network connectivity events to the |
+ * BackgroundSyncNetworkObserverAndroid even when the application is paused. The standard |
Yaron
2015/09/16 22:04:36
I take it this works to have multiple registered N
iclelland
2015/09/18 15:46:28
It appears to, but it's not very clean. I'll see i
Yaron
2015/09/22 21:20:35
Well you also aren't the only one to own an instan
|
+ * NetworkChangeNotifier does not listen for connectivity events when the application is paused. |
+ * |
+ * This class should live on the main thread. |
+ */ |
+@JNINamespace("content") |
+public class BackgroundSyncNetworkObserver implements NetworkChangeNotifierAutoDetect.Observer { |
Yaron
2015/09/16 22:04:36
nit: you can make this class and non-interface ove
iclelland
2015/09/18 15:46:28
Thanks, done.
|
+ |
+ private NetworkChangeNotifierAutoDetect mNotifier; |
+ private long mNativePtr; |
+ |
+ public BackgroundSyncNetworkObserver(Context ctx, long nativePtr) { |
+ mNotifier = new NetworkChangeNotifierAutoDetect(this, ctx, true); |
Yaron
2015/09/16 22:04:36
Hmm. You register this observer but never unregist
iclelland
2015/09/18 15:46:28
Thanks -- I forgot about the additional reference
|
+ mNativePtr = nativePtr; |
+ ThreadUtils.runOnUiThread(new Runnable() { |
iclelland
2015/09/16 19:14:16
This change, made necessary by the DCHECK_CURRENTL
|
+ @Override |
+ public void run() { |
+ onConnectionTypeChanged(mNotifier.getCurrentConnectionType( |
Yaron
2015/09/16 22:04:36
nit: looks overidented (should be 4)
iclelland
2015/09/18 15:46:28
Done.
|
+ mNotifier.getCurrentNetworkState())); |
+ } |
+ }); |
+ } |
+ |
+ @CalledByNative |
+ public static BackgroundSyncNetworkObserver createObserver(Context ctx, long nativePtr) { |
+ return new BackgroundSyncNetworkObserver(ctx, nativePtr); |
+ } |
+ |
+ @Override |
+ public void onConnectionTypeChanged(int newConnectionType) { |
+ nativeNotifyConnectionTypeChanged(mNativePtr, newConnectionType); |
+ } |
+ |
+ @Override |
+ public void onMaxBandwidthChanged(double maxBandwidthMbps) { |
+ } |
+ |
+ @NativeClassQualifiedName("BackgroundSyncNetworkObserverAndroid::Observer") |
+ private native void nativeNotifyConnectionTypeChanged(long nativePtr, int newConnectionType); |
+} |