Chromium Code Reviews| 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/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 12 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 12 #include "components/search_engines/template_url.h" | 13 #include "components/search_engines/template_url.h" |
| 13 #include "components/search_engines/template_url_service.h" | 14 #include "components/search_engines/template_url_service.h" |
| 14 #include "components/url_formatter/url_fixer.h" | 15 #include "components/url_formatter/url_fixer.h" |
| 15 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // TODO(pamg): Really, we should modify the entry so this later one | 98 // TODO(pamg): Really, we should modify the entry so this later one |
| 98 // overwrites it. But we don't expect this case to be common. | 99 // overwrites it. But we don't expect this case to be common. |
| 99 CleanUpCancelledAdd(); | 100 CleanUpCancelledAdd(); |
| 100 return; | 101 return; |
| 101 } | 102 } |
| 102 | 103 |
| 103 if (!edit_keyword_delegate_) { | 104 if (!edit_keyword_delegate_) { |
| 104 // 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 |
| 105 // hasn't yet been added to the model. | 106 // hasn't yet been added to the model. |
| 106 DCHECK(template_url_); | 107 DCHECK(template_url_); |
| 107 // TemplateURLService takes ownership of template_url_. | 108 // TemplateURLService takes ownership of template_url_. |
|
Peter Kasting
2016/08/31 04:12:56
Nit: Comment is now redundant.
Avi (use Gerrit)
2016/09/01 00:34:26
Done.
| |
| 108 template_url_service->AddWithOverrides(template_url_, title_input, | 109 template_url_service->AddWithOverrides(base::WrapUnique(template_url_), |
| 109 keyword_input, url_string); | 110 title_input, keyword_input, |
| 111 url_string); | |
| 110 content::RecordAction(UserMetricsAction("KeywordEditor_AddKeywordJS")); | 112 content::RecordAction(UserMetricsAction("KeywordEditor_AddKeywordJS")); |
| 111 } else { | 113 } else { |
| 112 // Adding or modifying an entry via the Delegate. | 114 // Adding or modifying an entry via the Delegate. |
| 113 edit_keyword_delegate_->OnEditedKeyword(template_url_, title_input, | 115 edit_keyword_delegate_->OnEditedKeyword(template_url_, title_input, |
| 114 keyword_input, url_string); | 116 keyword_input, url_string); |
| 115 } | 117 } |
| 116 } | 118 } |
| 117 | 119 |
| 118 void EditSearchEngineController::CleanUpCancelledAdd() { | 120 void EditSearchEngineController::CleanUpCancelledAdd() { |
| 119 if (!edit_keyword_delegate_ && template_url_) { | 121 if (!edit_keyword_delegate_ && template_url_) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 142 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( | 144 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( |
| 143 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), | 145 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), |
| 144 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); | 146 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); |
| 145 url::Parsed parts; | 147 url::Parsed parts; |
| 146 std::string scheme(url_formatter::SegmentURL(expanded_url, &parts)); | 148 std::string scheme(url_formatter::SegmentURL(expanded_url, &parts)); |
| 147 if (!parts.scheme.is_valid()) | 149 if (!parts.scheme.is_valid()) |
| 148 url.insert(0, scheme + "://"); | 150 url.insert(0, scheme + "://"); |
| 149 | 151 |
| 150 return url; | 152 return url; |
| 151 } | 153 } |
| OLD | NEW |