Commit 27cee15c authored by Travis Skare's avatar Travis Skare Committed by Commit Bot

Add client-side setting for omnibox Drive results

Bug: 864302
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: If94e1b5b1cff588da4b83dcee1bdc652889bc05f
Reviewed-on: https://chromium-review.googlesource.com/1141119
Commit-Queue: Travis Skare <skare@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576484}
parent cf26e0b5
......@@ -98,6 +98,9 @@
<message name="IDS_SETTINGS_SYNC_DISCONNECT_TITLE" desc="The title of the dialog to stop syncing and sign out.">
Sign out of Chromium?
</message>
<message name="IDS_DRIVE_SUGGEST_PREF_DESC" desc="The documentation string of the 'Show Drive Results in Omnibox' - full description sentence">
Chromium will access your Drive to make suggestions in the address bar
</message>
<if expr="not chromeos">
<message name="IDS_SETTINGS_SYNC_SIGN_IN_PROMPT_WITH_NO_ACCOUNT" desc="The text displayed to prompt users to sign in to Chromium.">
Sign in to sync and personalize Chromium across your devices
......
......@@ -98,6 +98,9 @@
<message name="IDS_SETTINGS_SYNC_DISCONNECT_TITLE" desc="The title of the dialog to stop syncing and sign out.">
Sign out of Chrome?
</message>
<message name="IDS_DRIVE_SUGGEST_PREF_DESC" desc="The documentation string of the 'Show Drive Results in Omnibox' - full description sentence">
Chrome will access your Drive to make suggestions in the address bar
</message>
<if expr="not chromeos">
<message name="IDS_SETTINGS_SYNC_SIGN_IN_PROMPT_WITH_NO_ACCOUNT" desc="The text displayed to prompt users to sign in to Chrome.">
Sign in to sync and personalize Chrome across your devices
......
......@@ -3567,6 +3567,9 @@
<message name="IDS_SETTINGS_OPEN_TABS_CHECKBOX_LABEL" desc="Label for the checkbox which enables or disables syncing open tabs between multiple browser instances.">
Open Tabs
</message>
<message name="IDS_DRIVE_SUGGEST_PREF" desc="The documentation string of the 'Show Drive Results in Omnibox' preference - short description">
Google Drive search suggestions
</message>
<message name="IDS_SETTINGS_USER_EVENTS_CHECKBOX_LABEL" desc="Label for the checkbox which enables or disables recording user events.">
Activity and interactions
</message>
......
......@@ -21,6 +21,7 @@
#include "components/content_settings/core/common/pref_names.h"
#include "components/drive/drive_pref_names.h"
#include "components/language/core/browser/pref_names.h"
#include "components/omnibox/browser/omnibox_pref_names.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/payments/core/payment_prefs.h"
#include "components/prefs/pref_service.h"
......@@ -208,6 +209,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
(*s_whitelist)
[::unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[::omnibox::kDocumentSuggestEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
// Languages page
(*s_whitelist)[spellcheck::prefs::kSpellCheckEnable] =
......
......@@ -93,6 +93,7 @@
#include "components/ntp_snippets/user_classifier.h"
#include "components/ntp_tiles/most_visited_sites.h"
#include "components/offline_pages/buildflags/buildflags.h"
#include "components/omnibox/browser/document_provider.h"
#include "components/omnibox/browser/zero_suggest_provider.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_manager.h"
......@@ -522,6 +523,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
chrome_browser_net::RegisterPredictionOptionsProfilePrefs(registry);
chrome_prefs::RegisterProfilePrefs(registry);
dom_distiller::DistilledPagePrefs::RegisterProfilePrefs(registry);
DocumentProvider::RegisterProfilePrefs(registry);
DownloadPrefs::RegisterProfilePrefs(registry);
HostContentSettingsMap::RegisterProfilePrefs(registry);
ImportantSitesUtil::RegisterProfilePrefs(registry);
......
......@@ -365,6 +365,15 @@
<div id="other-sync-items"
class$="[[getListFrameClass_(unifiedConsentEnabled)]]">
<template is="dom-if" if="[[driveSuggestAvailable_]]">
<settings-toggle-button
class$="[[getListItemClass_(unifiedConsentEnabled)]]"
pref="{{prefs.documentsuggest.enabled}}"
label="$i18n{driveSuggestPref}"
sub-label="$i18n{driveSuggestPrefDesc}">
</settings-toggle-button>
</template>
<a class$="inherit-color no-outline
[[getListItemClass_(unifiedConsentEnabled)]]" tabindex="-1"
target="_blank" href="$i18n{activityControlsUrl}"
......
......@@ -150,6 +150,14 @@ Polymer({
value: true,
},
/** @private */
driveSuggestAvailable_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('driveSuggestAvailable');
}
},
// <if expr="not chromeos">
diceEnabled: Boolean,
// </if>
......
......@@ -31,6 +31,7 @@
#include "components/autofill/core/common/autofill_constants.h"
#include "components/content_settings/core/common/features.h"
#include "components/google/core/browser/google_util.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
......@@ -1668,6 +1669,8 @@ void AddPeopleStrings(content::WebUIDataSource* html_source, Profile* profile) {
{"openTabsCheckboxLabel", IDS_SETTINGS_OPEN_TABS_CHECKBOX_LABEL},
{"userEventsCheckboxLabel", IDS_SETTINGS_USER_EVENTS_CHECKBOX_LABEL},
{"userEventsCheckboxText", IDS_SETTINGS_USER_EVENTS_CHECKBOX_TEXT},
{"driveSuggestPref", IDS_DRIVE_SUGGEST_PREF},
{"driveSuggestPrefDesc", IDS_DRIVE_SUGGEST_PREF_DESC},
{"manageSyncedDataTitle", IDS_SETTINGS_MANAGE_SYNCED_DATA_TITLE},
{"encryptionOptionsTitle", IDS_SETTINGS_ENCRYPTION_OPTIONS},
{"syncDataEncryptedText", IDS_SETTINGS_SYNC_DATA_ENCRYPTED_TEXT},
......@@ -1801,6 +1804,10 @@ void AddPeopleStrings(content::WebUIDataSource* html_source, Profile* profile) {
html_source->AddBoolean(
"changePictureVideoModeEnabled",
base::FeatureList::IsEnabled(features::kChangePictureVideoMode));
html_source->AddBoolean(
"driveSuggestAvailable",
base::FeatureList::IsEnabled(omnibox::kDocumentProvider));
}
void AddPrintingStrings(content::WebUIDataSource* html_source) {
......
......@@ -23,7 +23,9 @@
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/document_suggestions_service.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_pref_names.h"
#include "components/omnibox/browser/search_provider.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/search_engine_type.h"
#include "components/search_engines/template_url_service.h"
......@@ -56,6 +58,12 @@ DocumentProvider* DocumentProvider::Create(
return new DocumentProvider(client, listener);
}
// static
void DocumentProvider::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(omnibox::kDocumentSuggestEnabled, true);
}
bool DocumentProvider::IsDocumentProviderAllowed(
PrefService* prefs,
bool is_incognito,
......@@ -65,6 +73,10 @@ bool DocumentProvider::IsDocumentProviderAllowed(
if (!base::FeatureList::IsEnabled(omnibox::kDocumentProvider))
return false;
// Client-side toggle must be enabled.
if (!prefs->GetBoolean(omnibox::kDocumentSuggestEnabled))
return false;
// No incognito.
if (is_incognito)
return false;
......
......@@ -32,6 +32,10 @@ namespace network {
class SimpleURLLoader;
}
namespace user_prefs {
class PrefRegistrySyncable;
}
// Autocomplete provider for personalized documents owned or readable by the
// signed-in user. In practice this is a second request in parallel with that
// to the default search provider.
......@@ -47,9 +51,17 @@ class DocumentProvider : public AutocompleteProvider {
void DeleteMatch(const AutocompleteMatch& match) override;
void AddProviderInfo(ProvidersInfo* provider_info) const override;
// Registers a client-side preference to enable document suggestions.
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
private:
FRIEND_TEST_ALL_PREFIXES(DocumentProviderTest, CheckFeatureBehindFlag);
FRIEND_TEST_ALL_PREFIXES(DocumentProviderTest, CheckFeaturePrerequisites);
FRIEND_TEST_ALL_PREFIXES(DocumentProviderTest,
CheckFeaturePrerequisiteNoIncognito);
FRIEND_TEST_ALL_PREFIXES(DocumentProviderTest,
CheckFeaturePrerequisiteClientSettingOff);
FRIEND_TEST_ALL_PREFIXES(DocumentProviderTest,
CheckFeaturePrerequisiteDefaultSearch);
FRIEND_TEST_ALL_PREFIXES(DocumentProviderTest, ParseDocumentSearchResults);
DocumentProvider(AutocompleteProviderClient* client,
AutocompleteProviderListener* listener);
......
......@@ -12,6 +12,8 @@
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -20,7 +22,10 @@ namespace {
class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient {
public:
FakeAutocompleteProviderClient()
: template_url_service_(new TemplateURLService(nullptr, 0)) {}
: template_url_service_(new TemplateURLService(nullptr, 0)) {
pref_service_.registry()->RegisterBooleanPref(
omnibox::kDocumentSuggestEnabled, true);
}
bool SearchSuggestEnabled() const override { return true; }
......@@ -96,26 +101,56 @@ TEST_F(DocumentProviderTest, CheckFeatureBehindFlag) {
fake_prefs, is_incognito, is_authenticated, template_url_service));
}
TEST_F(DocumentProviderTest, CheckFeaturePrerequisites) {
TEST_F(DocumentProviderTest, CheckFeaturePrerequisiteNoIncognito) {
PrefService* fake_prefs = client_->GetPrefs();
TemplateURLService* template_url_service = client_->GetTemplateURLService();
// Make sure feature is turned on when prereqs are met, then turn them off
// one at a time and ensure each defeats the feature.
bool is_incognito = false;
bool is_authenticated = true;
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(omnibox::kDocumentProvider);
// Feature starts enabled.
EXPECT_TRUE(provider_->IsDocumentProviderAllowed(
fake_prefs, is_incognito, is_authenticated, template_url_service));
// Don't allow in incognito mode.
// Feature should be disabled in incognito.
is_incognito = true;
EXPECT_FALSE(provider_->IsDocumentProviderAllowed(
fake_prefs, is_incognito, is_authenticated, template_url_service));
is_incognito = false;
}
TEST_F(DocumentProviderTest, CheckFeaturePrerequisiteClientSettingOff) {
PrefService* fake_prefs = client_->GetPrefs();
TemplateURLService* template_url_service = client_->GetTemplateURLService();
bool is_incognito = false;
bool is_authenticated = true;
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(omnibox::kDocumentProvider);
// Feature starts enabled.
EXPECT_TRUE(provider_->IsDocumentProviderAllowed(
fake_prefs, is_incognito, is_authenticated, template_url_service));
// Don't allow if Google is not DSE.
// Disabling toggle in chrome://settings should be respected.
fake_prefs->SetBoolean(omnibox::kDocumentSuggestEnabled, false);
EXPECT_FALSE(provider_->IsDocumentProviderAllowed(
fake_prefs, is_incognito, is_authenticated, template_url_service));
fake_prefs->SetBoolean(omnibox::kDocumentSuggestEnabled, true);
}
TEST_F(DocumentProviderTest, CheckFeaturePrerequisiteDefaultSearch) {
PrefService* fake_prefs = client_->GetPrefs();
TemplateURLService* template_url_service = client_->GetTemplateURLService();
bool is_incognito = false;
bool is_authenticated = true;
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(omnibox::kDocumentProvider);
// Feature starts enabled.
EXPECT_TRUE(provider_->IsDocumentProviderAllowed(
fake_prefs, is_incognito, is_authenticated, template_url_service));
// Switching default search disables it.
TemplateURLData data;
data.SetShortName(base::ASCIIToUTF16("t"));
data.SetURL("https://www.notgoogle.com/?q={searchTerms}");
......@@ -129,10 +164,6 @@ TEST_F(DocumentProviderTest, CheckFeaturePrerequisites) {
template_url_service->SetUserSelectedDefaultSearchProvider(
default_template_url_);
template_url_service->Remove(new_default_provider);
// Prereqs are met again; verify we're able to get suggestions.
EXPECT_TRUE(provider_->IsDocumentProviderAllowed(
fake_prefs, is_incognito, is_authenticated, template_url_service));
}
TEST_F(DocumentProviderTest, ParseDocumentSearchResults) {
......
......@@ -6,6 +6,10 @@
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 cache of zero suggest results using JSON serialized into a string.
const char kZeroSuggestCachedResults[] = "zerosuggest.cachedresults";
......
......@@ -10,6 +10,7 @@ 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 kZeroSuggestCachedResults[];
} // namespace omnibox
......
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