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

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

Issue 74653002: sync: Add --enable-sync-sessions-v2 and necessary plumbing to use SessionsSyncManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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 | Annotate | Revision Log
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/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/favicon/favicon_service.h" 11 #include "chrome/browser/favicon/favicon_service.h"
12 #include "chrome/browser/sessions/tab_restore_service.h" 12 #include "chrome/browser/sessions/tab_restore_service.h"
13 #include "chrome/browser/sessions/tab_restore_service_observer.h" 13 #include "chrome/browser/sessions/tab_restore_service_observer.h"
14 #include "chrome/browser/sync/glue/synced_session.h" 14 #include "chrome/browser/sync/glue/synced_session.h"
15 #include "chrome/common/cancelable_task_tracker.h" 15 #include "chrome/common/cancelable_task_tracker.h"
16 #include "ui/base/accelerators/accelerator.h" 16 #include "ui/base/accelerators/accelerator.h"
17 #include "ui/base/models/simple_menu_model.h" 17 #include "ui/base/models/simple_menu_model.h"
18 18
19 class Browser; 19 class Browser;
20 struct SessionTab; 20 struct SessionTab;
21 21
22 namespace browser_sync { 22 namespace browser_sync {
23 class SessionModelAssociator; 23 class OpenTabsUIDelegate;
24 } 24 }
25 25
26 namespace chrome { 26 namespace chrome {
27 struct FaviconImageResult; 27 struct FaviconImageResult;
28 } 28 }
29 29
30 namespace gfx { 30 namespace gfx {
31 class Image; 31 class Image;
32 } 32 }
33 33
34 namespace ui { 34 namespace ui {
35 class AcceleratorProvider; 35 class AcceleratorProvider;
36 } 36 }
37 37
38 // A menu model that builds the contents of "Recent tabs" submenu, which include 38 // A menu model that builds the contents of "Recent tabs" submenu, which include
39 // the recently closed tabs/windows of current device i.e. local entries, and 39 // the recently closed tabs/windows of current device i.e. local entries, and
40 // opened tabs of other devices. 40 // opened tabs of other devices.
41 class RecentTabsSubMenuModel : public ui::SimpleMenuModel, 41 class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
42 public ui::SimpleMenuModel::Delegate, 42 public ui::SimpleMenuModel::Delegate,
43 public TabRestoreServiceObserver { 43 public TabRestoreServiceObserver {
44 public: 44 public:
45 // Command Id for recently closed items header or disabled item to which the 45 // Command Id for recently closed items header or disabled item to which the
46 // accelerator string will be appended. 46 // accelerator string will be appended.
47 static const int kRecentlyClosedHeaderCommandId; 47 static const int kRecentlyClosedHeaderCommandId;
48 static const int kDisabledRecentlyClosedHeaderCommandId; 48 static const int kDisabledRecentlyClosedHeaderCommandId;
49 49
50 // If |associator| is NULL, default associator for |browser|'s profile will 50 // If |open_tabs_delegate| is NULL, the default delegate for |browser|'s
51 // be used. Testing may require a specific |associator|. 51 // profile will be used. Testing may require a specific |open_tabs_delegate|.
52 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, 52 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider,
53 Browser* browser, 53 Browser* browser,
54 browser_sync::SessionModelAssociator* associator); 54 browser_sync::OpenTabsUIDelegate* open_tabs_delegate);
55 virtual ~RecentTabsSubMenuModel(); 55 virtual ~RecentTabsSubMenuModel();
56 56
57 // Overridden from ui::SimpleMenuModel::Delegate: 57 // Overridden from ui::SimpleMenuModel::Delegate:
58 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 58 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
59 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 59 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
60 virtual bool GetAcceleratorForCommandId( 60 virtual bool GetAcceleratorForCommandId(
61 int command_id, 61 int command_id,
62 ui::Accelerator* accelerator) OVERRIDE; 62 ui::Accelerator* accelerator) OVERRIDE;
63 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 63 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
64 virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE; 64 virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 void OnFaviconDataAvailable(int command_id, 110 void OnFaviconDataAvailable(int command_id,
111 const chrome::FaviconImageResult& image_result); 111 const chrome::FaviconImageResult& image_result);
112 112
113 // Clear all recently closed tabs and windows. 113 // Clear all recently closed tabs and windows.
114 void ClearLocalEntries(); 114 void ClearLocalEntries();
115 115
116 // Converts |command_id| of menu item to index in local or other devices' 116 // Converts |command_id| of menu item to index in local or other devices'
117 // TabNavigationItems, and returns the corresponding local or other devices' 117 // TabNavigationItems, and returns the corresponding local or other devices'
118 // TabNavigationItems in |tab_items|. 118 // TabNavigationItems in |tab_items|.
119 int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items); 119 int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items);
120 browser_sync::SessionModelAssociator* GetModelAssociator(); 120
121 // Used to access (and lazily initialize) open_tabs_delegate_.
122 // TODO(tim): This lazy-init for member variables is error prone because you
123 // can always skip going through the function and access the field directly.
124 // Consider instead having code just deal with potentially NULL open_tabs_
125 // and have it initialized by an event / callback.
126 browser_sync::OpenTabsUIDelegate* GetOpenTabsUIDelegate();
121 127
122 // Overridden from TabRestoreServiceObserver: 128 // Overridden from TabRestoreServiceObserver:
123 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; 129 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE;
124 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; 130 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE;
125 131
126 Browser* browser_; // Weak. 132 Browser* browser_; // Weak.
127 133
128 browser_sync::SessionModelAssociator* associator_; // Weak. 134 browser_sync::OpenTabsUIDelegate* open_tabs_delegate_; // Weak.
129 135
130 // Accelerator for reopening last closed tab. 136 // Accelerator for reopening last closed tab.
131 ui::Accelerator reopen_closed_tab_accelerator_; 137 ui::Accelerator reopen_closed_tab_accelerator_;
132 138
133 // Navigation items for local recently closed tabs. The |command_id| for 139 // Navigation items for local recently closed tabs. The |command_id| for
134 // these is set to |kFirstLocalTabCommandId| plus the index into the vector. 140 // these is set to |kFirstLocalTabCommandId| plus the index into the vector.
135 // Upon invocation of the menu, the navigation information is retrieved from 141 // Upon invocation of the menu, the navigation information is retrieved from
136 // |local_tab_navigation_items_| and used to navigate to the item specified. 142 // |local_tab_navigation_items_| and used to navigate to the item specified.
137 TabNavigationItems local_tab_navigation_items_; 143 TabNavigationItems local_tab_navigation_items_;
138 144
(...skipping 16 matching lines...) Expand all
155 161
156 CancelableTaskTracker local_tab_cancelable_task_tracker_; 162 CancelableTaskTracker local_tab_cancelable_task_tracker_;
157 CancelableTaskTracker other_devices_tab_cancelable_task_tracker_; 163 CancelableTaskTracker other_devices_tab_cancelable_task_tracker_;
158 164
159 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_; 165 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_;
160 166
161 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel); 167 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel);
162 }; 168 };
163 169
164 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ 170 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sessions_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