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

Side by Side Diff: chrome/browser/search_engines/template_url.cc

Issue 272573004: Handle TemplateURLService load failure better, and make some test correctness fixes that will be ne… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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/search_engines/template_url.h" 5 #include "chrome/browser/search_engines/template_url.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 int favicon_path_len = arraysize(favicon_path) - 1; 1105 int favicon_path_len = arraysize(favicon_path) - 1;
1106 1106
1107 rep.SetPath(favicon_path, url::Component(0, favicon_path_len)); 1107 rep.SetPath(favicon_path, url::Component(0, favicon_path_len));
1108 rep.ClearUsername(); 1108 rep.ClearUsername();
1109 rep.ClearPassword(); 1109 rep.ClearPassword();
1110 rep.ClearQuery(); 1110 rep.ClearQuery();
1111 rep.ClearRef(); 1111 rep.ClearRef();
1112 return url.ReplaceComponents(rep); 1112 return url.ReplaceComponents(rep);
1113 } 1113 }
1114 1114
1115 // static
1116 bool TemplateURL::MatchesData(const TemplateURL* t_url,
1117 const TemplateURLData* data) {
1118 if (!t_url || !data)
1119 return !t_url && !data;
1120
1121 return (t_url->short_name() == data->short_name) &&
1122 t_url->HasSameKeywordAs(*data) &&
1123 (t_url->url() == data->url()) &&
1124 (t_url->suggestions_url() == data->suggestions_url) &&
1125 (t_url->instant_url() == data->instant_url) &&
1126 (t_url->image_url() == data->image_url) &&
1127 (t_url->new_tab_url() == data->new_tab_url) &&
1128 (t_url->search_url_post_params() == data->search_url_post_params) &&
1129 (t_url->suggestions_url_post_params() ==
1130 data->suggestions_url_post_params) &&
1131 (t_url->instant_url_post_params() == data->instant_url_post_params) &&
1132 (t_url->image_url_post_params() == data->image_url_post_params) &&
1133 (t_url->favicon_url() == data->favicon_url) &&
1134 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) &&
1135 (t_url->show_in_default_list() == data->show_in_default_list) &&
1136 (t_url->input_encodings() == data->input_encodings) &&
1137 (t_url->alternate_urls() == data->alternate_urls) &&
1138 (t_url->search_terms_replacement_key() ==
1139 data->search_terms_replacement_key);
1140 }
1141
1115 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { 1142 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
1116 base::string16 bidi_safe_short_name = data_.short_name; 1143 base::string16 bidi_safe_short_name = data_.short_name;
1117 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); 1144 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name);
1118 return bidi_safe_short_name; 1145 return bidi_safe_short_name;
1119 } 1146 }
1120 1147
1121 bool TemplateURL::ShowInDefaultList() const { 1148 bool TemplateURL::ShowInDefaultList() const {
1122 return data_.show_in_default_list && url_ref_.SupportsReplacement(); 1149 return data_.show_in_default_list && url_ref_.SupportsReplacement();
1123 } 1150 }
1124 1151
1125 bool TemplateURL::SupportsReplacement() const { 1152 bool TemplateURL::SupportsReplacement() const {
1126 UIThreadSearchTermsData search_terms_data(profile_); 1153 UIThreadSearchTermsData search_terms_data(profile_);
1127 return SupportsReplacementUsingTermsData(search_terms_data); 1154 return SupportsReplacementUsingTermsData(search_terms_data);
1128 } 1155 }
1129 1156
1130 bool TemplateURL::SupportsReplacementUsingTermsData( 1157 bool TemplateURL::SupportsReplacementUsingTermsData(
1131 const SearchTermsData& search_terms_data) const { 1158 const SearchTermsData& search_terms_data) const {
1132 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); 1159 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data);
1133 } 1160 }
1134 1161
1162 bool TemplateURL::HasGoogleBaseURLs() const {
1163 return url_ref_.HasGoogleBaseURLs() ||
1164 suggestions_url_ref_.HasGoogleBaseURLs() ||
1165 instant_url_ref_.HasGoogleBaseURLs() ||
1166 image_url_ref_.HasGoogleBaseURLs() ||
1167 new_tab_url_ref_.HasGoogleBaseURLs();
1168 }
1169
1135 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const { 1170 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const {
1136 return (GetType() == NORMAL) && url_ref_.HasGoogleBaseURLs() && 1171 return (GetType() == NORMAL) && url_ref_.HasGoogleBaseURLs() &&
1137 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()), 1172 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()),
1138 google_util::DISALLOW_SUBDOMAIN); 1173 google_util::DISALLOW_SUBDOMAIN);
1139 } 1174 }
1140 1175
1141 bool TemplateURL::HasSameKeywordAs(const TemplateURLData& other) const { 1176 bool TemplateURL::HasSameKeywordAs(const TemplateURLData& other) const {
1142 return (data_.keyword() == other.keyword()) || 1177 return (data_.keyword() == other.keyword()) ||
1143 (IsGoogleSearchURLWithReplaceableKeyword() && 1178 (IsGoogleSearchURLWithReplaceableKeyword() &&
1144 TemplateURL(NULL, other).IsGoogleSearchURLWithReplaceableKeyword()); 1179 TemplateURL(NULL, other).IsGoogleSearchURLWithReplaceableKeyword());
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 // patterns. This means that given patterns 1365 // patterns. This means that given patterns
1331 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1366 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1332 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1367 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1333 // return false. This is important for at least Google, where such URLs 1368 // return false. This is important for at least Google, where such URLs
1334 // are invalid. 1369 // are invalid.
1335 return !search_terms->empty(); 1370 return !search_terms->empty();
1336 } 1371 }
1337 } 1372 }
1338 return false; 1373 return false;
1339 } 1374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698