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> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/task/cancelable_task_tracker.h" | 12 #include "base/task/cancelable_task_tracker.h" |
11 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
12 #include "components/favicon/core/favicon_service.h" | 14 #include "components/favicon/core/favicon_service.h" |
13 #include "components/favicon_base/favicon_types.h" | 15 #include "components/favicon_base/favicon_types.h" |
14 #include "components/search_engines/template_url.h" | 16 #include "components/search_engines/template_url.h" |
15 #include "components/search_engines/template_url_service.h" | 17 #include "components/search_engines/template_url_service.h" |
16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 DCHECK(!url.empty()); | 263 DCHECK(!url.empty()); |
262 template_url_service_->RemoveObserver(this); | 264 template_url_service_->RemoveObserver(this); |
263 TemplateURLData data; | 265 TemplateURLData data; |
264 data.SetShortName(short_name); | 266 data.SetShortName(short_name); |
265 data.SetKeyword(keyword); | 267 data.SetKeyword(keyword); |
266 data.SetURL(url); | 268 data.SetURL(url); |
267 TemplateURL* turl = new TemplateURL(data); | 269 TemplateURL* turl = new TemplateURL(data); |
268 template_url_service_->Add(turl); | 270 template_url_service_->Add(turl); |
269 scoped_ptr<ModelEntry> entry(new ModelEntry(this, turl)); | 271 scoped_ptr<ModelEntry> entry(new ModelEntry(this, turl)); |
270 template_url_service_->AddObserver(this); | 272 template_url_service_->AddObserver(this); |
271 AddEntry(index, entry.Pass()); | 273 AddEntry(index, std::move(entry)); |
272 } | 274 } |
273 | 275 |
274 void TemplateURLTableModel::ModifyTemplateURL(int index, | 276 void TemplateURLTableModel::ModifyTemplateURL(int index, |
275 const base::string16& title, | 277 const base::string16& title, |
276 const base::string16& keyword, | 278 const base::string16& keyword, |
277 const std::string& url) { | 279 const std::string& url) { |
278 DCHECK(index >= 0 && index <= RowCount()); | 280 DCHECK(index >= 0 && index <= RowCount()); |
279 DCHECK(!url.empty()); | 281 DCHECK(!url.empty()); |
280 TemplateURL* template_url = GetTemplateURL(index); | 282 TemplateURL* template_url = GetTemplateURL(index); |
281 // The default search provider should support replacement. | 283 // The default search provider should support replacement. |
(...skipping 28 matching lines...) Expand all Loading... |
310 } | 312 } |
311 return -1; | 313 return -1; |
312 } | 314 } |
313 | 315 |
314 int TemplateURLTableModel::MoveToMainGroup(int index) { | 316 int TemplateURLTableModel::MoveToMainGroup(int index) { |
315 if (index < last_search_engine_index_) | 317 if (index < last_search_engine_index_) |
316 return index; // Already in the main group. | 318 return index; // Already in the main group. |
317 | 319 |
318 scoped_ptr<ModelEntry> current_entry(RemoveEntry(index)); | 320 scoped_ptr<ModelEntry> current_entry(RemoveEntry(index)); |
319 const int new_index = last_search_engine_index_++; | 321 const int new_index = last_search_engine_index_++; |
320 AddEntry(new_index, current_entry.Pass()); | 322 AddEntry(new_index, std::move(current_entry)); |
321 return new_index; | 323 return new_index; |
322 } | 324 } |
323 | 325 |
324 int TemplateURLTableModel::MakeDefaultTemplateURL(int index) { | 326 int TemplateURLTableModel::MakeDefaultTemplateURL(int index) { |
325 if (index < 0 || index >= RowCount()) { | 327 if (index < 0 || index >= RowCount()) { |
326 NOTREACHED(); | 328 NOTREACHED(); |
327 return -1; | 329 return -1; |
328 } | 330 } |
329 | 331 |
330 TemplateURL* keyword = GetTemplateURL(index); | 332 TemplateURL* keyword = GetTemplateURL(index); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 scoped_ptr<TemplateURLTableModel::ModelEntry> | 376 scoped_ptr<TemplateURLTableModel::ModelEntry> |
375 TemplateURLTableModel::RemoveEntry(int index) { | 377 TemplateURLTableModel::RemoveEntry(int index) { |
376 scoped_ptr<ModelEntry> entry(entries_[index]); | 378 scoped_ptr<ModelEntry> entry(entries_[index]); |
377 entries_.erase(index + entries_.begin()); | 379 entries_.erase(index + entries_.begin()); |
378 if (index < last_search_engine_index_) | 380 if (index < last_search_engine_index_) |
379 --last_search_engine_index_; | 381 --last_search_engine_index_; |
380 if (index < last_other_engine_index_) | 382 if (index < last_other_engine_index_) |
381 --last_other_engine_index_; | 383 --last_other_engine_index_; |
382 if (observer_) | 384 if (observer_) |
383 observer_->OnItemsRemoved(index, 1); | 385 observer_->OnItemsRemoved(index, 1); |
384 return entry.Pass(); | 386 return entry; |
385 } | 387 } |
386 | 388 |
387 void TemplateURLTableModel::AddEntry(int index, scoped_ptr<ModelEntry> entry) { | 389 void TemplateURLTableModel::AddEntry(int index, scoped_ptr<ModelEntry> entry) { |
388 entries_.insert(entries_.begin() + index, entry.release()); | 390 entries_.insert(entries_.begin() + index, entry.release()); |
389 if (index <= last_other_engine_index_) | 391 if (index <= last_other_engine_index_) |
390 ++last_other_engine_index_; | 392 ++last_other_engine_index_; |
391 if (observer_) | 393 if (observer_) |
392 observer_->OnItemsAdded(index, 1); | 394 observer_->OnItemsAdded(index, 1); |
393 } | 395 } |
OLD | NEW |