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

Side by Side Diff: chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h

Issue 2768633003: Dynamic updating recent menu for tabs from other devices. (Closed)
Patch Set: Fixes compilation and test on Mac. Created 3 years, 8 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 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/scoped_observer.h"
12 #include "base/task/cancelable_task_tracker.h" 13 #include "base/task/cancelable_task_tracker.h"
13 #include "base/timer/elapsed_timer.h" 14 #include "base/timer/elapsed_timer.h"
14 #include "components/favicon/core/favicon_service.h" 15 #include "components/favicon/core/favicon_service.h"
15 #include "components/sessions/core/tab_restore_service.h" 16 #include "components/sessions/core/tab_restore_service.h"
16 #include "components/sessions/core/tab_restore_service_observer.h" 17 #include "components/sessions/core/tab_restore_service_observer.h"
18 #include "components/sync/driver/sync_service_observer.h"
17 #include "components/sync_sessions/synced_session.h" 19 #include "components/sync_sessions/synced_session.h"
18 #include "ui/base/accelerators/accelerator.h" 20 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/base/models/simple_menu_model.h" 21 #include "ui/base/models/simple_menu_model.h"
20 22
21 class Browser; 23 class Browser;
22 24
23 namespace favicon_base { 25 namespace favicon_base {
24 struct FaviconImageResult; 26 struct FaviconImageResult;
25 } 27 }
26 28
27 namespace gfx { 29 namespace gfx {
28 class Image; 30 class Image;
29 } 31 }
30 32
31 namespace sessions { 33 namespace sessions {
32 struct SessionTab; 34 struct SessionTab;
33 } 35 }
34 36
35 namespace sync_sessions { 37 namespace sync_sessions {
36 class OpenTabsUIDelegate; 38 class OpenTabsUIDelegate;
37 } 39 }
38 40
41 namespace syncer {
42 class SyncService;
43 class SyncServiceBase;
44 } // namespace syncer
45
39 namespace ui { 46 namespace ui {
40 class AcceleratorProvider; 47 class AcceleratorProvider;
41 } 48 }
42 49
43 // A menu model that builds the contents of "Recent tabs" submenu, which include 50 // 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 51 // the recently closed tabs/windows of current device i.e. local entries, and
45 // opened tabs of other devices. 52 // opened tabs of other devices.
46 class RecentTabsSubMenuModel : public ui::SimpleMenuModel, 53 class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
47 public ui::SimpleMenuModel::Delegate, 54 public ui::SimpleMenuModel::Delegate,
48 public sessions::TabRestoreServiceObserver { 55 public sessions::TabRestoreServiceObserver,
56 public syncer::SyncServiceObserver {
49 public: 57 public:
50 // Command Id for recently closed items header or disabled item to which the 58 // Command Id for recently closed items header or disabled item to which the
51 // accelerator string will be appended. 59 // accelerator string will be appended.
52 static const int kRecentlyClosedHeaderCommandId; 60 static const int kRecentlyClosedHeaderCommandId;
53 static const int kDisabledRecentlyClosedHeaderCommandId; 61 static const int kDisabledRecentlyClosedHeaderCommandId;
54 62
55 // Exposed for tests only: return the Command Id for the first entry in the 63 // Exposed for tests only: return the Command Id for the first entry in the
56 // recently closed window items list. 64 // recently closed window items list.
57 static int GetFirstRecentTabsCommandId(); 65 static int GetFirstRecentTabsCommandId();
58 66
59 // If |open_tabs_delegate| is NULL, the default delegate for |browser|'s 67 // 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|. 68 // profile will be used.
61 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, 69 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider,
62 Browser* browser, 70 Browser* browser);
63 sync_sessions::OpenTabsUIDelegate* open_tabs_delegate);
64 ~RecentTabsSubMenuModel() override; 71 ~RecentTabsSubMenuModel() override;
65 72
66 // Overridden from ui::SimpleMenuModel::Delegate: 73 // Overridden from ui::SimpleMenuModel::Delegate:
67 bool IsCommandIdChecked(int command_id) const override; 74 bool IsCommandIdChecked(int command_id) const override;
68 bool IsCommandIdEnabled(int command_id) const override; 75 bool IsCommandIdEnabled(int command_id) const override;
69 bool GetAcceleratorForCommandId(int command_id, 76 bool GetAcceleratorForCommandId(int command_id,
70 ui::Accelerator* accelerator) const override; 77 ui::Accelerator* accelerator) const override;
71 void ExecuteCommand(int command_id, int event_flags) override; 78 void ExecuteCommand(int command_id, int event_flags) override;
72 const gfx::FontList* GetLabelFontListAt(int index) const override; 79 const gfx::FontList* GetLabelFontListAt(int index) const override;
73 80
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Add the favicon for a local or other devices' tab asynchronously, 122 // Add the favicon for a local or other devices' tab asynchronously,
116 // OnFaviconDataAvailable() will be invoked when the favicon is ready. 123 // OnFaviconDataAvailable() will be invoked when the favicon is ready.
117 void AddTabFavicon(int command_id, const GURL& url); 124 void AddTabFavicon(int command_id, const GURL& url);
118 void OnFaviconDataAvailable( 125 void OnFaviconDataAvailable(
119 int command_id, 126 int command_id,
120 const favicon_base::FaviconImageResult& image_result); 127 const favicon_base::FaviconImageResult& image_result);
121 128
122 // Clear all recently closed tabs and windows. 129 // Clear all recently closed tabs and windows.
123 void ClearLocalEntries(); 130 void ClearLocalEntries();
124 131
132 // Clears all tabs from other devices.
133 void ClearTabsFromOtherDevices();
134
125 // Converts |command_id| of menu item to index in local or other devices' 135 // Converts |command_id| of menu item to index in local or other devices'
126 // TabNavigationItems, and returns the corresponding local or other devices' 136 // TabNavigationItems, and returns the corresponding local or other devices'
127 // TabNavigationItems in |tab_items|. 137 // TabNavigationItems in |tab_items|.
128 int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items); 138 int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items);
129 139
130 // Used to access (and lazily initialize) open_tabs_delegate_. 140 // Used to access (and lazily initialize) open_tabs_delegate_.
131 // TODO(tim): This lazy-init for member variables is error prone because you 141 // 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. 142 // can always skip going through the function and access the field directly.
133 // Consider instead having code just deal with potentially NULL open_tabs_ 143 // Consider instead having code just deal with potentially NULL open_tabs_
134 // and have it initialized by an event / callback. 144 // and have it initialized by an event / callback.
135 sync_sessions::OpenTabsUIDelegate* GetOpenTabsUIDelegate(); 145 sync_sessions::OpenTabsUIDelegate* GetOpenTabsUIDelegate();
136 146
137 // Overridden from TabRestoreServiceObserver: 147 // Overridden from TabRestoreServiceObserver:
138 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; 148 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override;
139 void TabRestoreServiceDestroyed( 149 void TabRestoreServiceDestroyed(
140 sessions::TabRestoreService* service) override; 150 sessions::TabRestoreService* service) override;
141 151
152 // Overridden from syncer::SyncServiceObserver:
153 void OnSyncConfigurationCompleted(syncer::SyncService* sync) override;
154 void OnForeignSessionUpdated(syncer::SyncService* sync) override;
155
142 Browser* browser_; // Weak. 156 Browser* browser_; // Weak.
143 157
144 sync_sessions::OpenTabsUIDelegate* open_tabs_delegate_; // Weak. 158 sync_sessions::OpenTabsUIDelegate* open_tabs_delegate_; // Weak.
145 159
146 // Accelerator for reopening last closed tab. 160 // Accelerator for reopening last closed tab.
147 ui::Accelerator reopen_closed_tab_accelerator_; 161 ui::Accelerator reopen_closed_tab_accelerator_;
148 162
149 // Accelerator for showing history. 163 // Accelerator for showing history.
150 ui::Accelerator show_history_accelerator_; 164 ui::Accelerator show_history_accelerator_;
151 165
(...skipping 19 matching lines...) Expand all
171 int last_local_model_index_; 185 int last_local_model_index_;
172 186
173 gfx::Image default_favicon_; 187 gfx::Image default_favicon_;
174 188
175 base::CancelableTaskTracker local_tab_cancelable_task_tracker_; 189 base::CancelableTaskTracker local_tab_cancelable_task_tracker_;
176 base::CancelableTaskTracker other_devices_tab_cancelable_task_tracker_; 190 base::CancelableTaskTracker other_devices_tab_cancelable_task_tracker_;
177 191
178 // Time the menu is open for until a recent tab is selected. 192 // Time the menu is open for until a recent tab is selected.
179 base::ElapsedTimer menu_opened_timer_; 193 base::ElapsedTimer menu_opened_timer_;
180 194
195 // Mac doesn't support the dynamic menu.
196 #if !defined(OS_MACOSX)
197 ScopedObserver<sessions::TabRestoreService, RecentTabsSubMenuModel>
198 tab_restore_service_observer_;
199
200 ScopedObserver<syncer::SyncServiceBase, RecentTabsSubMenuModel>
201 sync_observer_;
202 #endif
203
181 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_; 204 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_;
182 205
183 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel); 206 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel);
184 }; 207 };
185 208
186 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ 209 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.cc ('k') | chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698