jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 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 | |
iclelland | 8467f46 | 2015-10-21 14:03:13 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_ |
| 6 | #define CHROME_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_ |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 7 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 10 | #include <set> |
| 11 | |
| 12 | #include "base/android/jni_android.h" |
Mugdha Lakhani | 1f1ea8e | 2019-02-27 16:01:32 | [diff] [blame] | 13 | #include "base/callback_forward.h" |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 14 | #include "base/lazy_instance.h" |
| 15 | #include "base/macros.h" |
Mugdha Lakhani | eef7642 | 2019-03-22 18:04:49 | [diff] [blame] | 16 | #include "base/time/time.h" |
Mugdha Lakhani | eab4b18 | 2019-06-25 10:52:16 | [diff] [blame] | 17 | #include "third_party/blink/public/mojom/background_sync/background_sync.mojom.h" |
Mugdha Lakhani | 1f1ea8e | 2019-02-27 16:01:32 | [diff] [blame] | 18 | |
Mugdha Lakhani | 78e3b06 | 2019-09-20 13:38:00 | [diff] [blame^] | 19 | // BackgroundSyncLauncherAndroid is used to register interest in starting |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 20 | // the browser the next time the device goes online. This class runs on the UI |
| 21 | // thread. |
iclelland | 8467f46 | 2015-10-21 14:03:13 | [diff] [blame] | 22 | class BackgroundSyncLauncherAndroid { |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 23 | public: |
| 24 | static BackgroundSyncLauncherAndroid* Get(); |
| 25 | |
Mugdha Lakhani | eef7642 | 2019-03-22 18:04:49 | [diff] [blame] | 26 | // 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 Lakhani | e07dd9e | 2019-07-18 17:25:23 | [diff] [blame] | 31 | static void ScheduleBrowserWakeUp(blink::mojom::BackgroundSyncType sync_type); |
| 32 | |
iclelland | d054a6f | 2016-01-11 20:16:14 | [diff] [blame] | 33 | static bool ShouldDisableBackgroundSync(); |
| 34 | |
Mugdha Lakhani | 78e3b06 | 2019-09-20 13:38:00 | [diff] [blame^] | 35 | // TODO(crbug.com/514449): Remove this once the bots have their play services |
| 36 | // package updated before every test run. |
iclelland | d054a6f | 2016-01-11 20:16:14 | [diff] [blame] | 37 | static void SetPlayServicesVersionCheckDisabledForTests(bool disabled); |
| 38 | |
Mugdha Lakhani | 1f1ea8e | 2019-02-27 16:01:32 | [diff] [blame] | 39 | // Fires all pending Background Sync events across all storage partitions |
| 40 | // for the last used profile. |
Mugdha Lakhani | eab4b18 | 2019-06-25 10:52:16 | [diff] [blame] | 41 | // Fires one-shot Background Sync events for registration of |sync_type|. |
Mugdha Lakhani | 1f1ea8e | 2019-02-27 16:01:32 | [diff] [blame] | 42 | void FireBackgroundSyncEvents( |
Mugdha Lakhani | eab4b18 | 2019-06-25 10:52:16 | [diff] [blame] | 43 | blink::mojom::BackgroundSyncType sync_type, |
Mugdha Lakhani | 1f1ea8e | 2019-02-27 16:01:32 | [diff] [blame] | 44 | const base::android::JavaParamRef<jobject>& j_runnable); |
| 45 | |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 46 | private: |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 47 | friend struct base::LazyInstanceTraitsBase<BackgroundSyncLauncherAndroid>; |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 48 | |
| 49 | // Constructor and destructor marked private to enforce singleton |
| 50 | BackgroundSyncLauncherAndroid(); |
| 51 | ~BackgroundSyncLauncherAndroid(); |
| 52 | |
Mugdha Lakhani | e07dd9e | 2019-07-18 17:25:23 | [diff] [blame] | 53 | void ScheduleBrowserWakeUpImpl(blink::mojom::BackgroundSyncType sync_type); |
| 54 | void ScheduleBrowserWakeUpWithWakeUpDeltaImpl( |
| 55 | blink::mojom::BackgroundSyncType sync_type, |
| 56 | base::TimeDelta soonest_wakeup_delta); |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 57 | |
Mugdha Lakhani | fe82692b | 2019-02-08 13:08:40 | [diff] [blame] | 58 | base::android::ScopedJavaGlobalRef<jobject> |
Mugdha Lakhani | fe82692b | 2019-02-08 13:08:40 | [diff] [blame] | 59 | java_background_sync_background_task_scheduler_launcher_; |
Mugdha Lakhani | 1f1ea8e | 2019-02-27 16:01:32 | [diff] [blame] | 60 | |
jkarlin | db18522 | 2015-05-29 12:02:00 | [diff] [blame] | 61 | DISALLOW_COPY_AND_ASSIGN(BackgroundSyncLauncherAndroid); |
| 62 | }; |
| 63 | |
iclelland | 8467f46 | 2015-10-21 14:03:13 | [diff] [blame] | 64 | #endif // CHROME_BROWSER_ANDROID_BACKGROUND_SYNC_LAUNCHER_ANDROID_H_ |