summaryrefslogtreecommitdiffstats
path: root/net/android
diff options
context:
space:
mode:
authorgavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-25 08:24:17 +0000
committergavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-25 08:24:17 +0000
commit3e3d19696be308423e5aee52c52d618a63c02795 (patch)
tree2983057d87522778196dd27bd13994542c5d2e9d /net/android
parentb4e602f0f1565a0ec3d44bb9f34449bb8513aaa2 (diff)
downloadchromium_src-3e3d19696be308423e5aee52c52d618a63c02795.zip
chromium_src-3e3d19696be308423e5aee52c52d618a63c02795.tar.gz
chromium_src-3e3d19696be308423e5aee52c52d618a63c02795.tar.bz2
Revert 195845 "With this CL we can catch OnResume, OnPause, OnDe..."
> With this CL we can catch OnResume, OnPause, OnDestroy and OnStop notifications in SimpleCache, so we save our index before we get killed. > > OnPause means the app lost focus (went to the background). > > The idea is that we can write the index file to disk on every OnPause, and while the app is in the background we can aggressively increase the frequency we write the index file to disk. > > BUG=233536 > > Review URL: https://chromiumcodereview.appspot.com/14362009 BUG=235180 TBR=felipeg@chromium.org Review URL: https://codereview.chromium.org/14081031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196357 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/android')
-rw-r--r--net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java72
-rw-r--r--net/android/net_jni_registrar.cc5
-rw-r--r--net/android/simple_cache_activity_status_notifier.cc54
-rw-r--r--net/android/simple_cache_activity_status_notifier.h62
4 files changed, 1 insertions, 192 deletions
diff --git a/net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java b/net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java
deleted file mode 100644
index c9882fd..0000000
--- a/net/android/java/src/org/chromium/net/SimpleCacheActivityStatusNotifier.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// 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();
- 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);
-}
diff --git a/net/android/net_jni_registrar.cc b/net/android/net_jni_registrar.cc
index 39ab899..a6e09b6 100644
--- a/net/android/net_jni_registrar.cc
+++ b/net/android/net_jni_registrar.cc
@@ -4,14 +4,13 @@
#include "net/android/net_jni_registrar.h"
+#include "base/basictypes.h"
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
-#include "base/basictypes.h"
#include "net/android/gurl_utils.h"
#include "net/android/keystore.h"
#include "net/android/network_change_notifier_android.h"
#include "net/android/network_library.h"
-#include "net/android/simple_cache_activity_status_notifier.h"
#include "net/proxy/proxy_config_service_android.h"
namespace net {
@@ -24,8 +23,6 @@ static base::android::RegistrationMethod kNetRegisteredMethods[] = {
{ "NetworkChangeNotifierAndroid",
net::NetworkChangeNotifierAndroid::Register },
{ "ProxyConfigService", net::ProxyConfigServiceAndroid::Register },
- { "SimpleCacheActivityStatusNotifier",
- net::SimpleCacheActivityStatusNotifier::Register },
};
bool RegisterJni(JNIEnv* env) {
diff --git a/net/android/simple_cache_activity_status_notifier.cc b/net/android/simple_cache_activity_status_notifier.cc
deleted file mode 100644
index a13400c..0000000
--- a/net/android/simple_cache_activity_status_notifier.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-// 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.
-
-#include "net/android/simple_cache_activity_status_notifier.h"
-
-#include "base/android/jni_android.h"
-#include "base/basictypes.h"
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/callback.h"
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/message_loop_proxy.h"
-#include "base/task_runner.h"
-#include "jni/SimpleCacheActivityStatusNotifier_jni.h"
-
-namespace net {
-
-SimpleCacheActivityStatusNotifier::SimpleCacheActivityStatusNotifier(
- const ActivityStatusChangedCallback& notify_callback)
- : notify_callback_(notify_callback) {
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
- java_obj_.Reset(
- Java_SimpleCacheActivityStatusNotifier_newInstance(
- env, reinterpret_cast<jint>(this)));
-}
-
-SimpleCacheActivityStatusNotifier::~SimpleCacheActivityStatusNotifier() {
- DCHECK(thread_checker_.CalledOnValidThread());
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
- Java_SimpleCacheActivityStatusNotifier_prepareToBeDestroyed(
- env, java_obj_.obj());
-}
-
-void SimpleCacheActivityStatusNotifier::NotifyActivityStatusChanged(
- JNIEnv* env,
- jobject obj,
- jint j_new_activity_status) {
- DCHECK(thread_checker_.CalledOnValidThread());
- ActivityStatus new_activity_status =
- static_cast<ActivityStatus>(j_new_activity_status);
- DCHECK(!notify_callback_.is_null());
- notify_callback_.Run(new_activity_status);
-}
-
-// static
-bool SimpleCacheActivityStatusNotifier::Register(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
-} // namespace net
diff --git a/net/android/simple_cache_activity_status_notifier.h b/net/android/simple_cache_activity_status_notifier.h
deleted file mode 100644
index 023c112..0000000
--- a/net/android/simple_cache_activity_status_notifier.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// 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.
-
-#ifndef NET_ANDROID_SIMPLE_CACHE_ACTIVITY_STATUS_NOTIFIER_H_
-#define NET_ANDROID_SIMPLE_CACHE_ACTIVITY_STATUS_NOTIFIER_H_
-
-#include <jni.h>
-
-#include "base/android/jni_android.h"
-#include "base/basictypes.h"
-#include "base/callback.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-
-namespace base {
-class SingleThreadTaskRunner;
-}
-
-namespace net {
-
-// This class is the native twin of the class with same name in
-// SimpleCacheActivityStatusNotifier.java
-// This is used by the SimpleIndex in net/disk_cache/simple/ to listens to
-// changes in the android app state such as the app going to the background or
-// foreground.
-class SimpleCacheActivityStatusNotifier {
-public:
- // This enum must match the constants defined in
- // ./base/android/java/src/org/chromium/base/ActivityStatus.java
- enum ActivityStatus {
- CREATED = 1,
- STARTED = 2,
- RESUMED = 3,
- PAUSED = 4,
- STOPPED = 5,
- DESTROYED = 6
- };
-
- typedef base::Callback<void(ActivityStatus activity_status)>
- ActivityStatusChangedCallback;
-
- SimpleCacheActivityStatusNotifier(
- const ActivityStatusChangedCallback& notify_callback);
-
- ~SimpleCacheActivityStatusNotifier();
-
- void NotifyActivityStatusChanged(JNIEnv* env,
- jobject obj,
- jint new_activity_status);
-
- static bool Register(JNIEnv* env);
-
-private:
- base::android::ScopedJavaGlobalRef<jobject> java_obj_;
- const ActivityStatusChangedCallback notify_callback_;
- base::ThreadChecker thread_checker_;
-};
-
-} // namespace net
-
-#endif // NET_ANDROID_SIMPLE_CACHE_ACTIVITY_STATUS_NOTIFIER_H_