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. 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 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" 15 16class GURL; 17class Profile; 18class HistoryService; 19 20namespace history { 21class URLRow; 22} 23 24namespace ui { 25class TableModelObserver; 26} 27 28// CustomHomePagesTableModel is the model for the TableView showing the list 29// of pages the user wants opened on startup. 30 31class CustomHomePagesTableModel : public ui::TableModel { 32 public: 33 explicit CustomHomePagesTableModel(Profile* profile); 34 virtual ~CustomHomePagesTableModel(); 35 36 // Sets the set of urls that this model contains. 37 void SetURLs(const std::vector<GURL>& urls); 38 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); 43 44 // Adds an entry at the specified index. 45 void Add(int index, const GURL& url); 46 47 // Removes the entry at the specified index. 48 void Remove(int index); 49 50 // Clears any entries and fills the list with pages currently opened in the 51 // browser. 52 void SetToCurrentlyOpenPages(); 53 54 // Returns the set of urls this model contains. 55 std::vector<GURL> GetURLs(); 56 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; 62 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; 67 68 // Loads the title for the specified entry. 69 void LoadTitle(Entry* entry); 70 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); 77 78 // Returns the URL for a particular row, formatted for display to the user. 79 base::string16 FormattedURL(int row) const; 80 81 // Set of entries we're showing. 82 std::vector<Entry> entries_; 83 84 // Profile used to load titles. 85 Profile* profile_; 86 87 ui::TableModelObserver* observer_; 88 89 // Used in loading titles. 90 base::CancelableTaskTracker task_tracker_; 91 92 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel); 93}; 94 95#endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_ 96