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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/metrics/user_metrics.h" |
9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/search_engines/template_url_service_factory.h" | 13 #include "chrome/browser/search_engines/template_url_service_factory.h" |
13 #include "components/search_engines/template_url.h" | 14 #include "components/search_engines/template_url.h" |
14 #include "components/search_engines/template_url_service.h" | 15 #include "components/search_engines/template_url_service.h" |
15 #include "components/url_formatter/url_fixer.h" | 16 #include "components/url_formatter/url_fixer.h" |
16 #include "content/public/browser/user_metrics.h" | |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 using base::UserMetricsAction; | 19 using base::UserMetricsAction; |
20 | 20 |
21 EditSearchEngineController::EditSearchEngineController( | 21 EditSearchEngineController::EditSearchEngineController( |
22 TemplateURL* template_url, | 22 TemplateURL* template_url, |
23 EditSearchEngineControllerDelegate* edit_keyword_delegate, | 23 EditSearchEngineControllerDelegate* edit_keyword_delegate, |
24 Profile* profile) | 24 Profile* profile) |
25 : template_url_(template_url), | 25 : template_url_(template_url), |
26 edit_keyword_delegate_(edit_keyword_delegate), | 26 edit_keyword_delegate_(edit_keyword_delegate), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 if (!edit_keyword_delegate_) { | 104 if (!edit_keyword_delegate_) { |
105 // Confiming an entry we got from JS. We have a template_url_, but it | 105 // Confiming an entry we got from JS. We have a template_url_, but it |
106 // hasn't yet been added to the model. | 106 // hasn't yet been added to the model. |
107 DCHECK(template_url_); | 107 DCHECK(template_url_); |
108 template_url_service->AddWithOverrides(base::WrapUnique(template_url_), | 108 template_url_service->AddWithOverrides(base::WrapUnique(template_url_), |
109 title_input, keyword_input, | 109 title_input, keyword_input, |
110 url_string); | 110 url_string); |
111 content::RecordAction(UserMetricsAction("KeywordEditor_AddKeywordJS")); | 111 base::RecordAction(UserMetricsAction("KeywordEditor_AddKeywordJS")); |
112 } else { | 112 } else { |
113 // Adding or modifying an entry via the Delegate. | 113 // Adding or modifying an entry via the Delegate. |
114 edit_keyword_delegate_->OnEditedKeyword(template_url_, title_input, | 114 edit_keyword_delegate_->OnEditedKeyword(template_url_, title_input, |
115 keyword_input, url_string); | 115 keyword_input, url_string); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 void EditSearchEngineController::CleanUpCancelledAdd() { | 119 void EditSearchEngineController::CleanUpCancelledAdd() { |
120 if (!edit_keyword_delegate_ && template_url_) { | 120 if (!edit_keyword_delegate_ && template_url_) { |
121 // When we have no Delegate, we know that the template_url_ hasn't yet been | 121 // When we have no Delegate, we know that the template_url_ hasn't yet been |
(...skipping 21 matching lines...) Expand all Loading... |
143 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( | 143 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( |
144 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), | 144 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), |
145 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); | 145 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); |
146 url::Parsed parts; | 146 url::Parsed parts; |
147 std::string scheme(url_formatter::SegmentURL(expanded_url, &parts)); | 147 std::string scheme(url_formatter::SegmentURL(expanded_url, &parts)); |
148 if (!parts.scheme.is_valid()) | 148 if (!parts.scheme.is_valid()) |
149 url.insert(0, scheme + "://"); | 149 url.insert(0, scheme + "://"); |
150 | 150 |
151 return url; | 151 return url; |
152 } | 152 } |
OLD | NEW |