1 // Copyright (c) 2011 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_
12 #include "base/compiler_specific.h"
13 #include "chrome/browser/history/history.h"
14 #include "chrome/browser/favicon/favicon_service.h"
15 #include "ui/base/models/table_model.h"
22 class TableModelObserver
;
25 // CustomHomePagesTableModel is the model for the TableView showing the list
26 // of pages the user wants opened on startup.
28 class CustomHomePagesTableModel
: public ui::TableModel
{
30 explicit CustomHomePagesTableModel(Profile
* profile
);
31 virtual ~CustomHomePagesTableModel();
33 // Sets the set of urls that this model contains.
34 void SetURLs(const std::vector
<GURL
>& urls
);
36 // 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
);
41 // Adds an entry at the specified index.
42 void Add(int index
, const GURL
& url
);
44 // Removes the entry at the specified index.
45 void Remove(int index
);
47 // Clears any entries and fills the list with pages currently opened in the
49 void SetToCurrentlyOpenPages();
51 // Returns the set of urls this model contains.
52 std::vector
<GURL
> GetURLs();
54 // TableModel overrides:
55 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
;
59 virtual void SetObserver(ui::TableModelObserver
* observer
) OVERRIDE
;
62 // Each item in the model is represented as an Entry. Entry stores the URL,
63 // title, and favicon of the page.
66 // Loads the title and favicon for the specified entry.
67 void LoadTitleAndFavicon(Entry
* entry
);
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
,
73 const history::URLRow
* row
,
74 history::VisitVector
* visits
);
76 // Callback from history service. Updates the icon of the Entry whose
77 // |favicon_handle| matches |handle| and notifies the observer of the change.
78 void OnGotFavicon(FaviconService::Handle handle
,
79 history::FaviconData favicon
);
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
,
87 // Returns the URL for a particular row, formatted for display to the user.
88 string16
FormattedURL(int row
) const;
90 // Set of entries we're showing.
91 std::vector
<Entry
> entries_
;
93 // Default icon to show when one can't be found for the URL.
94 SkBitmap
* default_favicon_
;
96 // Profile used to load titles and icons.
99 ui::TableModelObserver
* observer_
;
101 // Used in loading titles and favicons.
102 CancelableRequestConsumer history_query_consumer_
;
103 CancelableRequestConsumer favicon_query_consumer_
;
105 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel
);
108 #endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_