Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Unified Diff: components/search_engines/default_search_manager.cc

Issue 2639153002: Make extensions DSE persistent in browser prefs (Reland) (Closed)
Patch Set: Rebased and updated after review, use new keyword conflicts resolution Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/search_engines/default_search_manager.cc
diff --git a/components/search_engines/default_search_manager.cc b/components/search_engines/default_search_manager.cc
index c448ebe60d2a16c1b9357aeb666da167c25997d5..a69aa74a9d507706378b4e1e913e10b6d00c1cf9 100644
--- a/components/search_engines/default_search_manager.cc
+++ b/components/search_engines/default_search_manager.cc
@@ -15,7 +15,6 @@
#include "base/compiler_specific.h"
#include "base/i18n/case_conversion.h"
#include "base/logging.h"
-#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -140,7 +139,6 @@ const TemplateURLData* DefaultSearchManager::GetDefaultSearchEngine(
*source = FROM_USER;
return prefs_default_search_.get();
}
-
if (source)
*source = FROM_FALLBACK;
return GetFallbackSearchEngine();
@@ -171,20 +169,6 @@ void DefaultSearchManager::SetUserSelectedDefaultSearchEngine(
*TemplateURLDataToDictionary(data));
}
-void DefaultSearchManager::SetExtensionControlledDefaultSearchEngine(
- const TemplateURLData& data) {
- extension_default_search_.reset(new TemplateURLData(data));
- if (GetDefaultSearchEngineSource() == FROM_EXTENSION)
- NotifyObserver();
-}
-
-void DefaultSearchManager::ClearExtensionControlledDefaultSearchEngine() {
- Source old_source = GetDefaultSearchEngineSource();
- extension_default_search_.reset();
- if (old_source == FROM_EXTENSION)
- NotifyObserver();
-}
-
void DefaultSearchManager::ClearUserSelectedDefaultSearchEngine() {
if (pref_service_) {
pref_service_->ClearPref(kDefaultSearchProviderDataPrefName);
@@ -195,13 +179,13 @@ void DefaultSearchManager::ClearUserSelectedDefaultSearchEngine() {
}
void DefaultSearchManager::OnDefaultSearchPrefChanged() {
- Source source = GetDefaultSearchEngineSource();
+ bool source_was_fallback = GetDefaultSearchEngineSource() == FROM_FALLBACK;
+
LoadDefaultSearchEngineFromPrefs();
- // If we were/are FROM_USER or FROM_POLICY the effective DSE may have changed.
- if (source != FROM_USER && source != FROM_POLICY)
- source = GetDefaultSearchEngineSource();
- if (source == FROM_USER || source == FROM_POLICY)
+ // The effective DSE may have changed unless we were using the fallback source
+ // both before and after the above load.
+ if (!source_was_fallback || (GetDefaultSearchEngineSource() != FROM_FALLBACK))
NotifyObserver();
}
@@ -249,6 +233,7 @@ void DefaultSearchManager::LoadDefaultSearchEngineFromPrefs() {
return;
prefs_default_search_.reset();
+ extension_default_search_.reset();
const PrefService::Preference* pref =
pref_service_->FindPreference(kDefaultSearchProviderDataPrefName);
DCHECK(pref);
@@ -270,8 +255,13 @@ void DefaultSearchManager::LoadDefaultSearchEngineFromPrefs() {
if (!turl_data)
return;
- prefs_default_search_ = std::move(turl_data);
- MergePrefsDataWithPrepopulated();
+ // Check if default search preference is overriden by extension.
+ if (pref->IsExtensionControlled()) {
+ extension_default_search_ = std::move(turl_data);
+ } else {
+ prefs_default_search_ = std::move(turl_data);
+ MergePrefsDataWithPrepopulated();
+ }
}
void DefaultSearchManager::LoadPrepopulatedDefaultSearch() {

Powered by Google App Engine
This is Rietveld 408576698