blob: c5d5a1138529981c04f55b2d1d4defb7b581c439 [file] [log] [blame]
jkarlindb185222015-05-29 12:02:001// 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
iclelland8467f462015-10-21 14:03:135#ifndef CHROME_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_
6#define CHROME_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_
jkarlindb185222015-05-29 12:02:007
avie4d7b6f2015-12-26 00:59:188#include <stdint.h>
9
jkarlindb185222015-05-29 12:02:0010#include <set>
11
12#include "base/android/jni_android.h"
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3213#include "base/callback_forward.h"
jkarlindb185222015-05-29 12:02:0014#include "base/lazy_instance.h"
15#include "base/macros.h"
Mugdha Lakhanieef76422019-03-22 18:04:4916#include "base/time/time.h"
Mugdha Lakhanieab4b182019-06-25 10:52:1617#include "third_party/blink/public/mojom/background_sync/background_sync.mojom.h"
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3218
Mugdha Lakhani78e3b062019-09-20 13:38:0019// BackgroundSyncLauncherAndroid is used to register interest in starting
jkarlindb185222015-05-29 12:02:0020// the browser the next time the device goes online. This class runs on the UI
21// thread.
iclelland8467f462015-10-21 14:03:1322class BackgroundSyncLauncherAndroid {
jkarlindb185222015-05-29 12:02:0023 public:
24 static BackgroundSyncLauncherAndroid* Get();
25
Mugdha Lakhanieb39fc232019-11-14 14:54:2526 // Schedules a BackgroundTaskScheduler task for |sync_type| with delay |delay|
27 // to ensure that the browser is running when the device next goes online
28 // after that time has passed. If |delay| is base::TimeDelta::Max(), the
29 // wake-up task is cancelled.
30 static void ScheduleBrowserWakeUpWithDelay(
31 blink::mojom::BackgroundSyncType sync_type,
32 base::TimeDelta delay);
33
34 // Cancels the BackgroundTaskScheduler task that wakes up the browser to
35 // process Background Sync registrations of type |sync_type|.
36 static void CancelBrowserWakeup(blink::mojom::BackgroundSyncType sync_type);
Mugdha Lakhanie07dd9e2019-07-18 17:25:2337
iclellandd054a6f2016-01-11 20:16:1438 static bool ShouldDisableBackgroundSync();
39
Mugdha Lakhani78e3b062019-09-20 13:38:0040 // TODO(crbug.com/514449): Remove this once the bots have their play services
41 // package updated before every test run.
iclellandd054a6f2016-01-11 20:16:1442 static void SetPlayServicesVersionCheckDisabledForTests(bool disabled);
43
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3244 // Fires all pending Background Sync events across all storage partitions
45 // for the last used profile.
Mugdha Lakhanieab4b182019-06-25 10:52:1646 // Fires one-shot Background Sync events for registration of |sync_type|.
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3247 void FireBackgroundSyncEvents(
Mugdha Lakhanieab4b182019-06-25 10:52:1648 blink::mojom::BackgroundSyncType sync_type,
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3249 const base::android::JavaParamRef<jobject>& j_runnable);
50
jkarlindb185222015-05-29 12:02:0051 private:
scottmg5e65e3a2017-03-08 08:48:4652 friend struct base::LazyInstanceTraitsBase<BackgroundSyncLauncherAndroid>;
jkarlindb185222015-05-29 12:02:0053
54 // Constructor and destructor marked private to enforce singleton
55 BackgroundSyncLauncherAndroid();
56 ~BackgroundSyncLauncherAndroid();
57
Mugdha Lakhanieb39fc232019-11-14 14:54:2558 void ScheduleBrowserWakeUpWithDelayImpl(
Mugdha Lakhanie07dd9e2019-07-18 17:25:2359 blink::mojom::BackgroundSyncType sync_type,
60 base::TimeDelta soonest_wakeup_delta);
Mugdha Lakhanieb39fc232019-11-14 14:54:2561 void CancelBrowserWakeupImpl(blink::mojom::BackgroundSyncType sync_type);
jkarlindb185222015-05-29 12:02:0062
Mugdha Lakhanife82692b2019-02-08 13:08:4063 base::android::ScopedJavaGlobalRef<jobject>
Mugdha Lakhanife82692b2019-02-08 13:08:4064 java_background_sync_background_task_scheduler_launcher_;
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3265
jkarlindb185222015-05-29 12:02:0066 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncLauncherAndroid);
67};
68
iclelland8467f462015-10-21 14:03:1369#endif // CHROME_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_