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 "base/task/cancelable_task_tracker.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/tab_restore_service.h" | 17 #include "chrome/browser/sessions/tab_restore_service.h" |
18 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 18 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
19 #import "chrome/browser/ui/cocoa/main_menu_item.h" | 19 #import "chrome/browser/ui/cocoa/main_menu_item.h" |
20 #include "components/history/core/browser/history_service_observer.h" | |
20 #include "components/sessions/session_id.h" | 21 #include "components/sessions/session_id.h" |
21 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
22 | 23 |
23 class NotificationRegistrar; | 24 class NotificationRegistrar; |
24 class PageUsageData; | 25 class PageUsageData; |
25 class Profile; | 26 class Profile; |
26 class TabRestoreService; | 27 class TabRestoreService; |
27 @class HistoryMenuCocoaController; | 28 @class HistoryMenuCocoaController; |
28 | 29 |
29 namespace { | 30 namespace { |
(...skipping 21 matching lines...) Expand all Loading... | |
51 // action mechanism. | 52 // action mechanism. |
52 // | 53 // |
53 // These menu items do not use firstResponder as their target. Rather, they are | 54 // These menu items do not use firstResponder as their target. Rather, they are |
54 // hooked directly up to the HistoryMenuCocoaController that then bridges back | 55 // hooked directly up to the HistoryMenuCocoaController that then bridges back |
55 // to this class. These items are created via the AddItemToMenu() helper. Also, | 56 // to this class. These items are created via the AddItemToMenu() helper. Also, |
56 // unlike the typical ownership model, this bridge owns its controller. The | 57 // unlike the typical ownership model, this bridge owns its controller. The |
57 // controller is very thin and only exists to interact with Cocoa, but this | 58 // controller is very thin and only exists to interact with Cocoa, but this |
58 // class does the bulk of the work. | 59 // class does the bulk of the work. |
59 class HistoryMenuBridge : public content::NotificationObserver, | 60 class HistoryMenuBridge : public content::NotificationObserver, |
60 public TabRestoreServiceObserver, | 61 public TabRestoreServiceObserver, |
61 public MainMenuItem { | 62 public MainMenuItem, |
63 public history::HistoryServiceObserver { | |
62 public: | 64 public: |
63 // This is a generalization of the data we store in the history menu because | 65 // This is a generalization of the data we store in the history menu because |
64 // we pull things from different sources with different data types. | 66 // we pull things from different sources with different data types. |
65 struct HistoryItem { | 67 struct HistoryItem { |
66 public: | 68 public: |
67 HistoryItem(); | 69 HistoryItem(); |
68 // Copy constructor allowed. | 70 // Copy constructor allowed. |
69 HistoryItem(const HistoryItem& copy); | 71 HistoryItem(const HistoryItem& copy); |
70 ~HistoryItem(); | 72 ~HistoryItem(); |
71 | 73 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 }; | 126 }; |
125 | 127 |
126 explicit HistoryMenuBridge(Profile* profile); | 128 explicit HistoryMenuBridge(Profile* profile); |
127 virtual ~HistoryMenuBridge(); | 129 virtual ~HistoryMenuBridge(); |
128 | 130 |
129 // content::NotificationObserver: | 131 // content::NotificationObserver: |
130 virtual void Observe(int type, | 132 virtual void Observe(int type, |
131 const content::NotificationSource& source, | 133 const content::NotificationSource& source, |
132 const content::NotificationDetails& details) override; | 134 const content::NotificationDetails& details) override; |
133 | 135 |
136 // history::HistoryServiceObserver: | |
Peter Kasting
2014/10/17 20:41:03
Nit: Please place overrides for classes in the sam
| |
137 virtual void OnURLVisited(HistoryService* history_service, | |
138 ui::PageTransition transition, | |
139 const history::URLRow& row, | |
140 const history::RedirectList& redirects, | |
141 base::Time visit_time) override; | |
142 | |
134 // TabRestoreServiceObserver: | 143 // TabRestoreServiceObserver: |
135 virtual void TabRestoreServiceChanged(TabRestoreService* service) override; | 144 virtual void TabRestoreServiceChanged(TabRestoreService* service) override; |
136 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) override; | 145 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) override; |
137 | 146 |
138 // MainMenuItem: | 147 // MainMenuItem: |
139 virtual void ResetMenu() override; | 148 virtual void ResetMenu() override; |
140 virtual void BuildMenu() override; | 149 virtual void BuildMenu() override; |
141 | 150 |
142 // Looks up an NSMenuItem in the |menu_item_map_| and returns the | 151 // Looks up an NSMenuItem in the |menu_item_map_| and returns the |
143 // corresponding HistoryItem. | 152 // corresponding HistoryItem. |
(...skipping 25 matching lines...) Expand all Loading... | |
169 NSInteger index); | 178 NSInteger index); |
170 | 179 |
171 // Called by the ctor if |service_| is ready at the time, or by a | 180 // Called by the ctor if |service_| is ready at the time, or by a |
172 // notification receiver. Finishes initialization tasks by subscribing for | 181 // notification receiver. Finishes initialization tasks by subscribing for |
173 // change notifications and calling CreateMenu(). | 182 // change notifications and calling CreateMenu(). |
174 void Init(); | 183 void Init(); |
175 | 184 |
176 // Does the query for the history information to create the menu. | 185 // Does the query for the history information to create the menu. |
177 void CreateMenu(); | 186 void CreateMenu(); |
178 | 187 |
188 // Invoked when the History information has changed. | |
189 void OnHistoryChanged(); | |
190 | |
179 // Callback method for when HistoryService query results are ready with the | 191 // Callback method for when HistoryService query results are ready with the |
180 // most recently-visited sites. | 192 // most recently-visited sites. |
181 void OnVisitedHistoryResults(history::QueryResults* results); | 193 void OnVisitedHistoryResults(history::QueryResults* results); |
182 | 194 |
183 // Creates a HistoryItem* for the given tab entry. Caller takes ownership of | 195 // Creates a HistoryItem* for the given tab entry. Caller takes ownership of |
184 // the result and must delete it when finished. | 196 // the result and must delete it when finished. |
185 HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry); | 197 HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry); |
186 | 198 |
187 // Helper function that sends an async request to the FaviconService to get | 199 // Helper function that sends an async request to the FaviconService to get |
188 // an icon. The callback will update the NSMenuItem directly. | 200 // an icon. The callback will update the NSMenuItem directly. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 bool create_in_progress_; | 235 bool create_in_progress_; |
224 bool need_recreate_; | 236 bool need_recreate_; |
225 | 237 |
226 // The default favicon if a HistoryItem does not have one. | 238 // The default favicon if a HistoryItem does not have one. |
227 base::scoped_nsobject<NSImage> default_favicon_; | 239 base::scoped_nsobject<NSImage> default_favicon_; |
228 | 240 |
229 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); | 241 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); |
230 }; | 242 }; |
231 | 243 |
232 #endif // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ | 244 #endif // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ |
OLD | NEW |