blob: a7ffb9ed926a005b8e73ce60b725ddce20c7979c [file] [log] [blame]
[email protected]ee2ed42c2011-04-28 22:19:141// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]7fff79012010-05-12 00:19:052// 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]7fff79012010-05-12 00:19:058
9#include <string>
10#include <vector>
11
[email protected]bdaab67c2010-12-30 00:50:0412#include "base/compiler_specific.h"
[email protected]7fff79012010-05-12 00:19:0513#include "chrome/browser/history/history.h"
[email protected]ee2ed42c2011-04-28 22:19:1414#include "chrome/browser/favicon/favicon_service.h"
[email protected]44cbd9e2011-01-14 15:49:4015#include "ui/base/models/table_model.h"
[email protected]7fff79012010-05-12 00:19:0516
[email protected]c3a4bd992010-08-18 20:25:0117class GURL;
[email protected]7fff79012010-05-12 00:19:0518class Profile;
[email protected]c3a4bd992010-08-18 20:25:0119class SkBitmap;
[email protected]44cbd9e2011-01-14 15:49:4020
21namespace ui {
[email protected]7fff79012010-05-12 00:19:0522class TableModelObserver;
[email protected]44cbd9e2011-01-14 15:49:4023}
[email protected]7fff79012010-05-12 00:19:0524
25// CustomHomePagesTableModel is the model for the TableView showing the list
26// of pages the user wants opened on startup.
27
[email protected]44cbd9e2011-01-14 15:49:4028class CustomHomePagesTableModel : public ui::TableModel {
[email protected]7fff79012010-05-12 00:19:0529 public:
30 explicit CustomHomePagesTableModel(Profile* profile);
[email protected]c3a4bd992010-08-18 20:25:0131 virtual ~CustomHomePagesTableModel();
[email protected]7fff79012010-05-12 00:19:0532
33 // Sets the set of urls that this model contains.
34 void SetURLs(const std::vector<GURL>& urls);
35
[email protected]21c52bd2011-06-14 01:00:4836 // Collect all entries indexed by |index_list|, and moves them to be right
37 // before the element addressed by |insert_before|. Used by Drag&Drop.
38 // Expects |index_list| to be ordered ascending.
39 void MoveURLs(int insert_before, const std::vector<int>& index_list);
40
[email protected]7fff79012010-05-12 00:19:0541 // Adds an entry at the specified index.
42 void Add(int index, const GURL& url);
43
44 // Removes the entry at the specified index.
45 void Remove(int index);
46
[email protected]b0c54872010-05-13 02:06:5547 // Clears any entries and fills the list with pages currently opened in the
48 // browser.
49 void SetToCurrentlyOpenPages();
50
[email protected]7fff79012010-05-12 00:19:0551 // Returns the set of urls this model contains.
52 std::vector<GURL> GetURLs();
53
54 // TableModel overrides:
[email protected]bdaab67c2010-12-30 00:50:0455 virtual int RowCount() OVERRIDE;
56 virtual string16 GetText(int row, int column_id) OVERRIDE;
57 virtual SkBitmap GetIcon(int row) OVERRIDE;
58 virtual string16 GetTooltip(int row) OVERRIDE;
[email protected]44cbd9e2011-01-14 15:49:4059 virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
[email protected]7fff79012010-05-12 00:19:0560
61 private:
62 // Each item in the model is represented as an Entry. Entry stores the URL,
63 // title, and favicon of the page.
[email protected]c3a4bd992010-08-18 20:25:0164 struct Entry;
[email protected]7fff79012010-05-12 00:19:0565
[email protected]7fff79012010-05-12 00:19:0566 // Loads the title and favicon for the specified entry.
[email protected]f16039d22011-03-16 18:54:0567 void LoadTitleAndFavicon(Entry* entry);
[email protected]7fff79012010-05-12 00:19:0568
69 // Callback from history service. Updates the title of the Entry whose
70 // |title_handle| matches |handle| and notifies the observer of the change.
71 void OnGotTitle(HistoryService::Handle handle,
72 bool found_url,
73 const history::URLRow* row,
74 history::VisitVector* visits);
75
76 // Callback from history service. Updates the icon of the Entry whose
[email protected]16be5c32011-03-15 17:52:0377 // |favicon_handle| matches |handle| and notifies the observer of the change.
[email protected]f16039d22011-03-16 18:54:0578 void OnGotFavicon(FaviconService::Handle handle,
[email protected]849ccee2011-03-16 17:05:3079 history::FaviconData favicon);
[email protected]7fff79012010-05-12 00:19:0580
81 // Returns the entry whose |member| matches |handle| and sets |entry_index| to
82 // the index of the entry.
83 Entry* GetEntryByLoadHandle(CancelableRequestProvider::Handle Entry::* member,
84 CancelableRequestProvider::Handle handle,
85 int* entry_index);
86
[email protected]7fff79012010-05-12 00:19:0587 // Returns the URL for a particular row, formatted for display to the user.
[email protected]bdaab67c2010-12-30 00:50:0488 string16 FormattedURL(int row) const;
[email protected]7fff79012010-05-12 00:19:0589
90 // Set of entries we're showing.
91 std::vector<Entry> entries_;
92
93 // Default icon to show when one can't be found for the URL.
[email protected]122b4682010-07-28 20:59:1294 SkBitmap* default_favicon_;
[email protected]7fff79012010-05-12 00:19:0595
96 // Profile used to load titles and icons.
97 Profile* profile_;
98
[email protected]44cbd9e2011-01-14 15:49:4099 ui::TableModelObserver* observer_;
[email protected]7fff79012010-05-12 00:19:05100
101 // Used in loading titles and favicons.
[email protected]9d52ae62011-06-21 04:04:19102 CancelableRequestConsumer history_query_consumer_;
103 CancelableRequestConsumer favicon_query_consumer_;
[email protected]7fff79012010-05-12 00:19:05104
105 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel);
106};
107
108#endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_