Chromium Code Reviews| Index: net/android/simple_cache_activity_status_notifier.cc |
| diff --git a/net/android/simple_cache_activity_status_notifier.cc b/net/android/simple_cache_activity_status_notifier.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..07c76438c1eba2c1c0b8038c4d06e69e5d9e15f2 |
| --- /dev/null |
| +++ b/net/android/simple_cache_activity_status_notifier.cc |
| @@ -0,0 +1,54 @@ |
| +// 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" |
| + |
|
Philippe
2013/04/23 11:34:25
Nit: no blank line here.
felipeg
2013/04/23 13:10:13
Done.
|
| +#include "jni/SimpleCacheActivityStatusNotifier_jni.h" |
| + |
| +namespace net { |
| + |
| +SimpleCacheActivityStatusNotifier::SimpleCacheActivityStatusNotifier( |
| + const ActivityStatusChangedCallback& notify_callback) : |
|
Philippe
2013/04/23 11:34:25
Nit: The ':' should be on the line below.
felipeg
2013/04/23 13:10:13
Done.
|
| + notify_callback_(notify_callback) { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + CHECK(env); |
|
Philippe
2013/04/23 11:34:25
Nit: DCHECK() should be enough.
felipeg
2013/04/23 13:10:13
Done.
|
| + java_obj_.Reset( |
| + Java_SimpleCacheActivityStatusNotifier_newInstance( |
| + env, reinterpret_cast<jint>(this))); |
| +} |
| + |
| +SimpleCacheActivityStatusNotifier::~SimpleCacheActivityStatusNotifier() { |
|
gavinp
2013/04/23 11:02:04
Why no thread check here?
Philippe
2013/04/23 11:34:25
+1 for a thread check here.
felipeg
2013/04/23 13:10:13
Done.
|
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + CHECK(env); |
| + Java_SimpleCacheActivityStatusNotifier_prepareToBeDestroyed( |
| + env, java_obj_.obj()); |
| +} |
| + |
| +void SimpleCacheActivityStatusNotifier::NotifyActivityStatusChanged( |
| + JNIEnv* env, |
| + jobject obj, |
| + jint j_new_activity_status) { |
| + DCHECK(io_thread_checker_.CalledOnValidThread()); |
| + ActivityStatus new_activity_status = |
| + static_cast<ActivityStatus>(j_new_activity_status); |
| + if (!notify_callback_.is_null()) |
|
Philippe
2013/04/23 11:34:25
Can we DCHECK(!notify_callback_.is_null()) in the
felipeg
2013/04/23 13:10:13
Done.
|
| + notify_callback_.Run(new_activity_status); |
| +} |
| + |
| +// static |
| +bool SimpleCacheActivityStatusNotifier::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +} // namespace net |