Commit c8a153e2 authored by James Vecore's avatar James Vecore Committed by Commit Bot

[Nearby] Reland: Trigger onboarding when first enabling Nearby

Reland as is because the fix was in the parent CL:
https://crrev.com/c/2426864/2

Original commit message:
> [Nearby] Trigger onboarding when first enabling Nearby
>
> This CL adds a pref to track if onboarding was run by this user before.
> If it has not, when enabling for the first time, onboarding is run first
> by navigating to the subpage and showing in a dialog. Once onboarding
> has been done once, the user can freely toggle on/off without
> triggering onboarding. However, onboarding will still run if the user
> triggers the pod button and the feature is disabled. This matches the
> Android behavior.
>
> Additionally, this CL fixes a bug with the premature closing of the
> shared receiveManager which needs to stay alive and connected after the
> dialog closes otherwise getReceiveManager returns a remote with a closed
> pipe.
>
> Bug: b/154866951
> Change-Id: I1e3cbd15f4995f019b3476c2f7a69f67d6eb1888
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424763
> Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
> Commit-Queue: James Vecore <vecore@google.com>
> Cr-Commit-Position: refs/heads/master@{#809623}

Change-Id: I91e3a3749ae15ae6bf7879c259e3622e74eba337
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2427004Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: James Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#810082}
parent 4944cfe1
......@@ -309,6 +309,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetAllowlistedKeys() {
// Nearby Share.
(*s_allowlist)[::prefs::kNearbySharingEnabledPrefName] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_allowlist)[::prefs::kNearbySharingOnboardingCompletePrefName] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_allowlist)[::prefs::kNearbySharingActiveProfilePrefName] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_allowlist)[::prefs::kNearbySharingDeviceNamePrefName] =
......
......@@ -26,6 +26,8 @@ const char kNearbySharingDataUsageName[] = "nearby_sharing.data_usage";
const char kNearbySharingDeviceIdPrefName[] = "nearby_sharing.device_id";
const char kNearbySharingDeviceNamePrefName[] = "nearby_sharing.device_name";
const char kNearbySharingEnabledPrefName[] = "nearby_sharing.enabled";
const char kNearbySharingOnboardingCompletePrefName[] =
"nearby_sharing.onboarding_complete";
const char kNearbySharingFullNamePrefName[] = "nearby_sharing.full_name";
const char kNearbySharingIconUrlPrefName[] = "nearby_sharing.icon_url";
const char kNearbySharingOnboardingDismissedTimePrefName[] =
......@@ -58,6 +60,8 @@ void RegisterNearbySharingPrefs(PrefRegistrySimple* registry) {
// available.
registry->RegisterBooleanPref(prefs::kNearbySharingEnabledPrefName,
/*default_value=*/true);
registry->RegisterBooleanPref(prefs::kNearbySharingOnboardingCompletePrefName,
/*default_value=*/false);
registry->RegisterIntegerPref(
prefs::kNearbySharingBackgroundVisibilityName,
/*default_value=*/static_cast<int>(Visibility::kUnknown));
......
......@@ -17,6 +17,7 @@ extern const char kNearbySharingDataUsageName[];
extern const char kNearbySharingDeviceIdPrefName[];
extern const char kNearbySharingDeviceNamePrefName[];
extern const char kNearbySharingEnabledPrefName[];
extern const char kNearbySharingOnboardingCompletePrefName[];
extern const char kNearbySharingFullNamePrefName[];
extern const char kNearbySharingIconUrlPrefName[];
extern const char kNearbySharingOnboardingDismissedTimePrefName[];
......
......@@ -83,6 +83,12 @@ void NearbyShareSettings::GetEnabled(base::OnceCallback<void(bool)> callback) {
void NearbyShareSettings::SetEnabled(bool enabled) {
pref_service_->SetBoolean(prefs::kNearbySharingEnabledPrefName, enabled);
if (enabled) {
// We rely on the the UI to enforce that if the feature was enabled for the
// first time, that onboarding was run.
pref_service_->SetBoolean(prefs::kNearbySharingOnboardingCompletePrefName,
true);
}
}
void NearbyShareSettings::GetDeviceName(
......
......@@ -467,12 +467,25 @@ Polymer({
* @private
*/
nearbyShareClick_(event) {
if (!this.getPref('nearby_sharing.enabled').value) {
this.setPrefValue('nearby_sharing.enabled', true);
} else {
// Navigate to Nearby Share subpage.
settings.Router.getInstance().navigateTo(settings.routes.NEARBY_SHARE);
const nearbyEnabled = this.getPref('nearby_sharing.enabled').value;
const onboardingComplete =
this.getPref('nearby_sharing.onboarding_complete').value;
let params = undefined;
if (!nearbyEnabled) {
if (onboardingComplete) {
// If we have already run onboarding at least once, we don't need to do
// it again, just enabled the feature in place.
this.setPrefValue('nearby_sharing.enabled', true);
return;
}
// Otherwise we need to go into the subpage and trigger the onboarding
// dialog.
params = new URLSearchParams();
params.set('onboarding', '');
}
settings.Router.getInstance().navigateTo(
settings.routes.NEARBY_SHARE, params);
},
/** @private */
......
......@@ -103,11 +103,6 @@ Polymer({
if (this.observerReceiver_) {
this.observerReceiver_.$.close();
}
if (this.receiveManager_) {
/** @type {nearbyShare.mojom.ReceiveManagerRemote} */
(this.receiveManager_).$.close();
}
},
/**
......
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