Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / custom_home_pages_table_model.h
blobbe6e7ec3c1626ecda343d7049e9978e3f16d62b0
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 "chrome/browser/history/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 virtual ~CustomHomePagesTableModel();
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 virtual int RowCount() OVERRIDE;
59 virtual base::string16 GetText(int row, int column_id) OVERRIDE;
60 virtual base::string16 GetTooltip(int row) OVERRIDE;
61 virtual 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 // Callback from history service. Updates the title of the Entry whose
72 // |url| matches |entry_url| and notifies the observer of the change.
73 void OnGotTitle(const GURL& entry_url,
74 bool found_url,
75 const history::URLRow& row,
76 const history::VisitVector& visits);
78 // Returns the URL for a particular row, formatted for display to the user.
79 base::string16 FormattedURL(int row) const;
81 // Set of entries we're showing.
82 std::vector<Entry> entries_;
84 // Profile used to load titles.
85 Profile* profile_;
87 ui::TableModelObserver* observer_;
89 // Used in loading titles.
90 base::CancelableTaskTracker task_tracker_;
92 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel);
95 #endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_