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

Unified Diff: chrome/browser/search_engines/util.cc

Issue 280113002: Revert of Use the DefaultSearchManager as the exclusive authority on DSE, ignoring Web Data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « chrome/browser/search_engines/util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search_engines/util.cc
diff --git a/chrome/browser/search_engines/util.cc b/chrome/browser/search_engines/util.cc
index 5378b3b05b747bcd1c275f070c515577b770eeec..afb3a53e82b1fac8cbf00f4ac92b0105ca56e32b 100644
--- a/chrome/browser/search_engines/util.cc
+++ b/chrome/browser/search_engines/util.cc
@@ -98,16 +98,8 @@
UncheckedURLMap::iterator best = unchecked_urls.begin();
bool matched_keyword = false;
for (UncheckedURLMap::iterator i = unchecked_urls.begin(); i != end; ++i) {
- // If the user-selected DSE is a prepopulated engine its properties will
- // either come from the prepopulation origin or from the user preferences
- // file (see DefaultSearchManager). Those properties will end up
- // overwriting whatever we load now anyway. If we are eliminating
- // duplicates, then, we err on the side of keeping the thing that looks
- // more like the value we will end up with in the end.
- if (default_search_provider &&
- (default_search_provider->prepopulate_id() ==
- i->second->prepopulate_id()) &&
- default_search_provider->HasSameKeywordAs(i->second->data())) {
+ // A URL is automatically the best if it's the default search engine.
+ if (i->second == default_search_provider) {
best = i;
break;
}
@@ -199,14 +191,17 @@
ScopedVector<TemplateURLData>* prepopulated_urls,
size_t default_search_index,
TemplateURLService::TemplateURLVector* template_urls,
- TemplateURL* default_search_provider,
+ TemplateURL** default_search_provider,
std::set<std::string>* removed_keyword_guids) {
DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(prepopulated_urls);
DCHECK(template_urls);
-
+ DCHECK(default_search_provider);
+
+ int default_prepopulated_id =
+ (*prepopulated_urls)[default_search_index]->prepopulate_id;
ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData(
- prepopulated_urls, *template_urls, default_search_provider));
+ prepopulated_urls, *template_urls, *default_search_provider));
// Remove items.
for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin();
@@ -215,8 +210,7 @@
TemplateURLService::TemplateURLVector::iterator j =
std::find(template_urls->begin(), template_urls->end(), template_url);
DCHECK(j != template_urls->end());
- DCHECK(!default_search_provider ||
- (*j)->prepopulate_id() != default_search_provider->prepopulate_id());
+ DCHECK(*j != *default_search_provider);
template_urls->erase(j);
if (service) {
service->RemoveKeyword(template_url->id());
@@ -237,6 +231,8 @@
TemplateURLService::TemplateURLVector::iterator j = std::find(
template_urls->begin(), template_urls->end(), existing_url.get());
*j = new TemplateURL(profile, data);
+ if (*default_search_provider == existing_url.get())
+ *default_search_provider = *j;
}
// Add items.
@@ -245,6 +241,13 @@
it != actions.added_engines.end();
++it) {
template_urls->push_back(new TemplateURL(profile, *it));
+ }
+
+ if (!*default_search_provider) {
+ // The user had no existing default search provider, so set the
+ // default to the default prepopulated engine.
+ *default_search_provider = FindURLByPrepopulateID(*template_urls,
+ default_prepopulated_id);
}
}
@@ -299,16 +302,10 @@
// The block above removed all the URLs from the |id_to_turl| map that were
// found in the prepopulate data. Any remaining URLs that haven't been
// user-edited or made default can be removed from the data store.
- // We assume that this entry is equivalent to the DSE if its prepopulate ID
- // and keyword both match. If the prepopulate ID _does_ match all properties
- // will be replaced with those from |default_search_provider| anyway.
for (IDMap::iterator i(id_to_turl.begin()); i != id_to_turl.end(); ++i) {
TemplateURL* template_url = i->second;
if ((template_url->safe_for_autoreplace()) &&
- (!default_search_provider ||
- (template_url->prepopulate_id() !=
- default_search_provider->prepopulate_id()) ||
- (template_url->keyword() != default_search_provider->keyword())))
+ (template_url != default_search_provider))
actions.removed_engines.push_back(template_url);
}
@@ -320,12 +317,14 @@
WebDataService* service,
Profile* profile,
TemplateURLService::TemplateURLVector* template_urls,
- TemplateURL* default_search_provider,
+ TemplateURL** default_search_provider,
int* new_resource_keyword_version,
std::set<std::string>* removed_keyword_guids) {
DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(template_urls);
DCHECK(template_urls->empty());
+ DCHECK(default_search_provider);
+ DCHECK(*default_search_provider == NULL);
DCHECK_EQ(KEYWORDS_RESULT, result.GetType());
DCHECK(new_resource_keyword_version);
@@ -348,6 +347,12 @@
template_urls->push_back(new TemplateURL(profile, *i));
}
+ int64 default_search_provider_id = keyword_result.default_search_provider_id;
+ if (default_search_provider_id) {
+ *default_search_provider =
+ GetTemplateURLByID(*template_urls, default_search_provider_id);
+ }
+
*new_resource_keyword_version = keyword_result.builtin_keyword_version;
GetSearchProvidersUsingLoadedEngines(service, profile, template_urls,
default_search_provider,
@@ -359,11 +364,12 @@
WebDataService* service,
Profile* profile,
TemplateURLService::TemplateURLVector* template_urls,
- TemplateURL* default_search_provider,
+ TemplateURL** default_search_provider,
int* resource_keyword_version,
std::set<std::string>* removed_keyword_guids) {
DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(template_urls);
+ DCHECK(default_search_provider);
DCHECK(resource_keyword_version);
PrefService* prefs = profile ? profile->GetPrefs() : NULL;
size_t default_search_index;
@@ -371,7 +377,7 @@
TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs,
&default_search_index);
RemoveDuplicatePrepopulateIDs(service, prepopulated_urls,
- default_search_provider, template_urls,
+ *default_search_provider, template_urls,
removed_keyword_guids);
const int prepopulate_resource_keyword_version =
« no previous file with comments | « chrome/browser/search_engines/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698