Commit bd23dace authored by My Nguyen's avatar My Nguyen Committed by Commit Bot

Add preference for personal info suggester showing setting link

Should stop showing setting link after showing 10 times or when user
have accepted it.

See: http://go/personal-info-setting-link

Bug: 1094267
Change-Id: I9d9c5f09aa77f56445722c5fd626a8caaa04da7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2245583
Commit-Queue: My Nguyen <myy@chromium.org>
Reviewed-by: default avatarJing Wang <jiwan@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779602}
parent 35338967
......@@ -134,13 +134,8 @@ SuggestionStatus PersonalInfoSuggester::HandleKeyEvent(
if (suggestion_shown_) {
if (event.key == "Tab" || event.key == "Right") {
AcceptSuggestion();
int tab_acceptance_count = GetTabAcceptanceCount();
if (tab_acceptance_count < kMaxTabAcceptanceCount) {
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kAssistiveInputFeatureSettings);
update->SetIntKey(kPersonalInfoSuggesterTabAcceptanceCount,
tab_acceptance_count + 1);
}
IncrementPrefValueTilCapped(kPersonalInfoSuggesterTabAcceptanceCount,
kMaxTabAcceptanceCount);
return SuggestionStatus::kAccept;
} else if (event.key == "Esc") {
DismissSuggestion();
......@@ -236,11 +231,16 @@ void PersonalInfoSuggester::ShowSuggestion(const base::string16& text,
}
std::string error;
bool show_tab = GetTabAcceptanceCount() < kMaxTabAcceptanceCount;
bool show_tab = GetPrefValue(kPersonalInfoSuggesterTabAcceptanceCount) <
kMaxTabAcceptanceCount;
ui::ime::SuggestionDetails details;
details.text = text;
details.confirmed_length = confirmed_length;
details.show_tab = show_tab;
details.show_setting_link =
GetPrefValue(kPersonalInfoSuggesterTabAcceptanceCount) == 0 &&
GetPrefValue(kPersonalInfoSuggesterShowSettingCount) <
kMaxShowSettingCount;
suggestion_handler_->SetSuggestion(context_id_, details, &error);
if (!error.empty()) {
LOG(ERROR) << "Fail to show suggestion. " << error;
......@@ -250,6 +250,8 @@ void PersonalInfoSuggester::ShowSuggestion(const base::string16& text,
first_shown_ = false;
} else {
first_shown_ = true;
IncrementPrefValueTilCapped(kPersonalInfoSuggesterShowSettingCount,
kMaxShowSettingCount);
tts_handler_->Announce(
// TODO(jiwan): Add translation to other languages when we support more
// than English.
......@@ -262,16 +264,26 @@ void PersonalInfoSuggester::ShowSuggestion(const base::string16& text,
suggestion_shown_ = true;
}
int PersonalInfoSuggester::GetTabAcceptanceCount() {
int PersonalInfoSuggester::GetPrefValue(const std::string& pref_name) {
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kAssistiveInputFeatureSettings);
auto tab_acceptance_count =
update->FindIntKey(kPersonalInfoSuggesterTabAcceptanceCount);
if (!tab_acceptance_count.has_value()) {
update->SetIntKey(kPersonalInfoSuggesterTabAcceptanceCount, 0);
auto value = update->FindIntKey(pref_name);
if (!value.has_value()) {
update->SetIntKey(pref_name, 0);
return 0;
}
return *tab_acceptance_count;
return *value;
}
void PersonalInfoSuggester::IncrementPrefValueTilCapped(
const std::string& pref_name,
int max_value) {
int value = GetPrefValue(pref_name);
if (value < max_value) {
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kAssistiveInputFeatureSettings);
update->SetIntKey(pref_name, value + 1);
}
}
AssistiveType PersonalInfoSuggester::GetProposeActionType() {
......
......@@ -25,6 +25,9 @@ namespace chromeos {
const char kPersonalInfoSuggesterTabAcceptanceCount[] =
"personal_info_suggester_tab_acceptance_count";
const int kMaxTabAcceptanceCount = 10;
const char kPersonalInfoSuggesterShowSettingCount[] =
"personal_info_suggester_show_setting_count";
const int kMaxShowSettingCount = 10;
AssistiveType ProposeAssistiveAction(const base::string16& text);
......@@ -86,7 +89,12 @@ class PersonalInfoSuggester : public Suggester {
void AcceptSuggestion();
int GetTabAcceptanceCount();
int GetPrefValue(const std::string& pref_name);
// Increment int value for the given pref_name by 1 every time the function is
// called. The function has no effect after the int value becomes equal to the
// max_value.
void IncrementPrefValueTilCapped(const std::string& pref_name, int max_value);
SuggestionHandlerInterface* const suggestion_handler_;
......
......@@ -38,6 +38,7 @@ class TestSuggestionHandler : public SuggestionHandlerInterface {
suggestion_text_ = details.text;
confirmed_length_ = details.confirmed_length;
show_tab_ = details.show_tab;
show_setting_link_ = details.show_setting_link;
return true;
}
......@@ -85,6 +86,9 @@ class TestSuggestionHandler : public SuggestionHandlerInterface {
}
void VerifyShowTab(const bool show_tab) { EXPECT_EQ(show_tab_, show_tab); }
void VerifyShowSettingLink(const bool show_setting_link) {
EXPECT_EQ(show_setting_link_, show_setting_link);
}
bool IsSuggestionAccepted() { return suggestion_accepted_; }
......@@ -92,6 +96,7 @@ class TestSuggestionHandler : public SuggestionHandlerInterface {
base::string16 suggestion_text_;
size_t confirmed_length_ = 0;
bool show_tab_ = false;
bool show_setting_link_ = false;
bool suggestion_accepted_ = false;
std::vector<std::string> previous_suggestions_;
};
......@@ -334,4 +339,31 @@ TEST_F(PersonalInfoSuggesterTest, DoNotAnnouncePressTabWhenTabNotShown) {
"Suggested text %s. ", base::UTF16ToUTF8(email_).c_str()));
}
TEST_F(PersonalInfoSuggesterTest, ShowSettingLink) {
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kAssistiveInputFeatureSettings);
update->RemoveKey(kPersonalInfoSuggesterShowSettingCount);
update->RemoveKey(kPersonalInfoSuggesterTabAcceptanceCount);
for (int i = 0; i < kMaxShowSettingCount; i++) {
suggester_->Suggest(base::UTF8ToUTF16("my email is "));
// Dismiss suggestion.
SendKeyboardEvent("Esc");
suggestion_handler_->VerifyShowSettingLink(true);
}
suggester_->Suggest(base::UTF8ToUTF16("my email is "));
suggestion_handler_->VerifyShowSettingLink(false);
}
TEST_F(PersonalInfoSuggesterTest, DoNotShowSettingLinkAfterAcceptance) {
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kAssistiveInputFeatureSettings);
update->SetIntKey(kPersonalInfoSuggesterShowSettingCount, 0);
suggester_->Suggest(base::UTF8ToUTF16("my email is "));
suggestion_handler_->VerifyShowSettingLink(true);
// Accept suggestion.
SendKeyboardEvent("Tab");
suggester_->Suggest(base::UTF8ToUTF16("my email is "));
suggestion_handler_->VerifyShowSettingLink(false);
}
} // namespace chromeos
......@@ -14,6 +14,7 @@ struct SuggestionDetails {
base::string16 text;
size_t confirmed_length;
bool show_tab;
bool show_setting_link;
};
} // namespace ime
......
......@@ -12,6 +12,7 @@
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/input_method/ui/assistive_delegate.h"
#include "chrome/browser/chromeos/input_method/ui/suggestion_details.h"
#include "chrome/browser/chromeos/input_method/ui/suggestion_view.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
......@@ -143,9 +144,11 @@ void SuggestionWindowView::Show(const SuggestionDetails& details) {
MaybeInitializeSuggestionViews(1);
candidate_views_[0]->SetEnabled(true);
candidate_views_[0]->SetView(details);
candidate_views_[0]->SetMinWidth(
setting_link_view_->GetPreferredSize().width());
setting_link_view_->SetVisible(true);
if (details.show_setting_link) {
candidate_views_[0]->SetMinWidth(
setting_link_view_->GetPreferredSize().width());
}
setting_link_view_->SetVisible(details.show_setting_link);
MakeVisible();
}
......
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