diff options
author | caitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-08 17:29:03 +0000 |
---|---|---|
committer | caitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-08 17:29:03 +0000 |
commit | 3118d343201e22bd71baac0955da5c776de70888 (patch) | |
tree | de613e6c89216482d396e42d7838523e1a5068e5 | |
parent | 7fa7892fb1b874a61469b1db457662ae839c29a0 (diff) | |
download | chromium_src-3118d343201e22bd71baac0955da5c776de70888.zip chromium_src-3118d343201e22bd71baac0955da5c776de70888.tar.gz chromium_src-3118d343201e22bd71baac0955da5c776de70888.tar.bz2 |
Convert NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED to CallbackList.
BUG=268984
TEST= no functional change
Review URL: https://codereview.chromium.org/23710022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227534 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 196 insertions, 243 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java b/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java index 721137f..c8b6cd2 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java @@ -161,7 +161,8 @@ public class TemplateUrlService { } /** - * Registers a listener for the TEMPLATE_URL_SERVICE_LOADED notification. + * Registers a listener for the callback that indicates that the + * TemplateURLService has loaded. */ public void registerLoadListener(LoadListener listener) { ThreadUtils.assertOnUiThread(); @@ -170,7 +171,8 @@ public class TemplateUrlService { } /** - * Unregisters a listener for the TEMPLATE_URL_SERVICE_LOADED notification. + * Unregisters a listener for the callback that indicates that the + * TemplateURLService has loaded. */ public void unregisterLoadListener(LoadListener listener) { ThreadUtils.assertOnUiThread(); diff --git a/chrome/browser/browsing_data/browsing_data_remover.cc b/chrome/browser/browsing_data/browsing_data_remover.cc index b7af2e1..b8d8e90 100644 --- a/chrome/browser/browsing_data/browsing_data_remover.cc +++ b/chrome/browser/browsing_data/browsing_data_remover.cc @@ -177,6 +177,7 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile, waiting_for_clear_session_storage_(false), waiting_for_clear_shader_cache_(false), waiting_for_clear_webrtc_identity_store_(false), + waiting_for_clear_keyword_data_(false), remove_mask_(0), remove_origin_(GURL()), origin_set_mask_(0) { @@ -304,9 +305,11 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask, TemplateURLService* keywords_model = TemplateURLServiceFactory::GetForProfile(profile_); if (keywords_model && !keywords_model->loaded()) { - registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(keywords_model)); + template_url_sub_ = keywords_model->RegisterOnLoadedCallback( + base::Bind(&BrowsingDataRemover::OnKeywordsLoaded, + base::Unretained(this))); keywords_model->Load(); + waiting_for_clear_keyword_data_ = true; } else if (keywords_model) { keywords_model->RemoveAutoGeneratedForOriginBetween(remove_origin_, delete_begin_, delete_end_); @@ -643,7 +646,8 @@ base::Time BrowsingDataRemover::CalculateBeginDeleteTime( } bool BrowsingDataRemover::AllDone() { - return registrar_.IsEmpty() && !waiting_for_clear_autofill_origin_urls_ && + return !waiting_for_clear_keyword_data_ && + !waiting_for_clear_autofill_origin_urls_ && !waiting_for_clear_cache_ && !waiting_for_clear_nacl_cache_ && !waiting_for_clear_cookies_count_ && !waiting_for_clear_history_ && !waiting_for_clear_local_storage_ && @@ -661,23 +665,23 @@ bool BrowsingDataRemover::AllDone() { !waiting_for_clear_webrtc_identity_store_; } -void BrowsingDataRemover::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - // TODO(brettw) bug 1139736: This should also observe session - // clearing (what about other things such as passwords, etc.?) and wait for - // them to complete before continuing. - DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); - TemplateURLService* model = content::Source<TemplateURLService>(source).ptr(); - if (model->profile() == profile_) { - registrar_.RemoveAll(); - model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); - NotifyAndDeleteIfDone(); - } +void BrowsingDataRemover::OnKeywordsLoaded() { + // Deletes the entries from the model, and if we're not waiting on anything + // else notifies observers and deletes this BrowsingDataRemover. + TemplateURLService* model = + TemplateURLServiceFactory::GetForProfile(profile_); + DCHECK_EQ(profile_, model->profile()); + model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); + waiting_for_clear_keyword_data_ = false; + template_url_sub_.reset(); + NotifyAndDeleteIfDone(); } void BrowsingDataRemover::NotifyAndDeleteIfDone() { - // TODO(brettw) bug 1139736: see TODO in Observe() above. + // TODO(brettw) http://crbug.com/305259: This should also observe session + // clearing (what about other things such as passwords, etc.?) and wait for + // them to complete before continuing. + if (!AllDone()) return; diff --git a/chrome/browser/browsing_data/browsing_data_remover.h b/chrome/browser/browsing_data/browsing_data_remover.h index be29059..ff31f09 100644 --- a/chrome/browser/browsing_data/browsing_data_remover.h +++ b/chrome/browser/browsing_data/browsing_data_remover.h @@ -15,9 +15,8 @@ #include "base/synchronization/waitable_event_watcher.h" #include "base/time/time.h" #include "chrome/browser/pepper_flash_settings_manager.h" +#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/common/cancelable_task_tracker.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "url/gurl.h" #include "webkit/common/quota/quota_types.h" @@ -50,11 +49,11 @@ struct SessionStorageUsageInfo; // BrowsingDataRemover is responsible for removing data related to browsing: // visits in url database, downloads, cookies ... -class BrowsingDataRemover : public content::NotificationObserver +class BrowsingDataRemover #if defined(ENABLE_PLUGINS) - , public PepperFlashSettingsManager::Client + : public PepperFlashSettingsManager::Client #endif - { + { public: // Time period ranges available when doing browsing data removals. enum TimePeriod { @@ -214,13 +213,9 @@ class BrowsingDataRemover : public content::NotificationObserver friend class base::DeleteHelper<BrowsingDataRemover>; virtual ~BrowsingDataRemover(); - // content::NotificationObserver method. Callback when TemplateURLService has - // finished loading. Deletes the entries from the model, and if we're not - // waiting on anything else notifies observers and deletes this - // BrowsingDataRemover. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // Callback for when TemplateURLService has finished loading. Clears the data, + // clears the respective waiting flag, and invokes NotifyAndDeleteIfDone. + void OnKeywordsLoaded(); // Called when plug-in data has been cleared. Invokes NotifyAndDeleteIfDone. void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); @@ -243,33 +238,35 @@ class BrowsingDataRemover : public content::NotificationObserver // object. void NotifyAndDeleteIfDone(); - // Callback when the hostname resolution cache has been cleared. + // Callback for when the hostname resolution cache has been cleared. // Clears the respective waiting flag and invokes NotifyAndDeleteIfDone. void OnClearedHostnameResolutionCache(); // Invoked on the IO thread to clear the hostname resolution cache. void ClearHostnameResolutionCacheOnIOThread(IOThread* io_thread); - // Callback when the LoggedIn Predictor has been cleared. + // Callback for when the LoggedIn Predictor has been cleared. // Clears the respective waiting flag and invokes NotifyAndDeleteIfDone. void OnClearedLoggedInPredictor(); // Clears the LoggedIn Predictor. void ClearLoggedInPredictor(); - // Callback when speculative data in the network Predictor has been cleared. - // Clears the respective waiting flag and invokes NotifyAndDeleteIfDone. + // Callback for when speculative data in the network Predictor has been + // cleared. Clears the respective waiting flag and invokes + // NotifyAndDeleteIfDone. void OnClearedNetworkPredictor(); // Invoked on the IO thread to clear speculative data related to hostname // pre-resolution from the network Predictor. void ClearNetworkPredictorOnIOThread(); - // Callback when network related data in ProfileIOData has been cleared. + // Callback for when network related data in ProfileIOData has been cleared. // Clears the respective waiting flag and invokes NotifyAndDeleteIfDone. void OnClearedNetworkingHistory(); - // Callback when the cache has been deleted. Invokes NotifyAndDeleteIfDone. + // Callback for when the cache has been deleted. Invokes + // NotifyAndDeleteIfDone. void ClearedCache(); // Invoked on the IO thread to delete from the cache. @@ -338,7 +335,7 @@ class BrowsingDataRemover : public content::NotificationObserver // deleted. Updates the waiting flag and invokes NotifyAndDeleteIfDone. void OnQuotaManagedDataDeleted(); - // Callback when Cookies has been deleted. Invokes NotifyAndDeleteIfDone. + // Callback for when Cookies has been deleted. Invokes NotifyAndDeleteIfDone. void OnClearedCookies(int num_deleted); // Invoked on the IO thread to delete cookies. @@ -353,18 +350,18 @@ class BrowsingDataRemover : public content::NotificationObserver void OnClearedServerBoundCertsOnIOThread( net::URLRequestContextGetter* rq_context); - // Callback when server bound certs have been deleted. Invokes + // Callback for when server bound certs have been deleted. Invokes // NotifyAndDeleteIfDone. void OnClearedServerBoundCerts(); // Callback from the above method. void OnClearedFormData(); - // Callback when the Autofill profile and credit card origin URLs have been - // deleted. + // Callback for when the Autofill profile and credit card origin URLs have + // been deleted. void OnClearedAutofillOriginURLs(); - // Callback when the shader cache has been deleted. + // Callback for when the shader cache has been deleted. // Invokes NotifyAndDeleteIfDone. void ClearedShaderCache(); @@ -377,8 +374,6 @@ class BrowsingDataRemover : public content::NotificationObserver // Returns true if we're all done. bool AllDone(); - content::NotificationRegistrar registrar_; - // Profile we're to remove from. Profile* profile_; @@ -440,6 +435,7 @@ class BrowsingDataRemover : public content::NotificationObserver bool waiting_for_clear_session_storage_; bool waiting_for_clear_shader_cache_; bool waiting_for_clear_webrtc_identity_store_; + bool waiting_for_clear_keyword_data_; // Tracking how many origins need to be deleted, and whether we're finished // gathering origins. @@ -460,6 +456,8 @@ class BrowsingDataRemover : public content::NotificationObserver // Used if we need to clear history. CancelableTaskTracker history_task_tracker_; + scoped_ptr<TemplateURLService::Subscription> template_url_sub_; + DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); }; diff --git a/chrome/browser/chrome_notification_types.h b/chrome/browser/chrome_notification_types.h index 9dd9de4..4937e980e 100644 --- a/chrome/browser/chrome_notification_types.h +++ b/chrome/browser/chrome_notification_types.h @@ -343,11 +343,6 @@ enum NotificationType { // Non-history storage services -------------------------------------------- - // Notification that the TemplateURLService has finished loading from the - // database. The source is the TemplateURLService, and the details are - // NoDetails. - NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - // Sent when a TemplateURL is removed from the model. The source is the // Profile, and the details the id of the TemplateURL being removed. NOTIFICATION_TEMPLATE_URL_REMOVED, diff --git a/chrome/browser/extensions/api/omnibox/omnibox_api.cc b/chrome/browser/extensions/api/omnibox/omnibox_api.cc index 55c7da8..30a4fab 100644 --- a/chrome/browser/extensions/api/omnibox/omnibox_api.cc +++ b/chrome/browser/extensions/api/omnibox/omnibox_api.cc @@ -183,8 +183,9 @@ OmniboxAPI::OmniboxAPI(Profile* profile) registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, content::Source<Profile>(profile)); if (url_service_) { - registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(url_service_)); + template_url_sub_ = url_service_->RegisterOnLoadedCallback( + base::Bind(&OmniboxAPI::OnTemplateURLsLoaded, + base::Unretained(this))); } // Use monochrome icons for Omnibox icons. @@ -194,6 +195,10 @@ OmniboxAPI::OmniboxAPI(Profile* profile) 0, kOmniboxIconPaddingRight)); } +void OmniboxAPI::Shutdown() { + template_url_sub_.reset(); +} + OmniboxAPI::~OmniboxAPI() { } @@ -245,15 +250,7 @@ void OmniboxAPI::Observe(int type, } } } else { - DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); - // Load pending extensions. - for (PendingExtensions::const_iterator i(pending_extensions_.begin()); - i != pending_extensions_.end(); ++i) { - url_service_->RegisterExtensionKeyword((*i)->id(), - (*i)->name(), - OmniboxInfo::GetKeyword(*i)); - } - pending_extensions_.clear(); + NOTREACHED(); } } @@ -267,6 +264,18 @@ gfx::Image OmniboxAPI::GetOmniboxPopupIcon(const std::string& extension_id) { omnibox_popup_icon_manager_.GetIcon(extension_id)); } +void OmniboxAPI::OnTemplateURLsLoaded() { + // Register keywords for pending extensions. + template_url_sub_.reset(); + for (PendingExtensions::const_iterator i(pending_extensions_.begin()); + i != pending_extensions_.end(); ++i) { + url_service_->RegisterExtensionKeyword((*i)->id(), + (*i)->name(), + OmniboxInfo::GetKeyword(*i)); + } + pending_extensions_.clear(); +} + template <> void ProfileKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies() { DependsOn(ExtensionSystemFactory::GetInstance()); diff --git a/chrome/browser/extensions/api/omnibox/omnibox_api.h b/chrome/browser/extensions/api/omnibox/omnibox_api.h index 3792dc5..ca2d4b6 100644 --- a/chrome/browser/extensions/api/omnibox/omnibox_api.h +++ b/chrome/browser/extensions/api/omnibox/omnibox_api.h @@ -15,6 +15,7 @@ #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" #include "chrome/browser/extensions/extension_function.h" #include "chrome/browser/extensions/extension_icon_manager.h" +#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/common/extensions/api/omnibox.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -98,6 +99,9 @@ class OmniboxAPI : public ProfileKeyedAPI, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // BrowserContextKeyedService implementation. + virtual void Shutdown() OVERRIDE; + // Returns the icon to display in the omnibox for the given extension. gfx::Image GetOmniboxIcon(const std::string& extension_id); @@ -110,6 +114,8 @@ class OmniboxAPI : public ProfileKeyedAPI, typedef std::set<const Extension*> PendingExtensions; + void OnTemplateURLsLoaded(); + // ProfileKeyedAPI implementation. static const char* service_name() { return "OmniboxAPI"; @@ -130,6 +136,8 @@ class OmniboxAPI : public ProfileKeyedAPI, ExtensionIconManager omnibox_icon_manager_; ExtensionIconManager omnibox_popup_icon_manager_; + scoped_ptr<TemplateURLService::Subscription> template_url_sub_; + DISALLOW_COPY_AND_ASSIGN(OmniboxAPI); }; diff --git a/chrome/browser/importer/external_process_importer_host.cc b/chrome/browser/importer/external_process_importer_host.cc index 28ccd3f..c9adc5b 100644 --- a/chrome/browser/importer/external_process_importer_host.cc +++ b/chrome/browser/importer/external_process_importer_host.cc @@ -16,13 +16,11 @@ #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_source.h" using content::BrowserThread; ExternalProcessImporterHost::ExternalProcessImporterHost() - : weak_ptr_factory_(this), - headless_(false), + : headless_(false), parent_window_(NULL), observer_(NULL), profile_(NULL), @@ -32,7 +30,8 @@ ExternalProcessImporterHost::ExternalProcessImporterHost() client_(NULL), items_(0), cancelled_(false), - import_process_launched_(false) { + import_process_launched_(false), + weak_ptr_factory_(this) { } void ExternalProcessImporterHost::Cancel() { @@ -99,7 +98,7 @@ ExternalProcessImporterHost::~ExternalProcessImporterHost() { } void ExternalProcessImporterHost::LaunchImportIfReady() { - if (waiting_for_bookmarkbar_model_ || !registrar_.IsEmpty() || + if (waiting_for_bookmarkbar_model_ || template_service_subscription_.get() || !is_source_readable_ || cancelled_) return; @@ -135,11 +134,8 @@ void ExternalProcessImporterHost::BookmarkModelBeingDeleted( void ExternalProcessImporterHost::BookmarkModelChanged() { } -void ExternalProcessImporterHost::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(type, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); - registrar_.RemoveAll(); +void ExternalProcessImporterHost::OnTemplateURLServiceLoaded() { + template_service_subscription_.reset(); LaunchImportIfReady(); } @@ -208,8 +204,9 @@ void ExternalProcessImporterHost::CheckForLoadedModels(uint16 items) { if (!writer_->TemplateURLServiceIsLoaded()) { TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(profile_); - registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(model)); + template_service_subscription_ = model->RegisterOnLoadedCallback( + base::Bind(&ExternalProcessImporterHost::OnTemplateURLServiceLoaded, + weak_ptr_factory_.GetWeakPtr())); model->Load(); } } diff --git a/chrome/browser/importer/external_process_importer_host.h b/chrome/browser/importer/external_process_importer_host.h index e97da4f..f055092 100644 --- a/chrome/browser/importer/external_process_importer_host.h +++ b/chrome/browser/importer/external_process_importer_host.h @@ -13,9 +13,8 @@ #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" #include "chrome/browser/importer/importer_progress_observer.h" #include "chrome/browser/importer/profile_writer.h" +#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/common/importer/importer_data_types.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "ui/gfx/native_widget_types.h" class ExternalProcessImporterClient; @@ -29,8 +28,7 @@ struct SourceProfile; // This class manages the import process. It creates the in-process half of the // importer bridge and the external process importer client. -class ExternalProcessImporterHost : public BaseBookmarkModelObserver, - public content::NotificationObserver { +class ExternalProcessImporterHost : public BaseBookmarkModelObserver { public: ExternalProcessImporterHost(); @@ -86,11 +84,8 @@ class ExternalProcessImporterHost : public BaseBookmarkModelObserver, virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; virtual void BookmarkModelChanged() OVERRIDE; - // content::NotificationObserver: // Called when TemplateURLService has been loaded. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + void OnTemplateURLServiceLoaded(); // ShowWarningDialog() asks user to close the application that is owning the // lock. They can retry or skip the importing process. @@ -114,9 +109,6 @@ class ExternalProcessImporterHost : public BaseBookmarkModelObserver, // which are to be imported. void CheckForLoadedModels(uint16 items); - // Vends weak pointers for the importer to call us back. - base::WeakPtrFactory<ExternalProcessImporterHost> weak_ptr_factory_; - // True if UI is not to be shown. bool headless_; @@ -136,15 +128,16 @@ class ExternalProcessImporterHost : public BaseBookmarkModelObserver, // True if we're waiting for the model to finish loading. bool waiting_for_bookmarkbar_model_; + // May contain a Subscription waiting for the TemplateURLService to finish + // loading. + scoped_ptr<TemplateURLService::Subscription> template_service_subscription_; + // Have we installed a listener on the bookmark model? bool installed_bookmark_observer_; // True if source profile is readable. bool is_source_readable_; - // Receives notification when the TemplateURLService has loaded. - content::NotificationRegistrar registrar_; - // Writes data from the importer back to the profile. scoped_refptr<ProfileWriter> writer_; @@ -164,6 +157,9 @@ class ExternalProcessImporterHost : public BaseBookmarkModelObserver, // conditions on import cancel. bool import_process_launched_; + // Vends weak pointers for the importer to call us back. + base::WeakPtrFactory<ExternalProcessImporterHost> weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterHost); }; diff --git a/chrome/browser/profile_resetter/profile_resetter.cc b/chrome/browser/profile_resetter/profile_resetter.cc index 0777632..8d0227d 100644 --- a/chrome/browser/profile_resetter/profile_resetter.cc +++ b/chrome/browser/profile_resetter/profile_resetter.cc @@ -6,7 +6,6 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/browsing_data/browsing_data_helper.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" @@ -23,7 +22,6 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_source.h" ProfileResetter::ProfileResetter(Profile* profile) : profile_(profile), @@ -32,8 +30,6 @@ ProfileResetter::ProfileResetter(Profile* profile) cookies_remover_(NULL) { DCHECK(CalledOnValidThread()); DCHECK(profile_); - registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(template_url_service_)); } ProfileResetter::~ProfileResetter() { @@ -108,13 +104,13 @@ void ProfileResetter::MarkAsDone(Resettable resettable) { callback_); callback_.Reset(); master_settings_.reset(); + template_url_service_sub_.reset(); } } void ProfileResetter::ResetDefaultSearchEngine() { DCHECK(CalledOnValidThread()); DCHECK(template_url_service_); - // If TemplateURLServiceFactory is ready we can clean it right now. // Otherwise, load it and continue from ProfileResetter::Observe. if (template_url_service_->loaded()) { @@ -142,6 +138,10 @@ void ProfileResetter::ResetDefaultSearchEngine() { MarkAsDone(DEFAULT_SEARCH_ENGINE); } else { + template_url_service_sub_ = + template_url_service_->RegisterOnLoadedCallback( + base::Bind(&ProfileResetter::OnTemplateURLServiceLoaded, + base::Unretained(this))); template_url_service_->Load(); } } @@ -249,12 +249,11 @@ void ProfileResetter::ResetPinnedTabs() { MarkAsDone(PINNED_TABS); } -void ProfileResetter::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(CalledOnValidThread()); +void ProfileResetter::OnTemplateURLServiceLoaded() { // TemplateURLService has loaded. If we need to clean search engines, it's // time to go on. + DCHECK(CalledOnValidThread()); + template_url_service_sub_.reset(); if (pending_reset_flags_ & DEFAULT_SEARCH_ENGINE) ResetDefaultSearchEngine(); } diff --git a/chrome/browser/profile_resetter/profile_resetter.h b/chrome/browser/profile_resetter/profile_resetter.h index 77e8a1c..44170a8 100644 --- a/chrome/browser/profile_resetter/profile_resetter.h +++ b/chrome/browser/profile_resetter/profile_resetter.h @@ -10,17 +10,14 @@ #include "base/threading/non_thread_safe.h" #include "chrome/browser/browsing_data/browsing_data_remover.h" #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" +#include "chrome/browser/search_engines/template_url_service.h" class Profile; -class TemplateURLService; // This class allows resetting certain aspects of a profile to default values. // It is used in case the profile has been damaged due to malware or bad user // settings. class ProfileResetter : public base::NonThreadSafe, - public content::NotificationObserver, public BrowsingDataRemover::Observer { public: // Flags indicating what aspects of a profile shall be reset. @@ -69,14 +66,12 @@ class ProfileResetter : public base::NonThreadSafe, void ResetStartupPages(); void ResetPinnedTabs(); - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - // BrowsingDataRemover::Observer: virtual void OnBrowsingDataRemoverDone() OVERRIDE; + // Callback for when TemplateURLService has loaded. + void OnTemplateURLServiceLoaded(); + Profile* const profile_; scoped_ptr<BrandcodedDefaultSettings> master_settings_; TemplateURLService* template_url_service_; @@ -88,12 +83,12 @@ class ProfileResetter : public base::NonThreadSafe, // Called on UI thread when reset has been completed. base::Closure callback_; - content::NotificationRegistrar registrar_; - // If non-null it means removal is in progress. BrowsingDataRemover takes care // of deleting itself when done. BrowsingDataRemover* cookies_remover_; + scoped_ptr<TemplateURLService::Subscription> template_url_service_sub_; + DISALLOW_COPY_AND_ASSIGN(ProfileResetter); }; diff --git a/chrome/browser/search_engines/template_url_fetcher.cc b/chrome/browser/search_engines/template_url_fetcher.cc index b20e59e..fec0a4e 100644 --- a/chrome/browser/search_engines/template_url_fetcher.cc +++ b/chrome/browser/search_engines/template_url_fetcher.cc @@ -8,16 +8,12 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_fetcher_callbacks.h" #include "chrome/browser/search_engines/template_url_parser.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_source.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" @@ -28,9 +24,7 @@ #include "net/url_request/url_request_status.h" // RequestDelegate ------------------------------------------------------------ -class TemplateURLFetcher::RequestDelegate - : public net::URLFetcherDelegate, - public content::NotificationObserver { +class TemplateURLFetcher::RequestDelegate : public net::URLFetcherDelegate { public: // Takes ownership of |callbacks|. RequestDelegate(TemplateURLFetcher* fetcher, @@ -41,11 +35,6 @@ class TemplateURLFetcher::RequestDelegate TemplateURLFetcherCallbacks* callbacks, ProviderType provider_type); - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - // net::URLFetcherDelegate: // If data contains a valid OSDD, a TemplateURL is created and added to // the TemplateURLService. @@ -61,6 +50,7 @@ class TemplateURLFetcher::RequestDelegate ProviderType provider_type() const { return provider_type_; } private: + void OnLoaded(); void AddSearchProvider(); scoped_ptr<net::URLFetcher> url_fetcher_; @@ -72,8 +62,7 @@ class TemplateURLFetcher::RequestDelegate const ProviderType provider_type_; scoped_ptr<TemplateURLFetcherCallbacks> callbacks_; - // Handles registering for our notifications. - content::NotificationRegistrar registrar_; + scoped_ptr<TemplateURLService::Subscription> template_url_subscription_; DISALLOW_COPY_AND_ASSIGN(RequestDelegate); }; @@ -100,9 +89,9 @@ TemplateURLFetcher::RequestDelegate::RequestDelegate( if (!model->loaded()) { // Start the model load and set-up waiting for it. - registrar_.Add(this, - chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(model)); + template_url_subscription_ = model->RegisterOnLoadedCallback( + base::Bind(&TemplateURLFetcher::RequestDelegate::OnLoaded, + base::Unretained(this))); model->Load(); } @@ -119,12 +108,8 @@ TemplateURLFetcher::RequestDelegate::RequestDelegate( url_fetcher_->Start(); } -void TemplateURLFetcher::RequestDelegate::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); - +void TemplateURLFetcher::RequestDelegate::OnLoaded() { + template_url_subscription_.reset(); if (!template_url_.get()) return; AddSearchProvider(); diff --git a/chrome/browser/search_engines/template_url_scraper_unittest.cc b/chrome/browser/search_engines/template_url_scraper_unittest.cc index aa70734..942580e 100644 --- a/chrome/browser/search_engines/template_url_scraper_unittest.cc +++ b/chrome/browser/search_engines/template_url_scraper_unittest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/search_engines/template_url_service.h" @@ -10,8 +9,6 @@ #include "chrome/browser/ui/browser.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_source.h" #include "net/base/net_util.h" #include "net/dns/mock_host_resolver.h" @@ -25,27 +22,19 @@ class TemplateURLScraperTest : public InProcessBrowserTest { DISALLOW_COPY_AND_ASSIGN(TemplateURLScraperTest); }; -class TemplateURLServiceLoader : public content::NotificationObserver { +class TemplateURLServiceLoader { public: explicit TemplateURLServiceLoader(TemplateURLService* model) : model_(model) { - registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(model)); + scoped_refptr<content::MessageLoopRunner> message_loop_runner = + new content::MessageLoopRunner; + scoped_ptr<TemplateURLService::Subscription> subscription = + model_->RegisterOnLoadedCallback( + message_loop_runner->QuitClosure()); model_->Load(); - content::RunMessageLoop(); - } - - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED && - content::Source<TemplateURLService>(source).ptr() == model_) { - base::MessageLoop::current()->Quit(); - } + message_loop_runner->Run(); } private: - content::NotificationRegistrar registrar_; - TemplateURLService* model_; DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceLoader); diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc index cca1a36..c560e8f 100644 --- a/chrome/browser/search_engines/template_url_service.cc +++ b/chrome/browser/search_engines/template_url_service.cc @@ -772,10 +772,18 @@ void TemplateURLService::Load() { load_handle_ = service_->GetKeywords(this); } else { ChangeToLoadedState(); - NotifyLoaded(); + on_loaded_callbacks_.Notify(); } } +scoped_ptr<TemplateURLService::Subscription> + TemplateURLService::RegisterOnLoadedCallback( + const base::Closure& callback) { + return loaded_ ? + scoped_ptr<TemplateURLService::Subscription>() : + on_loaded_callbacks_.Add(callback); +} + void TemplateURLService::OnWebDataServiceRequestDone( WebDataService::Handle h, const WDTypedResult* result) { @@ -788,7 +796,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( // loaded. load_failed_ = true; ChangeToLoadedState(); - NotifyLoaded(); + on_loaded_callbacks_.Notify(); return; } @@ -820,7 +828,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( EnsureDefaultSearchProviderExists(); NotifyObservers(); - NotifyLoaded(); + on_loaded_callbacks_.Notify(); } string16 TemplateURLService::GetKeywordShortName(const string16& keyword, @@ -1570,13 +1578,6 @@ void TemplateURLService::ChangeToLoadedState() { loaded_ = true; } -void TemplateURLService::NotifyLoaded() { - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(this), - content::NotificationService::NoDetails()); -} - void TemplateURLService::SaveDefaultSearchProviderToPrefs( const TemplateURL* t_url) { PrefService* prefs = GetPrefs(); diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h index c47c85e..588c2de 100644 --- a/chrome/browser/search_engines/template_url_service.h +++ b/chrome/browser/search_engines/template_url_service.h @@ -11,6 +11,7 @@ #include <string> #include <vector> +#include "base/callback_list.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" @@ -53,8 +54,8 @@ struct URLVisitedDetails; // TemplateURLService does not load the vector of TemplateURLs in its // constructor (except for testing). Use the Load method to trigger a load. // When TemplateURLService has completed loading, observers are notified via -// OnTemplateURLServiceChanged as well as the TEMPLATE_URL_SERVICE_LOADED -// notification message. +// OnTemplateURLServiceChanged, or by a callback registered prior to calling +// the Load method. // // TemplateURLService takes ownership of any TemplateURL passed to it. If there // is a WebDataService, deletion is handled by WebDataService, otherwise @@ -70,6 +71,7 @@ class TemplateURLService : public WebDataServiceConsumer, // Type for a static function pointer that acts as a time source. typedef base::Time(TimeProvider)(); typedef std::map<std::string, syncer::SyncData> SyncDataMap; + typedef base::CallbackList<void(void)>::Subscription Subscription; // Struct used for initializing the data store with fake data. // Each initializer is mapped to a TemplateURL. @@ -263,6 +265,12 @@ class TemplateURLService : public WebDataServiceConsumer, // OnTemplateURLServiceChanged. void Load(); + // Registers a callback to be called when the service has loaded. + // + // If the service has already loaded, this function does nothing. + scoped_ptr<Subscription> RegisterOnLoadedCallback( + const base::Closure& callback); + #if defined(UNIT_TEST) void set_loaded(bool value) { loaded_ = value; } #endif @@ -438,10 +446,6 @@ class TemplateURLService : public WebDataServiceConsumer, // Transitions to the loaded state. void ChangeToLoadedState(); - // If there is a notification service, sends TEMPLATE_URL_SERVICE_LOADED - // notification. - void NotifyLoaded(); - // Saves enough of url to preferences so that it can be loaded from // preferences on start up. void SaveDefaultSearchProviderToPrefs(const TemplateURL* url); @@ -731,6 +735,9 @@ class TemplateURLService : public WebDataServiceConsumer, // cause/origin of a default search change. DefaultSearchChangeOrigin dsp_change_origin_; + // Stores a list of callbacks to be run after TemplateURLService has loaded. + base::CallbackList<void(void)> on_loaded_callbacks_; + DISALLOW_COPY_AND_ASSIGN(TemplateURLService); }; diff --git a/chrome/browser/search_engines/template_url_service_android.cc b/chrome/browser/search_engines/template_url_service_android.cc index a84dd04..783725b 100644 --- a/chrome/browser/search_engines/template_url_service_android.cc +++ b/chrome/browser/search_engines/template_url_service_android.cc @@ -5,18 +5,16 @@ #include "chrome/browser/search_engines/template_url_service_android.h" #include "base/android/jni_string.h" +#include "base/bind.h" #include "base/format_macros.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/search_engines/search_terms_data.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" -#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "content/public/browser/notification_source.h" #include "jni/TemplateUrlService_jni.h" using base::android::ConvertJavaStringToUTF16; @@ -37,27 +35,15 @@ TemplateUrlServiceAndroid::TemplateUrlServiceAndroid(JNIEnv* env, : weak_java_obj_(env, obj), template_url_service_( TemplateURLServiceFactory::GetForProfile(GetOriginalProfile())) { - registrar_.Add(this, - chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(template_url_service_)); + template_url_subscription_ = + template_url_service_->RegisterOnLoadedCallback( + base::Bind(&TemplateUrlServiceAndroid::OnTemplateURLServiceLoaded, + base::Unretained(this))); } TemplateUrlServiceAndroid::~TemplateUrlServiceAndroid() { } -void TemplateUrlServiceAndroid::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, type); - JNIEnv* env = base::android::AttachCurrentThread(); - if (weak_java_obj_.get(env).is_null()) - return; - - Java_TemplateUrlService_templateUrlServiceLoaded(env, - weak_java_obj_.get(env).obj()); -} - void TemplateUrlServiceAndroid::Load(JNIEnv* env, jobject obj) { template_url_service_->Load(); } @@ -140,6 +126,16 @@ bool TemplateUrlServiceAndroid::IsPrepopulatedTemplate(TemplateURL* url) { return url->prepopulate_id() > 0; } +void TemplateUrlServiceAndroid::OnTemplateURLServiceLoaded() { + template_url_subscription_.reset(); + JNIEnv* env = base::android::AttachCurrentThread(); + if (weak_java_obj_.get(env).is_null()) + return; + + Java_TemplateUrlService_templateUrlServiceLoaded( + env, weak_java_obj_.get(env).obj()); +} + base::android::ScopedJavaLocalRef<jstring> TemplateUrlServiceAndroid::GetUrlForSearchQuery(JNIEnv* env, jobject obj, diff --git a/chrome/browser/search_engines/template_url_service_android.h b/chrome/browser/search_engines/template_url_service_android.h index f2543b7..761e246 100644 --- a/chrome/browser/search_engines/template_url_service_android.h +++ b/chrome/browser/search_engines/template_url_service_android.h @@ -7,17 +7,16 @@ #include "base/android/jni_helper.h" #include "base/android/scoped_java_ref.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/search_engines/template_url_service.h" class TemplateURL; -class TemplateURLService; // Android wrapper of the TemplateUrlService which provides access from the Java // layer. Note that on Android, there's only a single profile, and therefore // a single instance of this wrapper. -class TemplateUrlServiceAndroid : public content::NotificationObserver { +class TemplateUrlServiceAndroid { public: TemplateUrlServiceAndroid(JNIEnv* env, jobject obj); @@ -41,24 +40,22 @@ class TemplateUrlServiceAndroid : public content::NotificationObserver { jstring jquery, jstring jcurrent_url); - // NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - static bool Register(JNIEnv* env); private: - virtual ~TemplateUrlServiceAndroid(); + ~TemplateUrlServiceAndroid(); bool IsPrepopulatedTemplate(TemplateURL* url); + void OnTemplateURLServiceLoaded(); + JavaObjectWeakGlobalRef weak_java_obj_; - content::NotificationRegistrar registrar_; // Pointer to the TemplateUrlService for the main profile. TemplateURLService* template_url_service_; + scoped_ptr<TemplateURLService::Subscription> template_url_subscription_; + DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid); }; diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller.cc b/chrome/browser/sync/glue/search_engine_data_type_controller.cc index 9718b23..351fe6d 100644 --- a/chrome/browser/sync/glue/search_engine_data_type_controller.cc +++ b/chrome/browser/sync/glue/search_engine_data_type_controller.cc @@ -5,13 +5,10 @@ #include "chrome/browser/sync/glue/search_engine_data_type_controller.h" #include "base/metrics/histogram.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/sync/profile_sync_components_factory.h" #include "chrome/browser/sync/profile_sync_service.h" -#include "content/public/browser/notification_source.h" #include "sync/api/syncable_service.h" using content::BrowserThread; @@ -28,17 +25,6 @@ SearchEngineDataTypeController::SearchEngineDataTypeController( sync_service) { } -void SearchEngineDataTypeController::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, type); - registrar_.RemoveAll(); - DCHECK_EQ(state_, MODEL_STARTING); - OnModelLoaded(); -} - SearchEngineDataTypeController::~SearchEngineDataTypeController() {} // We want to start the TemplateURLService before we begin associating. @@ -54,15 +40,19 @@ bool SearchEngineDataTypeController::StartModels() { return true; // Continue to Associate(). } - // Add an observer and continue when the TemplateURLService is loaded. - registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(turl_service)); + // Register a callback and continue when the TemplateURLService is loaded. + template_url_subscription_ = turl_service->RegisterOnLoadedCallback( + base::Bind(&SearchEngineDataTypeController::OnTemplateURLServiceLoaded, + this)); + return false; // Don't continue Start. } -// Cleanup for our extra registrar usage. -void SearchEngineDataTypeController::StopModels() { - registrar_.RemoveAll(); +void SearchEngineDataTypeController::OnTemplateURLServiceLoaded() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(state_, MODEL_STARTING); + template_url_subscription_.reset(); + OnModelLoaded(); } } // namespace browser_sync diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller.h b/chrome/browser/sync/glue/search_engine_data_type_controller.h index 739af36..1beb7d7 100644 --- a/chrome/browser/sync/glue/search_engine_data_type_controller.h +++ b/chrome/browser/sync/glue/search_engine_data_type_controller.h @@ -8,6 +8,8 @@ #include <string> #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/sync/glue/generic_change_processor.h" #include "chrome/browser/sync/glue/ui_data_type_controller.h" #include "content/public/browser/notification_observer.h" @@ -15,27 +17,22 @@ namespace browser_sync { -class SearchEngineDataTypeController : public UIDataTypeController, - public content::NotificationObserver { +class SearchEngineDataTypeController : public UIDataTypeController { public: SearchEngineDataTypeController( ProfileSyncComponentsFactory* profile_sync_factory, Profile* profile, ProfileSyncService* sync_service); - // content::NotificationObserver interface. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - private: virtual ~SearchEngineDataTypeController(); // FrontendDataTypeController implementations. virtual bool StartModels() OVERRIDE; - virtual void StopModels() OVERRIDE; - content::NotificationRegistrar registrar_; + void OnTemplateURLServiceLoaded(); + + scoped_ptr<TemplateURLService::Subscription> template_url_subscription_; DISALLOW_COPY_AND_ASSIGN(SearchEngineDataTypeController); }; diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc index 3f95b14..4685446 100644 --- a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc @@ -8,7 +8,6 @@ #include "base/memory/scoped_ptr.h" #include "base/run_loop.h" #include "base/tracked_objects.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_test_util.h" #include "chrome/browser/sync/glue/data_type_controller_mock.h" @@ -17,7 +16,6 @@ #include "chrome/browser/sync/profile_sync_components_factory_mock.h" #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/test/base/profile_mock.h" -#include "content/public/browser/notification_service.h" #include "sync/api/fake_syncable_service.h" #include "testing/gtest/include/gtest/gtest.h" @@ -137,10 +135,7 @@ TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceNotReady) { EXPECT_FALSE(syncable_service_.syncing()); // Send the notification that the TemplateURLService has started. - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(test_util_.model()), - content::NotificationService::NoDetails()); + PreloadTemplateURLService(); EXPECT_EQ(DataTypeController::MODEL_LOADED, search_engine_dtc_->state()); // Wait until WebDB is loaded before we shut it down. diff --git a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc index fd815cd..41cc2e9 100644 --- a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc +++ b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc @@ -4,7 +4,6 @@ #include <stdio.h> -#include "base/message_loop/message_loop.h" #include "base/strings/string16.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" @@ -262,13 +261,7 @@ class OmniboxViewTest : public InProcessBrowserTest, TemplateURLServiceFactory::GetForProfile(profile); ASSERT_TRUE(model); - if (!model->loaded()) { - content::NotificationRegistrar registrar; - registrar.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(model)); - model->Load(); - content::RunMessageLoop(); - } + ui_test_utils::WaitForTemplateURLServiceToLoad(model); ASSERT_TRUE(model->loaded()); // Remove built-in template urls, like google.com, bing.com etc., as they @@ -364,7 +357,6 @@ class OmniboxViewTest : public InProcessBrowserTest, case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY: case chrome::NOTIFICATION_HISTORY_LOADED: case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: - case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED: break; default: FAIL() << "Unexpected notification type"; diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index 37ce12e..4f65067 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -15,8 +15,8 @@ #include "base/file_util.h" #include "base/files/file_path.h" #include "base/json/json_reader.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "base/message_loop/message_loop.h" #include "base/path_service.h" #include "base/prefs/pref_service.h" #include "base/strings/stringprintf.h" @@ -335,12 +335,13 @@ int FindInPage(WebContents* tab, const string16& search_string, void WaitForTemplateURLServiceToLoad(TemplateURLService* service) { if (service->loaded()) return; - - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, - content::Source<TemplateURLService>(service)); + scoped_refptr<content::MessageLoopRunner> message_loop_runner = + new content::MessageLoopRunner; + scoped_ptr<TemplateURLService::Subscription> subscription = + service->RegisterOnLoadedCallback( + message_loop_runner->QuitClosure()); service->Load(); - observer.Wait(); + message_loop_runner->Run(); ASSERT_TRUE(service->loaded()); } |