Commit f014bf4e authored by Quentin Fiard's avatar Quentin Fiard Committed by Commit Bot

Add a flag to disable /searchdomaincheck in Chrome and instead always use google.com.

Design doc: go/chrome-no-searchdomaincheck

Bug: 825255
Change-Id: I6be6ca5928a52901fba2fbd24405a1b11fd9d54a
Reviewed-on: https://chromium-review.googlesource.com/1002842
Commit-Queue: Quentin Fiard <qfiard@google.com>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550647}
parent 7eb54c85
......@@ -6,6 +6,7 @@
#include <utility>
#include "base/feature_list.h"
#include "chrome/browser/google/chrome_google_url_tracker_client.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
......@@ -25,6 +26,32 @@ GoogleURLTrackerFactory* GoogleURLTrackerFactory::GetInstance() {
return base::Singleton<GoogleURLTrackerFactory>::get();
}
namespace {
std::unique_ptr<KeyedService> BuildGoogleURLTracker(
content::BrowserContext* context) {
// Delete this now-unused pref.
// At some point in the future, this code can be removed entirely.
static_cast<Profile*>(context)->GetOriginalProfile()->GetPrefs()->ClearPref(
prefs::kLastPromptedGoogleURL);
auto client = std::make_unique<ChromeGoogleURLTrackerClient>(
Profile::FromBrowserContext(context));
return std::make_unique<GoogleURLTracker>(
std::move(client),
base::FeatureList::IsEnabled(GoogleURLTracker::kNoSearchDomainCheck)
? GoogleURLTracker::ALWAYS_DOT_COM_MODE
: GoogleURLTracker::NORMAL_MODE);
}
} // namespace
// static
BrowserContextKeyedServiceFactory::TestingFactoryFunction
GoogleURLTrackerFactory::GetDefaultFactory() {
return &BuildGoogleURLTracker;
}
GoogleURLTrackerFactory::GoogleURLTrackerFactory()
: BrowserContextKeyedServiceFactory(
"GoogleURLTracker",
......@@ -36,14 +63,7 @@ GoogleURLTrackerFactory::~GoogleURLTrackerFactory() {
KeyedService* GoogleURLTrackerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
// Delete this now-unused pref.
// At some point in the future, this code can be removed entirely.
static_cast<Profile*>(context)->GetOriginalProfile()->GetPrefs()->ClearPref(
prefs::kLastPromptedGoogleURL);
std::unique_ptr<GoogleURLTrackerClient> client(
new ChromeGoogleURLTrackerClient(Profile::FromBrowserContext(context)));
return new GoogleURLTracker(std::move(client), GoogleURLTracker::NORMAL_MODE);
return BuildGoogleURLTracker(context).release();
}
void GoogleURLTrackerFactory::RegisterProfilePrefs(
......
......@@ -21,8 +21,14 @@ class GoogleURLTrackerFactory : public BrowserContextKeyedServiceFactory {
static GoogleURLTrackerFactory* GetInstance();
// Returns the default factory used to build GoogleURLTracker. Can be
// registered with SetTestingFactory to use a real GoogleURLTracker instance
// for testing.
static TestingFactoryFunction GetDefaultFactory();
private:
friend struct base::DefaultSingletonTraits<GoogleURLTrackerFactory>;
friend class GoogleURLTrackerFactoryTest;
GoogleURLTrackerFactory();
~GoogleURLTrackerFactory() override;
......
// Copyright 2018 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 "chrome/browser/google/google_url_tracker_factory.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.h"
#include "chrome/test/base/testing_profile.h"
#include "components/google/core/browser/google_pref_names.h"
#include "components/google/core/browser/google_url_tracker.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
class GoogleURLTrackerFactoryTest : public testing::Test {
protected:
void SetUp() override {
// TestingProfile requires a testing factory to be set otherwise it
// registers a factory that returns nullptr. Here we simply use the real
// factory.
GoogleURLTrackerFactory::GetInstance()->SetTestingFactory(
&profile_, GoogleURLTrackerFactory::GetDefaultFactory());
}
// Required because GetForProfile() wants to run on the browser thread.
content::TestBrowserThreadBundle test_browser_thread_bundle_;
TestingProfile profile_;
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(GoogleURLTrackerFactoryTest, UsesLocalDomainByDefault) {
profile_.GetPrefs()->SetString(prefs::kLastKnownGoogleURL,
"https://www.google.co.uk/");
GoogleURLTracker* tracker =
GoogleURLTrackerFactory::GetInstance()->GetForProfile(&profile_);
ASSERT_NE(nullptr, tracker);
EXPECT_EQ(GURL("https://www.google.co.uk/"), tracker->google_url());
}
TEST_F(GoogleURLTrackerFactoryTest, UsesDotComWithNoSearchDomainCheck) {
profile_.GetPrefs()->SetString(prefs::kLastKnownGoogleURL,
"https://www.google.co.uk/");
scoped_feature_list_.InitAndEnableFeature(
GoogleURLTracker::kNoSearchDomainCheck);
GoogleURLTracker* tracker =
GoogleURLTrackerFactory::GetInstance()->GetForProfile(&profile_);
ASSERT_NE(nullptr, tracker);
EXPECT_EQ(GURL("https://www.google.com/"), tracker->google_url());
}
......@@ -2339,6 +2339,7 @@ test("unit_tests") {
"../browser/geolocation/geolocation_permission_context_unittest.cc",
"../browser/global_keyboard_shortcuts_mac_unittest.mm",
"../browser/google/google_update_settings_unittest.cc",
"../browser/google/google_url_tracker_factory_unittest.cc",
"../browser/history/android/android_cache_database_unittest.cc",
"../browser/history/android/android_history_provider_service_unittest.cc",
"../browser/history/android/android_provider_backend_unittest.cc",
......
......@@ -29,6 +29,8 @@ const char GoogleURLTracker::kDefaultGoogleHomepage[] =
"https://www.google.com/";
const char GoogleURLTracker::kSearchDomainCheckURL[] =
"https://www.google.com/searchdomaincheck?format=domain&type=chrome";
const base::Feature GoogleURLTracker::kNoSearchDomainCheck{
"NoSearchDomainCheck", base::FEATURE_DISABLED_BY_DEFAULT};
GoogleURLTracker::GoogleURLTracker(
std::unique_ptr<GoogleURLTrackerClient> client,
......
......@@ -9,6 +9,7 @@
#include "base/callback_forward.h"
#include "base/callback_list.h"
#include "base/feature_list.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/google/core/browser/google_url_tracker_client.h"
......@@ -55,6 +56,12 @@ class GoogleURLTracker
static const char kDefaultGoogleHomepage[];
// Flag to disable /searchdomaincheck lookups in Chrome and instead always use
// google.com. The tracker should be used in ALWAYS_DOT_COM_MODE when this
// flag is enabled.
// For more details, see http://goto.google.com/chrome-no-searchdomaincheck.
static const base::Feature kNoSearchDomainCheck;
// Only the GoogleURLTrackerFactory and tests should call this.
// Note: you *must* manually call Shutdown() before this instance gets
// destroyed if you want to create another instance in the same binary
......
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