diff options
author | Ben Murdoch <benm@google.com> | 2010-07-29 17:14:53 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-08-04 14:29:45 +0100 |
commit | c407dc5cd9bdc5668497f21b26b09d988ab439de (patch) | |
tree | 7eaf8707c0309516bdb042ad976feedaf72b0bb1 /chrome/browser/search_engines/keyword_editor_controller.cc | |
parent | 0998b1cdac5733f299c12d88bc31ef9c8035b8fa (diff) | |
download | external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.zip external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.tar.gz external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.tar.bz2 |
Merge Chromium src@r53293
Change-Id: Ia79acf8670f385cee48c45b0a75371d8e950af34
Diffstat (limited to 'chrome/browser/search_engines/keyword_editor_controller.cc')
-rw-r--r-- | chrome/browser/search_engines/keyword_editor_controller.cc | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/chrome/browser/search_engines/keyword_editor_controller.cc b/chrome/browser/search_engines/keyword_editor_controller.cc new file mode 100644 index 0000000..d4f9848 --- /dev/null +++ b/chrome/browser/search_engines/keyword_editor_controller.cc @@ -0,0 +1,111 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/search_engines/keyword_editor_controller.h" + +#include "base/utf_string_conversions.h" +#include "chrome/browser/metrics/user_metrics.h" +#include "chrome/browser/pref_service.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/search_engines/template_url.h" +#include "chrome/browser/search_engines/template_url_model.h" +#include "chrome/browser/search_engines/template_url_table_model.h" +#include "chrome/common/pref_names.h" + +KeywordEditorController::KeywordEditorController(Profile* profile) + : profile_(profile) { + table_model_.reset(new TemplateURLTableModel(profile->GetTemplateURLModel())); +} + +KeywordEditorController::~KeywordEditorController() { +} + +// static +// TODO(rsesek): Other platforms besides Mac should remember window +// placement. http://crbug.com/22269 +void KeywordEditorController::RegisterPrefs(PrefService* prefs) { + prefs->RegisterDictionaryPref(prefs::kKeywordEditorWindowPlacement); +} + +int KeywordEditorController::AddTemplateURL(const std::wstring& title, + const std::wstring& keyword, + const std::string& url) { + DCHECK(!url.empty()); + + UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword"), + profile_); + + TemplateURL* template_url = new TemplateURL(); + template_url->set_short_name(title); + template_url->set_keyword(keyword); + template_url->SetURL(url, 0, 0); + + // There's a bug (1090726) in TableView with groups enabled such that newly + // added items in groups ALWAYS appear at the end, regardless of the index + // passed in. Worse yet, the selected rows get messed up when this happens + // causing other problems. As a work around we always add the item to the end + // of the list. + const int new_index = table_model_->RowCount(); + table_model_->Add(new_index, template_url); + + return new_index; +} + +void KeywordEditorController::ModifyTemplateURL(const TemplateURL* template_url, + const std::wstring& title, + const std::wstring& keyword, + const std::string& url) { + const int index = table_model_->IndexOfTemplateURL(template_url); + if (index == -1) { + // Will happen if url was deleted out from under us while the user was + // editing it. + return; + } + + // Don't do anything if the entry didn't change. + if (template_url->short_name() == title && + template_url->keyword() == keyword && + ((url.empty() && !template_url->url()) || + (!url.empty() && template_url->url() && + template_url->url()->url() == url))) { + return; + } + + table_model_->ModifyTemplateURL(index, title, keyword, url); + + UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_ModifiedKeyword"), + profile_); +} + +bool KeywordEditorController::CanMakeDefault(const TemplateURL* url) const { + return (url != url_model()->GetDefaultSearchProvider() && + url->url() && + url->url()->SupportsReplacement()); +} + +bool KeywordEditorController::CanRemove(const TemplateURL* url) const { + return url != url_model()->GetDefaultSearchProvider(); +} + +void KeywordEditorController::RemoveTemplateURL(int index) { + table_model_->Remove(index); + UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_RemoveKeyword"), + profile_); +} + +int KeywordEditorController::MakeDefaultTemplateURL(int index) { + return table_model_->MakeDefaultTemplateURL(index); +} + +bool KeywordEditorController::loaded() const { + return url_model()->loaded(); +} + +const TemplateURL* KeywordEditorController::GetTemplateURL(int index) const { + return &table_model_->GetTemplateURL(index); +} + +TemplateURLModel* KeywordEditorController::url_model() const { + return table_model_->template_url_model(); +} |