1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CUSTOM_HOME_PAGES_TABLE_MODEL_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_CUSTOM_HOME_PAGES_TABLE_MODEL_H_
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/history/core/browser/history_types.h"
#include "ui/base/models/table_model.h"
class Browser;
class GURL;
class Profile;
namespace content {
class WebContents;
}
namespace ui {
class TableModelObserver;
}
// CustomHomePagesTableModel is the model for the TableView showing the list
// of pages the user wants opened on startup.
class CustomHomePagesTableModel : public ui::TableModel {
public:
explicit CustomHomePagesTableModel(Profile* profile);
CustomHomePagesTableModel(const CustomHomePagesTableModel&) = delete;
CustomHomePagesTableModel& operator=(const CustomHomePagesTableModel&) =
delete;
~CustomHomePagesTableModel() override;
// Sets the set of urls that this model contains.
void SetURLs(const std::vector<GURL>& urls);
// Adds an entry at the specified index.
void Add(size_t index, const GURL& url);
// Removes the entry at the specified index.
void Remove(size_t index);
// Clears any entries and fills the list with pages currently opened in the
// browser. |ignore_contents| is omitted from the open pages.
void SetToCurrentlyOpenPages(content::WebContents* ignore_contents);
// Returns the set of urls this model contains.
std::vector<GURL> GetURLs();
// TableModel overrides:
size_t RowCount() override;
std::u16string GetText(size_t row, int column_id) override;
std::u16string GetTooltip(size_t row) override;
void SetObserver(ui::TableModelObserver* observer) override;
private:
// Each item in the model is represented as an Entry. Entry stores the URL
// and title of the page.
struct Entry;
// Returns false if pages from |browser| should not be considered.
bool ShouldIncludeBrowser(Browser* browser);
// Loads the title for the specified entry.
void LoadTitle(Entry* entry);
// Loads all the titles, notifies the observer of the change once all loads
// are complete.
void LoadAllTitles();
// Callback from history service. Updates the title of the Entry whose
// |url| matches |entry_url| and notifies the observer of the change if
// |observable| is true.
void OnGotTitle(const GURL& entry_url,
bool observable,
history::QueryURLResult result);
// Like OnGotTitle, except that num_outstanding_title_lookups_ is decremented
// and if the count reaches zero the observer is notifed.
void OnGotOneOfManyTitles(const GURL& entry_url,
history::QueryURLResult result);
// Adds an entry at the specified index, but doesn't load the title or tell
// the observer.
void AddWithoutNotification(size_t index, const GURL& url);
// Removes the entry at the specified index, but doesn't tell the observer.
void RemoveWithoutNotification(size_t index);
// Returns the URL for a particular row, formatted for display to the user.
std::u16string FormattedURL(size_t row) const;
// Set of entries we're showing.
std::vector<Entry> entries_;
// Profile used to load titles.
raw_ptr<Profile> profile_;
raw_ptr<ui::TableModelObserver> observer_;
// Used in loading titles.
base::CancelableTaskTracker task_tracker_;
// Used to keep track of when it's time to update the observer when loading
// multiple titles.
int num_outstanding_title_lookups_;
};
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CUSTOM_HOME_PAGES_TABLE_MODEL_H_
|