| 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 50456dc3b42fc303f6d71cf757fb6fb7bc5d42a7..5bb7e721c6d8e106c6230a76b06ed9fcfc4c8dcf 100644
|
| --- a/chrome/browser/ui/cocoa/history_menu_bridge.mm
|
| +++ b/chrome/browser/ui/cocoa/history_menu_bridge.mm
|
| @@ -65,7 +65,8 @@ HistoryMenuBridge::HistoryMenuBridge(Profile* profile)
|
| history_service_(NULL),
|
| tab_restore_service_(NULL),
|
| create_in_progress_(false),
|
| - need_recreate_(false) {
|
| + need_recreate_(false),
|
| + history_service_observer_(this) {
|
| // If we don't have a profile, do not bother initializing our data sources.
|
| // This shouldn't happen except in unit tests.
|
| if (profile_) {
|
| @@ -77,6 +78,8 @@ HistoryMenuBridge::HistoryMenuBridge(Profile* profile)
|
| if (hs != NULL && hs->BackendLoaded()) {
|
| history_service_ = hs;
|
| Init();
|
| + } else if (hs) {
|
| + history_service_observer_.Add(hs);
|
| }
|
|
|
| tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile_);
|
| @@ -100,12 +103,6 @@ HistoryMenuBridge::HistoryMenuBridge(Profile* profile)
|
| 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
|
| @@ -119,10 +116,6 @@ HistoryMenuBridge::~HistoryMenuBridge() {
|
| 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_));
|
| }
|
|
|
| if (tab_restore_service_)
|
| @@ -140,22 +133,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.
|
| OnHistoryChanged();
|
| @@ -280,6 +257,15 @@ void HistoryMenuBridge::OnURLVisited(HistoryService* history_service,
|
| OnHistoryChanged();
|
| }
|
|
|
| +void HistoryMenuBridge::OnHistoryServiceLoaded(
|
| + HistoryService* history_service) {
|
| + DCHECK(history_service);
|
| + DCHECK(history_service->BackendLoaded());
|
| + history_service_ = history_service;
|
| + Init();
|
| + OnHistoryChanged();
|
| +}
|
| +
|
| HistoryMenuBridge::HistoryItem* HistoryMenuBridge::HistoryItemForMenuItem(
|
| NSMenuItem* item) {
|
| std::map<NSMenuItem*, HistoryItem*>::iterator it = menu_item_map_.find(item);
|
| @@ -484,3 +470,4 @@ void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) {
|
| item->icon_task_id = base::CancelableTaskTracker::kBadTaskId;
|
| }
|
| }
|
| +
|
|
|