Stop depending on TemplateURLService from DefaultSearchManager

TemplateURLService::fallback_search_engines_disabled only affects the behavior of DefaultSearchManager.
Move it to DefaultSearchManager.

BUG=371535
TEST=git cl try

Review URL: https://codereview.chromium.org/340553005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278038 0039d316-1c4b-4281-b951-d872f2087c98
parent daa7eaa8
...@@ -21,12 +21,16 @@ ...@@ -21,12 +21,16 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/util.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/search_engines/template_url_data.h" #include "components/search_engines/template_url_data.h"
namespace {
bool g_fallback_search_engines_disabled = false;
} // namespace
// A dictionary to hold all data related to the Default Search Engine. // A dictionary to hold all data related to the Default Search Engine.
// Eventually, this should replace all the data stored in the // Eventually, this should replace all the data stored in the
// default_search_provider.* prefs. // default_search_provider.* prefs.
...@@ -107,6 +111,12 @@ void DefaultSearchManager::AddPrefValueToMap(base::DictionaryValue* value, ...@@ -107,6 +111,12 @@ void DefaultSearchManager::AddPrefValueToMap(base::DictionaryValue* value,
pref_value_map->SetValue(kDefaultSearchProviderDataPrefName, value); pref_value_map->SetValue(kDefaultSearchProviderDataPrefName, value);
} }
// static
void DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(
bool disabled) {
g_fallback_search_engines_disabled = disabled;
}
TemplateURLData* DefaultSearchManager::GetDefaultSearchEngine( TemplateURLData* DefaultSearchManager::GetDefaultSearchEngine(
Source* source) const { Source* source) const {
if (default_search_controlled_by_policy_) { if (default_search_controlled_by_policy_) {
...@@ -127,7 +137,7 @@ TemplateURLData* DefaultSearchManager::GetDefaultSearchEngine( ...@@ -127,7 +137,7 @@ TemplateURLData* DefaultSearchManager::GetDefaultSearchEngine(
if (source) if (source)
*source = FROM_FALLBACK; *source = FROM_FALLBACK;
return TemplateURLService::fallback_search_engines_disabled() ? return g_fallback_search_engines_disabled ?
NULL : fallback_default_search_.get(); NULL : fallback_default_search_.get();
} }
......
...@@ -80,6 +80,11 @@ class DefaultSearchManager { ...@@ -80,6 +80,11 @@ class DefaultSearchManager {
static void AddPrefValueToMap(base::DictionaryValue* value, static void AddPrefValueToMap(base::DictionaryValue* value,
PrefValueMap* pref_value_map); PrefValueMap* pref_value_map);
// Testing code can call this with |disabled| set to true to cause
// GetDefaultSearchEngine() to return NULL instead of
// |fallback_default_search_| in cases where the DSE source is FROM_FALLBACK.
static void SetFallbackSearchEnginesDisabledForTesting(bool disabled);
// Gets a pointer to the current Default Search Engine. If NULL, indicates // Gets a pointer to the current Default Search Engine. If NULL, indicates
// that Default Search is explicitly disabled. |source|, if not NULL, will be // that Default Search is explicitly disabled. |source|, if not NULL, will be
// filled in with the source of the result. // filled in with the source of the result.
......
...@@ -230,9 +230,6 @@ class TemplateURLService::LessWithPrefix { ...@@ -230,9 +230,6 @@ class TemplateURLService::LessWithPrefix {
// TemplateURLService --------------------------------------------------------- // TemplateURLService ---------------------------------------------------------
// static
bool TemplateURLService::g_fallback_search_engines_disabled = false;
TemplateURLService::TemplateURLService(Profile* profile) TemplateURLService::TemplateURLService(Profile* profile)
: provider_map_(new SearchHostToURLsMap), : provider_map_(new SearchHostToURLsMap),
profile_(profile), profile_(profile),
......
...@@ -387,18 +387,7 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -387,18 +387,7 @@ class TemplateURLService : public WebDataServiceConsumer,
static SyncDataMap CreateGUIDToSyncDataMap( static SyncDataMap CreateGUIDToSyncDataMap(
const syncer::SyncDataList& sync_data); const syncer::SyncDataList& sync_data);
// Indicates whether the pre-populated TemplateURLs should be disabled. May
// only be true in tests.
static bool fallback_search_engines_disabled() {
return g_fallback_search_engines_disabled;
}
#if defined(UNIT_TEST) #if defined(UNIT_TEST)
// Disables the pre-populated TemplateURLs for testing purposes.
static void set_fallback_search_engines_disabled(bool disabled) {
g_fallback_search_engines_disabled = disabled;
}
// Sets a different time provider function, such as // Sets a different time provider function, such as
// base::MockTimeProvider::StaticNow, for testing calls to base::Time::Now. // base::MockTimeProvider::StaticNow, for testing calls to base::Time::Now.
void set_time_provider(TimeProvider* time_provider) { void set_time_provider(TimeProvider* time_provider) {
...@@ -785,9 +774,6 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -785,9 +774,6 @@ class TemplateURLService : public WebDataServiceConsumer,
scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_;
// Used to disable the prepopulated search engines in tests.
static bool g_fallback_search_engines_disabled;
DISALLOW_COPY_AND_ASSIGN(TemplateURLService); DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
}; };
......
...@@ -228,7 +228,7 @@ TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() ...@@ -228,7 +228,7 @@ TemplateURLServiceSyncTest::TemplateURLServiceSyncTest()
sync_processor_.get())) {} sync_processor_.get())) {}
void TemplateURLServiceSyncTest::SetUp() { void TemplateURLServiceSyncTest::SetUp() {
TemplateURLService::set_fallback_search_engines_disabled(true); DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true);
test_util_a_.SetUp(); test_util_a_.SetUp();
// Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull
// in the prepopulate data, which the sync tests don't care about (and would // in the prepopulate data, which the sync tests don't care about (and would
...@@ -243,7 +243,7 @@ void TemplateURLServiceSyncTest::SetUp() { ...@@ -243,7 +243,7 @@ void TemplateURLServiceSyncTest::SetUp() {
void TemplateURLServiceSyncTest::TearDown() { void TemplateURLServiceSyncTest::TearDown() {
test_util_a_.TearDown(); test_util_a_.TearDown();
TemplateURLService::set_fallback_search_engines_disabled(false); DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false);
} }
scoped_ptr<syncer::SyncChangeProcessor> scoped_ptr<syncer::SyncChangeProcessor>
......
...@@ -203,13 +203,13 @@ class TemplateURLServiceWithoutFallbackTest : public TemplateURLServiceTest { ...@@ -203,13 +203,13 @@ class TemplateURLServiceWithoutFallbackTest : public TemplateURLServiceTest {
TemplateURLServiceWithoutFallbackTest() : TemplateURLServiceTest() {} TemplateURLServiceWithoutFallbackTest() : TemplateURLServiceTest() {}
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
TemplateURLService::set_fallback_search_engines_disabled(true); DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true);
TemplateURLServiceTest::SetUp(); TemplateURLServiceTest::SetUp();
} }
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
TemplateURLServiceTest::TearDown(); TemplateURLServiceTest::TearDown();
TemplateURLService::set_fallback_search_engines_disabled(false); DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false);
} }
}; };
......
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