Skip to content

Commit

Permalink
[iOS] Create IsUserEligibleParcelTrackingOptInPrompt util method
Browse files Browse the repository at this point in the history
This CL creates a util method that will be used to check a
user's eligibility for the parcel tracking opt-in prompt.

Bug: 1473449
Change-Id: I74460cc747f21bc49238d985ce58302d0ca28cbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4803184
Commit-Queue: Hira Mahmood <hiramahmood@google.com>
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1187511}
  • Loading branch information
Hira Mahmood authored and Chromium LUCI CQ committed Aug 23, 2023
1 parent 166b648 commit b4c6e97
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ios/chrome/browser/parcel_tracking/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ source_set("util") {
"parcel_tracking_util.h",
"parcel_tracking_util.mm",
]
public_deps = [ "//base" ]
deps = [
"//base",
"//components/prefs",
"//components/signin/public/base",
"//ios/chrome/browser/shared/model/browser_state",
"//ios/chrome/browser/shared/model/prefs:pref_names",
"//ios/chrome/browser/signin",
]
}
3 changes: 3 additions & 0 deletions ios/chrome/browser/parcel_tracking/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+ios/chrome/browser/signin",
]
6 changes: 6 additions & 0 deletions ios/chrome/browser/parcel_tracking/parcel_tracking_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@

#import "base/feature_list.h"

class ChromeBrowserState;

// Feature flag to enable the parcel tracking feature.
BASE_DECLARE_FEATURE(kIOSParcelTracking);

// Returns true if the parcel tracking feature is enabled.
bool IsIOSParcelTrackingEnabled();

// Returns true if the user is eligible for the parcel tracking opt-in prompt.
// The user must have never before seen the prompt and must be signed in.
bool IsUserEligibleParcelTrackingOptInPrompt(ChromeBrowserState* browser_state);

#endif // IOS_CHROME_BROWSER_PARCEL_TRACKING_PARCEL_TRACKING_UTIL_H_
23 changes: 23 additions & 0 deletions ios/chrome/browser/parcel_tracking/parcel_tracking_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,33 @@

#import "ios/chrome/browser/parcel_tracking/parcel_tracking_util.h"

#import "components/prefs/pref_service.h"
#import "components/signin/public/base/consent_level.h"
#import "ios/chrome/browser/shared/model/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/shared/model/prefs/pref_names.h"
#import "ios/chrome/browser/signin/authentication_service.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h"

BASE_FEATURE(kIOSParcelTracking,
"IOSParcelTracking",
base::FEATURE_DISABLED_BY_DEFAULT);

bool IsIOSParcelTrackingEnabled() {
return base::FeatureList::IsEnabled(kIOSParcelTracking);
}

bool IsUserEligibleParcelTrackingOptInPrompt(
ChromeBrowserState* browser_state) {
PrefService* pref_service = browser_state->GetPrefs();
AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state);
if (!authentication_service || !authentication_service->initialized()) {
return false;
}
bool signed_in =
authentication_service->HasPrimaryIdentity(signin::ConsentLevel::kSignin);
return IsIOSParcelTrackingEnabled() &&
!pref_service->GetBoolean(
prefs::kIosParcelTrackingOptInPromptDisplayed) &&
signed_in;
}
3 changes: 3 additions & 0 deletions ios/chrome/browser/shared/model/prefs/browser_prefs.mm
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ void RegisterBrowserStatePrefs(user_prefs::PrefRegistrySyncable* registry) {
// Preferences related to Save to Photos settings.
registry->RegisterStringPref(prefs::kIosSaveToPhotosDefaultGaiaId,
std::string());

registry->RegisterBooleanPref(prefs::kIosParcelTrackingOptInPromptDisplayed,
false);
}

// This method should be periodically pruned of year+ old migrations.
Expand Down
5 changes: 5 additions & 0 deletions ios/chrome/browser/shared/model/prefs/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ const char kIosMagicStackSegmentationShortcutsImpressionsSinceFreshness[] =
const char kIosMagicStackSegmentationSafetyCheckImpressionsSinceFreshness[] =
"ios.magic_stack_segmentation.safety_check_freshness";

// Boolean to represent if the parcel tracking opt-in prompt has been displayed
// for the user.
const char kIosParcelTrackingOptInPromptDisplayed[] =
"ios.parcel_tracking.opt_in_prompt_displayed";

// The number of consecutive times the user dismissed the password bottom sheet.
// This gets reset to 0 whenever the user selects a password from the bottom
// sheet or from the keyboard accessory.
Expand Down
1 change: 1 addition & 0 deletions ios/chrome/browser/shared/model/prefs/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern const char
kIosMagicStackSegmentationShortcutsImpressionsSinceFreshness[];
extern const char
kIosMagicStackSegmentationSafetyCheckImpressionsSinceFreshness[];
extern const char kIosParcelTrackingOptInPromptDisplayed[];
extern const char kIosPasswordBottomSheetDismissCount[];
extern const char kIosPreRestoreAccountInfo[];
extern const char kIosPromosManagerActivePromos[];
Expand Down

0 comments on commit b4c6e97

Please sign in to comment.