Skip to content

Commit

Permalink
[PwaRestore]: Link up the startup promo with the feature flag.
Browse files Browse the repository at this point in the history
This sets up a promo for startup to the PWA Restore feature.
At the moment, the flag for it is disabled, so this won't
be a material change.

Also, the flag needed to be moved to account for where it is
being used (the location wasn't known beforehand).

Bug: 1481570
Low-Coverage-Reason: An integration test is planned in the near future, but at the moment the dialog shows only dummy data, so further tests are a bit premature.
Change-Id: I3a45776802bbc6f197ef19dabb7f293249a8daca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5002592
Reviewed-by: Glenn Hartmann <hartmanng@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1219905}
  • Loading branch information
Finnur Thorarinsson authored and Chromium LUCI CQ committed Nov 4, 2023
1 parent 2821846 commit 7e70e2a
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 9 deletions.
Expand Up @@ -109,6 +109,7 @@
import org.chromium.chrome.browser.ui.system.StatusBarColorController.StatusBarColorProvider;
import org.chromium.chrome.browser.webapps.AddToHomescreenIPHController;
import org.chromium.chrome.browser.webapps.AddToHomescreenMostVisitedTileClickObserver;
import org.chromium.chrome.browser.webapps.PwaRestorePromoUtils;
import org.chromium.chrome.features.start_surface.StartSurface;
import org.chromium.chrome.features.start_surface.StartSurfaceUserData;
import org.chromium.components.browser_ui.accessibility.PageZoomCoordinator;
Expand Down Expand Up @@ -957,7 +958,17 @@ private boolean triggerPromo(boolean intentWithEffect) {
}

