| OLD | NEW | 
|    1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2011 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_COCOA_HISTORY_MENU_BRIDGE_H_ |    5 #ifndef CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ | 
|    6 #define CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ |    6 #define CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ | 
|    7  |    7  | 
|    8 #import <Cocoa/Cocoa.h> |    8 #import <Cocoa/Cocoa.h> | 
|    9 #include <map> |    9 #include <map> | 
|   10 #include <vector> |   10 #include <vector> | 
|   11  |   11  | 
|   12 #include "base/mac/scoped_nsobject.h" |   12 #include "base/mac/scoped_nsobject.h" | 
|   13 #include "base/memory/ref_counted.h" |   13 #include "base/memory/ref_counted.h" | 
|   14 #include "base/scoped_observer.h" |   14 #include "base/scoped_observer.h" | 
|   15 #include "base/task/cancelable_task_tracker.h" |   15 #include "base/task/cancelable_task_tracker.h" | 
|   16 #import "chrome/browser/ui/cocoa/main_menu_item.h" |   16 #import "chrome/browser/ui/cocoa/main_menu_item.h" | 
|   17 #import "components/favicon/core/favicon_service.h" |   17 #import "components/favicon/core/favicon_service.h" | 
|   18 #include "components/history/core/browser/history_service.h" |   18 #include "components/history/core/browser/history_service.h" | 
|   19 #include "components/history/core/browser/history_service_observer.h" |   19 #include "components/history/core/browser/history_service_observer.h" | 
|   20 #include "components/sessions/core/tab_restore_service.h" |   20 #include "components/sessions/core/tab_restore_service.h" | 
|   21 #include "components/sessions/core/tab_restore_service_observer.h" |   21 #include "components/sessions/core/tab_restore_service_observer.h" | 
|   22 #include "components/sessions/session_id.h" |   22 #include "components/sessions/session_id.h" | 
|   23  |   23  | 
|   24 class Profile; |   24 class Profile; | 
|   25 class TabRestoreService; |  | 
|   26 @class HistoryMenuCocoaController; |   25 @class HistoryMenuCocoaController; | 
|   27  |   26  | 
|   28 namespace { |   27 namespace { | 
|   29 class HistoryMenuBridgeTest; |   28 class HistoryMenuBridgeTest; | 
|   30 } |   29 } | 
|   31  |   30  | 
|   32 namespace favicon_base { |   31 namespace favicon_base { | 
|   33 struct FaviconImageResult; |   32 struct FaviconImageResult; | 
|   34 } |   33 } | 
|   35  |   34  | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|   48 // have a tag that's equal to the parent + 1. Tags within the history menu have |   47 // have a tag that's equal to the parent + 1. Tags within the history menu have | 
|   49 // a range of [400,500) and do not go through CommandDispatch for their target- |   48 // a range of [400,500) and do not go through CommandDispatch for their target- | 
|   50 // action mechanism. |   49 // action mechanism. | 
|   51 // |   50 // | 
|   52 // These menu items do not use firstResponder as their target. Rather, they are |   51 // These menu items do not use firstResponder as their target. Rather, they are | 
|   53 // hooked directly up to the HistoryMenuCocoaController that then bridges back |   52 // hooked directly up to the HistoryMenuCocoaController that then bridges back | 
|   54 // to this class. These items are created via the AddItemToMenu() helper. Also, |   53 // to this class. These items are created via the AddItemToMenu() helper. Also, | 
|   55 // unlike the typical ownership model, this bridge owns its controller. The |   54 // unlike the typical ownership model, this bridge owns its controller. The | 
|   56 // controller is very thin and only exists to interact with Cocoa, but this |   55 // controller is very thin and only exists to interact with Cocoa, but this | 
|   57 // class does the bulk of the work. |   56 // class does the bulk of the work. | 
|   58 class HistoryMenuBridge : public TabRestoreServiceObserver, |   57 class HistoryMenuBridge : public sessions::TabRestoreServiceObserver, | 
|   59                           public MainMenuItem, |   58                           public MainMenuItem, | 
|   60                           public history::HistoryServiceObserver { |   59                           public history::HistoryServiceObserver { | 
|   61  public: |   60  public: | 
|   62   // This is a generalization of the data we store in the history menu because |   61   // This is a generalization of the data we store in the history menu because | 
|   63   // we pull things from different sources with different data types. |   62   // we pull things from different sources with different data types. | 
|   64   struct HistoryItem { |   63   struct HistoryItem { | 
|   65    public: |   64    public: | 
|   66     HistoryItem(); |   65     HistoryItem(); | 
|   67     // Copy constructor allowed. |   66     // Copy constructor allowed. | 
|   68     HistoryItem(const HistoryItem& copy); |   67     HistoryItem(const HistoryItem& copy); | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  119     kVisitedSeparator = 440,  // Separator before visited section. |  118     kVisitedSeparator = 440,  // Separator before visited section. | 
|  120     kVisitedTitle = 441,  // Title of the visited section. |  119     kVisitedTitle = 441,  // Title of the visited section. | 
|  121     kVisited = 460,  // Used for all entries in the visited section. |  120     kVisited = 460,  // Used for all entries in the visited section. | 
|  122     kShowFullSeparator = 480  // Separator after the visited section. |  121     kShowFullSeparator = 480  // Separator after the visited section. | 
|  123   }; |  122   }; | 
|  124  |  123  | 
|  125   explicit HistoryMenuBridge(Profile* profile); |  124   explicit HistoryMenuBridge(Profile* profile); | 
|  126   ~HistoryMenuBridge() override; |  125   ~HistoryMenuBridge() override; | 
|  127  |  126  | 
|  128   // TabRestoreServiceObserver: |  127   // TabRestoreServiceObserver: | 
|  129   void TabRestoreServiceChanged(TabRestoreService* service) override; |  128   void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; | 
|  130   void TabRestoreServiceDestroyed(TabRestoreService* service) override; |  129   void TabRestoreServiceDestroyed( | 
 |  130       sessions::TabRestoreService* service) override; | 
|  131  |  131  | 
|  132   // MainMenuItem: |  132   // MainMenuItem: | 
|  133   void ResetMenu() override; |  133   void ResetMenu() override; | 
|  134   void BuildMenu() override; |  134   void BuildMenu() override; | 
|  135  |  135  | 
|  136   // Looks up an NSMenuItem in the |menu_item_map_| and returns the |  136   // Looks up an NSMenuItem in the |menu_item_map_| and returns the | 
|  137   // corresponding HistoryItem. |  137   // corresponding HistoryItem. | 
|  138   HistoryItem* HistoryItemForMenuItem(NSMenuItem* item); |  138   HistoryItem* HistoryItemForMenuItem(NSMenuItem* item); | 
|  139  |  139  | 
|  140   // I wish I has a "friend @class" construct. These are used by the HMCC |  140   // I wish I has a "friend @class" construct. These are used by the HMCC | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  172  |  172  | 
|  173   // Invoked when the History information has changed. |  173   // Invoked when the History information has changed. | 
|  174   void OnHistoryChanged(); |  174   void OnHistoryChanged(); | 
|  175  |  175  | 
|  176   // Callback method for when HistoryService query results are ready with the |  176   // Callback method for when HistoryService query results are ready with the | 
|  177   // most recently-visited sites. |  177   // most recently-visited sites. | 
|  178   void OnVisitedHistoryResults(history::QueryResults* results); |  178   void OnVisitedHistoryResults(history::QueryResults* results); | 
|  179  |  179  | 
|  180   // Creates a HistoryItem* for the given tab entry. Caller takes ownership of |  180   // Creates a HistoryItem* for the given tab entry. Caller takes ownership of | 
|  181   // the result and must delete it when finished. |  181   // the result and must delete it when finished. | 
|  182   HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry); |  182   HistoryItem* HistoryItemForTab(const sessions::TabRestoreService::Tab& entry); | 
|  183  |  183  | 
|  184   // Helper function that sends an async request to the FaviconService to get |  184   // Helper function that sends an async request to the FaviconService to get | 
|  185   // an icon. The callback will update the NSMenuItem directly. |  185   // an icon. The callback will update the NSMenuItem directly. | 
|  186   void GetFaviconForHistoryItem(HistoryItem* item); |  186   void GetFaviconForHistoryItem(HistoryItem* item); | 
|  187  |  187  | 
|  188   // Callback for the FaviconService to return favicon image data when we |  188   // Callback for the FaviconService to return favicon image data when we | 
|  189   // request it. This decodes the raw data, updates the HistoryItem, and then |  189   // request it. This decodes the raw data, updates the HistoryItem, and then | 
|  190   // sets the image on the menu. Called on the same same thread that |  190   // sets the image on the menu. Called on the same same thread that | 
|  191   // GetFaviconForHistoryItem() was called on (UI thread). |  191   // GetFaviconForHistoryItem() was called on (UI thread). | 
|  192   void GotFaviconData(HistoryItem* item, |  192   void GotFaviconData(HistoryItem* item, | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  212                      bool all_history, |  212                      bool all_history, | 
|  213                      bool expired, |  213                      bool expired, | 
|  214                      const history::URLRows& deleted_rows, |  214                      const history::URLRows& deleted_rows, | 
|  215                      const std::set<GURL>& favicon_urls) override; |  215                      const std::set<GURL>& favicon_urls) override; | 
|  216   void OnHistoryServiceLoaded(history::HistoryService* service) override; |  216   void OnHistoryServiceLoaded(history::HistoryService* service) override; | 
|  217  |  217  | 
|  218   base::scoped_nsobject<HistoryMenuCocoaController> controller_;  // strong |  218   base::scoped_nsobject<HistoryMenuCocoaController> controller_;  // strong | 
|  219  |  219  | 
|  220   Profile* profile_;  // weak |  220   Profile* profile_;  // weak | 
|  221   history::HistoryService* history_service_;  // weak |  221   history::HistoryService* history_service_;  // weak | 
|  222   TabRestoreService* tab_restore_service_;  // weak |  222   sessions::TabRestoreService* tab_restore_service_;  // weak | 
|  223  |  223  | 
|  224   base::CancelableTaskTracker cancelable_task_tracker_; |  224   base::CancelableTaskTracker cancelable_task_tracker_; | 
|  225  |  225  | 
|  226   // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until |  226   // Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until | 
|  227   // they are removed and deleted via ClearMenuSection(). |  227   // they are removed and deleted via ClearMenuSection(). | 
|  228   std::map<NSMenuItem*, HistoryItem*> menu_item_map_; |  228   std::map<NSMenuItem*, HistoryItem*> menu_item_map_; | 
|  229  |  229  | 
|  230   // Requests to re-create the menu are coalesced. |create_in_progress_| is true |  230   // Requests to re-create the menu are coalesced. |create_in_progress_| is true | 
|  231   // when either waiting for the history service to return query results, or |  231   // when either waiting for the history service to return query results, or | 
|  232   // when the menu is rebuilding. |need_recreate_| is true whenever a rebuild |  232   // when the menu is rebuilding. |need_recreate_| is true whenever a rebuild | 
|  233   // has been scheduled but is waiting for the current one to finish. |  233   // has been scheduled but is waiting for the current one to finish. | 
|  234   bool create_in_progress_; |  234   bool create_in_progress_; | 
|  235   bool need_recreate_; |  235   bool need_recreate_; | 
|  236  |  236  | 
|  237   // The default favicon if a HistoryItem does not have one. |  237   // The default favicon if a HistoryItem does not have one. | 
|  238   base::scoped_nsobject<NSImage> default_favicon_; |  238   base::scoped_nsobject<NSImage> default_favicon_; | 
|  239  |  239  | 
|  240   ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |  240   ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 
|  241       history_service_observer_; |  241       history_service_observer_; | 
|  242  |  242  | 
|  243   DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); |  243   DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); | 
|  244 }; |  244 }; | 
|  245  |  245  | 
|  246 #endif  // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ |  246 #endif  // CHROME_BROWSER_UI_COCOA_HISTORY_MENU_BRIDGE_H_ | 
| OLD | NEW |