[Background Sync] Reland: Add Periodic Background Sync Scheduling
Add Periodic Background Sync Scheduling logic which does the following:
1. Schedule a background task to launch Chrome to process pending
periodic Background Sync registrations.
2. Schedule a delayed task to process periodic Background Sync
registrations.
In follow-up Cls, I'll add logic to revive suspended registrations.
===========
An assert was being hit in BackgroundTaskSchedulerUma::toUmaEnumValueFromTaskId()
because we weren't handling the case of PERIODIC_BACKGROUND_SYNC_CHROME_WAKEUP_TASK_JOB_IDs.
I've fixed this now and also run various additional trybots to try and capture tests
that were failing before. In addition, Jonathan has verified that his local repro
(which I sadly don't have) of the failing gpu tests are fixed with this patch.
For the change since the last land, please compare Patchset 3 against 1.
Bug: 925297, 984580, 984563
Change-Id: Ie5df1a0370797671217ffc4ed6884e10fb13789c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1704754
Reviewed-by: Tommy Nyquist <[email protected]>
Reviewed-by: David Trainor <[email protected]>
Reviewed-by: Avi Drissman <[email protected]>
Commit-Queue: Mugdha Lakhani <[email protected]>
Commit-Queue: David Trainor <[email protected]>
Auto-Submit: Mugdha Lakhani <[email protected]>
Cr-Commit-Position: refs/heads/master@{#678740}
diff --git a/chrome/browser/android/background_sync_launcher_android.cc b/chrome/browser/android/background_sync_launcher_android.cc
index c7a05ba..5800344 100644
--- a/chrome/browser/android/background_sync_launcher_android.cc
+++ b/chrome/browser/android/background_sync_launcher_android.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/background_sync_context.h"
+#include "content/public/browser/background_sync_parameters.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
@@ -32,6 +33,12 @@
// updated before every test run. (https://crbug.com/514449)
bool disable_play_services_version_check_for_tests = false;
+// Returns 0 to create a ONE_SHOT_SYNC_CHROME_WAKE_UP task, or 1 to create a
+// PERIODIC_SYNC_CHROME_WAKE_UP task, based on |sync_type|.
+int GetBackgroundTaskType(blink::mojom::BackgroundSyncType sync_type) {
+ return static_cast<int>(sync_type);
+}
+
} // namespace
// static
@@ -62,10 +69,21 @@
}
// static
-void BackgroundSyncLauncherAndroid::LaunchBrowserIfStopped() {
+void BackgroundSyncLauncherAndroid::ScheduleBrowserWakeUp(
+ blink::mojom::BackgroundSyncType sync_type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- Get()->LaunchBrowserIfStoppedImpl();
+ Get()->ScheduleBrowserWakeUpImpl(sync_type);
+}
+
+// static
+void BackgroundSyncLauncherAndroid::LaunchBrowserWithWakeUpDelta(
+ blink::mojom::BackgroundSyncType sync_type,
+ base::TimeDelta soonest_wakeup_delta) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ Get()->ScheduleBrowserWakeUpWithWakeUpDeltaImpl(sync_type,
+ soonest_wakeup_delta);
}
// static
@@ -84,19 +102,22 @@
base::android::AttachCurrentThread());
}
-void BackgroundSyncLauncherAndroid::LaunchBrowserIfStoppedImpl() {
+void BackgroundSyncLauncherAndroid::ScheduleBrowserWakeUpImpl(
+ blink::mojom::BackgroundSyncType sync_type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto* profile = ProfileManager::GetLastUsedProfile();
DCHECK(profile);
content::BackgroundSyncContext::GetSoonestWakeupDeltaAcrossPartitions(
- profile, base::BindOnce(
- &BackgroundSyncLauncherAndroid::LaunchBrowserWithWakeupDelta,
- base::Unretained(this)));
+ sync_type, profile,
+ base::BindOnce(&BackgroundSyncLauncherAndroid::
+ ScheduleBrowserWakeUpWithWakeUpDeltaImpl,
+ base::Unretained(this), sync_type));
}
-void BackgroundSyncLauncherAndroid::LaunchBrowserWithWakeupDelta(
+void BackgroundSyncLauncherAndroid::ScheduleBrowserWakeUpWithWakeUpDeltaImpl(
+ blink::mojom::BackgroundSyncType sync_type,
base::TimeDelta soonest_wakeup_delta) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -113,7 +134,8 @@
Java_BackgroundSyncBackgroundTaskScheduler_launchBrowserIfStopped(
env, java_background_sync_background_task_scheduler_launcher_,
- !soonest_wakeup_delta.is_max(), min_delay_ms);
+ GetBackgroundTaskType(sync_type), !soonest_wakeup_delta.is_max(),
+ min_delay_ms);
}
void BackgroundSyncLauncherAndroid::FireBackgroundSyncEvents(