Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / android / background_sync_launcher_android.cc
blob78110c14f6428b08b9ca0ed3d22bb20418bfa00b
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.
5 #include "content/browser/android/background_sync_launcher_android.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "jni/BackgroundSyncLauncher_jni.h"
10 namespace content {
12 namespace {
13 base::LazyInstance<BackgroundSyncLauncherAndroid> g_background_sync_launcher =
14 LAZY_INSTANCE_INITIALIZER;
17 // static
18 BackgroundSyncLauncherAndroid* BackgroundSyncLauncherAndroid::Get() {
19 DCHECK_CURRENTLY_ON(BrowserThread::UI);
21 return g_background_sync_launcher.Pointer();
24 // static
25 void BackgroundSyncLauncherAndroid::LaunchBrowserWhenNextOnline(
26 const BackgroundSyncManager* registrant,
27 bool launch_when_next_online) {
28 DCHECK_CURRENTLY_ON(BrowserThread::UI);
30 Get()->LaunchBrowserWhenNextOnlineImpl(registrant, launch_when_next_online);
33 void BackgroundSyncLauncherAndroid::LaunchBrowserWhenNextOnlineImpl(
34 const BackgroundSyncManager* registrant,
35 bool launch_when_next_online) {
36 DCHECK_CURRENTLY_ON(BrowserThread::UI);
38 bool was_launching = !launch_when_next_online_registrants_.empty();
40 if (launch_when_next_online)
41 launch_when_next_online_registrants_.insert(registrant);
42 else
43 launch_when_next_online_registrants_.erase(registrant);
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(), now_launching);
53 // static
54 bool BackgroundSyncLauncherAndroid::RegisterLauncher(JNIEnv* env) {
55 return RegisterNativesImpl(env);
58 BackgroundSyncLauncherAndroid::BackgroundSyncLauncherAndroid() {
59 DCHECK_CURRENTLY_ON(BrowserThread::UI);
61 JNIEnv* env = base::android::AttachCurrentThread();
62 java_launcher_.Reset(Java_BackgroundSyncLauncher_create(
63 env, base::android::GetApplicationContext()));
66 BackgroundSyncLauncherAndroid::~BackgroundSyncLauncherAndroid() {
67 DCHECK_CURRENTLY_ON(BrowserThread::UI);
69 JNIEnv* env = base::android::AttachCurrentThread();
70 Java_BackgroundSyncLauncher_destroy(env, java_launcher_.obj());
73 } // namespace content