if (history_service_) {
registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
content::Source<Profile>(profile_));
- registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
- content::Source<Profile>(profile_));
registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
content::Source<Profile>(profile_));
+ history_service_->RemoveObserver(this);
} else {
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;
- CreateMenu();
+ // changed.
+ OnHistoryChanged();
}
void HistoryMenuBridge::TabRestoreServiceChanged(TabRestoreService* service) {
CreateMenu();
}
+void HistoryMenuBridge::OnURLVisited(HistoryService* history_service,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) {
+ OnHistoryChanged();
+}
+
HistoryMenuBridge::HistoryItem* HistoryMenuBridge::HistoryItemForMenuItem(
NSMenuItem* item) {
std::map<NSMenuItem*, HistoryItem*>::iterator it = menu_item_map_.find(item);
}
void HistoryMenuBridge::Init() {
+ DCHECK(history_service_);
registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
content::Source<Profile>(profile_));
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
- content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
content::Source<Profile>(profile_));
+ history_service_->AddObserver(this);
}
void HistoryMenuBridge::CreateMenu() {
&cancelable_task_tracker_);
}
+void HistoryMenuBridge::OnHistoryChanged() {
+ // History has changed, rebuild menu.
+ need_recreate_ = true;
+ CreateMenu();
+}
+
void HistoryMenuBridge::OnVisitedHistoryResults(
history::QueryResults* results) {
NSMenu* menu = HistoryMenu();