blob: 384fb54c252c38f0b672c606eb2aab3c6fe99ef9 [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
dbeam6f94b072017-06-08 00:20:1821namespace content {
22class WebContents;
23}
24
[email protected]f61f003a2014-06-16 14:39:2525namespace history {
26class URLRow;
27}
[email protected]44cbd9e2011-01-14 15:49:4028
29namespace ui {
[email protected]7fff79012010-05-12 00:19:0530class TableModelObserver;
[email protected]44cbd9e2011-01-14 15:49:4031}
[email protected]7fff79012010-05-12 00:19:0532
33// CustomHomePagesTableModel is the model for the TableView showing the list
34// of pages the user wants opened on startup.
35
[email protected]44cbd9e2011-01-14 15:49:4036class CustomHomePagesTableModel : public ui::TableModel {
[email protected]7fff79012010-05-12 00:19:0537 public:
38 explicit CustomHomePagesTableModel(Profile* profile);
Daniel Chenga542fca2014-10-21 09:51:2939 ~CustomHomePagesTableModel() override;
[email protected]7fff79012010-05-12 00:19:0540
41 // Sets the set of urls that this model contains.
42 void SetURLs(const std::vector<GURL>& urls);
43
[email protected]21c52bd2011-06-14 01:00:4844 // Collect all entries indexed by |index_list|, and moves them to be right
45 // before the element addressed by |insert_before|. Used by Drag&Drop.
46 // Expects |index_list| to be ordered ascending.
47 void MoveURLs(int insert_before, const std::vector<int>& index_list);
48
[email protected]7fff79012010-05-12 00:19:0549 // Adds an entry at the specified index.
50 void Add(int index, const GURL& url);
51
52 // Removes the entry at the specified index.
53 void Remove(int index);
54
[email protected]b0c54872010-05-13 02:06:5555 // Clears any entries and fills the list with pages currently opened in the
dbeam6f94b072017-06-08 00:20:1856 // browser. |ignore_contents| is omitted from the open pages.
57 void SetToCurrentlyOpenPages(const content::WebContents* ignore_contents);
[email protected]b0c54872010-05-13 02:06:5558
[email protected]7fff79012010-05-12 00:19:0559 // Returns the set of urls this model contains.
60 std::vector<GURL> GetURLs();
61
62 // TableModel overrides:
Daniel Chenga542fca2014-10-21 09:51:2963 int RowCount() override;
64 base::string16 GetText(int row, int column_id) override;
65 base::string16 GetTooltip(int row) override;
66 void SetObserver(ui::TableModelObserver* observer) override;
[email protected]7fff79012010-05-12 00:19:0567
68 private:
[email protected]46441d12012-02-28 07:27:0269 // Each item in the model is represented as an Entry. Entry stores the URL
70 // and title of the page.
[email protected]c3a4bd992010-08-18 20:25:0171 struct Entry;
[email protected]7fff79012010-05-12 00:19:0572
stevenjb7bd174182015-10-27 21:04:0173 // Returns false if pages from |browser| should not be considered.
74 bool ShouldIncludeBrowser(Browser* browser);
75
[email protected]46441d12012-02-28 07:27:0276 // Loads the title for the specified entry.
77 void LoadTitle(Entry* entry);
[email protected]7fff79012010-05-12 00:19:0578
alexclarkee6cdee7f2015-01-22 23:05:0279 // Loads all the titles, notifies the observer of the change once all loads
80 // are complete.
81 void LoadAllTitles();
82
[email protected]7fff79012010-05-12 00:19:0583 // Callback from history service. Updates the title of the Entry whose
alexclarkee6cdee7f2015-01-22 23:05:0284 // |url| matches |entry_url| and notifies the observer of the change if
85 // |observable| is true.
[email protected]f61f003a2014-06-16 14:39:2586 void OnGotTitle(const GURL& entry_url,
alexclarkee6cdee7f2015-01-22 23:05:0287 bool observable,
[email protected]7fff79012010-05-12 00:19:0588 bool found_url,
[email protected]f61f003a2014-06-16 14:39:2589 const history::URLRow& row,
90 const history::VisitVector& visits);
[email protected]7fff79012010-05-12 00:19:0591
alexclarkee6cdee7f2015-01-22 23:05:0292 // Like OnGotTitle, except that num_outstanding_title_lookups_ is decremented
93 // and if the count reaches zero the observer is notifed.
94 void OnGotOneOfManyTitles(const GURL& entry_url,
95 bool found_url,
96 const history::URLRow& row,
97 const history::VisitVector& visits);
98
99 // Adds an entry at the specified index, but doesn't load the title or tell
100 // the observer.
101 void AddWithoutNotification(int index, const GURL& url);
102
103 // Removes the entry at the specified index, but doesn't tell the observer.
104 void RemoveWithoutNotification(int index);
105
[email protected]7fff79012010-05-12 00:19:05106 // Returns the URL for a particular row, formatted for display to the user.
[email protected]96920152013-12-04 21:00:16107 base::string16 FormattedURL(int row) const;
[email protected]7fff79012010-05-12 00:19:05108
109 // Set of entries we're showing.
110 std::vector<Entry> entries_;
111
[email protected]46441d12012-02-28 07:27:02112 // Profile used to load titles.
[email protected]7fff79012010-05-12 00:19:05113 Profile* profile_;
114
[email protected]44cbd9e2011-01-14 15:49:40115 ui::TableModelObserver* observer_;
[email protected]7fff79012010-05-12 00:19:05116
[email protected]46441d12012-02-28 07:27:02117 // Used in loading titles.
[email protected]f61f003a2014-06-16 14:39:25118 base::CancelableTaskTracker task_tracker_;
[email protected]7fff79012010-05-12 00:19:05119
alexclarkee6cdee7f2015-01-22 23:05:02120 // Used to keep track of when it's time to update the observer when loading
121 // multiple titles.
122 int num_outstanding_title_lookups_;
123
[email protected]7fff79012010-05-12 00:19:05124 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel);
125};
126
127#endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_