OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/search_engines/template_url_table_model.h" | 5 #include "chrome/browser/ui/search_engines/template_url_table_model.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 void TemplateURLTableModel::Reload() { | 136 void TemplateURLTableModel::Reload() { |
137 entries_.clear(); | 137 entries_.clear(); |
138 | 138 |
139 TemplateURLService::TemplateURLVector urls = | 139 TemplateURLService::TemplateURLVector urls = |
140 template_url_service_->GetTemplateURLs(); | 140 template_url_service_->GetTemplateURLs(); |
141 | 141 |
142 std::vector<std::unique_ptr<ModelEntry>> default_entries, other_entries, | 142 std::vector<std::unique_ptr<ModelEntry>> default_entries, other_entries, |
143 extension_entries; | 143 extension_entries; |
144 // Keywords that can be made the default first. | 144 // Keywords that can be made the default first. |
145 for (auto* template_url : urls) { | 145 for (auto* template_url : urls) { |
146 // NOTE: we don't use ShowInDefaultList here to avoid items bouncing around | 146 auto entry = base::MakeUnique<ModelEntry>(this, template_url); |
147 // the lists while editing. | 147 if (template_url_service_->ShowInDefaultList(template_url)) |
148 if (template_url->show_in_default_list()) | 148 default_entries.push_back(std::move(entry)); |
149 default_entries.push_back( | |
150 base::MakeUnique<ModelEntry>(this, template_url)); | |
151 else if (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION) | 149 else if (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION) |
152 extension_entries.push_back( | 150 extension_entries.push_back(std::move(entry)); |
153 base::MakeUnique<ModelEntry>(this, template_url)); | |
154 else | 151 else |
155 other_entries.push_back(base::MakeUnique<ModelEntry>(this, template_url)); | 152 other_entries.push_back(std::move(entry)); |
156 } | 153 } |
157 | 154 |
158 last_search_engine_index_ = static_cast<int>(default_entries.size()); | 155 last_search_engine_index_ = static_cast<int>(default_entries.size()); |
159 last_other_engine_index_ = last_search_engine_index_ + | 156 last_other_engine_index_ = last_search_engine_index_ + |
160 static_cast<int>(other_entries.size()); | 157 static_cast<int>(other_entries.size()); |
161 | 158 |
162 std::move(default_entries.begin(), default_entries.end(), | 159 std::move(default_entries.begin(), default_entries.end(), |
163 std::back_inserter(entries_)); | 160 std::back_inserter(entries_)); |
164 | 161 |
165 std::move(other_entries.begin(), other_entries.end(), | 162 std::move(other_entries.begin(), other_entries.end(), |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 } | 383 } |
387 | 384 |
388 void TemplateURLTableModel::AddEntry(int index, | 385 void TemplateURLTableModel::AddEntry(int index, |
389 std::unique_ptr<ModelEntry> entry) { | 386 std::unique_ptr<ModelEntry> entry) { |
390 entries_.insert(entries_.begin() + index, std::move(entry)); | 387 entries_.insert(entries_.begin() + index, std::move(entry)); |
391 if (index <= last_other_engine_index_) | 388 if (index <= last_other_engine_index_) |
392 ++last_other_engine_index_; | 389 ++last_other_engine_index_; |
393 if (observer_) | 390 if (observer_) |
394 observer_->OnItemsAdded(index, 1); | 391 observer_->OnItemsAdded(index, 1); |
395 } | 392 } |
OLD | NEW |