| OLD | NEW |
| (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_launcher_android.h" | |
| 6 | |
| 7 #include "content/public/browser/browser_thread.h" | |
| 8 #include "jni/BackgroundSyncLauncher_jni.h" | |
| 9 | |
| 10 namespace content { | |
| 11 | |
| 12 namespace { | |
| 13 base::LazyInstance<BackgroundSyncLauncherAndroid> g_background_sync_launcher = | |
| 14 LAZY_INSTANCE_INITIALIZER; | |
| 15 } | |
| 16 | |
| 17 // static | |
| 18 BackgroundSyncLauncherAndroid* BackgroundSyncLauncherAndroid::Get() { | |
| 19 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 20 | |
| 21 return g_background_sync_launcher.Pointer(); | |
| 22 } | |
| 23 | |
| 24 // static | |
| 25 void BackgroundSyncLauncherAndroid::LaunchBrowserWhenNextOnline( | |
| 26 const BackgroundSyncManager* registrant, | |
| 27 bool launch_when_next_online) { | |
| 28 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 29 | |
| 30 Get()->LaunchBrowserWhenNextOnlineImpl(registrant, launch_when_next_online); | |
| 31 } | |
| 32 | |
| 33 void BackgroundSyncLauncherAndroid::LaunchBrowserWhenNextOnlineImpl( | |
| 34 const BackgroundSyncManager* registrant, | |
| 35 bool launch_when_next_online) { | |
| 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 37 | |
| 38 bool was_launching = !launch_when_next_online_registrants_.empty(); | |
| 39 | |
| 40 if (launch_when_next_online) | |
| 41 launch_when_next_online_registrants_.insert(registrant); | |
| 42 else | |
| 43 launch_when_next_online_registrants_.erase(registrant); | |
| 44 | |
| 45 bool now_launching = !launch_when_next_online_registrants_.empty(); | |
| 46 if (was_launching != now_launching) { | |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 48 Java_BackgroundSyncLauncher_setLaunchWhenNextOnline( | |
| 49 env, java_launcher_.obj(), base::android::GetApplicationContext(), | |
| 50 now_launching); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 // static | |
| 55 bool BackgroundSyncLauncherAndroid::RegisterLauncher(JNIEnv* env) { | |
| 56 return RegisterNativesImpl(env); | |
| 57 } | |
| 58 | |
| 59 BackgroundSyncLauncherAndroid::BackgroundSyncLauncherAndroid() { | |
| 60 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 61 | |
| 62 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 63 java_launcher_.Reset(Java_BackgroundSyncLauncher_create( | |
| 64 env, base::android::GetApplicationContext())); | |
| 65 } | |
| 66 | |
| 67 BackgroundSyncLauncherAndroid::~BackgroundSyncLauncherAndroid() { | |
| 68 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 69 | |
| 70 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 71 Java_BackgroundSyncLauncher_destroy(env, java_launcher_.obj()); | |
| 72 } | |
| 73 | |
| 74 } // namespace content | |
| OLD | NEW |