blob: 9c649fa37e06dedfccdc01d1dc09621d254faac6 [file] [log] [blame]
[email protected]46441d12012-02-28 07:27:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7fff79012010-05-12 00:19:052// 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]bdaab67c2010-12-30 00:50:0411#include "base/compiler_specific.h"
avie4d7b6f2015-12-26 00:59:1812#include "base/macros.h"
[email protected]f61f003a2014-06-16 14:39:2513#include "base/task/cancelable_task_tracker.h"
sdefresnebc766ef2014-09-25 09:28:1314#include "components/history/core/browser/history_types.h"
[email protected]44cbd9e2011-01-14 15:49:4015#include "ui/base/models/table_model.h"
[email protected]7fff79012010-05-12 00:19:0516
stevenjb7bd174182015-10-27 21:04:0117class Browser;
[email protected]c3a4bd992010-08-18 20:25:0118class GURL;
[email protected]7fff79012010-05-12 00:19:0519class Profile;
[email protected]f61f003a2014-06-16 14:39:2520
21namespace history {
22class URLRow;
23}
[email protected]44cbd9e2011-01-14 15:49:4024
25namespace ui {
[email protected]7fff79012010-05-12 00:19:0526class TableModelObserver;
[email protected]44cbd9e2011-01-14 15:49:4027}
[email protected]7fff79012010-05-12 00:19:0528
29// CustomHomePagesTableModel is the model for the TableView showing the list
30// of pages the user wants opened on startup.
31
[email protected]44cbd9e2011-01-14 15:49:4032class CustomHomePagesTableModel : public ui::TableModel {
[email protected]7fff79012010-05-12 00:19:0533 public:
34 explicit CustomHomePagesTableModel(Profile* profile);
Daniel Chenga542fca2014-10-21 09:51:2935 ~CustomHomePagesTableModel() override;
[email protected]7fff79012010-05-12 00:19:0536
37 // Sets the set of urls that this model contains.
38 void SetURLs(const std::vector<GURL>& urls);
39
[email protected]21c52bd2011-06-14 01:00:4840 // 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]7fff79012010-05-12 00:19:0545 // 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]b0c54872010-05-13 02:06:5551 // Clears any entries and fills the list with pages currently opened in the
52 // browser.
53 void SetToCurrentlyOpenPages();
54
[email protected]7fff79012010-05-12 00:19:0555 // Returns the set of urls this model contains.
56 std::vector<GURL> GetURLs();
57
58 // TableModel overrides:
Daniel Chenga542fca2014-10-21 09:51:2959 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]7fff79012010-05-12 00:19:0563
64 private:
[email protected]46441d12012-02-28 07:27:0265 // Each item in the model is represented as an Entry. Entry stores the URL
66 // and title of the page.
[email protected]c3a4bd992010-08-18 20:25:0167 struct Entry;
[email protected]7fff79012010-05-12 00:19:0568
stevenjb7bd174182015-10-27 21:04:0169 // Returns false if pages from |browser| should not be considered.
70 bool ShouldIncludeBrowser(Browser* browser);
71
[email protected]46441d12012-02-28 07:27:0272 // Loads the title for the specified entry.
73 void LoadTitle(Entry* entry);
[email protected]7fff79012010-05-12 00:19:0574
alexclarkee6cdee7f2015-01-22 23:05:0275 // Loads all the titles, notifies the observer of the change once all loads
76 // are complete.
77 void LoadAllTitles();
78
[email protected]7fff79012010-05-12 00:19:0579 // Callback from history service. Updates the title of the Entry whose
alexclarkee6cdee7f2015-01-22 23:05:0280 // |url| matches |entry_url| and notifies the observer of the change if
81 // |observable| is true.
[email protected]f61f003a2014-06-16 14:39:2582 void OnGotTitle(const GURL& entry_url,
alexclarkee6cdee7f2015-01-22 23:05:0283 bool observable,
[email protected]7fff79012010-05-12 00:19:0584 bool found_url,
[email protected]f61f003a2014-06-16 14:39:2585 const history::URLRow& row,
86 const history::VisitVector& visits);
[email protected]7fff79012010-05-12 00:19:0587
alexclarkee6cdee7f2015-01-22 23:05:0288 // 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]7fff79012010-05-12 00:19:05102 // Returns the URL for a particular row, formatted for display to the user.
[email protected]96920152013-12-04 21:00:16103 base::string16 FormattedURL(int row) const;
[email protected]7fff79012010-05-12 00:19:05104
105 // Set of entries we're showing.
106 std::vector<Entry> entries_;
107
[email protected]46441d12012-02-28 07:27:02108 // Profile used to load titles.
[email protected]7fff79012010-05-12 00:19:05109 Profile* profile_;
110
[email protected]44cbd9e2011-01-14 15:49:40111 ui::TableModelObserver* observer_;
[email protected]7fff79012010-05-12 00:19:05112
[email protected]46441d12012-02-28 07:27:02113 // Used in loading titles.
[email protected]f61f003a2014-06-16 14:39:25114 base::CancelableTaskTracker task_tracker_;
[email protected]7fff79012010-05-12 00:19:05115
alexclarkee6cdee7f2015-01-22 23:05:02116 // 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]7fff79012010-05-12 00:19:05120 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel);
121};
122
123#endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_