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

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

Issue 23710022: Convert NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED to CallbackList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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.h
diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h
index c47c85ee525072e98830691a762e66c03599008e..588c2de95b36904575c51902f1f629f93f741038 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);
};
« no previous file with comments | « chrome/browser/search_engines/template_url_scraper_unittest.cc ('k') | chrome/browser/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698