diff options
author | ivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 11:28:35 +0000 |
---|---|---|
committer | ivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 11:28:35 +0000 |
commit | ee8be82da8467894853869239adadc5d1e8cd454 (patch) | |
tree | 0adf9776b06ae99781b1d3c556c5feb5226b8127 /chrome/browser/protector/default_search_provider_change.cc | |
parent | 16c179ad5f531e1ea3aefe56ba40d82cd579908d (diff) | |
download | chromium_src-ee8be82da8467894853869239adadc5d1e8cd454.zip chromium_src-ee8be82da8467894853869239adadc5d1e8cd454.tar.gz chromium_src-ee8be82da8467894853869239adadc5d1e8cd454.tar.bz2 |
Protector: update and sign backup with --no-protector flag.
This effectively makes --no-protector flags usable because it will report UMA stat only once when a change is detected and update the backup thereafter.
BUG=108051
TEST=Manual: the first time Chrome is started with --no-protector after making a change in Web Data, chrome://histograms should contain histograms under Protector.*; on the second time, it shouldn't.
Review URL: http://codereview.chromium.org/8992010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/protector/default_search_provider_change.cc')
-rw-r--r-- | chrome/browser/protector/default_search_provider_change.cc | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/chrome/browser/protector/default_search_provider_change.cc b/chrome/browser/protector/default_search_provider_change.cc index eadf588..cf702be 100644 --- a/chrome/browser/protector/default_search_provider_change.cc +++ b/chrome/browser/protector/default_search_provider_change.cc @@ -120,6 +120,9 @@ class DefaultSearchProviderChange : public BaseSettingChange, // Opens the Search engine settings page in a new tab. void OpenSearchEngineSettings(); + // Stops observing the TemplateURLService changes. + void StopObservingTemplateURLService(); + int64 old_id_; int64 new_id_; // ID of the search engine that we fall back to if the backup is lost. @@ -161,7 +164,6 @@ DefaultSearchProviderChange::DefaultSearchProviderChange( // with the ID. Old ID is useless in this case so the prepopulated default // search provider will be used. old_id_ = 0; - // TODO(ivankr): restore the default search provider from the backup table. } } @@ -169,7 +171,8 @@ DefaultSearchProviderChange::~DefaultSearchProviderChange() { } bool DefaultSearchProviderChange::Init(Protector* protector) { - BaseSettingChange::Init(protector); + if (!BaseSettingChange::Init(protector)) + return false; if (old_id_) { UMA_HISTOGRAM_ENUMERATION( @@ -208,7 +211,9 @@ bool DefaultSearchProviderChange::Init(Protector* protector) { kProtectorMaxSearchProviderID); } - protector->GetTemplateURLService()->AddObserver(this); + TemplateURLService* url_service = protector->GetTemplateURLService(); + if (url_service) + url_service->AddObserver(this); return true; } @@ -219,7 +224,7 @@ void DefaultSearchProviderChange::Apply() { new_histogram_id_, kProtectorMaxSearchProviderID); - protector()->GetTemplateURLService()->RemoveObserver(this); + StopObservingTemplateURLService(); if (!new_id_) { // Open settings page in case the new setting is invalid. OpenSearchEngineSettings(); @@ -234,7 +239,7 @@ void DefaultSearchProviderChange::Discard() { new_histogram_id_, kProtectorMaxSearchProviderID); - protector()->GetTemplateURLService()->RemoveObserver(this); + StopObservingTemplateURLService(); if (!old_id_) { // Open settings page in case the old setting is invalid. OpenSearchEngineSettings(); @@ -251,7 +256,7 @@ void DefaultSearchProviderChange::Timeout() { } void DefaultSearchProviderChange::OnBeforeRemoved() { - protector()->GetTemplateURLService()->RemoveObserver(this); + StopObservingTemplateURLService(); } int DefaultSearchProviderChange::GetBadgeIconID() const { @@ -385,6 +390,12 @@ void DefaultSearchProviderChange::OpenSearchEngineSettings() { chrome::kSearchEnginesSubPage)); } +void DefaultSearchProviderChange::StopObservingTemplateURLService() { + TemplateURLService* url_service = protector()->GetTemplateURLService(); + if (url_service) + url_service->RemoveObserver(this); +} + BaseSettingChange* CreateDefaultSearchProviderChange( const TemplateURL* actual, const TemplateURL* backup) { |