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

Side by Side Diff: net/android/simple_cache_activity_status_notifier.cc

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: gavins comments 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 unified diff | Download patch
OLDNEW
(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
Philippe 2013/04/22 11:35:48 No, you can remove this comment.
felipeg 2013/04/22 16:14:32 Done.
27 // other code doing that.
28 JNIEnv* env = base::android::AttachCurrentThread();
29 CHECK(env);
30 java_obj_.Reset(
31 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.
32 env, reinterpret_cast<jint>(this)));
33 }
34
35 SimpleCacheActivityStatusNotifier::~SimpleCacheActivityStatusNotifier() {}
36
37 void SimpleCacheActivityStatusNotifier::NotifyActivityStatusChanged(
38 JNIEnv* env,
39 jobject obj,
40 jint j_new_activity_status) {
41 ActivityStatus new_activity_status =
42 static_cast<ActivityStatus>(j_new_activity_status);
43 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.
44 callback_runner_->PostTask(FROM_HERE, base::Bind(notify_callback_,
45 new_activity_status));
46 }
47 }
48
49 // static
50 bool SimpleCacheActivityStatusNotifier::Register(JNIEnv* env) {
51 return RegisterNativesImpl(env);
52 }
53
54 } // net
Philippe 2013/04/22 11:35:48 Nit: namespace net
felipeg 2013/04/22 16:14:32 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698