[email protected] | 46441d1 | 2012-02-28 07:27:02 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_ |
| 6 | #define CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | bdaab67c | 2010-12-30 00:50:04 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | f61f003a | 2014-06-16 14:39:25 | [diff] [blame] | 13 | #include "base/task/cancelable_task_tracker.h" |
sdefresne | bc766ef | 2014-09-25 09:28:13 | [diff] [blame] | 14 | #include "components/history/core/browser/history_types.h" |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 15 | #include "ui/base/models/table_model.h" |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 16 | |
stevenjb | 7bd17418 | 2015-10-27 21:04:01 | [diff] [blame] | 17 | class Browser; |
[email protected] | c3a4bd99 | 2010-08-18 20:25:01 | [diff] [blame] | 18 | class GURL; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 19 | class Profile; |
[email protected] | f61f003a | 2014-06-16 14:39:25 | [diff] [blame] | 20 | |
| 21 | namespace history { |
| 22 | class URLRow; |
| 23 | } |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 24 | |
| 25 | namespace ui { |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 26 | class TableModelObserver; |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 27 | } |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 28 | |
| 29 | // CustomHomePagesTableModel is the model for the TableView showing the list |
| 30 | // of pages the user wants opened on startup. |
| 31 | |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 32 | class CustomHomePagesTableModel : public ui::TableModel { |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 33 | public: |
| 34 | explicit CustomHomePagesTableModel(Profile* profile); |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 35 | ~CustomHomePagesTableModel() override; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 36 | |
| 37 | // Sets the set of urls that this model contains. |
| 38 | void SetURLs(const std::vector<GURL>& urls); |
| 39 | |
[email protected] | 21c52bd | 2011-06-14 01:00:48 | [diff] [blame] | 40 | // Collect all entries indexed by |index_list|, and moves them to be right |
| 41 | // before the element addressed by |insert_before|. Used by Drag&Drop. |
| 42 | // Expects |index_list| to be ordered ascending. |
| 43 | void MoveURLs(int insert_before, const std::vector<int>& index_list); |
| 44 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 45 | // Adds an entry at the specified index. |
| 46 | void Add(int index, const GURL& url); |
| 47 | |
| 48 | // Removes the entry at the specified index. |
| 49 | void Remove(int index); |
| 50 | |
[email protected] | b0c5487 | 2010-05-13 02:06:55 | [diff] [blame] | 51 | // Clears any entries and fills the list with pages currently opened in the |
| 52 | // browser. |
| 53 | void SetToCurrentlyOpenPages(); |
| 54 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 55 | // Returns the set of urls this model contains. |
| 56 | std::vector<GURL> GetURLs(); |
| 57 | |
| 58 | // TableModel overrides: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 59 | int RowCount() override; |
| 60 | base::string16 GetText(int row, int column_id) override; |
| 61 | base::string16 GetTooltip(int row) override; |
| 62 | void SetObserver(ui::TableModelObserver* observer) override; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 63 | |
| 64 | private: |
[email protected] | 46441d1 | 2012-02-28 07:27:02 | [diff] [blame] | 65 | // Each item in the model is represented as an Entry. Entry stores the URL |
| 66 | // and title of the page. |
[email protected] | c3a4bd99 | 2010-08-18 20:25:01 | [diff] [blame] | 67 | struct Entry; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 68 | |
stevenjb | 7bd17418 | 2015-10-27 21:04:01 | [diff] [blame] | 69 | // Returns false if pages from |browser| should not be considered. |
| 70 | bool ShouldIncludeBrowser(Browser* browser); |
| 71 | |
[email protected] | 46441d1 | 2012-02-28 07:27:02 | [diff] [blame] | 72 | // Loads the title for the specified entry. |
| 73 | void LoadTitle(Entry* entry); |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 74 | |
alexclarke | e6cdee7f | 2015-01-22 23:05:02 | [diff] [blame] | 75 | // Loads all the titles, notifies the observer of the change once all loads |
| 76 | // are complete. |
| 77 | void LoadAllTitles(); |
| 78 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 79 | // Callback from history service. Updates the title of the Entry whose |
alexclarke | e6cdee7f | 2015-01-22 23:05:02 | [diff] [blame] | 80 | // |url| matches |entry_url| and notifies the observer of the change if |
| 81 | // |observable| is true. |
[email protected] | f61f003a | 2014-06-16 14:39:25 | [diff] [blame] | 82 | void OnGotTitle(const GURL& entry_url, |
alexclarke | e6cdee7f | 2015-01-22 23:05:02 | [diff] [blame] | 83 | bool observable, |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 84 | bool found_url, |
[email protected] | f61f003a | 2014-06-16 14:39:25 | [diff] [blame] | 85 | const history::URLRow& row, |
| 86 | const history::VisitVector& visits); |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 87 | |
alexclarke | e6cdee7f | 2015-01-22 23:05:02 | [diff] [blame] | 88 | // Like OnGotTitle, except that num_outstanding_title_lookups_ is decremented |
| 89 | // and if the count reaches zero the observer is notifed. |
| 90 | void OnGotOneOfManyTitles(const GURL& entry_url, |
| 91 | bool found_url, |
| 92 | const history::URLRow& row, |
| 93 | const history::VisitVector& visits); |
| 94 | |
| 95 | // Adds an entry at the specified index, but doesn't load the title or tell |
| 96 | // the observer. |
| 97 | void AddWithoutNotification(int index, const GURL& url); |
| 98 | |
| 99 | // Removes the entry at the specified index, but doesn't tell the observer. |
| 100 | void RemoveWithoutNotification(int index); |
| 101 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 102 | // Returns the URL for a particular row, formatted for display to the user. |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 103 | base::string16 FormattedURL(int row) const; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 104 | |
| 105 | // Set of entries we're showing. |
| 106 | std::vector<Entry> entries_; |
| 107 | |
[email protected] | 46441d1 | 2012-02-28 07:27:02 | [diff] [blame] | 108 | // Profile used to load titles. |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 109 | Profile* profile_; |
| 110 | |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 111 | ui::TableModelObserver* observer_; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 112 | |
[email protected] | 46441d1 | 2012-02-28 07:27:02 | [diff] [blame] | 113 | // Used in loading titles. |
[email protected] | f61f003a | 2014-06-16 14:39:25 | [diff] [blame] | 114 | base::CancelableTaskTracker task_tracker_; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 115 | |
alexclarke | e6cdee7f | 2015-01-22 23:05:02 | [diff] [blame] | 116 | // Used to keep track of when it's time to update the observer when loading |
| 117 | // multiple titles. |
| 118 | int num_outstanding_title_lookups_; |
| 119 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 120 | DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel); |
| 121 | }; |
| 122 | |
| 123 | #endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_ |