OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/android/simple_cache_activity_status_notifier.h" | |
6 | |
7 #include "base/android/jni_android.h" | |
8 #include "base/basictypes.h" | |
9 #include "base/bind.h" | |
10 #include "base/bind_helpers.h" | |
11 #include "base/callback.h" | |
12 #include "base/logging.h" | |
13 #include "base/message_loop.h" | |
14 #include "base/message_loop_proxy.h" | |
15 #include "base/task_runner.h" | |
16 | |
17 #include "jni/SimpleCacheActivityStatusNotifier_jni.h" | |
18 | |
19 namespace net { | |
20 | |
21 SimpleCacheActivityStatusNotifier::SimpleCacheActivityStatusNotifier( | |
22 base::SingleThreadTaskRunner* callback_runner, | |
23 const ActivityStatusChangedCallback& notify_callback) : | |
24 callback_runner_(callback_runner), | |
25 notify_callback_(notify_callback) { | |
26 // TODO(felipeg): Do we have to call DetachFromVM somewhere ? I don't see | |
27 // other code doing that. | |
28 JNIEnv* env = base::android::AttachCurrentThread(); | |
29 CHECK(env); | |
30 java_obj_.Reset( | |
31 Java_SimpleCacheActivityStatusNotifier_NewInstance( | |
32 env, reinterpret_cast<jint>(this))); | |
33 } | |
34 | |
35 SimpleCacheActivityStatusNotifier::~SimpleCacheActivityStatusNotifier() {} | |
36 | |
37 void SimpleCacheActivityStatusNotifier::NotifyActivityStatusChanged( | |
38 JNIEnv* env, | |
39 jobject obj, | |
40 jint new_activity_status) { | |
41 if (callback_runner_.get() && !notify_callback_.is_null()) { | |
gavinp
2013/04/19 15:58:55
Lose this .get()
felipeg
2013/04/19 17:10:15
Done.
| |
42 callback_runner_->PostTask(FROM_HERE, base::Bind(notify_callback_, | |
43 new_activity_status)); | |
44 } | |
45 } | |
46 | |
47 // static | |
48 bool SimpleCacheActivityStatusNotifier::Register(JNIEnv* env) { | |
49 return RegisterNativesImpl(env); | |
50 } | |
51 | |
52 } // net | |
OLD | NEW |