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

Unified Diff: chrome/browser/ui/cocoa/history_menu_bridge.mm

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/ui/cocoa/history_menu_bridge.mm
diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.mm b/chrome/browser/ui/cocoa/history_menu_bridge.mm
index e4785f345b4979c20bc3295acd408558705f72ab..f4991a520b9ff38bea02c749dbd034091ecd5fbb 100644
--- a/chrome/browser/ui/cocoa/history_menu_bridge.mm
+++ b/chrome/browser/ui/cocoa/history_menu_bridge.mm
@@ -77,6 +77,9 @@ HistoryMenuBridge::HistoryMenuBridge(Profile* profile)
if (hs != NULL && hs->BackendLoaded()) {
history_service_ = hs;
Init();
+ } else if (hs != NULL) {
+ // The service is not ready for use yet, so become notified when it does.
+ hs->AddHistoryServiceObserver(this);
sdefresne 2014/10/20 13:15:42 Use ScopedObserver<>
}
tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile_);
@@ -99,13 +102,6 @@ HistoryMenuBridge::HistoryMenuBridge(Profile* profile)
// Set the static icons in the menu.
NSMenuItem* item = [HistoryMenu() itemWithTag:IDC_SHOW_HISTORY];
[item setImage:rb.GetNativeImageNamed(IDR_HISTORY_FAVICON).ToNSImage()];
-
- // The service is not ready for use yet, so become notified when it does.
- if (!history_service_) {
- registrar_.Add(
- this, chrome::NOTIFICATION_HISTORY_LOADED,
- content::Source<Profile>(profile_));
- }
}
// Note that all requests sent to either the history service or the favicon
@@ -121,9 +117,7 @@ HistoryMenuBridge::~HistoryMenuBridge() {
content::Source<Profile>(profile_));
registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
content::Source<Profile>(profile_));
- } else {
- registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_LOADED,
- content::Source<Profile>(profile_));
+ history_service_->RemoveHistoryServiceObserver(this);
}
if (tab_restore_service_)
@@ -141,22 +135,6 @@ HistoryMenuBridge::~HistoryMenuBridge() {
void HistoryMenuBridge::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- // A history service is now ready. Check to see if it's the one for the main
- // profile. If so, perform final initialization.
- if (type == chrome::NOTIFICATION_HISTORY_LOADED) {
- HistoryService* hs = HistoryServiceFactory::GetForProfile(
- profile_, Profile::EXPLICIT_ACCESS);
- if (hs != NULL && hs->BackendLoaded()) {
- history_service_ = hs;
- Init();
-
- // Found our HistoryService, so stop listening for this notification.
- registrar_.Remove(this,
- chrome::NOTIFICATION_HISTORY_LOADED,
- content::Source<Profile>(profile_));
- }
- }
-
// All other notification types that we observe indicate that the history has
// changed and we need to rebuild.
need_recreate_ = true;
@@ -472,3 +450,13 @@ void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) {
item->icon_task_id = base::CancelableTaskTracker::kBadTaskId;
}
}
+
+void HistoryMenuBridge::HistoryServiceLoaded(HistoryService* history_service) {
+ HistoryService* hs =
+ HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
sdefresne 2014/10/20 13:15:42 No need to use HistoryServiceFactory to get the Hi
nshaik 2014/10/29 08:43:39 Okay. The only reason why I did this was to ensure
+ if (hs != NULL && hs->BackendLoaded()) {
+ history_service_ = hs;
+ Init();
+ history_service_->RemoveHistoryServiceObserver(this);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698