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..2c1d808df3e02a9d31944c6cc32e2057e367da87 |
| --- /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" |
| + |
| +#include "jni/SimpleCacheActivityStatusNotifier_jni.h" |
| + |
| +namespace net { |
| + |
| +SimpleCacheActivityStatusNotifier::SimpleCacheActivityStatusNotifier( |
| + base::SingleThreadTaskRunner* callback_runner, |
| + const ActivityStatusChangedCallback& notify_callback) : |
| + callback_runner_(callback_runner), |
| + notify_callback_(notify_callback) { |
| + // TODO(felipeg): Do we have to call DetachFromVM somewhere ? I don't see |
|
Philippe
2013/04/22 11:35:48
No, you can remove this comment.
felipeg
2013/04/22 16:14:32
Done.
|
| + // other code doing that. |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + CHECK(env); |
| + java_obj_.Reset( |
| + Java_SimpleCacheActivityStatusNotifier_NewInstance( |
|
Philippe
2013/04/22 11:35:48
The threading is dangerously subtle here. I guess
felipeg
2013/04/22 16:14:32
Done.
|
| + env, reinterpret_cast<jint>(this))); |
| +} |
| + |
| +SimpleCacheActivityStatusNotifier::~SimpleCacheActivityStatusNotifier() {} |
| + |
| +void SimpleCacheActivityStatusNotifier::NotifyActivityStatusChanged( |
| + JNIEnv* env, |
| + jobject obj, |
| + jint j_new_activity_status) { |
| + ActivityStatus new_activity_status = |
| + static_cast<ActivityStatus>(j_new_activity_status); |
| + if (callback_runner_ && !notify_callback_.is_null()) { |
|
Philippe
2013/04/22 11:35:48
I would add a DCHECK(callback_runner_) in the cons
felipeg
2013/04/22 16:14:32
Done.
|
| + callback_runner_->PostTask(FROM_HERE, base::Bind(notify_callback_, |
| + new_activity_status)); |
| + } |
| +} |
| + |
| +// static |
| +bool SimpleCacheActivityStatusNotifier::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +} // net |
|
Philippe
2013/04/22 11:35:48
Nit: namespace net
felipeg
2013/04/22 16:14:32
Done.
|