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 #ifndef CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_
6 #define CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_
10 #include "base/android/jni_android.h"
11 #include "base/lazy_instance.h"
12 #include "base/macros.h"
13 #include "content/common/content_export.h"
17 class BackgroundSyncManager
;
19 // The BackgroundSyncLauncherAndroid singleton owns the Java
20 // BackgroundSyncLauncher object and is used to register interest in starting
21 // the browser the next time the device goes online. This class runs on the UI
23 class CONTENT_EXPORT BackgroundSyncLauncherAndroid
{
25 static BackgroundSyncLauncherAndroid
* Get();
27 // Register the |registrant|'s interest (or disinterest) in starting the
28 // browser the next time the device goes online after the browser has closed.
29 // |registrant| is used to count the number of interested objects and is not
30 // accessed, therefore it is okay for |registrant| to be deleted before this
31 // class. Interest is reset the next time the BackgroundSyncLauncherAndroid is
32 // created (browser restart). The caller can remove interest in launching the
33 // browser by calling with |launch_when_next_online| set to false.
34 static void LaunchBrowserWhenNextOnline(
35 const BackgroundSyncManager
* registrant
,
36 bool launch_when_next_online
);
38 static bool RegisterLauncher(JNIEnv
* env
);
41 friend struct base::DefaultLazyInstanceTraits
<BackgroundSyncLauncherAndroid
>;
43 // Constructor and destructor marked private to enforce singleton
44 BackgroundSyncLauncherAndroid();
45 ~BackgroundSyncLauncherAndroid();
47 void LaunchBrowserWhenNextOnlineImpl(const BackgroundSyncManager
* registrant
,
48 bool launch_when_next_online
);
50 std::set
<const BackgroundSyncManager
*> launch_when_next_online_registrants_
;
51 base::android::ScopedJavaGlobalRef
<jobject
> java_launcher_
;
52 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncLauncherAndroid
);
55 } // namespace content
57 #endif // CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_