blob: a81b38cecd92346b384b364a3c5c8c9eeff13fb1 [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 Lakhanieef76422019-03-22 18:04:4926 // Calculates the soonest wakeup time across all the storage
27 // partitions for the non-incognito profile and ensures that the browser
28 // is running when the device next goes online after that time has passed.
29 // If this time is set to base::TimeDelta::Max() across all storage
30 // partitions, the wake-up task is cancelled.
Mugdha Lakhanie07dd9e2019-07-18 17:25:2331 static void ScheduleBrowserWakeUp(blink::mojom::BackgroundSyncType sync_type);
32
iclellandd054a6f2016-01-11 20:16:1433 static bool ShouldDisableBackgroundSync();
34
Mugdha Lakhani78e3b062019-09-20 13:38:0035 // TODO(crbug.com/514449): Remove this once the bots have their play services
36 // package updated before every test run.
iclellandd054a6f2016-01-11 20:16:1437 static void SetPlayServicesVersionCheckDisabledForTests(bool disabled);
38
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3239 // Fires all pending Background Sync events across all storage partitions
40 // for the last used profile.
Mugdha Lakhanieab4b182019-06-25 10:52:1641 // Fires one-shot Background Sync events for registration of |sync_type|.
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3242 void FireBackgroundSyncEvents(
Mugdha Lakhanieab4b182019-06-25 10:52:1643 blink::mojom::BackgroundSyncType sync_type,
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3244 const base::android::JavaParamRef<jobject>& j_runnable);
45
jkarlindb185222015-05-29 12:02:0046 private:
scottmg5e65e3a2017-03-08 08:48:4647 friend struct base::LazyInstanceTraitsBase<BackgroundSyncLauncherAndroid>;
jkarlindb185222015-05-29 12:02:0048
49 // Constructor and destructor marked private to enforce singleton
50 BackgroundSyncLauncherAndroid();
51 ~BackgroundSyncLauncherAndroid();
52
Mugdha Lakhanie07dd9e2019-07-18 17:25:2353 void ScheduleBrowserWakeUpImpl(blink::mojom::BackgroundSyncType sync_type);
54 void ScheduleBrowserWakeUpWithWakeUpDeltaImpl(
55 blink::mojom::BackgroundSyncType sync_type,
56 base::TimeDelta soonest_wakeup_delta);
jkarlindb185222015-05-29 12:02:0057
Mugdha Lakhanife82692b2019-02-08 13:08:4058 base::android::ScopedJavaGlobalRef<jobject>
Mugdha Lakhanife82692b2019-02-08 13:08:4059 java_background_sync_background_task_scheduler_launcher_;
Mugdha Lakhani1f1ea8e2019-02-27 16:01:3260
jkarlindb185222015-05-29 12:02:0061 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncLauncherAndroid);
62};
63
iclelland8467f462015-10-21 14:03:1364#endif // CHROME_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_