Commit ec9c3ae7 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Sync] Move Play Services check to a new file.

This paves way for deleting BackgroundSyncLauncher code, which is the
old way of waking up Chrome on Android to process Background Sync
registrations, and is no longer being used.

The logic that is still being used is to check whether Google Play
Services is up to date, which is checked at Chrome start up. This CL
refactors that out in to a separate class and updates C++ logic to
use the new class.

Bug: 924490
Change-Id: I4c412738e496c250a556d00408169ace1223a4a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1804484
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Auto-Submit: Mugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698422}
parent ea10e44d
...@@ -2459,6 +2459,7 @@ generate_jni("chrome_jni_headers") { ...@@ -2459,6 +2459,7 @@ generate_jni("chrome_jni_headers") {
"java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTask.java", "java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTask.java",
"java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTaskScheduler.java", "java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTaskScheduler.java",
"java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncPwaDetector.java", "java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncPwaDetector.java",
"java/src/org/chromium/chrome/browser/background_sync/GooglePlayServicesChecker.java",
"java/src/org/chromium/chrome/browser/background_sync/PeriodicBackgroundSyncChromeWakeUpTask.java", "java/src/org/chromium/chrome/browser/background_sync/PeriodicBackgroundSyncChromeWakeUpTask.java",
"java/src/org/chromium/chrome/browser/background_task_scheduler/ChromeBackgroundTaskFactory.java", "java/src/org/chromium/chrome/browser/background_task_scheduler/ChromeBackgroundTaskFactory.java",
"java/src/org/chromium/chrome/browser/banners/AppBannerManager.java", "java/src/org/chromium/chrome/browser/banners/AppBannerManager.java",
......
...@@ -105,6 +105,7 @@ chrome_java_sources = [ ...@@ -105,6 +105,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/autofill/PhoneNumberUtil.java", "java/src/org/chromium/chrome/browser/autofill/PhoneNumberUtil.java",
"java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTaskScheduler.java", "java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTaskScheduler.java",
"java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTask.java", "java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTask.java",
"java/src/org/chromium/chrome/browser/background_sync/GooglePlayServicesChecker.java",
"java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncPwaDetector.java", "java/src/org/chromium/chrome/browser/background_sync/BackgroundSyncPwaDetector.java",
"java/src/org/chromium/chrome/browser/background_sync/PeriodicBackgroundSyncChromeWakeUpTask.java", "java/src/org/chromium/chrome/browser/background_sync/PeriodicBackgroundSyncChromeWakeUpTask.java",
"java/src/org/chromium/chrome/browser/background_task_scheduler/NativeBackgroundTask.java", "java/src/org/chromium/chrome/browser/background_task_scheduler/NativeBackgroundTask.java",
......
...@@ -13,12 +13,10 @@ import com.google.android.gms.gcm.OneoffTask; ...@@ -13,12 +13,10 @@ import com.google.android.gms.gcm.OneoffTask;
import com.google.android.gms.gcm.Task; import com.google.android.gms.gcm.Task;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.task.AsyncTask; import org.chromium.base.task.AsyncTask;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
/** /**
* The {@link BackgroundSyncLauncher} singleton is created and owned by the C++ browser. It * The {@link BackgroundSyncLauncher} singleton is created and owned by the C++ browser. It
...@@ -162,31 +160,6 @@ public class BackgroundSyncLauncher { ...@@ -162,31 +160,6 @@ public class BackgroundSyncLauncher {
launchBrowserIfStopped(false, 0); launchBrowserIfStopped(false, 0);
} }
/**
* Returns true if the Background Sync Manager should be automatically disabled on startup.
* This is currently only the case if Play Services is not up to date, since any sync attempts
* which fail cannot be reregistered. Better to wait until Play Services is updated before
* attempting them.
*
*/
@CalledByNative
private static boolean shouldDisableBackgroundSync() {
// Check to see if Play Services is up to date, and disable GCM if not.
// This will not automatically set {@link sGCMEnabled} to true, in case it has been
// disabled in tests.
if (sGCMEnabled) {
boolean isAvailable = true;
if (!ExternalAuthUtils.canUseGooglePlayServices()) {
setGCMEnabled(false);
Log.i(TAG, "Disabling Background Sync because Play Services is not up to date.");
isAvailable = false;
}
RecordHistogram.recordBooleanHistogram(
"BackgroundSync.LaunchTask.PlayServicesAvailable", isAvailable);
}
return !sGCMEnabled;
}
private static boolean scheduleLaunchTask(GcmNetworkManager scheduler, long minDelayMs) { private static boolean scheduleLaunchTask(GcmNetworkManager scheduler, long minDelayMs) {
// Google Play Services may not be up to date, if the application was not installed through // Google Play Services may not be up to date, if the application was not installed through
// the Play Store. In this case, scheduling the task will fail silently. // the Play Store. In this case, scheduling the task will fail silently.
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.background_sync;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
/**
* Used to check whether Google Play Services version on the device is as
* expected for BackgroundSync. This check is made at browser startup.
*/
final class GooglePlayServicesChecker {
private static final String TAG = "PlayServicesChecker";
private GooglePlayServicesChecker() {}
/**
* Returns true if the Background Sync Manager should be automatically disabled
* on startup. This is currently only the case if Play Services is not up to
* date, since any sync attempts which fail cannot be reregistered. Better to
* wait until Play Services is updated before attempting them.
*/
@CalledByNative
private static boolean shouldDisableBackgroundSync() {
boolean isAvailable = true;
if (!ExternalAuthUtils.canUseGooglePlayServices()) {
Log.i(TAG, "Disabling Background Sync because Play Services is not up to date.");
isAvailable = false;
}
RecordHistogram.recordBooleanHistogram(
"BackgroundSync.LaunchTask.PlayServicesAvailable", isAvailable);
return isAvailable;
}
}
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/android/chrome_jni_headers/BackgroundSyncBackgroundTaskScheduler_jni.h" #include "chrome/android/chrome_jni_headers/BackgroundSyncBackgroundTaskScheduler_jni.h"
#include "chrome/android/chrome_jni_headers/BackgroundSyncBackgroundTask_jni.h" #include "chrome/android/chrome_jni_headers/BackgroundSyncBackgroundTask_jni.h"
#include "chrome/android/chrome_jni_headers/BackgroundSyncLauncher_jni.h" #include "chrome/android/chrome_jni_headers/BackgroundSyncLauncher_jni.h"
#include "chrome/android/chrome_jni_headers/GooglePlayServicesChecker_jni.h"
#include "chrome/android/chrome_jni_headers/PeriodicBackgroundSyncChromeWakeUpTask_jni.h" #include "chrome/android/chrome_jni_headers/PeriodicBackgroundSyncChromeWakeUpTask_jni.h"
#include "chrome/browser/android/chrome_feature_list.h" #include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -95,7 +96,7 @@ bool BackgroundSyncLauncherAndroid::ShouldDisableBackgroundSync() { ...@@ -95,7 +96,7 @@ bool BackgroundSyncLauncherAndroid::ShouldDisableBackgroundSync() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (disable_play_services_version_check_for_tests) if (disable_play_services_version_check_for_tests)
return false; return false;
return Java_BackgroundSyncLauncher_shouldDisableBackgroundSync( return Java_GooglePlayServicesChecker_shouldDisableBackgroundSync(
base::android::AttachCurrentThread()); base::android::AttachCurrentThread());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment