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

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: Created 3 years, 9 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/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/driver/sync_service_observer.h"
17 #include "components/sync_sessions/synced_session.h" 18 #include "components/sync_sessions/synced_session.h"
18 #include "ui/base/accelerators/accelerator.h" 19 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/base/models/simple_menu_model.h" 20 #include "ui/base/models/simple_menu_model.h"
20 21
21 class Browser; 22 class Browser;
22 23
23 namespace favicon_base { 24 namespace favicon_base {
24 struct FaviconImageResult; 25 struct FaviconImageResult;
25 } 26 }
26 27
27 namespace gfx { 28 namespace gfx {
28 class Image; 29 class Image;
29 } 30 }
30 31
31 namespace sessions { 32 namespace sessions {
32 struct SessionTab; 33 struct SessionTab;
33 } 34 }
34 35
35 namespace sync_sessions { 36 namespace sync_sessions {
36 class OpenTabsUIDelegate; 37 class OpenTabsUIDelegate;
37 } 38 }
38 39
40 namespace syncer {
41 class SyncService;
42 } // namespace syncer
43
39 namespace ui { 44 namespace ui {
40 class AcceleratorProvider; 45 class AcceleratorProvider;
41 } 46 }
42 47
43 // A menu model that builds the contents of "Recent tabs" submenu, which include 48 // 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 49 // the recently closed tabs/windows of current device i.e. local entries, and
45 // opened tabs of other devices. 50 // opened tabs of other devices.
46 class RecentTabsSubMenuModel : public ui::SimpleMenuModel, 51 class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
47 public ui::SimpleMenuModel::Delegate, 52 public ui::SimpleMenuModel::Delegate,
48 public sessions::TabRestoreServiceObserver { 53 public sessions::TabRestoreServiceObserver,
54 public syncer::SyncServiceObserver {
49 public: 55 public:
50 // Command Id for recently closed items header or disabled item to which the 56 // Command Id for recently closed items header or disabled item to which the
51 // accelerator string will be appended. 57 // accelerator string will be appended.
52 static const int kRecentlyClosedHeaderCommandId; 58 static const int kRecentlyClosedHeaderCommandId;
53 static const int kDisabledRecentlyClosedHeaderCommandId; 59 static const int kDisabledRecentlyClosedHeaderCommandId;
54 60
55 // Exposed for tests only: return the Command Id for the first entry in the 61 // Exposed for tests only: return the Command Id for the first entry in the
56 // recently closed window items list. 62 // recently closed window items list.
57 static int GetFirstRecentTabsCommandId(); 63 static int GetFirstRecentTabsCommandId();
58 64
59 // If |open_tabs_delegate| is NULL, the default delegate for |browser|'s 65 // 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|. 66 // profile will be used.
61 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, 67 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider,
62 Browser* browser, 68 Browser* browser);
63 sync_sessions::OpenTabsUIDelegate* open_tabs_delegate);
64 ~RecentTabsSubMenuModel() override; 69 ~RecentTabsSubMenuModel() override;
65 70
66 // Overridden from ui::SimpleMenuModel::Delegate: 71 // Overridden from ui::SimpleMenuModel::Delegate:
67 bool IsCommandIdChecked(int command_id) const override; 72 bool IsCommandIdChecked(int command_id) const override;
68 bool IsCommandIdEnabled(int command_id) const override; 73 bool IsCommandIdEnabled(int command_id) const override;
69 bool GetAcceleratorForCommandId(int command_id, 74 bool GetAcceleratorForCommandId(int command_id,
70 ui::Accelerator* accelerator) const override; 75 ui::Accelerator* accelerator) const override;
71 void ExecuteCommand(int command_id, int event_flags) override; 76 void ExecuteCommand(int command_id, int event_flags) override;
72 const gfx::FontList* GetLabelFontListAt(int index) const override; 77 const gfx::FontList* GetLabelFontListAt(int index) const override;
73 78
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Add the favicon for a local or other devices' tab asynchronously, 120 // Add the favicon for a local or other devices' tab asynchronously,
116 // OnFaviconDataAvailable() will be invoked when the favicon is ready. 121 // OnFaviconDataAvailable() will be invoked when the favicon is ready.
117 void AddTabFavicon(int command_id, const GURL& url); 122 void AddTabFavicon(int command_id, const GURL& url);
118 void OnFaviconDataAvailable( 123 void OnFaviconDataAvailable(
119 int command_id, 124 int command_id,
120 const favicon_base::FaviconImageResult& image_result); 125 const favicon_base::FaviconImageResult& image_result);
121 126
122 // Clear all recently closed tabs and windows. 127 // Clear all recently closed tabs and windows.
123 void ClearLocalEntries(); 128 void ClearLocalEntries();
124 129
130 // Clear all tabs from other devices.
Peter Kasting 2017/03/23 04:48:34 Nit: Clear -> Clears; see http://google.github.io/
Peter Kasting 2017/03/24 00:06:27 Looks like you removed this comment instead of upd
131 void ClearTabsFromOtherDevices();
132
125 // Converts |command_id| of menu item to index in local or other devices' 133 // Converts |command_id| of menu item to index in local or other devices'
126 // TabNavigationItems, and returns the corresponding local or other devices' 134 // TabNavigationItems, and returns the corresponding local or other devices'
127 // TabNavigationItems in |tab_items|. 135 // TabNavigationItems in |tab_items|.
128 int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items); 136 int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items);
129 137
130 // Used to access (and lazily initialize) open_tabs_delegate_. 138 // Used to access (and lazily initialize) open_tabs_delegate_.
131 // TODO(tim): This lazy-init for member variables is error prone because you 139 // 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. 140 // can always skip going through the function and access the field directly.
133 // Consider instead having code just deal with potentially NULL open_tabs_ 141 // Consider instead having code just deal with potentially NULL open_tabs_
134 // and have it initialized by an event / callback. 142 // and have it initialized by an event / callback.
135 sync_sessions::OpenTabsUIDelegate* GetOpenTabsUIDelegate(); 143 sync_sessions::OpenTabsUIDelegate* GetOpenTabsUIDelegate();
136 144
137 // Overridden from TabRestoreServiceObserver: 145 // Overridden from TabRestoreServiceObserver:
138 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; 146 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override;
139 void TabRestoreServiceDestroyed( 147 void TabRestoreServiceDestroyed(
140 sessions::TabRestoreService* service) override; 148 sessions::TabRestoreService* service) override;
141 149
150 // Overridden from syncer::SyncServiceObserver
Peter Kasting 2017/03/23 04:48:34 Nit: Trailing colon
Peter Kasting 2017/03/24 00:06:27 Looks like you removed the namespace instead of ad
151 void OnSyncCycleCompleted(syncer::SyncService* sync) override {}
Peter Kasting 2017/03/23 04:48:34 Nit: I'd weakly prefer defining this in the .cc th
152 void OnForeignSessionUpdated(syncer::SyncService* sync) override;
153
142 Browser* browser_; // Weak. 154 Browser* browser_; // Weak.
143 155
144 sync_sessions::OpenTabsUIDelegate* open_tabs_delegate_; // Weak. 156 sync_sessions::OpenTabsUIDelegate* open_tabs_delegate_ = nullptr; // Weak.
Peter Kasting 2017/03/23 04:48:34 Nit: I'm a fan of initializing at the declaration
145 157
146 // Accelerator for reopening last closed tab. 158 // Accelerator for reopening last closed tab.
147 ui::Accelerator reopen_closed_tab_accelerator_; 159 ui::Accelerator reopen_closed_tab_accelerator_;
148 160
149 // Accelerator for showing history. 161 // Accelerator for showing history.
150 ui::Accelerator show_history_accelerator_; 162 ui::Accelerator show_history_accelerator_;
151 163
152 // Navigation items for local recently closed tabs. The |command_id| for 164 // Navigation items for local recently closed tabs. The |command_id| for
153 // these is set to |kFirstLocalTabCommandId| plus the index into the vector. 165 // these is set to |kFirstLocalTabCommandId| plus the index into the vector.
154 // Upon invocation of the menu, the navigation information is retrieved from 166 // Upon invocation of the menu, the navigation information is retrieved from
(...skipping 22 matching lines...) Expand all
177 189
178 // Time the menu is open for until a recent tab is selected. 190 // Time the menu is open for until a recent tab is selected.
179 base::ElapsedTimer menu_opened_timer_; 191 base::ElapsedTimer menu_opened_timer_;
180 192
181 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_; 193 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_;
182 194
183 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel); 195 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel);
184 }; 196 };
185 197
186 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ 198 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698