Print Preview: Changing displayed error message when PDF Viewer is missing.
[chromium-blink-merge.git] / chrome / browser / custom_home_pages_table_model.h
blob51455645ac4a1a38a1b081419494705e875cc48a
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_
7 #pragma once
9 #include <string>
10 #include <vector>
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"
17 class GURL;
18 class Profile;
19 class SkBitmap;
21 namespace ui {
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 {
29 public:
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 // Adds an entry at the specified index.
37 void Add(int index, const GURL& url);
39 // Removes the entry at the specified index.
40 void Remove(int index);
42 // Clears any entries and fills the list with pages currently opened in the
43 // browser.
44 void SetToCurrentlyOpenPages();
46 // Returns the set of urls this model contains.
47 std::vector<GURL> GetURLs();
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;
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;
61 // Loads the title and favicon for the specified entry.
62 void LoadTitleAndFavicon(Entry* entry);
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);
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);
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);
82 // Returns the URL for a particular row, formatted for display to the user.
83 string16 FormattedURL(int row) const;
85 // Set of entries we're showing.
86 std::vector<Entry> entries_;
88 // Default icon to show when one can't be found for the URL.
89 SkBitmap* default_favicon_;
91 // Profile used to load titles and icons.
92 Profile* profile_;
94 ui::TableModelObserver* observer_;
96 // Used in loading titles and favicons.
97 CancelableRequestConsumer query_consumer_;
99 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel);
102 #endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_