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

Side by Side Diff: content/browser/android/background_sync_network_observer_android.cc

Issue 1294603003: [BackgroundSync] Trigger Background Sync events when Chrome is backgrounded on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update browser tests to trigger network observer directly Created 5 years, 3 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 2015 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 "content/browser/android/background_sync_network_observer_android.h"
6
7 #include "content/public/browser/browser_thread.h"
8 #include "jni/BackgroundSyncNetworkObserver_jni.h"
9
10 namespace content {
11
12 // static
13 bool BackgroundSyncNetworkObserverAndroid::RegisterNetworkObserver(
14 JNIEnv* env) {
15 return RegisterNativesImpl(env);
16 }
17
18 BackgroundSyncNetworkObserverAndroid::BackgroundSyncNetworkObserverAndroid(
19 const base::Closure& network_changed_callback)
20 : BackgroundSyncNetworkObserver(network_changed_callback) {
21 DCHECK_CURRENTLY_ON(BrowserThread::IO);
jkarlin 2015/09/11 00:05:23 I'm pretty tired so I may be wrong but I believe t
iclelland 2015/09/11 14:42:15 Well... JNI is usable from any thread, and this cl
jkarlin 2015/09/11 15:16:06 Good point. This class needs to be on the IO threa
jkarlin 2015/09/11 20:58:55 Sorry, I meant the class that talks to Java should
22
23 // Remove the observer attached by the NetworkObserver constructor
24 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
25
26 // Attach a Java BackgroundSyncNetworkObserver object. Its lifetime will be
27 // scoped to the lifetime of this object.
28 JNIEnv* env = base::android::AttachCurrentThread();
29 base::android::ScopedJavaLocalRef<jobject> obj =
30 Java_BackgroundSyncNetworkObserver_createObserver(
31 env, base::android::GetApplicationContext(),
32 reinterpret_cast<jlong>(this));
33 observer_ = obj;
34 }
35
36 BackgroundSyncNetworkObserverAndroid::~BackgroundSyncNetworkObserverAndroid() {
37 }
38
39 void BackgroundSyncNetworkObserverAndroid::NotifyConnectionTypeChanged(
40 JNIEnv* env,
41 jobject jcaller,
42 jint new_connection_type) {
43 DCHECK_CURRENTLY_ON(BrowserThread::IO);
jkarlin 2015/09/11 00:05:23 I believe this will be called on UI? Probably exp
iclelland 2015/09/11 14:42:15 Apparently you weren't the only tired one. I fixed
44 OnNetworkChanged(static_cast<net::NetworkChangeNotifier::ConnectionType>(
45 new_connection_type));
46 }
47
48 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698