Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(892)

Side by Side Diff: chrome/browser/ui/search_engines/keyword_editor_controller.cc

Issue 8919017: Split UserMetrics into API vs. implementation. Move API to content/public. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Version for commit (merged again). Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/keyword_editor_controller.h" 5 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search_engines/template_url.h" 10 #include "chrome/browser/search_engines/template_url.h"
11 #include "chrome/browser/search_engines/template_url_service.h" 11 #include "chrome/browser/search_engines/template_url_service.h"
12 #include "chrome/browser/search_engines/template_url_service_factory.h" 12 #include "chrome/browser/search_engines/template_url_service_factory.h"
13 #include "chrome/browser/ui/search_engines/template_url_table_model.h" 13 #include "chrome/browser/ui/search_engines/template_url_table_model.h"
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "content/browser/user_metrics.h" 15 #include "content/public/browser/user_metrics.h"
16
17 using content::UserMetricsAction;
16 18
17 KeywordEditorController::KeywordEditorController(Profile* profile) 19 KeywordEditorController::KeywordEditorController(Profile* profile)
18 : profile_(profile) { 20 : profile_(profile) {
19 table_model_.reset(new TemplateURLTableModel( 21 table_model_.reset(new TemplateURLTableModel(
20 TemplateURLServiceFactory::GetForProfile(profile))); 22 TemplateURLServiceFactory::GetForProfile(profile)));
21 } 23 }
22 24
23 KeywordEditorController::~KeywordEditorController() { 25 KeywordEditorController::~KeywordEditorController() {
24 } 26 }
25 27
26 // static 28 // static
27 // TODO(rsesek): Other platforms besides Mac should remember window 29 // TODO(rsesek): Other platforms besides Mac should remember window
28 // placement. http://crbug.com/22269 30 // placement. http://crbug.com/22269
29 void KeywordEditorController::RegisterPrefs(PrefService* prefs) { 31 void KeywordEditorController::RegisterPrefs(PrefService* prefs) {
30 prefs->RegisterDictionaryPref(prefs::kKeywordEditorWindowPlacement); 32 prefs->RegisterDictionaryPref(prefs::kKeywordEditorWindowPlacement);
31 } 33 }
32 34
33 int KeywordEditorController::AddTemplateURL(const string16& title, 35 int KeywordEditorController::AddTemplateURL(const string16& title,
34 const string16& keyword, 36 const string16& keyword,
35 const std::string& url) { 37 const std::string& url) {
36 DCHECK(!url.empty()); 38 DCHECK(!url.empty());
37 39
38 UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword")); 40 content::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword"));
39 41
40 TemplateURL* template_url = new TemplateURL(); 42 TemplateURL* template_url = new TemplateURL();
41 template_url->set_short_name(title); 43 template_url->set_short_name(title);
42 template_url->set_keyword(keyword); 44 template_url->set_keyword(keyword);
43 template_url->SetURL(url, 0, 0); 45 template_url->SetURL(url, 0, 0);
44 46
45 // There's a bug (1090726) in TableView with groups enabled such that newly 47 // There's a bug (1090726) in TableView with groups enabled such that newly
46 // added items in groups ALWAYS appear at the end, regardless of the index 48 // added items in groups ALWAYS appear at the end, regardless of the index
47 // passed in. Worse yet, the selected rows get messed up when this happens 49 // passed in. Worse yet, the selected rows get messed up when this happens
48 // causing other problems. As a work around we always add the item to the end 50 // causing other problems. As a work around we always add the item to the end
(...skipping 19 matching lines...) Expand all
68 if (template_url->short_name() == title && 70 if (template_url->short_name() == title &&
69 template_url->keyword() == keyword && 71 template_url->keyword() == keyword &&
70 ((url.empty() && !template_url->url()) || 72 ((url.empty() && !template_url->url()) ||
71 (!url.empty() && template_url->url() && 73 (!url.empty() && template_url->url() &&
72 template_url->url()->url() == url))) { 74 template_url->url()->url() == url))) {
73 return; 75 return;
74 } 76 }
75 77
76 table_model_->ModifyTemplateURL(index, title, keyword, url); 78 table_model_->ModifyTemplateURL(index, title, keyword, url);
77 79
78 UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_ModifiedKeyword")); 80 content::RecordAction(UserMetricsAction("KeywordEditor_ModifiedKeyword"));
79 } 81 }
80 82
81 bool KeywordEditorController::CanEdit(const TemplateURL* url) const { 83 bool KeywordEditorController::CanEdit(const TemplateURL* url) const {
82 return !url_model()->is_default_search_managed() || 84 return !url_model()->is_default_search_managed() ||
83 url != url_model()->GetDefaultSearchProvider(); 85 url != url_model()->GetDefaultSearchProvider();
84 } 86 }
85 87
86 bool KeywordEditorController::CanMakeDefault(const TemplateURL* url) const { 88 bool KeywordEditorController::CanMakeDefault(const TemplateURL* url) const {
87 return url_model()->CanMakeDefault(url); 89 return url_model()->CanMakeDefault(url);
88 } 90 }
89 91
90 bool KeywordEditorController::CanRemove(const TemplateURL* url) const { 92 bool KeywordEditorController::CanRemove(const TemplateURL* url) const {
91 return url != url_model()->GetDefaultSearchProvider(); 93 return url != url_model()->GetDefaultSearchProvider();
92 } 94 }
93 95
94 void KeywordEditorController::RemoveTemplateURL(int index) { 96 void KeywordEditorController::RemoveTemplateURL(int index) {
95 table_model_->Remove(index); 97 table_model_->Remove(index);
96 UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_RemoveKeyword")); 98 content::RecordAction(UserMetricsAction("KeywordEditor_RemoveKeyword"));
97 } 99 }
98 100
99 int KeywordEditorController::MakeDefaultTemplateURL(int index) { 101 int KeywordEditorController::MakeDefaultTemplateURL(int index) {
100 return table_model_->MakeDefaultTemplateURL(index); 102 return table_model_->MakeDefaultTemplateURL(index);
101 } 103 }
102 104
103 bool KeywordEditorController::loaded() const { 105 bool KeywordEditorController::loaded() const {
104 return url_model()->loaded(); 106 return url_model()->loaded();
105 } 107 }
106 108
107 const TemplateURL* KeywordEditorController::GetTemplateURL(int index) const { 109 const TemplateURL* KeywordEditorController::GetTemplateURL(int index) const {
108 return &table_model_->GetTemplateURL(index); 110 return &table_model_->GetTemplateURL(index);
109 } 111 }
110 112
111 TemplateURLService* KeywordEditorController::url_model() const { 113 TemplateURLService* KeywordEditorController::url_model() const {
112 return table_model_->template_url_service(); 114 return table_model_->template_url_service();
113 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698