OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ | 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ |
6 #define CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ | 6 #define CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/task/cancelable_task_tracker.h" | 12 #include "base/task/cancelable_task_tracker.h" |
13 #include "base/timer/elapsed_timer.h" | 13 #include "base/timer/elapsed_timer.h" |
14 #include "components/favicon/core/favicon_service.h" | 14 #include "components/favicon/core/favicon_service.h" |
15 #include "components/sessions/core/tab_restore_service.h" | 15 #include "components/sessions/core/tab_restore_service.h" |
16 #include "components/sessions/core/tab_restore_service_observer.h" | 16 #include "components/sessions/core/tab_restore_service_observer.h" |
17 #include "components/sync_sessions/synced_session.h" | 17 #include "components/sync_sessions/synced_session.h" |
18 #include "ui/base/accelerators/accelerator.h" | 18 #include "ui/base/accelerators/accelerator.h" |
19 #include "ui/base/models/simple_menu_model.h" | 19 #include "ui/base/models/simple_menu_model.h" |
20 | 20 |
21 class Browser; | 21 class Browser; |
22 | 22 |
23 namespace sync_driver { | |
24 class OpenTabsUIDelegate; | |
25 } | |
26 | |
27 namespace favicon_base { | 23 namespace favicon_base { |
28 struct FaviconImageResult; | 24 struct FaviconImageResult; |
29 } | 25 } |
30 | 26 |
31 namespace gfx { | 27 namespace gfx { |
32 class Image; | 28 class Image; |
33 } | 29 } |
34 | 30 |
35 namespace sessions { | 31 namespace sessions { |
36 struct SessionTab; | 32 struct SessionTab; |
37 } | 33 } |
38 | 34 |
| 35 namespace sync_sessions { |
| 36 class OpenTabsUIDelegate; |
| 37 } |
| 38 |
39 namespace ui { | 39 namespace ui { |
40 class AcceleratorProvider; | 40 class AcceleratorProvider; |
41 } | 41 } |
42 | 42 |
43 // A menu model that builds the contents of "Recent tabs" submenu, which include | 43 // A menu model that builds the contents of "Recent tabs" submenu, which include |
44 // the recently closed tabs/windows of current device i.e. local entries, and | 44 // the recently closed tabs/windows of current device i.e. local entries, and |
45 // opened tabs of other devices. | 45 // opened tabs of other devices. |
46 class RecentTabsSubMenuModel : public ui::SimpleMenuModel, | 46 class RecentTabsSubMenuModel : public ui::SimpleMenuModel, |
47 public ui::SimpleMenuModel::Delegate, | 47 public ui::SimpleMenuModel::Delegate, |
48 public sessions::TabRestoreServiceObserver { | 48 public sessions::TabRestoreServiceObserver { |
49 public: | 49 public: |
50 // Command Id for recently closed items header or disabled item to which the | 50 // Command Id for recently closed items header or disabled item to which the |
51 // accelerator string will be appended. | 51 // accelerator string will be appended. |
52 static const int kRecentlyClosedHeaderCommandId; | 52 static const int kRecentlyClosedHeaderCommandId; |
53 static const int kDisabledRecentlyClosedHeaderCommandId; | 53 static const int kDisabledRecentlyClosedHeaderCommandId; |
54 | 54 |
55 // Exposed for tests only: return the Command Id for the first entry in the | 55 // Exposed for tests only: return the Command Id for the first entry in the |
56 // recently closed window items list. | 56 // recently closed window items list. |
57 static int GetFirstRecentTabsCommandId(); | 57 static int GetFirstRecentTabsCommandId(); |
58 | 58 |
59 // If |open_tabs_delegate| is NULL, the default delegate for |browser|'s | 59 // If |open_tabs_delegate| is NULL, the default delegate for |browser|'s |
60 // profile will be used. Testing may require a specific |open_tabs_delegate|. | 60 // profile will be used. Testing may require a specific |open_tabs_delegate|. |
61 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, | 61 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, |
62 Browser* browser, | 62 Browser* browser, |
63 sync_driver::OpenTabsUIDelegate* open_tabs_delegate); | 63 sync_sessions::OpenTabsUIDelegate* open_tabs_delegate); |
64 ~RecentTabsSubMenuModel() override; | 64 ~RecentTabsSubMenuModel() override; |
65 | 65 |
66 // Overridden from ui::SimpleMenuModel::Delegate: | 66 // Overridden from ui::SimpleMenuModel::Delegate: |
67 bool IsCommandIdChecked(int command_id) const override; | 67 bool IsCommandIdChecked(int command_id) const override; |
68 bool IsCommandIdEnabled(int command_id) const override; | 68 bool IsCommandIdEnabled(int command_id) const override; |
69 bool GetAcceleratorForCommandId(int command_id, | 69 bool GetAcceleratorForCommandId(int command_id, |
70 ui::Accelerator* accelerator) const override; | 70 ui::Accelerator* accelerator) const override; |
71 void ExecuteCommand(int command_id, int event_flags) override; | 71 void ExecuteCommand(int command_id, int event_flags) override; |
72 const gfx::FontList* GetLabelFontListAt(int index) const override; | 72 const gfx::FontList* GetLabelFontListAt(int index) const override; |
73 | 73 |
(...skipping 29 matching lines...) Expand all Loading... |
103 void BuildLocalWindowItem(const SessionID::id_type& window_id, | 103 void BuildLocalWindowItem(const SessionID::id_type& window_id, |
104 int num_tabs, | 104 int num_tabs, |
105 int curr_model_index); | 105 int curr_model_index); |
106 | 106 |
107 // Build the tab item for other devices with parameters needed to restore it. | 107 // Build the tab item for other devices with parameters needed to restore it. |
108 void BuildOtherDevicesTabItem(const std::string& session_tag, | 108 void BuildOtherDevicesTabItem(const std::string& session_tag, |
109 const sessions::SessionTab& tab); | 109 const sessions::SessionTab& tab); |
110 | 110 |
111 // Add the favicon for the device section header. | 111 // Add the favicon for the device section header. |
112 void AddDeviceFavicon(int index_in_menu, | 112 void AddDeviceFavicon(int index_in_menu, |
113 sync_driver::SyncedSession::DeviceType device_type); | 113 sync_sessions::SyncedSession::DeviceType device_type); |
114 | 114 |
115 // Add the favicon for a local or other devices' tab asynchronously, | 115 // Add the favicon for a local or other devices' tab asynchronously, |
116 // OnFaviconDataAvailable() will be invoked when the favicon is ready. | 116 // OnFaviconDataAvailable() will be invoked when the favicon is ready. |
117 void AddTabFavicon(int command_id, const GURL& url); | 117 void AddTabFavicon(int command_id, const GURL& url); |
118 void OnFaviconDataAvailable( | 118 void OnFaviconDataAvailable( |
119 int command_id, | 119 int command_id, |
120 const favicon_base::FaviconImageResult& image_result); | 120 const favicon_base::FaviconImageResult& image_result); |
121 | 121 |
122 // Clear all recently closed tabs and windows. | 122 // Clear all recently closed tabs and windows. |
123 void ClearLocalEntries(); | 123 void ClearLocalEntries(); |
124 | 124 |
125 // Converts |command_id| of menu item to index in local or other devices' | 125 // Converts |command_id| of menu item to index in local or other devices' |
126 // TabNavigationItems, and returns the corresponding local or other devices' | 126 // TabNavigationItems, and returns the corresponding local or other devices' |
127 // TabNavigationItems in |tab_items|. | 127 // TabNavigationItems in |tab_items|. |
128 int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items); | 128 int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items); |
129 | 129 |
130 // Used to access (and lazily initialize) open_tabs_delegate_. | 130 // Used to access (and lazily initialize) open_tabs_delegate_. |
131 // TODO(tim): This lazy-init for member variables is error prone because you | 131 // TODO(tim): This lazy-init for member variables is error prone because you |
132 // can always skip going through the function and access the field directly. | 132 // can always skip going through the function and access the field directly. |
133 // Consider instead having code just deal with potentially NULL open_tabs_ | 133 // Consider instead having code just deal with potentially NULL open_tabs_ |
134 // and have it initialized by an event / callback. | 134 // and have it initialized by an event / callback. |
135 sync_driver::OpenTabsUIDelegate* GetOpenTabsUIDelegate(); | 135 sync_sessions::OpenTabsUIDelegate* GetOpenTabsUIDelegate(); |
136 | 136 |
137 // Overridden from TabRestoreServiceObserver: | 137 // Overridden from TabRestoreServiceObserver: |
138 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; | 138 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; |
139 void TabRestoreServiceDestroyed( | 139 void TabRestoreServiceDestroyed( |
140 sessions::TabRestoreService* service) override; | 140 sessions::TabRestoreService* service) override; |
141 | 141 |
142 Browser* browser_; // Weak. | 142 Browser* browser_; // Weak. |
143 | 143 |
144 sync_driver::OpenTabsUIDelegate* open_tabs_delegate_; // Weak. | 144 sync_sessions::OpenTabsUIDelegate* open_tabs_delegate_; // Weak. |
145 | 145 |
146 // Accelerator for reopening last closed tab. | 146 // Accelerator for reopening last closed tab. |
147 ui::Accelerator reopen_closed_tab_accelerator_; | 147 ui::Accelerator reopen_closed_tab_accelerator_; |
148 | 148 |
149 // Accelerator for showing history. | 149 // Accelerator for showing history. |
150 ui::Accelerator show_history_accelerator_; | 150 ui::Accelerator show_history_accelerator_; |
151 | 151 |
152 // Navigation items for local recently closed tabs. The |command_id| for | 152 // Navigation items for local recently closed tabs. The |command_id| for |
153 // these is set to |kFirstLocalTabCommandId| plus the index into the vector. | 153 // these is set to |kFirstLocalTabCommandId| plus the index into the vector. |
154 // Upon invocation of the menu, the navigation information is retrieved from | 154 // Upon invocation of the menu, the navigation information is retrieved from |
(...skipping 22 matching lines...) Expand all Loading... |
177 | 177 |
178 // Time the menu is open for until a recent tab is selected. | 178 // Time the menu is open for until a recent tab is selected. |
179 base::ElapsedTimer menu_opened_timer_; | 179 base::ElapsedTimer menu_opened_timer_; |
180 | 180 |
181 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_; | 181 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_; |
182 | 182 |
183 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel); | 183 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel); |
184 }; | 184 }; |
185 | 185 |
186 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ | 186 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ |
OLD | NEW |