forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Omnibox][PZPS] pref to control visibility of grouped suggestions
Certain types of suggestions such as the proactive zero-prefix suggestions may be associated with suggestion group IDs that indicate their type, e.g., trending or onboarding PZPS. Since proactive zero-prefix suggestions cannot be individually deleted, users should be able to hide/show all suggestions belonging to a given group ID. This CL introduces a list pref that controls the visibility of suggestion group IDs. Convenience methods are added to the omnibox:: namespace to check whether a given suggestion group ID is hidden and to toggle visibility of a given suggestion group ID. This CL also renames the files omnibox_pref_names.h/cc to omnibox_prefs.h/cc as they contain more than just the pref names. Bug: 1046547 Change-Id: Iea9a03eb70b780c583e3cf8f48d819a9aa9c1f20 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137866 Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Tommy Li <tommycli@chromium.org> Commit-Queue: Moe Ahmadi <mahmadi@chromium.org> Cr-Commit-Position: refs/heads/master@{#758223}
- Loading branch information
Moe Ahmadi
authored and
Commit Bot
committed
Apr 10, 2020
1 parent
996ba3e
commit 1266de8
Showing
25 changed files
with
168 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/omnibox/browser/omnibox_prefs.h" | ||
|
||
#include "base/logging.h" | ||
#include "base/stl_util.h" | ||
#include "base/values.h" | ||
#include "components/prefs/pref_registry_simple.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "components/prefs/scoped_user_pref_update.h" | ||
|
||
namespace omnibox { | ||
|
||
// A client-side toggle for document (Drive) suggestions. | ||
// Also gated by a feature and server-side Admin Panel controls. | ||
const char kDocumentSuggestEnabled[] = "documentsuggest.enabled"; | ||
|
||
// A list of suggestion group IDs for zero suggest that are not allowed to | ||
// appear in the results. | ||
const char kOmniboxHiddenGroupIds[] = "omnibox.hiddenGroupIds"; | ||
|
||
// Boolean that specifies whether to always show full URLs in the omnibox. | ||
const char kPreventUrlElisionsInOmnibox[] = "omnibox.prevent_url_elisions"; | ||
|
||
// A cache of zero suggest results using JSON serialized into a string. | ||
const char kZeroSuggestCachedResults[] = "zerosuggest.cachedresults"; | ||
|
||
void RegisterProfilePrefs(PrefRegistrySimple* registry) { | ||
registry->RegisterListPref(omnibox::kOmniboxHiddenGroupIds, | ||
base::Value(base::Value::Type::LIST)); | ||
} | ||
|
||
bool IsSuggestionGroupIdHidden(PrefService* prefs, int suggestion_group_id) { | ||
DCHECK(prefs); | ||
const base::ListValue* group_id_values = | ||
prefs->GetList(kOmniboxHiddenGroupIds); | ||
return std::find(group_id_values->begin(), group_id_values->end(), | ||
base::Value(suggestion_group_id)) != group_id_values->end(); | ||
} | ||
|
||
void ToggleSuggestionGroupIdVisibility(PrefService* prefs, | ||
int suggestion_group_id) { | ||
DCHECK(prefs); | ||
ListPrefUpdate update(prefs, kOmniboxHiddenGroupIds); | ||
if (IsSuggestionGroupIdHidden(prefs, suggestion_group_id)) { | ||
update->EraseListValue(base::Value(suggestion_group_id)); | ||
} else { | ||
update->Append(suggestion_group_id); | ||
} | ||
} | ||
|
||
} // namespace omnibox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_PREFS_H_ | ||
#define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_PREFS_H_ | ||
|
||
#include <vector> | ||
|
||
class PrefRegistrySimple; | ||
class PrefService; | ||
|
||
namespace omnibox { | ||
|
||
// Alphabetical list of preference names specific to the omnibox component. | ||
// Keep alphabetized, and document each in the .cc file. | ||
|
||
extern const char kDocumentSuggestEnabled[]; | ||
extern const char kOmniboxHiddenGroupIds[]; | ||
extern const char kPreventUrlElisionsInOmnibox[]; | ||
extern const char kZeroSuggestCachedResults[]; | ||
|
||
void RegisterProfilePrefs(PrefRegistrySimple* registry); | ||
|
||
// Returns whether the given suggestion group ID is allowed to appear in the | ||
// results. | ||
bool IsSuggestionGroupIdHidden(PrefService* prefs, int suggestion_group_id); | ||
|
||
// Allows suggestions with the given suggestion group ID to appear in the | ||
// results if they currently are not allowed to or prevents them from | ||
// appearing in the results if they are currently permitted to. | ||
void ToggleSuggestionGroupIdVisibility(PrefService* prefs, | ||
int suggestion_group_id); | ||
|
||
} // namespace omnibox | ||
|
||
#endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_PREFS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/omnibox/browser/omnibox_prefs.h" | ||
#include "components/prefs/testing_pref_service.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
using omnibox::IsSuggestionGroupIdHidden; | ||
using omnibox::ToggleSuggestionGroupIdVisibility; | ||
|
||
class OmniboxPrefsTest : public ::testing::Test { | ||
public: | ||
OmniboxPrefsTest() = default; | ||
|
||
void SetUp() override { | ||
omnibox::RegisterProfilePrefs(GetPrefs()->registry()); | ||
} | ||
|
||
TestingPrefServiceSimple* GetPrefs() { return &pref_service_; } | ||
|
||
private: | ||
TestingPrefServiceSimple pref_service_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(OmniboxPrefsTest); | ||
}; | ||
|
||
TEST_F(OmniboxPrefsTest, SuggestionGroupId) { | ||
const int kRecommendedForYouGroupId = 1; | ||
const int kRecentSearchesGroupId = 2; | ||
|
||
EXPECT_FALSE( | ||
IsSuggestionGroupIdHidden(GetPrefs(), kRecommendedForYouGroupId)); | ||
EXPECT_FALSE(IsSuggestionGroupIdHidden(GetPrefs(), kRecentSearchesGroupId)); | ||
|
||
ToggleSuggestionGroupIdVisibility(GetPrefs(), kRecommendedForYouGroupId); | ||
EXPECT_TRUE(IsSuggestionGroupIdHidden(GetPrefs(), kRecommendedForYouGroupId)); | ||
EXPECT_FALSE(IsSuggestionGroupIdHidden(GetPrefs(), kRecentSearchesGroupId)); | ||
|
||
ToggleSuggestionGroupIdVisibility(GetPrefs(), kRecommendedForYouGroupId); | ||
ToggleSuggestionGroupIdVisibility(GetPrefs(), kRecentSearchesGroupId); | ||
EXPECT_FALSE( | ||
IsSuggestionGroupIdHidden(GetPrefs(), kRecommendedForYouGroupId)); | ||
EXPECT_TRUE(IsSuggestionGroupIdHidden(GetPrefs(), kRecentSearchesGroupId)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.