diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 20:32:21 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 20:32:21 +0000 |
commit | cbce8ffb3d90ed63e9fb36407d31f7f6ce8a991d (patch) | |
tree | 4a20baf9dfdd076afba4517d4feef75677c468cf /chrome/browser/search_engines | |
parent | 677c8e35386e63fa00e87a03ef5b6e05326dcdbc (diff) | |
download | chromium_src-cbce8ffb3d90ed63e9fb36407d31f7f6ce8a991d.zip chromium_src-cbce8ffb3d90ed63e9fb36407d31f7f6ce8a991d.tar.gz chromium_src-cbce8ffb3d90ed63e9fb36407d31f7f6ce8a991d.tar.bz2 |
Use a NotificationRegistrar to listen for notifications.
BUG=2381
Review URL: http://codereview.chromium.org/115653
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines')
-rw-r--r-- | chrome/browser/search_engines/template_url_model.cc | 17 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model.h | 8 |
2 files changed, 9 insertions, 16 deletions
diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 97dd1d0..5a36b0e 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -92,30 +92,21 @@ TemplateURLModel::~TemplateURLModel() { } STLDeleteElements(&template_urls_); - - NotificationService* ns = NotificationService::current(); - if (profile_) { - ns->RemoveObserver(this, NotificationType::HISTORY_URL_VISITED, - Source<Profile>(profile_->GetOriginalProfile())); - } - ns->RemoveObserver(this, NotificationType::GOOGLE_URL_UPDATED, - NotificationService::AllSources()); } void TemplateURLModel::Init(const Initializer* initializers, int num_initializers) { // Register for notifications. - NotificationService* ns = NotificationService::current(); if (profile_) { // TODO(sky): bug 1166191. The keywords should be moved into the history // db, which will mean we no longer need this notification and the history // backend can handle automatically adding the search terms as the user // navigates. - ns->AddObserver(this, NotificationType::HISTORY_URL_VISITED, - Source<Profile>(profile_->GetOriginalProfile())); + registrar_.Add(this, NotificationType::HISTORY_URL_VISITED, + Source<Profile>(profile_->GetOriginalProfile())); } - ns->AddObserver(this, NotificationType::GOOGLE_URL_UPDATED, - NotificationService::AllSources()); + registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED, + NotificationService::AllSources()); // Add specific initializers, if any. for (int i(0); i < num_initializers; ++i) { diff --git a/chrome/browser/search_engines/template_url_model.h b/chrome/browser/search_engines/template_url_model.h index 094c506..c0e169b 100644 --- a/chrome/browser/search_engines/template_url_model.h +++ b/chrome/browser/search_engines/template_url_model.h @@ -13,7 +13,7 @@ #include "chrome/browser/history/history_notifications.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/webdata/web_data_service.h" -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" class GURL; class PrefService; @@ -217,6 +217,8 @@ class TemplateURLModel : public WebDataServiceConsumer, typedef std::map<std::wstring, const TemplateURL*> KeywordToTemplateMap; typedef std::vector<const TemplateURL*> TemplateURLVector; + typedef std::set<const TemplateURL*> TemplateURLSet; + typedef std::map<std::string, TemplateURLSet> HostToURLsMap; // Helper functor for FindMatchingKeywords(), for finding the range of // keywords which begin with a prefix. @@ -298,6 +300,8 @@ class TemplateURLModel : public WebDataServiceConsumer, // {google:baseSuggestURL}. void GoogleBaseURLChanged(); + NotificationRegistrar registrar_; + // Mapping from keyword to the TemplateURL. KeywordToTemplateMap keyword_to_template_map_; @@ -306,8 +310,6 @@ class TemplateURLModel : public WebDataServiceConsumer, ObserverList<TemplateURLModelObserver> model_observers_; // Maps from host to set of TemplateURLs whose search url host is host. - typedef std::set<const TemplateURL*> TemplateURLSet; - typedef std::map<std::string, TemplateURLSet> HostToURLsMap; HostToURLsMap host_to_urls_map_; // Used to obtain the WebDataService. |