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/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_nsobject.h" | |
14 #include "chrome/browser/common/cancelable_request.h" | 14 #include "chrome/browser/common/cancelable_request.h" |
15 #import "chrome/browser/favicon/favicon_service.h" | 15 #import "chrome/browser/favicon/favicon_service.h" |
16 #include "chrome/browser/history/history_service.h" | 16 #include "chrome/browser/history/history_service.h" |
17 #include "chrome/browser/sessions/session_id.h" | 17 #include "chrome/browser/sessions/session_id.h" |
18 #include "chrome/browser/sessions/tab_restore_service.h" | 18 #include "chrome/browser/sessions/tab_restore_service.h" |
19 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 19 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
20 #import "chrome/browser/ui/cocoa/main_menu_item.h" | 20 #import "chrome/browser/ui/cocoa/main_menu_item.h" |
21 #include "chrome/common/cancelable_task_tracker.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 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 HistoryItem(); | 68 HistoryItem(); |
69 // Copy constructor allowed. | 69 // Copy constructor allowed. |
70 HistoryItem(const HistoryItem& copy); | 70 HistoryItem(const HistoryItem& copy); |
71 ~HistoryItem(); | 71 ~HistoryItem(); |
72 | 72 |
73 // The title for the menu item. | 73 // The title for the menu item. |
74 string16 title; | 74 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 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 CancelableTaskTracker::kBadTaskId. |
83 bool icon_requested; | 83 bool icon_requested; |
84 // The Handle given to us by the FaviconService for the icon fetch request. | 84 // The Handle given to us by the FaviconService for the icon fetch request. |
85 CancelableTaskTracker::TaskId icon_task_id; | 85 CancelableTaskTracker::TaskId icon_task_id; |
86 | 86 |
87 // The pointer to the item after it has been created. Strong; NSMenu also | 87 // 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 | 88 // 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 | 89 // 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 | 90 // been fully deleted. If this were a weak pointer, it would result in a |
91 // zombie. | 91 // zombie. |
92 scoped_nsobject<NSMenuItem> menu_item; | 92 base::scoped_nsobject<NSMenuItem> menu_item; |
93 | 93 |
94 // This ID is unique for a browser session and can be passed to the | 94 // 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 | 95 // TabRestoreService to re-open the closed window or tab that this |
96 // references. A non-0 session ID indicates that this is an entry can be | 96 // references. A non-0 session ID indicates that this is an entry can be |
97 // restored that way. Otherwise, the URL will be used to open the item and | 97 // restored that way. Otherwise, the URL will be used to open the item and |
98 // this ID will be 0. | 98 // this ID will be 0. |
99 SessionID::id_type session_id; | 99 SessionID::id_type session_id; |
100 | 100 |
101 // If the HistoryItem is a window, this will be the vector of tabs. Note | 101 // If the HistoryItem is a window, this will be the vector of tabs. Note |
102 // that this is a list of weak references. The |menu_item_map_| is the owner | 102 // that this is a list of weak references. The |menu_item_map_| is the owner |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 const chrome::FaviconImageResult& image_result); | 197 const chrome::FaviconImageResult& image_result); |
198 | 198 |
199 // Cancels a favicon load request for a given HistoryItem, if one is in | 199 // Cancels a favicon load request for a given HistoryItem, if one is in |
200 // progress. | 200 // progress. |
201 void CancelFaviconRequest(HistoryItem* item); | 201 void CancelFaviconRequest(HistoryItem* item); |
202 | 202 |
203 private: | 203 private: |
204 friend class ::HistoryMenuBridgeTest; | 204 friend class ::HistoryMenuBridgeTest; |
205 friend class HistoryMenuCocoaControllerTest; | 205 friend class HistoryMenuCocoaControllerTest; |
206 | 206 |
207 scoped_nsobject<HistoryMenuCocoaController> controller_; // strong | 207 base::scoped_nsobject<HistoryMenuCocoaController> controller_; // strong |
208 | 208 |
209 Profile* profile_; // weak | 209 Profile* profile_; // weak |
210 HistoryService* history_service_; // weak | 210 HistoryService* history_service_; // weak |
211 TabRestoreService* tab_restore_service_; // weak | 211 TabRestoreService* tab_restore_service_; // weak |
212 | 212 |
213 content::NotificationRegistrar registrar_; | 213 content::NotificationRegistrar registrar_; |
214 CancelableRequestConsumer cancelable_request_consumer_; | 214 CancelableRequestConsumer cancelable_request_consumer_; |
215 CancelableTaskTracker cancelable_task_tracker_; | 215 CancelableTaskTracker cancelable_task_tracker_; |
216 | 216 |
217 // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until | 217 // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until |
218 // they are removed and deleted via ClearMenuSection(). | 218 // they are removed and deleted via ClearMenuSection(). |
219 std::map<NSMenuItem*, HistoryItem*> menu_item_map_; | 219 std::map<NSMenuItem*, HistoryItem*> menu_item_map_; |
220 | 220 |
221 // Maps HistoryItems to favicon request Handles. | 221 // Maps HistoryItems to favicon request Handles. |
222 CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_; | 222 CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_; |
223 | 223 |
224 // Requests to re-create the menu are coalesced. |create_in_progress_| is true | 224 // 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 | 225 // 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 | 226 // 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. | 227 // has been scheduled but is waiting for the current one to finish. |
228 bool create_in_progress_; | 228 bool create_in_progress_; |
229 bool need_recreate_; | 229 bool need_recreate_; |
230 | 230 |
231 // The default favicon if a HistoryItem does not have one. | 231 // The default favicon if a HistoryItem does not have one. |
232 scoped_nsobject<NSImage> default_favicon_; | 232 base::scoped_nsobject<NSImage> default_favicon_; |
233 | 233 |
234 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); | 234 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); |
235 }; | 235 }; |
236 | 236 |
237 #endif // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ | 237 #endif // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ |
OLD | NEW |