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

Unified Diff: net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java

Issue 14362009: Receive app notifications in SimpleCache, so we save our index file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/android/net_jni_registrar.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java
diff --git a/net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java b/net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java
new file mode 100644
index 0000000000000000000000000000000000000000..c9882fd574307fd35344a9494f27254bcb3edac4
--- /dev/null
+++ b/net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java
@@ -0,0 +1,72 @@
+// Copyright (c) 2013 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.net;
+
+import android.util.Log;
+
+import org.chromium.base.ActivityStatus;
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+import org.chromium.base.NativeClassQualifiedName;
+
+import android.os.Handler;
+import android.os.Looper;
+
+/**
+ * Used by the SimpleIndex in net/disk_cache/simple/ to listen to changes in the android app state
+ * such as the app going to the background or foreground.
+ */
+public class SimpleCacheActivityStatusNotifier implements ActivityStatus.StateListener {
+ private int mNativePtr = 0;
+ private final Looper mIoLooper;
+
+ @CalledByNative
+ public static SimpleCacheActivityStatusNotifier newInstance(int nativePtr) {
+ return new SimpleCacheActivityStatusNotifier(nativePtr);
+ }
+
+ private SimpleCacheActivityStatusNotifier(int nativePtr) {
+ this.mIoLooper = Looper.myLooper();
gavinp 2013/04/25 08:28:27 Since the construction comes from the net thread (
+ this.mNativePtr = nativePtr;
+ // Call the singleton's ActivityStatus in the UI thread.
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
+ @Override
+ public void run() {
+ ActivityStatus.registerStateListener(SimpleCacheActivityStatusNotifier.this);
+ }
+ });
+ }
+
+ @CalledByNative
+ public void prepareToBeDestroyed() {
+ this.mNativePtr = 0;
+ // Call the singleton's ActivityStatus in the UI thread.
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
+ @Override
+ public void run() {
+ ActivityStatus.unregisterStateListener(SimpleCacheActivityStatusNotifier.this);
+ }
+ });
+ }
+
+ // ActivityStatus.StateListener
+ @Override
+ public void onActivityStateChange(final int state) {
+ if (state == ActivityStatus.RESUMED ||
+ state == ActivityStatus.STOPPED) {
+ new Handler(mIoLooper).post(new Runnable() {
+ @Override
+ public void run() {
+ if (SimpleCacheActivityStatusNotifier.this.mNativePtr != 0)
+ nativeNotifyActivityStatusChanged(
+ SimpleCacheActivityStatusNotifier.this.mNativePtr, state);
+ }
+ });
+ }
+ }
+
+ @NativeClassQualifiedName("net::SimpleCacheActivityStatusNotifier")
+ private native void nativeNotifyActivityStatusChanged(int nativePtr, int newActivityStatus);
+}
« no previous file with comments | « no previous file | net/android/net_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698