Skip to content

Commit

Permalink
[M-116] Fix What's New M116 not being shown by the promo manager
Browse files Browse the repository at this point in the history
This CL fixes a buug when What's New v1 was previous shown by the promo manager, it doesn't show What's New M116

(cherry picked from commit f43715b)

Bug: 1462402
Change-Id: I8d1eaddbc7150bfedcc459ca160c02f17c8be603
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4663177
Reviewed-by: Robbie Gibson <rkgibson@google.com>
Commit-Queue: Cheick Cisse <cheickcisse@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#1168172}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4678981
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/5845@{#441}
Cr-Branched-From: 5a5dff6-refs/heads/main@{#1160321}
  • Loading branch information
ciss1995 authored and Chromium LUCI CQ committed Jul 12, 2023
1 parent 4f4df72 commit 7000da9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
9 changes: 9 additions & 0 deletions ios/chrome/browser/ui/whats_new/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@
// Key to store whether the What's New promo has been register.
extern NSString* const kWhatsNewPromoRegistrationKey;

// Key to store whether the What's New M116 promo has been register.
extern NSString* const kWhatsNewM116PromoRegistrationKey;

// Key to store the date of FRE.
extern NSString* const kWhatsNewDaysAfterFre;

// Key to store the number of launches after FRE.
extern NSString* const kWhatsNewLaunchesAfterFre;

// Key to store the date of FRE What's New M116.
extern NSString* const kWhatsNewM116DaysAfterFre;

// Key to store the number of launches after FRE for What's New M116.
extern NSString* const kWhatsNewM116LaunchesAfterFre;

// Key to store whether a user interacted with What's New from the overflow
// menu.
extern NSString* const kWhatsNewUsageEntryKey;
Expand Down
7 changes: 7 additions & 0 deletions ios/chrome/browser/ui/whats_new/constants.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@

NSString* const kWhatsNewPromoRegistrationKey = @"whatsNewPromoRegistration";

NSString* const kWhatsNewM116PromoRegistrationKey =
@"whatsNewM116PromoRegistration";

NSString* const kWhatsNewDaysAfterFre = @"whatsNewDaysAfterFre";

NSString* const kWhatsNewLaunchesAfterFre = @"whatsNewLaunchesAfterFre";

NSString* const kWhatsNewM116DaysAfterFre = @"whatsNewM116DaysAfterFre";

NSString* const kWhatsNewM116LaunchesAfterFre = @"whatsNewM116LaunchesAfterFre";

NSString* const kWhatsNewUsageEntryKey = @"userHasInteractedWithWhatsNew";

NSString* const kWhatsNewM116UsageEntryKey =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void ClearWhatsNewUserData() {
removeObjectForKey:kWhatsNewLaunchesAfterFre];
[[NSUserDefaults standardUserDefaults]
removeObjectForKey:kWhatsNewPromoRegistrationKey];
[[NSUserDefaults standardUserDefaults]
removeObjectForKey:kWhatsNewM116PromoRegistrationKey];
[[NSUserDefaults standardUserDefaults]
removeObjectForKey:kWhatsNewUsageEntryKey];
[[NSUserDefaults standardUserDefaults]
Expand Down
9 changes: 9 additions & 0 deletions ios/chrome/browser/ui/whats_new/whats_new_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ BASE_DECLARE_FEATURE(kWhatsNewIOSM116);
// Key to store whether the What's New promo has been register.
extern NSString* const kWhatsNewPromoRegistrationKey;

// Key to store whether the What's New m116 promo has been register.
extern NSString* const kWhatsNewM116PromoRegistrationKey;

// Key to store the date of FRE.
extern NSString* const kWhatsNewDaysAfterFre;

// Key to store the date of FRE for What's New M116.
extern NSString* const kWhatsNewM116DaysAfterFre;

// Key to store the number of launches after FRE.
extern NSString* const kWhatsNewLaunchesAfterFre;

// Key to store the number of launches after FRE for What's New M116.
extern NSString* const kWhatsNewM116LaunchesAfterFre;

// Key to store whether a user interacted with What's New from the overflow
// menu.
extern NSString* const kWhatsNewUsageEntryKey;
Expand Down
46 changes: 37 additions & 9 deletions ios/chrome/browser/ui/whats_new/whats_new_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@
// Returns whether today is the 6th and more day after the FRE. This is used to
// decide to register What's New promo in the promo manager or not.
bool IsSixDaysAfterFre() {
NSDate* startDate = [[NSUserDefaults standardUserDefaults]
objectForKey:kWhatsNewDaysAfterFre];
// TODO(crbug.com/1462404): Clean up unused user defaults and find a better
// solution to update existing user defaults for future versions of What's
// New.
NSString* const daysAfterFre = IsWhatsNewM116Enabled()
? kWhatsNewM116DaysAfterFre
: kWhatsNewDaysAfterFre;
NSDate* startDate =
[[NSUserDefaults standardUserDefaults] objectForKey:daysAfterFre];
if (!startDate) {
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date]
forKey:kWhatsNewDaysAfterFre];
forKey:daysAfterFre];
return false;
}

Expand All @@ -44,21 +50,36 @@ bool IsSixDaysAfterFre() {
// Returns whether this launch is the 6th and more launches after the FRE. This
// is used to decide to register What's New promo in the promo manager or not.
bool IsSixLaunchAfterFre() {
NSInteger num = [[NSUserDefaults standardUserDefaults]
integerForKey:kWhatsNewLaunchesAfterFre];
// TODO(crbug.com/1462404): Clean up unused user defaults and find a better
// solution to update existing user defaults for future versions of What's
// New.
NSString* const launchesAfterFre = IsWhatsNewM116Enabled()
? kWhatsNewM116LaunchesAfterFre
: kWhatsNewLaunchesAfterFre;

NSInteger num =
[[NSUserDefaults standardUserDefaults] integerForKey:launchesAfterFre];

if (num >= 6) {
return true;
}

num++;
[[NSUserDefaults standardUserDefaults] setInteger:num
forKey:kWhatsNewLaunchesAfterFre];
forKey:launchesAfterFre];
return false;
}

// Returns whether What's New promo has been registered in the promo manager.
bool IsWhatsNewPromoRegistered() {
if (IsWhatsNewM116Enabled()) {
return [[NSUserDefaults standardUserDefaults]
boolForKey:kWhatsNewM116PromoRegistrationKey];
}

// TODO(crbug.com/1462404): Clean up unused user defaults and find a better
// solution to update existing user defaults for future versions of What's
// New.
return [[NSUserDefaults standardUserDefaults]
boolForKey:kWhatsNewPromoRegistrationKey];
}
Expand All @@ -71,13 +92,13 @@ bool IsWhatsNewPromoRegistered() {

bool WasWhatsNewUsed() {
if (IsWhatsNewM116Enabled()) {
// Remove the previous user defaults
[[NSUserDefaults standardUserDefaults]
removeObjectForKey:kWhatsNewUsageEntryKey];
return [[NSUserDefaults standardUserDefaults]
boolForKey:kWhatsNewM116UsageEntryKey];
}

// TODO(crbug.com/1462404): Clean up unused user defaults and find a better
// solution to update existing user defaults for future versions of What's
// New.
return
[[NSUserDefaults standardUserDefaults] boolForKey:kWhatsNewUsageEntryKey];
}
Expand All @@ -101,6 +122,13 @@ void SetWhatsNewUsed(PromosManager* promosManager) {
}

void setWhatsNewPromoRegistration() {
if (IsWhatsNewM116Enabled()) {
[[NSUserDefaults standardUserDefaults]
setBool:YES
forKey:kWhatsNewM116PromoRegistrationKey];
return;
}

[[NSUserDefaults standardUserDefaults] setBool:YES
forKey:kWhatsNewPromoRegistrationKey];
}
Expand Down

0 comments on commit 7000da9

Please sign in to comment.