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

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

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Always persist default search provider in db Created 9 years, 2 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: chrome/browser/search_engines/template_url_service.cc
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index 9d9f694437929fd9561e3f8cee54e6fdeb9a5fdc..8a3a334b44dab4df8b728e04ae314e8a3cf64b78 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -22,6 +22,8 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/pref_set_observer.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/protector/protector.h"
+#include "chrome/browser/protector/setting_change.h"
#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/search_engines/search_host_to_urls_map.h"
#include "chrome/browser/search_engines/search_terms_data.h"
@@ -436,10 +438,14 @@ void TemplateURLService::SetDefaultSearchProvider(const TemplateURL* url) {
NOTREACHED();
return;
}
- if (default_search_provider_ == url)
- return;
+ // We must always persist the setting in the database since we have to
sky 2011/10/24 17:23:21 How about changing this comment to: Always persist
whywhat 2011/10/25 10:30:41 Done.
+ // sync backup and its signature with the setting. So the cached default
+ // search engine provider could be equal to |url| but its backup and
+ // signature might be missing or corrupted. We don't need to send
+ // notifications out each time, however.
SetDefaultSearchProviderNoNotify(url);
- NotifyObservers();
+ if (default_search_provider_ != url)
+ NotifyObservers();
}
const TemplateURL* TemplateURLService::GetDefaultSearchProvider() {
@@ -450,6 +456,22 @@ const TemplateURL* TemplateURLService::GetDefaultSearchProvider() {
return initial_default_search_provider_.get();
}
+const TemplateURL* TemplateURLService::FindNewDefaultSearchProvider() {
+ // See if the prepoluated default still exists.
+ scoped_ptr<TemplateURL> prepopulated_default(
+ TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(GetPrefs()));
+ for (TemplateURLVector::iterator i = template_urls_.begin();
+ i != template_urls_.end(); ) {
+ if ((*i)->prepopulate_id() == prepopulated_default->prepopulate_id())
+ return *i;
+ }
+ // If not, use the first of the templates.
+ if (!template_urls_.empty()) {
sky 2011/10/24 17:04:13 change this to: return template_urls_.empty() ? NU
whywhat 2011/10/25 10:30:41 Done.
+ return template_urls_[0];
+ }
+ return NULL;
+}
+
void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) {
model_observers_.AddObserver(observer);
}
@@ -511,6 +533,22 @@ void TemplateURLService::OnWebDataServiceRequestDone(
LoadDefaultSearchProviderFromPrefs(&default_from_prefs,
&is_default_search_managed_);
+ // Check if the default search provider has been changed and notify
+ // Protector instance about it. Don't check if the default search is
+ // managed.
+ const TemplateURL* backup_default_search_provider = NULL;
+ if (!is_default_search_managed_ &&
+ DidDefaultSearchProviderChange(
+ *result,
+ template_urls,
+ &backup_default_search_provider)) {
+ // Protector will delete itself when it's needed no longer.
+ protector::Protector* protector = new protector::Protector(profile());
+ protector->ShowChange(protector::CreateDefaultSearchProviderChange(
+ default_search_provider,
+ backup_default_search_provider));
+ }
+
// Remove entries that were created because of policy as they may have
// changed since the database was saved.
RemoveProvidersCreatedByPolicy(&template_urls,
@@ -1454,22 +1492,6 @@ void TemplateURLService::UpdateDefaultSearch() {
NotifyObservers();
}
-const TemplateURL* TemplateURLService::FindNewDefaultSearchProvider() {
- // See if the prepoluated default still exists.
- scoped_ptr<TemplateURL> prepopulated_default(
- TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(GetPrefs()));
- for (TemplateURLVector::iterator i = template_urls_.begin();
- i != template_urls_.end(); ) {
- if ((*i)->prepopulate_id() == prepopulated_default->prepopulate_id())
- return *i;
- }
- // If not, use the first of the templates.
- if (!template_urls_.empty()) {
- return template_urls_[0];
- }
- return NULL;
-}
-
void TemplateURLService::SetDefaultSearchProviderNoNotify(
const TemplateURL* url) {
DCHECK(!url || find(template_urls_.begin(), template_urls_.end(), url) !=

Powered by Google App Engine
This is Rietveld 408576698