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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 last_search_engine_index_--; | 241 last_search_engine_index_--; |
242 if (observer_) | 242 if (observer_) |
243 observer_->OnItemsRemoved(index, 1); | 243 observer_->OnItemsRemoved(index, 1); |
244 | 244 |
245 // Make sure to remove from the table model first, otherwise the | 245 // Make sure to remove from the table model first, otherwise the |
246 // TemplateURL would be freed. | 246 // TemplateURL would be freed. |
247 template_url_service_->Remove(template_url); | 247 template_url_service_->Remove(template_url); |
248 template_url_service_->AddObserver(this); | 248 template_url_service_->AddObserver(this); |
249 } | 249 } |
250 | 250 |
251 void TemplateURLTableModel::Add(int index, TemplateURL* turl) { | 251 void TemplateURLTableModel::Add(int index, |
| 252 const string16& short_name, |
| 253 const string16& keyword, |
| 254 const std::string& url) { |
252 DCHECK(index >= 0 && index <= RowCount()); | 255 DCHECK(index >= 0 && index <= RowCount()); |
253 template_url_service_->RemoveObserver(this); | 256 template_url_service_->RemoveObserver(this); |
| 257 TemplateURL* turl = new TemplateURL(); |
| 258 turl->set_short_name(short_name); |
| 259 turl->set_keyword(keyword); |
| 260 turl->SetURL(url, 0, 0); |
254 template_url_service_->Add(turl); | 261 template_url_service_->Add(turl); |
255 ModelEntry* entry = new ModelEntry(this, turl); | 262 ModelEntry* entry = new ModelEntry(this, turl); |
256 template_url_service_->AddObserver(this); | 263 template_url_service_->AddObserver(this); |
257 entries_.insert(entries_.begin() + index, entry); | 264 entries_.insert(entries_.begin() + index, entry); |
258 if (observer_) | 265 if (observer_) |
259 observer_->OnItemsAdded(index, 1); | 266 observer_->OnItemsAdded(index, 1); |
260 } | 267 } |
261 | 268 |
262 void TemplateURLTableModel::ModifyTemplateURL(int index, | 269 void TemplateURLTableModel::ModifyTemplateURL(int index, |
263 const string16& title, | 270 const string16& title, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) { | 366 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) { |
360 std::vector<ModelEntry*>::iterator i = | 367 std::vector<ModelEntry*>::iterator i = |
361 std::find(entries_.begin(), entries_.end(), entry); | 368 std::find(entries_.begin(), entries_.end(), entry); |
362 DCHECK(i != entries_.end()); | 369 DCHECK(i != entries_.end()); |
363 NotifyChanged(static_cast<int>(i - entries_.begin())); | 370 NotifyChanged(static_cast<int>(i - entries_.begin())); |
364 } | 371 } |
365 | 372 |
366 void TemplateURLTableModel::OnTemplateURLServiceChanged() { | 373 void TemplateURLTableModel::OnTemplateURLServiceChanged() { |
367 Reload(); | 374 Reload(); |
368 } | 375 } |
OLD | NEW |