1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_
6 #define CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_
11 #include "base/compiler_specific.h"
12 #include "base/task/cancelable_task_tracker.h"
13 #include "components/history/core/browser/history_types.h"
14 #include "ui/base/models/table_model.h"
24 class TableModelObserver
;
27 // CustomHomePagesTableModel is the model for the TableView showing the list
28 // of pages the user wants opened on startup.
30 class CustomHomePagesTableModel
: public ui::TableModel
{
32 explicit CustomHomePagesTableModel(Profile
* profile
);
33 ~CustomHomePagesTableModel() override
;
35 // Sets the set of urls that this model contains.
36 void SetURLs(const std::vector
<GURL
>& urls
);
38 // Collect all entries indexed by |index_list|, and moves them to be right
39 // before the element addressed by |insert_before|. Used by Drag&Drop.
40 // Expects |index_list| to be ordered ascending.
41 void MoveURLs(int insert_before
, const std::vector
<int>& index_list
);
43 // Adds an entry at the specified index.
44 void Add(int index
, const GURL
& url
);
46 // Removes the entry at the specified index.
47 void Remove(int index
);
49 // Clears any entries and fills the list with pages currently opened in the
51 void SetToCurrentlyOpenPages();
53 // Returns the set of urls this model contains.
54 std::vector
<GURL
> GetURLs();
56 // TableModel overrides:
57 int RowCount() override
;
58 base::string16
GetText(int row
, int column_id
) override
;
59 base::string16
GetTooltip(int row
) override
;
60 void SetObserver(ui::TableModelObserver
* observer
) override
;
63 // Each item in the model is represented as an Entry. Entry stores the URL
64 // and title of the page.
67 // Loads the title for the specified entry.
68 void LoadTitle(Entry
* entry
);
70 // Loads all the titles, notifies the observer of the change once all loads
74 // Callback from history service. Updates the title of the Entry whose
75 // |url| matches |entry_url| and notifies the observer of the change if
76 // |observable| is true.
77 void OnGotTitle(const GURL
& entry_url
,
80 const history::URLRow
& row
,
81 const history::VisitVector
& visits
);
83 // Like OnGotTitle, except that num_outstanding_title_lookups_ is decremented
84 // and if the count reaches zero the observer is notifed.
85 void OnGotOneOfManyTitles(const GURL
& entry_url
,
87 const history::URLRow
& row
,
88 const history::VisitVector
& visits
);
90 // Adds an entry at the specified index, but doesn't load the title or tell
92 void AddWithoutNotification(int index
, const GURL
& url
);
94 // Removes the entry at the specified index, but doesn't tell the observer.
95 void RemoveWithoutNotification(int index
);
97 // Returns the URL for a particular row, formatted for display to the user.
98 base::string16
FormattedURL(int row
) const;
100 // Set of entries we're showing.
101 std::vector
<Entry
> entries_
;
103 // Profile used to load titles.
106 ui::TableModelObserver
* observer_
;
108 // Used in loading titles.
109 base::CancelableTaskTracker task_tracker_
;
111 // Used to keep track of when it's time to update the observer when loading
113 int num_outstanding_title_lookups_
;
115 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel
);
118 #endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_