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

Unified Diff: chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h

Issue 23530070: backup for dynamic recent tabs submenu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new RecentTabsMenuModelDelegate w/ new intf Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h
diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h
index 62d9a078f5d06e99b2b35e5ca29a28c0190d94ec..25ebb1ca0e04dea791f7bb251971896ac4befd6a 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h
+++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h
@@ -10,6 +10,7 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/sessions/tab_restore_service.h"
+#include "chrome/browser/sessions/tab_restore_service_observer.h"
#include "chrome/browser/sync/glue/synced_session.h"
#include "chrome/common/cancelable_task_tracker.h"
#include "ui/base/accelerators/accelerator.h"
@@ -35,9 +36,11 @@ class AcceleratorProvider;
}
// A menu model that builds the contents of "Recent tabs" submenu, which include
-// the last closed tab and opened tabs of other devices.
+// the recently closed tabs/windows of current device i.e. local entries, and
+// opened tabs of other devices i.e. foreign tabs.
class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
- public ui::SimpleMenuModel::Delegate {
+ public ui::SimpleMenuModel::Delegate,
+ public TabRestoreServiceObserver {
public:
// If |associator| is NULL, default associator for |browser|'s profile will
// be used. Testing may require a specific |associator|.
@@ -46,6 +49,11 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
browser_sync::SessionModelAssociator* associator);
virtual ~RecentTabsSubMenuModel();
+ // Converts index in model to item Id in parent menu (i.e. wrench menu).
+ int ModelIndexToIdInParentMenu(int model_index) const;
+ // Converts item Id in parent menu (i.e. wrench menu) to index in model.
+ int IdInParentMenuToModelIndex(int id_in_parent_menu) const;
+
// Overridden from ui::SimpleMenuModel::Delegate:
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
@@ -58,7 +66,7 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
int GetMaxWidthForItemAtIndex(int item_index) const;
bool GetURLAndTitleForItemAtIndex(int index,
std::string* url,
- string16* title) const;
+ string16* title);
// Command Id for recently closed items header or disabled item to which the
// accelerator string will be appended.
@@ -76,21 +84,33 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
// Build the menu items by populating the model.
void Build();
- void BuildRecentTabs();
- void BuildDevices();
+ void BuildLocalEntries();
+ void BuildForeignTabs();
void BuildLocalTabItem(int seesion_id,
const string16& title,
- const GURL& url);
+ const GURL& url,
+ int curr_model_index);
+ void BuildLocalWindowItem(const SessionID::id_type& window_id,
+ int num_tabs,
+ int curr_model_index);
void BuildForeignTabItem(const std::string& session_tag,
const SessionTab& tab);
- void BuildWindowItem(const SessionID::id_type& window_id, int num_tabs);
void AddDeviceFavicon(int index_in_menu,
browser_sync::SyncedSession::DeviceType device_type);
- void AddTabFavicon(int model_index, int command_id, const GURL& url);
+ void AddTabFavicon(int command_id, const GURL& url);
void OnFaviconDataAvailable(int command_id,
const chrome::FaviconImageResult& image_result);
+ void ClearLocalEntries();
+ // Converts |command_id| of menu item to index in local or foreign tab model,
+ // and return the corresponding local or foreign TabNavigationItems in
+ // |tab_items|.
+ int CommandIdToTabModelIndex(int command_id, TabNavigationItems** tab_items);
browser_sync::SessionModelAssociator* GetModelAssociator();
+ // Overridden from TabRestoreServiceObserver:
+ virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE;
+ virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE;
+
Browser* browser_; // Weak.
browser_sync::SessionModelAssociator* associator_; // Weak.
@@ -98,21 +118,30 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
// Accelerator for reopening last closed tab.
ui::Accelerator reopen_closed_tab_accelerator_;
- // Navigation items for other devices and recent tabs. The |command_id| for
- // these is set to kFirstTabCommandId plus the index into the vector. Upon
- // invocation of the menu, the navigation information is retrieved from
- // |tab_navigation_items_| and used to navigate to the item specified.
- TabNavigationItems tab_navigation_items_;
+ // Navigation items for local recently closed tabs. The |command_id| for
+ // these is set to kFirstLocalTabCommandId plus the index into the vector.
+ // Upon invocation of the menu, the navigation information is retrieved from
+ // |local_tab_navigation_items_| and used to navigate to the item specified.
+ TabNavigationItems local_tab_navigation_items_;
+
+ // Similar to |local_tab_navigation_items_| except the tabs are foreign i.e.
+ // opened tabs from other devices, and the first |command_id| is
+ // kFirstForeignTabCommandId.
+ TabNavigationItems foreign_tab_navigation_items_;
+
+ // Window items for local recently closed windows. The |command_id| for
+ // these is set to kFirstLocalWindowCommandId plus the index into the vector.
+ // Upon invocation of the menu, information is retrieved from
+ // |local_window_items_| and used to create the specified window.
+ WindowItems local_window_items_;
- // Window items for recently closed windows. The |command_id| for
- // these is set to kFirstWindowCommandId plus the index into the vector. Upon
- // invocation of the menu, information is retrieved from |window_items_|
- // and used to create the specified window.
- WindowItems window_items_;
+ // Index of the last local entry (recently closed tab or window) in the model.
+ int last_local_model_index_;
gfx::Image default_favicon_;
- CancelableTaskTracker cancelable_task_tracker_;
+ CancelableTaskTracker local_tab_cancelable_task_tracker_;
+ CancelableTaskTracker foreign_tab_cancelable_task_tracker_;
base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_;
« no previous file with comments | « no previous file | 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