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 #ifndef CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ |
6 #define CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ | 6 #define CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/task/cancelable_task_tracker.h" |
14 #include "chrome/browser/common/cancelable_request.h" | 15 #include "chrome/browser/common/cancelable_request.h" |
15 #import "chrome/browser/favicon/favicon_service.h" | 16 #import "chrome/browser/favicon/favicon_service.h" |
16 #include "chrome/browser/history/history_service.h" | 17 #include "chrome/browser/history/history_service.h" |
17 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
18 #include "chrome/browser/sessions/tab_restore_service.h" | 19 #include "chrome/browser/sessions/tab_restore_service.h" |
19 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 20 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
20 #import "chrome/browser/ui/cocoa/main_menu_item.h" | 21 #import "chrome/browser/ui/cocoa/main_menu_item.h" |
21 #include "chrome/common/cancelable_task_tracker.h" | |
22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
23 | 23 |
24 class NotificationRegistrar; | 24 class NotificationRegistrar; |
25 class PageUsageData; | 25 class PageUsageData; |
26 class Profile; | 26 class Profile; |
27 class TabRestoreService; | 27 class TabRestoreService; |
28 @class HistoryMenuCocoaController; | 28 @class HistoryMenuCocoaController; |
29 | 29 |
30 namespace { | 30 namespace { |
31 class HistoryMenuBridgeTest; | 31 class HistoryMenuBridgeTest; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 // The title for the menu item. | 73 // The title for the menu item. |
74 base::string16 title; | 74 base::string16 title; |
75 // The URL that will be navigated to if the user selects this item. | 75 // The URL that will be navigated to if the user selects this item. |
76 GURL url; | 76 GURL url; |
77 // Favicon for the URL. | 77 // Favicon for the URL. |
78 base::scoped_nsobject<NSImage> icon; | 78 base::scoped_nsobject<NSImage> icon; |
79 | 79 |
80 // If the icon is being requested from the FaviconService, |icon_requested| | 80 // If the icon is being requested from the FaviconService, |icon_requested| |
81 // will be true and |icon_task_id| will be valid. If this is false, then | 81 // will be true and |icon_task_id| will be valid. If this is false, then |
82 // |icon_task_id| will be CancelableTaskTracker::kBadTaskId. | 82 // |icon_task_id| will be |
| 83 // base::CancelableTaskTracker::kBadTaskId. |
83 bool icon_requested; | 84 bool icon_requested; |
84 // The Handle given to us by the FaviconService for the icon fetch request. | 85 // The Handle given to us by the FaviconService for the icon fetch request. |
85 CancelableTaskTracker::TaskId icon_task_id; | 86 base::CancelableTaskTracker::TaskId icon_task_id; |
86 | 87 |
87 // The pointer to the item after it has been created. Strong; NSMenu also | 88 // The pointer to the item after it has been created. Strong; NSMenu also |
88 // retains this. During a rebuild flood (if the user closes a lot of tabs | 89 // retains this. During a rebuild flood (if the user closes a lot of tabs |
89 // quickly), the NSMenu can release the item before the HistoryItem has | 90 // quickly), the NSMenu can release the item before the HistoryItem has |
90 // been fully deleted. If this were a weak pointer, it would result in a | 91 // been fully deleted. If this were a weak pointer, it would result in a |
91 // zombie. | 92 // zombie. |
92 base::scoped_nsobject<NSMenuItem> menu_item; | 93 base::scoped_nsobject<NSMenuItem> menu_item; |
93 | 94 |
94 // This ID is unique for a browser session and can be passed to the | 95 // This ID is unique for a browser session and can be passed to the |
95 // TabRestoreService to re-open the closed window or tab that this | 96 // TabRestoreService to re-open the closed window or tab that this |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 friend class HistoryMenuCocoaControllerTest; | 206 friend class HistoryMenuCocoaControllerTest; |
206 | 207 |
207 base::scoped_nsobject<HistoryMenuCocoaController> controller_; // strong | 208 base::scoped_nsobject<HistoryMenuCocoaController> controller_; // strong |
208 | 209 |
209 Profile* profile_; // weak | 210 Profile* profile_; // weak |
210 HistoryService* history_service_; // weak | 211 HistoryService* history_service_; // weak |
211 TabRestoreService* tab_restore_service_; // weak | 212 TabRestoreService* tab_restore_service_; // weak |
212 | 213 |
213 content::NotificationRegistrar registrar_; | 214 content::NotificationRegistrar registrar_; |
214 CancelableRequestConsumer cancelable_request_consumer_; | 215 CancelableRequestConsumer cancelable_request_consumer_; |
215 CancelableTaskTracker cancelable_task_tracker_; | 216 base::CancelableTaskTracker cancelable_task_tracker_; |
216 | 217 |
217 // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until | 218 // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until |
218 // they are removed and deleted via ClearMenuSection(). | 219 // they are removed and deleted via ClearMenuSection(). |
219 std::map<NSMenuItem*, HistoryItem*> menu_item_map_; | 220 std::map<NSMenuItem*, HistoryItem*> menu_item_map_; |
220 | 221 |
221 // Maps HistoryItems to favicon request Handles. | 222 // Maps HistoryItems to favicon request Handles. |
222 CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_; | 223 CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_; |
223 | 224 |
224 // Requests to re-create the menu are coalesced. |create_in_progress_| is true | 225 // Requests to re-create the menu are coalesced. |create_in_progress_| is true |
225 // when either waiting for the history service to return query results, or | 226 // when either waiting for the history service to return query results, or |
226 // when the menu is rebuilding. |need_recreate_| is true whenever a rebuild | 227 // when the menu is rebuilding. |need_recreate_| is true whenever a rebuild |
227 // has been scheduled but is waiting for the current one to finish. | 228 // has been scheduled but is waiting for the current one to finish. |
228 bool create_in_progress_; | 229 bool create_in_progress_; |
229 bool need_recreate_; | 230 bool need_recreate_; |
230 | 231 |
231 // The default favicon if a HistoryItem does not have one. | 232 // The default favicon if a HistoryItem does not have one. |
232 base::scoped_nsobject<NSImage> default_favicon_; | 233 base::scoped_nsobject<NSImage> default_favicon_; |
233 | 234 |
234 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); | 235 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); |
235 }; | 236 }; |
236 | 237 |
237 #endif // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ | 238 #endif // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ |
OLD | NEW |