Extract code handling PrinterProviderAPI from PrintPreviewHandler
[chromium-blink-merge.git] / chrome / browser / custom_home_pages_table_model.h
blob797cc14efa7122cb42e0b3eb3238a67a2da63c5c
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_
8 #include <string>
9 #include <vector>
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"
16 class GURL;
17 class Profile;
18 class HistoryService;
20 namespace history {
21 class URLRow;
24 namespace ui {
25 class TableModelObserver;
28 // CustomHomePagesTableModel is the model for the TableView showing the list
29 // of pages the user wants opened on startup.
31 class CustomHomePagesTableModel : public ui::TableModel {
32 public:
33 explicit CustomHomePagesTableModel(Profile* profile);
34 ~CustomHomePagesTableModel() override;
36 // Sets the set of urls that this model contains.
37 void SetURLs(const std::vector<GURL>& urls);
39 // Collect all entries indexed by |index_list|, and moves them to be right
40 // before the element addressed by |insert_before|. Used by Drag&Drop.
41 // Expects |index_list| to be ordered ascending.
42 void MoveURLs(int insert_before, const std::vector<int>& index_list);
44 // Adds an entry at the specified index.
45 void Add(int index, const GURL& url);
47 // Removes the entry at the specified index.
48 void Remove(int index);
50 // Clears any entries and fills the list with pages currently opened in the
51 // browser.
52 void SetToCurrentlyOpenPages();
54 // Returns the set of urls this model contains.
55 std::vector<GURL> GetURLs();
57 // TableModel overrides:
58 int RowCount() override;
59 base::string16 GetText(int row, int column_id) override;
60 base::string16 GetTooltip(int row) override;
61 void SetObserver(ui::TableModelObserver* observer) override;
63 private:
64 // Each item in the model is represented as an Entry. Entry stores the URL
65 // and title of the page.
66 struct Entry;
68 // Loads the title for the specified entry.
69 void LoadTitle(Entry* entry);
71 // Loads all the titles, notifies the observer of the change once all loads
72 // are complete.
73 void LoadAllTitles();
75 // Callback from history service. Updates the title of the Entry whose
76 // |url| matches |entry_url| and notifies the observer of the change if
77 // |observable| is true.
78 void OnGotTitle(const GURL& entry_url,
79 bool observable,
80 bool found_url,
81 const history::URLRow& row,
82 const history::VisitVector& visits);
84 // Like OnGotTitle, except that num_outstanding_title_lookups_ is decremented
85 // and if the count reaches zero the observer is notifed.
86 void OnGotOneOfManyTitles(const GURL& entry_url,
87 bool found_url,
88 const history::URLRow& row,
89 const history::VisitVector& visits);
91 // Adds an entry at the specified index, but doesn't load the title or tell
92 // the observer.
93 void AddWithoutNotification(int index, const GURL& url);
95 // Removes the entry at the specified index, but doesn't tell the observer.
96 void RemoveWithoutNotification(int index);
98 // Returns the URL for a particular row, formatted for display to the user.
99 base::string16 FormattedURL(int row) const;
101 // Set of entries we're showing.
102 std::vector<Entry> entries_;
104 // Profile used to load titles.
105 Profile* profile_;
107 ui::TableModelObserver* observer_;
109 // Used in loading titles.
110 base::CancelableTaskTracker task_tracker_;
112 // Used to keep track of when it's time to update the observer when loading
113 // multiple titles.
114 int num_outstanding_title_lookups_;
116 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel);
119 #endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_