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

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

Issue 11298004: alternate ntp: add "Recent Tabs" submenu to wrench menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed fred's comments Created 8 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..c453700029c34d7de69ce13e2c1f434224d200b5
--- /dev/null
+++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h
@@ -0,0 +1,95 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_
+#define CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_
+
+#include <set>
+
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/favicon/favicon_service.h"
+#include "chrome/browser/sessions/tab_restore_service.h"
+#include "ui/base/accelerators/accelerator.h"
+#include "ui/base/models/simple_menu_model.h"
+
+class Browser;
+struct SessionTab;
+
+namespace browser_sync {
+class SessionModelAssociator;
+}
+
+namespace gfx {
+class Image;
+}
+
+namespace ui {
+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.
+class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
+ public ui::SimpleMenuModel::Delegate {
+ public:
+ RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider,
+ Browser* browser);
+ // Constructor for testing.
+ RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider,
+ Browser* browser,
+ browser_sync::SessionModelAssociator* associator,
+ bool setup_for_test);
+ virtual ~RecentTabsSubMenuModel();
+
+ // Overridden from ui::SimpleMenuModel::Delegate:
+ virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
+ virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
+ virtual bool GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) OVERRIDE;
+ virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
+ virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE;
+ virtual void ExecuteCommand(int command_id) OVERRIDE;
+ virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
+
+ private:
+ struct NavigationItem;
+ typedef std::vector<NavigationItem> NavigationItems;
+
+ // Build the menu items by populating the model.
+ void Build();
+ void BuildLastClosed();
+ void BuildDevices();
+ void BuildForeignTabItem(const std::string& session_tag,
+ const SessionTab& tab,
+ const std::string& session_name,
+ bool need_separator);
+ void AddFavicon(int model_index, int command_id, const GURL& url);
+ void OnFaviconDataAvailable(FaviconService::Handle handle,
+ const history::FaviconImageResult& image_result);
+ browser_sync::SessionModelAssociator* GetModelAssociator();
+
+ Browser* browser_; // Weak.
+
+ browser_sync::SessionModelAssociator* associator_; // Weak.
+
+ // Accelerator for reopening last closed tab.
+ ui::Accelerator reopen_closed_tab_accelerator_;
+
+ // Navigation items. The |command_id| is set to kFirstTabCommandId plus the
+ // index into this vector. Upon invocation of the menu, the navigation
+ // information is retrieved from |model_| and used to navigate to the item
+ // specified.
+ NavigationItems model_;
+
+ gfx::Image default_favicon_;
+
+ CancelableRequestConsumerTSimple<int> favicon_consumer_;
+
+ base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel);
+};
+
+#endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_

Powered by Google App Engine
This is Rietveld 408576698