Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/ui/cocoa/history_menu_bridge.h

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to tip Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scoped_observer.h" 14 #include "base/scoped_observer.h"
15 #include "base/task/cancelable_task_tracker.h" 15 #include "base/task/cancelable_task_tracker.h"
16 #import "chrome/browser/favicon/favicon_service.h" 16 #import "chrome/browser/favicon/favicon_service.h"
17 #include "chrome/browser/history/history_service.h" 17 #include "chrome/browser/history/history_service.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 "components/history/core/browser/history_service_observer.h" 21 #include "components/history/core/browser/history_service_observer.h"
22 #include "components/sessions/session_id.h" 22 #include "components/sessions/session_id.h"
23 #include "content/public/browser/notification_observer.h"
24 23
25 class NotificationRegistrar;
26 class PageUsageData; 24 class PageUsageData;
27 class Profile; 25 class Profile;
28 class TabRestoreService; 26 class TabRestoreService;
29 @class HistoryMenuCocoaController; 27 @class HistoryMenuCocoaController;
30 28
31 namespace { 29 namespace {
32 class HistoryMenuBridgeTest; 30 class HistoryMenuBridgeTest;
33 } 31 }
34 32
35 namespace favicon_base { 33 namespace favicon_base {
(...skipping 15 matching lines...) Expand all
51 // have a tag that's equal to the parent + 1. Tags within the history menu have 49 // have a tag that's equal to the parent + 1. Tags within the history menu have
52 // a range of [400,500) and do not go through CommandDispatch for their target- 50 // a range of [400,500) and do not go through CommandDispatch for their target-
53 // action mechanism. 51 // action mechanism.
54 // 52 //
55 // These menu items do not use firstResponder as their target. Rather, they are 53 // These menu items do not use firstResponder as their target. Rather, they are
56 // hooked directly up to the HistoryMenuCocoaController that then bridges back 54 // hooked directly up to the HistoryMenuCocoaController that then bridges back
57 // to this class. These items are created via the AddItemToMenu() helper. Also, 55 // to this class. These items are created via the AddItemToMenu() helper. Also,
58 // unlike the typical ownership model, this bridge owns its controller. The 56 // unlike the typical ownership model, this bridge owns its controller. The
59 // controller is very thin and only exists to interact with Cocoa, but this 57 // controller is very thin and only exists to interact with Cocoa, but this
60 // class does the bulk of the work. 58 // class does the bulk of the work.
61 class HistoryMenuBridge : public content::NotificationObserver, 59 class HistoryMenuBridge : public TabRestoreServiceObserver,
62 public TabRestoreServiceObserver,
63 public MainMenuItem, 60 public MainMenuItem,
64 public history::HistoryServiceObserver { 61 public history::HistoryServiceObserver {
65 public: 62 public:
66 // This is a generalization of the data we store in the history menu because 63 // This is a generalization of the data we store in the history menu because
67 // we pull things from different sources with different data types. 64 // we pull things from different sources with different data types.
68 struct HistoryItem { 65 struct HistoryItem {
69 public: 66 public:
70 HistoryItem(); 67 HistoryItem();
71 // Copy constructor allowed. 68 // Copy constructor allowed.
72 HistoryItem(const HistoryItem& copy); 69 HistoryItem(const HistoryItem& copy);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 kRecentlyClosed = 420, // Used for items in the recently closed section. 119 kRecentlyClosed = 420, // Used for items in the recently closed section.
123 kVisitedSeparator = 440, // Separator before visited section. 120 kVisitedSeparator = 440, // Separator before visited section.
124 kVisitedTitle = 441, // Title of the visited section. 121 kVisitedTitle = 441, // Title of the visited section.
125 kVisited = 460, // Used for all entries in the visited section. 122 kVisited = 460, // Used for all entries in the visited section.
126 kShowFullSeparator = 480 // Separator after the visited section. 123 kShowFullSeparator = 480 // Separator after the visited section.
127 }; 124 };
128 125
129 explicit HistoryMenuBridge(Profile* profile); 126 explicit HistoryMenuBridge(Profile* profile);
130 ~HistoryMenuBridge() override; 127 ~HistoryMenuBridge() override;
131 128
132 // content::NotificationObserver:
133 void Observe(int type,
134 const content::NotificationSource& source,
135 const content::NotificationDetails& details) override;
136
137 // TabRestoreServiceObserver: 129 // TabRestoreServiceObserver:
138 void TabRestoreServiceChanged(TabRestoreService* service) override; 130 void TabRestoreServiceChanged(TabRestoreService* service) override;
139 void TabRestoreServiceDestroyed(TabRestoreService* service) override; 131 void TabRestoreServiceDestroyed(TabRestoreService* service) override;
140 132
141 // MainMenuItem: 133 // MainMenuItem:
142 void ResetMenu() override; 134 void ResetMenu() override;
143 void BuildMenu() override; 135 void BuildMenu() override;
144 136
145 // history::HistoryServiceObserver:
146 void OnURLVisited(HistoryService* history_service,
147 ui::PageTransition transition,
148 const history::URLRow& row,
149 const history::RedirectList& redirects,
150 base::Time visit_time) override;
151 void OnURLsModified(HistoryService* history_service,
152 const history::URLRows& changed_urls) override;
153 void OnHistoryServiceLoaded(HistoryService* service) override;
154
155 // Looks up an NSMenuItem in the |menu_item_map_| and returns the 137 // Looks up an NSMenuItem in the |menu_item_map_| and returns the
156 // corresponding HistoryItem. 138 // corresponding HistoryItem.
157 HistoryItem* HistoryItemForMenuItem(NSMenuItem* item); 139 HistoryItem* HistoryItemForMenuItem(NSMenuItem* item);
158 140
159 // I wish I has a "friend @class" construct. These are used by the HMCC 141 // I wish I has a "friend @class" construct. These are used by the HMCC
160 // to access model information when responding to actions. 142 // to access model information when responding to actions.
161 HistoryService* service(); 143 HistoryService* service();
162 Profile* profile(); 144 Profile* profile();
163 145
164 protected: 146 protected:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const favicon_base::FaviconImageResult& image_result); 194 const favicon_base::FaviconImageResult& image_result);
213 195
214 // Cancels a favicon load request for a given HistoryItem, if one is in 196 // Cancels a favicon load request for a given HistoryItem, if one is in
215 // progress. 197 // progress.
216 void CancelFaviconRequest(HistoryItem* item); 198 void CancelFaviconRequest(HistoryItem* item);
217 199
218 private: 200 private:
219 friend class ::HistoryMenuBridgeTest; 201 friend class ::HistoryMenuBridgeTest;
220 friend class HistoryMenuCocoaControllerTest; 202 friend class HistoryMenuCocoaControllerTest;
221 203
204 // history::HistoryServiceObserver:
205 void OnURLVisited(HistoryService* history_service,
206 ui::PageTransition transition,
207 const history::URLRow& row,
208 const history::RedirectList& redirects,
209 base::Time visit_time) override;
210 void OnURLsModified(HistoryService* history_service,
211 const history::URLRows& changed_urls) override;
212 void OnURLsDeleted(HistoryService* history_service,
213 bool all_history,
214 bool expired,
215 const history::URLRows& deleted_rows,
216 const std::set<GURL>& favicon_urls) override;
217 void OnHistoryServiceLoaded(HistoryService* service) override;
218
222 base::scoped_nsobject<HistoryMenuCocoaController> controller_; // strong 219 base::scoped_nsobject<HistoryMenuCocoaController> controller_; // strong
223 220
224 Profile* profile_; // weak 221 Profile* profile_; // weak
225 HistoryService* history_service_; // weak 222 HistoryService* history_service_; // weak
226 TabRestoreService* tab_restore_service_; // weak 223 TabRestoreService* tab_restore_service_; // weak
227 224
228 content::NotificationRegistrar registrar_;
229 base::CancelableTaskTracker cancelable_task_tracker_; 225 base::CancelableTaskTracker cancelable_task_tracker_;
230 226
231 // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until 227 // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until
232 // they are removed and deleted via ClearMenuSection(). 228 // they are removed and deleted via ClearMenuSection().
233 std::map<NSMenuItem*, HistoryItem*> menu_item_map_; 229 std::map<NSMenuItem*, HistoryItem*> menu_item_map_;
234 230
235 // Requests to re-create the menu are coalesced. |create_in_progress_| is true 231 // Requests to re-create the menu are coalesced. |create_in_progress_| is true
236 // when either waiting for the history service to return query results, or 232 // when either waiting for the history service to return query results, or
237 // when the menu is rebuilding. |need_recreate_| is true whenever a rebuild 233 // when the menu is rebuilding. |need_recreate_| is true whenever a rebuild
238 // has been scheduled but is waiting for the current one to finish. 234 // has been scheduled but is waiting for the current one to finish.
239 bool create_in_progress_; 235 bool create_in_progress_;
240 bool need_recreate_; 236 bool need_recreate_;
241 237
242 // The default favicon if a HistoryItem does not have one. 238 // The default favicon if a HistoryItem does not have one.
243 base::scoped_nsobject<NSImage> default_favicon_; 239 base::scoped_nsobject<NSImage> default_favicon_;
244 240
245 ScopedObserver<HistoryService, HistoryServiceObserver> 241 ScopedObserver<HistoryService, HistoryServiceObserver>
246 history_service_observer_; 242 history_service_observer_;
247 243
248 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); 244 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge);
249 }; 245 };
250 246
251 #endif // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ 247 #endif // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_typed_url_unittest.cc ('k') | chrome/browser/ui/cocoa/history_menu_bridge.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698