Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / search_engines / template_url_table_model.h
blob03a2bde1dfeac5e8fae16d80111bcd157c21edee
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_UI_SEARCH_ENGINES_TEMPLATE_URL_TABLE_MODEL_H_
6 #define CHROME_BROWSER_UI_SEARCH_ENGINES_TEMPLATE_URL_TABLE_MODEL_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "components/search_engines/template_url_service_observer.h"
15 #include "ui/base/models/table_model.h"
17 class TemplateURL;
18 class TemplateURLService;
20 namespace favicon {
21 class FaviconService;
24 namespace gfx {
25 class ImageSkia;
28 // TemplateURLTableModel is the TableModel implementation used by
29 // KeywordEditorView to show the keywords in a TableView.
31 // TemplateURLTableModel has two columns, the first showing the description,
32 // the second the keyword.
34 // TemplateURLTableModel maintains a vector of ModelEntrys that correspond to
35 // each row in the tableview. Each ModelEntry wraps a TemplateURL, providing
36 // the favicon. The entries in the model are sorted such that non-generated
37 // appear first (grouped together) and are followed by generated keywords.
39 class TemplateURLTableModel : public ui::TableModel,
40 TemplateURLServiceObserver {
41 public:
42 TemplateURLTableModel(TemplateURLService* template_url_service,
43 favicon::FaviconService* favicon_service);
45 ~TemplateURLTableModel() override;
47 // Reloads the entries from the TemplateURLService. This should ONLY be
48 // invoked if the TemplateURLService wasn't initially loaded and has been
49 // loaded.
50 void Reload();
52 // ui::TableModel overrides.
53 int RowCount() override;
54 base::string16 GetText(int row, int column) override;
55 gfx::ImageSkia GetIcon(int row) override;
56 void SetObserver(ui::TableModelObserver* observer) override;
57 bool HasGroups() override;
58 Groups GetGroups() override;
59 int GetGroupID(int row) override;
61 // Removes the entry at the specified index.
62 void Remove(int index);
64 // Adds a new entry at the specified index.
65 void Add(int index,
66 const base::string16& short_name,
67 const base::string16& keyword,
68 const std::string& url);
70 // Update the entry at the specified index.
71 void ModifyTemplateURL(int index,
72 const base::string16& title,
73 const base::string16& keyword,
74 const std::string& url);
76 // Reloads the icon at the specified index.
77 void ReloadIcon(int index);
79 // Returns the TemplateURL at the specified index.
80 TemplateURL* GetTemplateURL(int index);
82 // Returns the index of the TemplateURL, or -1 if it the TemplateURL is not
83 // found.
84 int IndexOfTemplateURL(const TemplateURL* template_url);
86 // Moves the keyword at the specified index to be at the end of the main
87 // group. Returns the new index. If the entry is already in the main group,
88 // no action is taken, and the current index is returned.
89 int MoveToMainGroup(int index);
91 // Make the TemplateURL at |index| the default. Returns the new index, or -1
92 // if the index is invalid or it is already the default.
93 int MakeDefaultTemplateURL(int index);
95 // If there is an observer, it's notified the selected row has changed.
96 void NotifyChanged(int index);
98 // Returns the index of the last entry shown in the search engines group.
99 int last_search_engine_index() const { return last_search_engine_index_; }
101 // Returns the index of the last entry shown in the other search engines
102 // group.
103 int last_other_engine_index() const { return last_other_engine_index_; }
105 private:
106 class ModelEntry;
108 // Notification that a model entry has fetched its icon.
109 void FaviconAvailable(ModelEntry* entry);
111 // TemplateURLServiceObserver notification.
112 void OnTemplateURLServiceChanged() override;
114 // Removes the entry at |index| from |entries_| and returns the removed item.
115 scoped_ptr<ModelEntry> RemoveEntry(int index);
117 // Adds |entry| to |entries_| at |index| and takes ownership.
118 void AddEntry(int index, scoped_ptr<ModelEntry> entry);
120 ui::TableModelObserver* observer_;
122 // The entries.
123 std::vector<ModelEntry*> entries_;
125 // The model we're displaying entries from.
126 TemplateURLService* template_url_service_;
128 favicon::FaviconService* favicon_service_;
130 // Index of the last search engine in entries_. This is used to determine the
131 // group boundaries.
132 int last_search_engine_index_;
134 // Index of the last other engine in entries_. This is used to determine the
135 // group boundaries.
136 int last_other_engine_index_;
138 DISALLOW_COPY_AND_ASSIGN(TemplateURLTableModel);
142 #endif // CHROME_BROWSER_UI_SEARCH_ENGINES_TEMPLATE_URL_TABLE_MODEL_H_