private boolean maybeShowPromo() {
// Only one promo can be shown in one run to avoid nagging users too much.
// NOTE: Only one promo can be shown in one run to avoid nagging users too much.

// The PWA Restore promotion runs when we've detected that a user has switched to a new
// device but is leaving behind web apps on the old device. It promotes the idea that the
// user can restore their web apps from their old device (if they have any), and as such it
// is most effective when shown shortly after the first-run experience. It is therefore
// at the front of the list of promotions.
if (PwaRestorePromoUtils.launchPromoIfNeeded(
mActivity, mWindowAndroid, R.drawable.ic_arrow_back_24dp)) {
return true;
}
if (FullScreenSyncPromoUtil.launchPromoIfNeeded(mActivity,
SyncConsentActivityLauncherImpl.get(), VersionInfo.getProductMajorVersion())) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/about_flags.cc
Expand Up @@ -9853,7 +9853,7 @@ const FeatureEntry kFeatureEntries[] = {

{"pwa-restore-ui", flag_descriptions::kPwaRestoreUiName,
flag_descriptions::kPwaRestoreUiDescription, kOsAndroid,
FEATURE_VALUE_TYPE(ui::kPwaRestoreUi)},
FEATURE_VALUE_TYPE(chrome::android::kPwaRestoreUi)},
#endif // BUILDFLAG(IS_ANDROID)
{"autofill-enable-ranking-formula-address-profiles",
flag_descriptions::kAutofillEnableRankingFormulaAddressProfilesName,
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/flags/android/chrome_feature_list.cc
Expand Up @@ -263,6 +263,7 @@ const base::Feature* const kFeaturesExposedToJava[] = {
&kPageAnnotationsService,
&kPaintPreviewNewColdStartHeuristic,
&kPreconnectOnTabCreation,
&kPwaRestoreUi,
&kBookmarksImprovedSaveFlow,
&kBookmarksRefresh,
&kOmahaMinSdkVersionAndroid,
Expand Down Expand Up @@ -844,6 +845,8 @@ BASE_FEATURE(kPreconnectOnTabCreation,
"PreconnectOnTabCreation",
base::FEATURE_DISABLED_BY_DEFAULT);

BASE_FEATURE(kPwaRestoreUi, "PwaRestoreUi", base::FEATURE_DISABLED_BY_DEFAULT);

BASE_FEATURE(kBookmarksImprovedSaveFlow,
"BookmarksImprovedSaveFlow",
base::FEATURE_DISABLED_BY_DEFAULT);
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/flags/android/chrome_feature_list.h
Expand Up @@ -137,6 +137,7 @@ BASE_DECLARE_FEATURE(kOptimizeGeolocationHeaderGeneration);
BASE_DECLARE_FEATURE(kPageAnnotationsService);
BASE_DECLARE_FEATURE(kPaintPreviewNewColdStartHeuristic);
BASE_DECLARE_FEATURE(kPreconnectOnTabCreation);
BASE_DECLARE_FEATURE(kPwaRestoreUi);
BASE_DECLARE_FEATURE(kBookmarksImprovedSaveFlow);
BASE_DECLARE_FEATURE(kBookmarksRefresh);
BASE_DECLARE_FEATURE(kPartnerCustomizationsUma);
Expand Down
Expand Up @@ -378,6 +378,7 @@ public static Map<String, String> getFieldTrialParamsForFeature(String featureNa
public static final String PUSH_MESSAGING_DISALLOW_SENDER_IDS =
"PushMessagingDisallowSenderIDs";
public static final String PWA_UPDATE_DIALOG_FOR_ICON = "PwaUpdateDialogForIcon";
public static final String PWA_RESTORE_UI = "PwaRestoreUi";
public static final String QUERY_TILES = "QueryTiles";
public static final String QUERY_TILES_IN_NTP = "QueryTilesInNTP";
public static final String QUERY_TILES_ON_START = "QueryTilesOnStart";
Expand Down
6 changes: 5 additions & 1 deletion chrome/browser/webapps/android/BUILD.gn
Expand Up @@ -8,7 +8,10 @@ import("//build/config/android/rules.gni")
android_library("java") {
resources_package = "org.chromium.chrome.browser.webapps"

sources = [ "java/src/org/chromium/chrome/browser/webapps/AddToHomescreenIPHController.java" ]
sources = [
"java/src/org/chromium/chrome/browser/webapps/AddToHomescreenIPHController.java",
"java/src/org/chromium/chrome/browser/webapps/PwaRestorePromoUtils.java",
]

deps = [
"//base:base_java",
Expand All @@ -19,6 +22,7 @@ android_library("java") {
"//chrome/browser/ui/android/appmenu:java",
"//chrome/browser/ui/android/strings:ui_strings_grd",
"//chrome/browser/user_education:java",
"//components/browser_ui/bottomsheet/android:java",
"//components/browser_ui/styles/android:java_resources",
"//components/browser_ui/util/android:java",
"//components/embedder_support/android:util_java",
Expand Down
@@ -0,0 +1,50 @@
// Copyright 2023 The Chromium Authors
// 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.webapps;

import android.app.Activity;

import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetControllerProvider;
import org.chromium.components.webapps.pwa_restore_ui.PwaRestoreBottomSheetCoordinator;
import org.chromium.ui.base.WindowAndroid;

/**
* This class is responsible for coordinating the showing of the PWA Restore promo (which aims to
* remind users that they had PWAs installed on their old device, and can restore them on their new
* device.
*/
public class PwaRestorePromoUtils {
/**
* Launch the PWA Restore promotion, if we've determined that this launch meets the criteria for
* for showing it.
*
* @param activity The current {@link Activity} to use for this promo.
* @param windowAndroid The current {@link WindowAndroid} to use for this promo.
* @param arrowResourceId The resource id for the Back arrow to use.
* @return Whether the PWA Restore promo was shown.
*/
public static boolean launchPromoIfNeeded(
Activity activity, WindowAndroid windowAndroid, int arrowResourceId) {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.PWA_RESTORE_UI)) {
return false;
}

// TODO(finnur): The criteria for this needs to be fleshed out, but the flag above is
// disabled by default, so we can just attempt to show the dialog for now (which also helps
// during development).
return launchPromo(activity, windowAndroid, arrowResourceId);
}

private static boolean launchPromo(
Activity activity, WindowAndroid windowAndroid, int arrowResourceId) {
BottomSheetController controller = BottomSheetControllerProvider.from(windowAndroid);
if (controller == null) return false;
PwaRestoreBottomSheetCoordinator pwaRestoreBottomSheetCoordinator =
new PwaRestoreBottomSheetCoordinator(activity, controller, arrowResourceId);
return pwaRestoreBottomSheetCoordinator != null && pwaRestoreBottomSheetCoordinator.show();
}
}
1 change: 0 additions & 1 deletion ui/android/ui_android_feature_map.cc
Expand Up @@ -16,7 +16,6 @@ namespace {
const base::Feature* const kFeaturesExposedToJava[] = {
&ui::kConvertTrackpadEventsToMouse,
&ui::kDeprecatedExternalPickerFunction,
&ui::kPwaRestoreUi,
&ui::kReportAllAvailablePointerTypes,
};

Expand Down
2 changes: 0 additions & 2 deletions ui/android/ui_android_features.cc
Expand Up @@ -17,8 +17,6 @@ BASE_FEATURE(kDeprecatedExternalPickerFunction,
"DeprecatedExternalPickerFunction",
base::FEATURE_ENABLED_BY_DEFAULT);

BASE_FEATURE(kPwaRestoreUi, "PwaRestoreUi", base::FEATURE_DISABLED_BY_DEFAULT);

BASE_FEATURE(kReportAllAvailablePointerTypes,
"ReportAllAvailablePointerTypes",
base::FEATURE_ENABLED_BY_DEFAULT);
Expand Down
3 changes: 0 additions & 3 deletions ui/android/ui_android_features.h
Expand Up @@ -25,9 +25,6 @@ UI_ANDROID_EXPORT BASE_DECLARE_FEATURE(kConvertTrackpadEventsToMouse);
// Use the old-style opening of an External Picker when uploading files.
UI_ANDROID_EXPORT BASE_DECLARE_FEATURE(kDeprecatedExternalPickerFunction);

// Enable the PWA Restore functionality.
UI_ANDROID_EXPORT BASE_DECLARE_FEATURE(kPwaRestoreUi);

// Reports all of the available pointer types (i.e. coarse, fine) to content
// rather than just the first one detected.
UI_ANDROID_EXPORT BASE_DECLARE_FEATURE(kReportAllAvailablePointerTypes);
Expand Down

0 comments on commit 7e70e2a

Please sign in to comment.