Remove the dependency of PasswordStore on BrowserContextKeyedService
[chromium-blink-merge.git] / chrome / browser / custom_home_pages_table_model.h
blob64a8b82362d0de30d5e4f5f9a21a36b808a79bab
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.
5 #ifndef CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_
6 #define CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/history/history_service.h"
13 #include "ui/base/models/table_model.h"
15 class GURL;
16 class Profile;
18 namespace ui {
19 class TableModelObserver;
22 // CustomHomePagesTableModel is the model for the TableView showing the list
23 // of pages the user wants opened on startup.
25 class CustomHomePagesTableModel : public ui::TableModel {
26 public:
27 explicit CustomHomePagesTableModel(Profile* profile);
28 virtual ~CustomHomePagesTableModel();
30 // Sets the set of urls that this model contains.
31 void SetURLs(const std::vector<GURL>& urls);
33 // Collect all entries indexed by |index_list|, and moves them to be right
34 // before the element addressed by |insert_before|. Used by Drag&Drop.
35 // Expects |index_list| to be ordered ascending.
36 void MoveURLs(int insert_before, const std::vector<int>& index_list);
38 // Adds an entry at the specified index.
39 void Add(int index, const GURL& url);
41 // Removes the entry at the specified index.
42 void Remove(int index);
44 // Clears any entries and fills the list with pages currently opened in the
45 // browser.
46 void SetToCurrentlyOpenPages();
48 // Returns the set of urls this model contains.
49 std::vector<GURL> GetURLs();
51 // TableModel overrides:
52 virtual int RowCount() OVERRIDE;
53 virtual base::string16 GetText(int row, int column_id) OVERRIDE;
54 virtual base::string16 GetTooltip(int row) OVERRIDE;
55 virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
57 private:
58 // Each item in the model is represented as an Entry. Entry stores the URL
59 // and title of the page.
60 struct Entry;
62 // Loads the title for the specified entry.
63 void LoadTitle(Entry* entry);
65 // Callback from history service. Updates the title of the Entry whose
66 // |title_handle| matches |handle| and notifies the observer of the change.
67 void OnGotTitle(HistoryService::Handle handle,
68 bool found_url,
69 const history::URLRow* row,
70 history::VisitVector* visits);
72 // Returns the entry whose |member| matches |handle| and sets |entry_index| to
73 // the index of the entry.
74 Entry* GetEntryByLoadHandle(CancelableRequestProvider::Handle Entry::* member,
75 CancelableRequestProvider::Handle handle,
76 int* entry_index);
78 // Returns the URL for a particular row, formatted for display to the user.
79 base::string16 FormattedURL(int row) const;
81 // Set of entries we're showing.
82 std::vector<Entry> entries_;
84 // Profile used to load titles.
85 Profile* profile_;
87 ui::TableModelObserver* observer_;
89 // Used in loading titles.
90 CancelableRequestConsumer history_query_consumer_;
92 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel);
95 #endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_