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/edit_search_engine_controller.h" | 5 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h" |
6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" |
7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
11 #include "components/search_engines/template_url.h" | 12 #include "components/search_engines/template_url.h" |
12 #include "components/search_engines/template_url_service.h" | 13 #include "components/search_engines/template_url_service.h" |
13 #include "components/url_formatter/url_fixer.h" | 14 #include "components/url_formatter/url_fixer.h" |
14 #include "content/public/browser/user_metrics.h" | 15 #include "content/public/browser/user_metrics.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
17 using base::UserMetricsAction; | 18 using base::UserMetricsAction; |
18 | 19 |
19 EditSearchEngineController::EditSearchEngineController( | 20 EditSearchEngineController::EditSearchEngineController( |
20 TemplateURL* template_url, | 21 TemplateURL* template_url, |
21 EditSearchEngineControllerDelegate* edit_keyword_delegate, | 22 EditSearchEngineControllerDelegate* edit_keyword_delegate, |
22 Profile* profile) | 23 Profile* profile) |
23 : template_url_(template_url), | 24 : template_url_(template_url), |
24 edit_keyword_delegate_(edit_keyword_delegate), | 25 edit_keyword_delegate_(edit_keyword_delegate), |
25 profile_(profile) { | 26 profile_(profile) { |
26 DCHECK(profile_); | 27 DCHECK(profile_); |
| 28 UMA_HISTOGRAM_ENUMERATION("Search.AddSearchProvider", |
| 29 CONFIRMATION_DIALOG_SHOWN, |
| 30 NUM_EDIT_SEARCH_ENGINE_ACTIONS); |
27 } | 31 } |
28 | 32 |
29 bool EditSearchEngineController::IsTitleValid( | 33 bool EditSearchEngineController::IsTitleValid( |
30 const base::string16& title_input) const { | 34 const base::string16& title_input) const { |
31 return !base::CollapseWhitespace(title_input, true).empty(); | 35 return !base::CollapseWhitespace(title_input, true).empty(); |
32 } | 36 } |
33 | 37 |
34 bool EditSearchEngineController::IsURLValid( | 38 bool EditSearchEngineController::IsURLValid( |
35 const std::string& url_input) const { | 39 const std::string& url_input) const { |
36 std::string url = GetFixedUpURL(url_input); | 40 std::string url = GetFixedUpURL(url_input); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 DCHECK(template_url_); | 109 DCHECK(template_url_); |
106 // TemplateURLService takes ownership of template_url_. | 110 // TemplateURLService takes ownership of template_url_. |
107 template_url_service->AddWithOverrides(template_url_, title_input, | 111 template_url_service->AddWithOverrides(template_url_, title_input, |
108 keyword_input, url_string); | 112 keyword_input, url_string); |
109 content::RecordAction(UserMetricsAction("KeywordEditor_AddKeywordJS")); | 113 content::RecordAction(UserMetricsAction("KeywordEditor_AddKeywordJS")); |
110 } else { | 114 } else { |
111 // Adding or modifying an entry via the Delegate. | 115 // Adding or modifying an entry via the Delegate. |
112 edit_keyword_delegate_->OnEditedKeyword(template_url_, title_input, | 116 edit_keyword_delegate_->OnEditedKeyword(template_url_, title_input, |
113 keyword_input, url_string); | 117 keyword_input, url_string); |
114 } | 118 } |
| 119 |
| 120 UMA_HISTOGRAM_ENUMERATION("Search.AddSearchProvider", |
| 121 CONFIRMATION_DIALOG_CONFIRMED, |
| 122 NUM_EDIT_SEARCH_ENGINE_ACTIONS); |
115 } | 123 } |
116 | 124 |
117 void EditSearchEngineController::CleanUpCancelledAdd() { | 125 void EditSearchEngineController::CleanUpCancelledAdd() { |
118 if (!edit_keyword_delegate_ && template_url_) { | 126 if (!edit_keyword_delegate_ && template_url_) { |
119 // When we have no Delegate, we know that the template_url_ hasn't yet been | 127 // When we have no Delegate, we know that the template_url_ hasn't yet been |
120 // added to the model, so we need to clean it up. | 128 // added to the model, so we need to clean it up. |
121 delete template_url_; | 129 delete template_url_; |
122 template_url_ = NULL; | 130 template_url_ = NULL; |
123 } | 131 } |
| 132 |
| 133 UMA_HISTOGRAM_ENUMERATION("Search.AddSearchProvider", |
| 134 CONFIRMATION_DIALOG_CANCELLED, |
| 135 NUM_EDIT_SEARCH_ENGINE_ACTIONS); |
124 } | 136 } |
125 | 137 |
126 std::string EditSearchEngineController::GetFixedUpURL( | 138 std::string EditSearchEngineController::GetFixedUpURL( |
127 const std::string& url_input) const { | 139 const std::string& url_input) const { |
128 std::string url; | 140 std::string url; |
129 base::TrimWhitespace(TemplateURLRef::DisplayURLToURLRef( | 141 base::TrimWhitespace(TemplateURLRef::DisplayURLToURLRef( |
130 base::UTF8ToUTF16(url_input)), | 142 base::UTF8ToUTF16(url_input)), |
131 base::TRIM_ALL, &url); | 143 base::TRIM_ALL, &url); |
132 if (url.empty()) | 144 if (url.empty()) |
133 return url; | 145 return url; |
134 | 146 |
135 // Parse the string as a URL to determine the scheme. If we need to, add the | 147 // Parse the string as a URL to determine the scheme. If we need to, add the |
136 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) | 148 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) |
137 // we need to replace the search terms before testing for the scheme. | 149 // we need to replace the search terms before testing for the scheme. |
138 TemplateURLData data; | 150 TemplateURLData data; |
139 data.SetURL(url); | 151 data.SetURL(url); |
140 TemplateURL t_url(data); | 152 TemplateURL t_url(data); |
141 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( | 153 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( |
142 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), | 154 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), |
143 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); | 155 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); |
144 url::Parsed parts; | 156 url::Parsed parts; |
145 std::string scheme(url_formatter::SegmentURL(expanded_url, &parts)); | 157 std::string scheme(url_formatter::SegmentURL(expanded_url, &parts)); |
146 if (!parts.scheme.is_valid()) | 158 if (!parts.scheme.is_valid()) |
147 url.insert(0, scheme + "://"); | 159 url.insert(0, scheme + "://"); |
148 | 160 |
149 return url; | 161 return url; |
150 } | 162 } |
OLD | NEW |