Skip to content

Commit

Permalink
🧇 Preserve old choice on reprompt parse error
Browse files Browse the repository at this point in the history
Bug: 330855149
Change-Id: I362f4714bc4ced2f57f70b8c6d74c25a2d44482d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5385786
Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1276969}
  • Loading branch information
Nicolas Dossou-Gbete authored and Chromium LUCI CQ committed Mar 22, 2024
1 parent bea27ef commit f40d035
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,16 @@ void SearchEngineChoiceService::PreprocessPrefsForReprompt() {
return;
}

// Check parameters from `switches::kSearchEngineChoiceTriggerRepromptParams`.
std::optional<base::Value::Dict> reprompt_params = base::JSONReader::ReadDict(
switches::kSearchEngineChoiceTriggerRepromptParams.Get());
if (!reprompt_params) {
// No valid reprompt parameters.
base::UmaHistogramEnumeration(kSearchEngineChoiceRepromptHistogram,
RepromptResult::kInvalidDictionary);
return;
}

// If existing prefs are missing or have a wrong format, force a reprompt.
if (!profile_prefs_->HasPrefPath(
prefs::kDefaultSearchProviderChoiceScreenCompletionVersion)) {
Expand All @@ -378,16 +388,6 @@ void SearchEngineChoiceService::PreprocessPrefsForReprompt() {
return;
}

// Check parameters from `switches::kSearchEngineChoiceTriggerRepromptParams`.
std::optional<base::Value::Dict> reprompt_params = base::JSONReader::ReadDict(
switches::kSearchEngineChoiceTriggerRepromptParams.Get());
if (!reprompt_params) {
// No valid reprompt parameters.
base::UmaHistogramEnumeration(kSearchEngineChoiceRepromptHistogram,
RepromptResult::kInvalidDictionary);
return;
}

const base::Version& current_version = version_info::GetVersion();
int country_id = GetCountryId();
const std::string wildcard_string("*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,6 @@ TEST_F(SearchEngineChoiceServiceTest, NoRepromptForSyntaxError) {
pref_service()->SetInt64(
prefs::kDefaultSearchProviderChoiceScreenCompletionTimestamp,
kPreviousTimestamp);
base::Version choice_version({1, 2, 3, 4});
pref_service()->SetString(
prefs::kDefaultSearchProviderChoiceScreenCompletionVersion,
choice_version.GetString());

// Trigger the creation of the service, which should check for the reprompt.
search_engine_choice_service();
Expand All @@ -1052,9 +1048,6 @@ TEST_F(SearchEngineChoiceServiceTest, NoRepromptForSyntaxError) {
EXPECT_EQ(kPreviousTimestamp,
pref_service()->GetInt64(
prefs::kDefaultSearchProviderChoiceScreenCompletionTimestamp));
EXPECT_EQ(choice_version.GetString(),
pref_service()->GetString(
prefs::kDefaultSearchProviderChoiceScreenCompletionVersion));
histogram_tester_.ExpectTotalCount(
search_engines::kSearchEngineChoiceWipeReasonHistogram, 0);
histogram_tester_.ExpectTotalCount(
Expand Down

0 comments on commit f40d035

Please sign in to comment.