15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/mac/scoped_nsobject.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/task/cancelable_task_tracker.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import "chrome/browser/favicon/favicon_service.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/history/history_service.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/tab_restore_service.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/tab_restore_service_observer.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import "chrome/browser/ui/cocoa/main_menu_item.h"
2003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/sessions/session_id.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NotificationRegistrar;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PageUsageData;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TabRestoreService;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class HistoryMenuCocoaController;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryMenuBridgeTest;
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace favicon_base {
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct FaviconImageResult;
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// C++ bridge for the history menu; one per AppController (means there
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is only one). This class observes various data sources, namely the
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryService and the TabRestoreService, and then updates the NSMenu when
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// there is new data.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The history menu is broken up into sections: most visisted and recently
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// closed. The overall menu has a tag of IDC_HISTORY_MENU, with the user content
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// items having the local tags defined in the enum below. Items within a section
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// all share the same tag. The structure of the menu is laid out in MainMenu.xib
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and the generated content is inserted after the Title elements. The recently
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// closed section is special in that those menu items can have submenus to list
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// all the tabs within that closed window. By convention, these submenu items
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// have a tag that's equal to the parent + 1. Tags within the history menu have
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// a range of [400,500) and do not go through CommandDispatch for their target-
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// action mechanism.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// These menu items do not use firstResponder as their target. Rather, they are
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// hooked directly up to the HistoryMenuCocoaController that then bridges back
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to this class. These items are created via the AddItemToMenu() helper. Also,
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// unlike the typical ownership model, this bridge owns its controller. The
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// controller is very thin and only exists to interact with Cocoa, but this
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// class does the bulk of the work.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryMenuBridge : public content::NotificationObserver,
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          public TabRestoreServiceObserver,
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          public MainMenuItem {
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This is a generalization of the data we store in the history menu because
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // we pull things from different sources with different data types.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct HistoryItem {
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    HistoryItem();
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Copy constructor allowed.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    HistoryItem(const HistoryItem& copy);
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ~HistoryItem();
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The title for the menu item.
73a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    base::string16 title;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The URL that will be navigated to if the user selects this item.
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Favicon for the URL.
77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    base::scoped_nsobject<NSImage> icon;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If the icon is being requested from the FaviconService, |icon_requested|
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // will be true and |icon_task_id| will be valid. If this is false, then
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // |icon_task_id| will be
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // base::CancelableTaskTracker::kBadTaskId.
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool icon_requested;
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The Handle given to us by the FaviconService for the icon fetch request.
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::CancelableTaskTracker::TaskId icon_task_id;
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The pointer to the item after it has been created. Strong; NSMenu also
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // retains this. During a rebuild flood (if the user closes a lot of tabs
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // quickly), the NSMenu can release the item before the HistoryItem has
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // been fully deleted. If this were a weak pointer, it would result in a
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // zombie.
92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    base::scoped_nsobject<NSMenuItem> menu_item;
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // This ID is unique for a browser session and can be passed to the
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TabRestoreService to re-open the closed window or tab that this
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // references. A non-0 session ID indicates that this is an entry can be
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // restored that way. Otherwise, the URL will be used to open the item and
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // this ID will be 0.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SessionID::id_type session_id;
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If the HistoryItem is a window, this will be the vector of tabs. Note
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // that this is a list of weak references. The |menu_item_map_| is the owner
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // of all items. If it is not a window, then the entry is a single page and
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the vector will be empty.
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::vector<HistoryItem*> tabs;
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Copying is explicitly allowed, but assignment is not.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void operator=(const HistoryItem&);
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These tags are not global view tags and are local to the history menu. The
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // normal procedure for menu items is to go through CommandDispatch, but since
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history menu items are hooked directly up to their target, they do not need
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to have the global IDC view tags.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Tags {
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kRecentlyClosedSeparator = 400,  // Item before recently closed section.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kRecentlyClosedTitle = 401,  // Title of recently closed section.
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kRecentlyClosed = 420,  // Used for items in the recently closed section.
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kVisitedSeparator = 440,  // Separator before visited section.
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kVisitedTitle = 441,  // Title of the visited section.
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kVisited = 460,  // Used for all entries in the visited section.
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kShowFullSeparator = 480  // Separator after the visited section.
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit HistoryMenuBridge(Profile* profile);
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~HistoryMenuBridge();
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // content::NotificationObserver:
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Observe(int type,
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationSource& source,
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TabRestoreServiceObserver:
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE;
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE;
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // MainMenuItem:
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ResetMenu() OVERRIDE;
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void BuildMenu() OVERRIDE;
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Looks up an NSMenuItem in the |menu_item_map_| and returns the
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // corresponding HistoryItem.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HistoryItem* HistoryItemForMenuItem(NSMenuItem* item);
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // I wish I has a "friend @class" construct. These are used by the HMCC
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to access model information when responding to actions.
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HistoryService* service();
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile();
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the History menu.
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual NSMenu* HistoryMenu();
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Clear items in the given |menu|. Menu items in the same section are given
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the same tag. This will go through the entire history menu, removing all
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // items with a given tag. Note that this will recurse to submenus, removing
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // child items from the menu item map. This will only remove items that have
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a target hooked up to the |controller_|.
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ClearMenuSection(NSMenu* menu, NSInteger tag);
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds a given title and URL to the passed-in menu with a certain tag and
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // index. This will add |item| and the newly created menu item to the
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |menu_item_map_|, which takes ownership. Items are deleted in
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ClearMenuSection(). This returns the new menu item that was just added.
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NSMenuItem* AddItemToMenu(HistoryItem* item,
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            NSMenu* menu,
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            NSInteger tag,
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            NSInteger index);
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the ctor if |service_| is ready at the time, or by a
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // notification receiver. Finishes initialization tasks by subscribing for
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // change notifications and calling CreateMenu().
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Init();
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Does the query for the history information to create the menu.
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CreateMenu();
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Callback method for when HistoryService query results are ready with the
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // most recently-visited sites.
181116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void OnVisitedHistoryResults(history::QueryResults* results);
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates a HistoryItem* for the given tab entry. Caller takes ownership of
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the result and must delete it when finished.
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry);
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper function that sends an async request to the FaviconService to get
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // an icon. The callback will update the NSMenuItem directly.
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetFaviconForHistoryItem(HistoryItem* item);
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Callback for the FaviconService to return favicon image data when we
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // request it. This decodes the raw data, updates the HistoryItem, and then
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // sets the image on the menu. Called on the same same thread that
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // GetFaviconForHistoryItem() was called on (UI thread).
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void GotFaviconData(HistoryItem* item,
1960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                      const favicon_base::FaviconImageResult& image_result);
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels a favicon load request for a given HistoryItem, if one is in
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // progress.
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CancelFaviconRequest(HistoryItem* item);
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::HistoryMenuBridgeTest;
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class HistoryMenuCocoaControllerTest;
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
206eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<HistoryMenuCocoaController> controller_;  // strong
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_;  // weak
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HistoryService* history_service_;  // weak
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabRestoreService* tab_restore_service_;  // weak
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationRegistrar registrar_;
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker cancelable_task_tracker_;
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // they are removed and deleted via ClearMenuSection().
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::map<NSMenuItem*, HistoryItem*> menu_item_map_;
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Requests to re-create the menu are coalesced. |create_in_progress_| is true
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // when either waiting for the history service to return query results, or
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // when the menu is rebuilding. |need_recreate_| is true whenever a rebuild
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // has been scheduled but is waiting for the current one to finish.
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool create_in_progress_;
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool need_recreate_;
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The default favicon if a HistoryItem does not have one.
227eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<NSImage> default_favicon_;
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge);
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_
233