| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" | 5 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 96 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 97 default_favicon_.reset([gfx::GetCachedImageWithName(@"nav.pdf") retain]); | 97 default_favicon_.reset([gfx::GetCachedImageWithName(@"nav.pdf") retain]); |
| 98 | 98 |
| 99 // Set the static icons in the menu. | 99 // Set the static icons in the menu. |
| 100 NSMenuItem* item = [HistoryMenu() itemWithTag:IDC_SHOW_HISTORY]; | 100 NSMenuItem* item = [HistoryMenu() itemWithTag:IDC_SHOW_HISTORY]; |
| 101 [item setImage:rb.GetNativeImageNamed(IDR_HISTORY_FAVICON)]; | 101 [item setImage:rb.GetNativeImageNamed(IDR_HISTORY_FAVICON)]; |
| 102 | 102 |
| 103 // The service is not ready for use yet, so become notified when it does. | 103 // The service is not ready for use yet, so become notified when it does. |
| 104 if (!history_service_) { | 104 if (!history_service_) { |
| 105 registrar_.Add( | 105 registrar_.Add( |
| 106 this, NotificationType::HISTORY_LOADED, Source<Profile>(profile_)); | 106 this, chrome::HISTORY_LOADED, Source<Profile>(profile_)); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Note that all requests sent to either the history service or the favicon | 110 // Note that all requests sent to either the history service or the favicon |
| 111 // service will be automatically cancelled by their respective Consumers, so | 111 // service will be automatically cancelled by their respective Consumers, so |
| 112 // task cancellation is not done manually here in the dtor. | 112 // task cancellation is not done manually here in the dtor. |
| 113 HistoryMenuBridge::~HistoryMenuBridge() { | 113 HistoryMenuBridge::~HistoryMenuBridge() { |
| 114 // Unregister ourselves as observers and notifications. | 114 // Unregister ourselves as observers and notifications. |
| 115 if (history_service_) { | 115 if (history_service_) { |
| 116 const NotificationSource& src = NotificationService::AllSources(); | 116 const NotificationSource& src = NotificationService::AllSources(); |
| 117 registrar_.Remove(this, NotificationType::HISTORY_TYPED_URLS_MODIFIED, src); | 117 registrar_.Remove(this, chrome::HISTORY_TYPED_URLS_MODIFIED, src); |
| 118 registrar_.Remove(this, NotificationType::HISTORY_URL_VISITED, src); | 118 registrar_.Remove(this, chrome::HISTORY_URL_VISITED, src); |
| 119 registrar_.Remove(this, NotificationType::HISTORY_URLS_DELETED, src); | 119 registrar_.Remove(this, chrome::HISTORY_URLS_DELETED, src); |
| 120 } else { | 120 } else { |
| 121 registrar_.Remove( | 121 registrar_.Remove( |
| 122 this, NotificationType::HISTORY_LOADED, Source<Profile>(profile_)); | 122 this, chrome::HISTORY_LOADED, Source<Profile>(profile_)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 if (tab_restore_service_) | 125 if (tab_restore_service_) |
| 126 tab_restore_service_->RemoveObserver(this); | 126 tab_restore_service_->RemoveObserver(this); |
| 127 | 127 |
| 128 // Since the map owns the HistoryItems, delete anything that still exists. | 128 // Since the map owns the HistoryItems, delete anything that still exists. |
| 129 std::map<NSMenuItem*, HistoryItem*>::iterator it = menu_item_map_.begin(); | 129 std::map<NSMenuItem*, HistoryItem*>::iterator it = menu_item_map_.begin(); |
| 130 while (it != menu_item_map_.end()) { | 130 while (it != menu_item_map_.end()) { |
| 131 HistoryItem* item = it->second; | 131 HistoryItem* item = it->second; |
| 132 menu_item_map_.erase(it++); | 132 menu_item_map_.erase(it++); |
| 133 delete item; | 133 delete item; |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 void HistoryMenuBridge::Observe(NotificationType type, | 137 void HistoryMenuBridge::Observe(NotificationType type, |
| 138 const NotificationSource& source, | 138 const NotificationSource& source, |
| 139 const NotificationDetails& details) { | 139 const NotificationDetails& details) { |
| 140 // A history service is now ready. Check to see if it's the one for the main | 140 // A history service is now ready. Check to see if it's the one for the main |
| 141 // profile. If so, perform final initialization. | 141 // profile. If so, perform final initialization. |
| 142 if (type == NotificationType::HISTORY_LOADED) { | 142 if (type == chrome::HISTORY_LOADED) { |
| 143 HistoryService* hs = | 143 HistoryService* hs = |
| 144 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 144 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 145 if (hs != NULL && hs->BackendLoaded()) { | 145 if (hs != NULL && hs->BackendLoaded()) { |
| 146 history_service_ = hs; | 146 history_service_ = hs; |
| 147 Init(); | 147 Init(); |
| 148 | 148 |
| 149 // Found our HistoryService, so stop listening for this notification. | 149 // Found our HistoryService, so stop listening for this notification. |
| 150 registrar_.Remove(this, | 150 registrar_.Remove(this, |
| 151 NotificationType::HISTORY_LOADED, | 151 chrome::HISTORY_LOADED, |
| 152 Source<Profile>(profile_)); | 152 Source<Profile>(profile_)); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 // All other notification types that we observe indicate that the history has | 156 // All other notification types that we observe indicate that the history has |
| 157 // changed and we need to rebuild. | 157 // changed and we need to rebuild. |
| 158 need_recreate_ = true; | 158 need_recreate_ = true; |
| 159 CreateMenu(); | 159 CreateMenu(); |
| 160 } | 160 } |
| 161 | 161 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 [item->menu_item setToolTip:tooltip]; | 356 [item->menu_item setToolTip:tooltip]; |
| 357 | 357 |
| 358 [menu insertItem:item->menu_item.get() atIndex:index]; | 358 [menu insertItem:item->menu_item.get() atIndex:index]; |
| 359 menu_item_map_.insert(std::make_pair(item->menu_item.get(), item)); | 359 menu_item_map_.insert(std::make_pair(item->menu_item.get(), item)); |
| 360 | 360 |
| 361 return item->menu_item.get(); | 361 return item->menu_item.get(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void HistoryMenuBridge::Init() { | 364 void HistoryMenuBridge::Init() { |
| 365 const NotificationSource& source = NotificationService::AllSources(); | 365 const NotificationSource& source = NotificationService::AllSources(); |
| 366 registrar_.Add(this, NotificationType::HISTORY_TYPED_URLS_MODIFIED, source); | 366 registrar_.Add(this, chrome::HISTORY_TYPED_URLS_MODIFIED, source); |
| 367 registrar_.Add(this, NotificationType::HISTORY_URL_VISITED, source); | 367 registrar_.Add(this, chrome::HISTORY_URL_VISITED, source); |
| 368 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, source); | 368 registrar_.Add(this, chrome::HISTORY_URLS_DELETED, source); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void HistoryMenuBridge::CreateMenu() { | 371 void HistoryMenuBridge::CreateMenu() { |
| 372 // If we're currently running CreateMenu(), wait until it finishes. | 372 // If we're currently running CreateMenu(), wait until it finishes. |
| 373 if (create_in_progress_) | 373 if (create_in_progress_) |
| 374 return; | 374 return; |
| 375 create_in_progress_ = true; | 375 create_in_progress_ = true; |
| 376 need_recreate_ = false; | 376 need_recreate_ = false; |
| 377 | 377 |
| 378 DCHECK(history_service_); | 378 DCHECK(history_service_); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { | 476 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { |
| 477 DCHECK(item); | 477 DCHECK(item); |
| 478 if (item->icon_requested) { | 478 if (item->icon_requested) { |
| 479 FaviconService* service = | 479 FaviconService* service = |
| 480 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 480 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 481 service->CancelRequest(item->icon_handle); | 481 service->CancelRequest(item->icon_handle); |
| 482 item->icon_requested = false; | 482 item->icon_requested = false; |
| 483 item->icon_handle = NULL; | 483 item->icon_handle = NULL; |
| 484 } | 484 } |
| 485 } | 485 } |
| OLD | NEW |