1// Copyright (c) 2010 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#pragma once 8 9#include <string> 10#include <vector> 11 12#include "base/compiler_specific.h" 13#include "chrome/browser/history/history.h" 14#include "chrome/browser/favicon_service.h" 15#include "ui/base/models/table_model.h" 16 17class GURL; 18class Profile; 19class SkBitmap; 20 21namespace ui { 22class TableModelObserver; 23} 24 25// CustomHomePagesTableModel is the model for the TableView showing the list 26// of pages the user wants opened on startup. 27 28class CustomHomePagesTableModel : public ui::TableModel { 29 public: 30 explicit CustomHomePagesTableModel(Profile* profile); 31 virtual ~CustomHomePagesTableModel(); 32 33 // Sets the set of urls that this model contains. 34 void SetURLs(const std::vector<GURL>& urls); 35 36 // Adds an entry at the specified index. 37 void Add(int index, const GURL& url); 38 39 // Removes the entry at the specified index. 40 void Remove(int index); 41 42 // Clears any entries and fills the list with pages currently opened in the 43 // browser. 44 void SetToCurrentlyOpenPages(); 45 46 // Returns the set of urls this model contains. 47 std::vector<GURL> GetURLs(); 48 49 // TableModel overrides: 50 virtual int RowCount() OVERRIDE; 51 virtual string16 GetText(int row, int column_id) OVERRIDE; 52 virtual SkBitmap GetIcon(int row) OVERRIDE; 53 virtual string16 GetTooltip(int row) OVERRIDE; 54 virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE; 55 56 private: 57 // Each item in the model is represented as an Entry. Entry stores the URL, 58 // title, and favicon of the page. 59 struct Entry; 60 61 // Loads the title and favicon for the specified entry. 62 void LoadTitleAndFavicon(Entry* entry); 63 64 // Callback from history service. Updates the title of the Entry whose 65 // |title_handle| matches |handle| and notifies the observer of the change. 66 void OnGotTitle(HistoryService::Handle handle, 67 bool found_url, 68 const history::URLRow* row, 69 history::VisitVector* visits); 70 71 // Callback from history service. Updates the icon of the Entry whose 72 // |favicon_handle| matches |handle| and notifies the observer of the change. 73 void OnGotFavicon(FaviconService::Handle handle, 74 history::FaviconData favicon); 75 76 // Returns the entry whose |member| matches |handle| and sets |entry_index| to 77 // the index of the entry. 78 Entry* GetEntryByLoadHandle(CancelableRequestProvider::Handle Entry::* member, 79 CancelableRequestProvider::Handle handle, 80 int* entry_index); 81 82 // Returns the URL for a particular row, formatted for display to the user. 83 string16 FormattedURL(int row) const; 84 85 // Set of entries we're showing. 86 std::vector<Entry> entries_; 87 88 // Default icon to show when one can't be found for the URL. 89 SkBitmap* default_favicon_; 90 91 // Profile used to load titles and icons. 92 Profile* profile_; 93 94 ui::TableModelObserver* observer_; 95 96 // Used in loading titles and favicons. 97 CancelableRequestConsumer query_consumer_; 98 99 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel); 100}; 101 102#endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_ 103