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

Side by Side Diff: components/search_engines/template_url.cc

Issue 2814743006: Refactoring after comments in https://codereview.chromium.org/2639153002 (Closed)
Patch Set: Fixed after review, round 2 Created 3 years, 8 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/search_engines/template_url.h" 5 #include "components/search_engines/template_url.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 if (!post_params_.empty()) 1131 if (!post_params_.empty())
1132 EncodeFormData(post_params_, post_content); 1132 EncodeFormData(post_params_, post_content);
1133 1133
1134 return url; 1134 return url;
1135 } 1135 }
1136 1136
1137 1137
1138 // TemplateURL ---------------------------------------------------------------- 1138 // TemplateURL ----------------------------------------------------------------
1139 1139
1140 TemplateURL::AssociatedExtensionInfo::AssociatedExtensionInfo( 1140 TemplateURL::AssociatedExtensionInfo::AssociatedExtensionInfo(
1141 const std::string& extension_id) 1141 const std::string& extension_id,
1142 : extension_id(extension_id), wants_to_be_default_engine(false) {} 1142 base::Time install_time,
1143 bool wants_to_be_default_engine)
1144 : extension_id(extension_id),
1145 install_time(install_time),
1146 wants_to_be_default_engine(wants_to_be_default_engine) {}
1143 1147
1144 TemplateURL::AssociatedExtensionInfo::~AssociatedExtensionInfo() { 1148 TemplateURL::AssociatedExtensionInfo::~AssociatedExtensionInfo() {
1145 } 1149 }
1146 1150
1147 TemplateURL::TemplateURL(const TemplateURLData& data, Type type) 1151 TemplateURL::TemplateURL(const TemplateURLData& data, Type type)
1148 : data_(data), 1152 : data_(data),
1149 url_ref_(nullptr), 1153 url_ref_(nullptr),
1150 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), 1154 suggestions_url_ref_(this, TemplateURLRef::SUGGEST),
1151 instant_url_ref_(this, TemplateURLRef::INSTANT), 1155 instant_url_ref_(this, TemplateURLRef::INSTANT),
1152 image_url_ref_(this, TemplateURLRef::IMAGE), 1156 image_url_ref_(this, TemplateURLRef::IMAGE),
1153 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), 1157 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB),
1154 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), 1158 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH),
1155 type_(type), 1159 type_(type),
1156 engine_type_(SEARCH_ENGINE_UNKNOWN) { 1160 engine_type_(SEARCH_ENGINE_UNKNOWN) {
1157 ResizeURLRefVector(); 1161 ResizeURLRefVector();
1158 SetPrepopulateId(data_.prepopulate_id); 1162 SetPrepopulateId(data_.prepopulate_id);
1159 1163
1160 if (data_.search_terms_replacement_key == 1164 if (data_.search_terms_replacement_key ==
1161 google_util::kGoogleInstantExtendedEnabledKeyFull) 1165 google_util::kGoogleInstantExtendedEnabledKeyFull)
1162 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; 1166 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam;
1163 } 1167 }
1164 1168
1169 TemplateURL::TemplateURL(const TemplateURLData& data,
1170 Type type,
1171 std::string extension_id,
1172 base::Time install_time,
1173 bool wants_to_be_default_engine)
1174 : TemplateURL(data, type) {
1175 DCHECK(type == NORMAL_CONTROLLED_BY_EXTENSION ||
1176 type == OMNIBOX_API_EXTENSION);
1177 // Omnibox keywords may not be set as default.
1178 DCHECK(!wants_to_be_default_engine || type != OMNIBOX_API_EXTENSION) << type;
1179 DCHECK_EQ(kInvalidTemplateURLID, data.id);
1180 extension_info_ = base::MakeUnique<AssociatedExtensionInfo>(
1181 extension_id, install_time, wants_to_be_default_engine);
1182 }
1183
1165 TemplateURL::~TemplateURL() { 1184 TemplateURL::~TemplateURL() {
1166 } 1185 }
1167 1186
1168 // static 1187 // static
1169 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { 1188 base::string16 TemplateURL::GenerateKeyword(const GURL& url) {
1170 DCHECK(url.is_valid()); 1189 DCHECK(url.is_valid());
1171 // Strip "www." off the front of the keyword; otherwise the keyword won't work 1190 // Strip "www." off the front of the keyword; otherwise the keyword won't work
1172 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . 1191 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 .
1173 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it, 1192 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it,
1174 // convert to Unicode, so it won't look like a confusing punycode string. 1193 // convert to Unicode, so it won't look like a confusing punycode string.
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 // patterns. This means that given patterns 1518 // patterns. This means that given patterns
1500 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1519 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1501 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1520 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1502 // return false. This is important for at least Google, where such URLs 1521 // return false. This is important for at least Google, where such URLs
1503 // are invalid. 1522 // are invalid.
1504 return !search_terms->empty(); 1523 return !search_terms->empty();
1505 } 1524 }
1506 } 1525 }
1507 return false; 1526 return false;
1508 } 1527 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url.h ('k') | components/search_engines/template_url_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698