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

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

Issue 9965143: Revert 130431 - Move the URL string from TemplateURLRef onto the owning TemplateURL. This will mak… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | 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_service.h" 5 #include "chrome/browser/search_engines/template_url_service.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const char kReplacementTerm[] = "blah.blah.blah.blah.blah"; 64 const char kReplacementTerm[] = "blah.blah.blah.blah.blah";
65 65
66 bool TemplateURLsHaveSamePrefs(const TemplateURL* url1, 66 bool TemplateURLsHaveSamePrefs(const TemplateURL* url1,
67 const TemplateURL* url2) { 67 const TemplateURL* url2) {
68 if (url1 == url2) 68 if (url1 == url2)
69 return true; 69 return true;
70 return NULL != url1 && 70 return NULL != url1 &&
71 NULL != url2 && 71 NULL != url2 &&
72 url1->short_name() == url2->short_name() && 72 url1->short_name() == url2->short_name() &&
73 url1->keyword() == url2->keyword() && 73 url1->keyword() == url2->keyword() &&
74 url1->url() == url2->url() && 74 TemplateURLRef::SameUrlRefs(url1->url(), url2->url()) &&
75 url1->suggestions_url() == url2->suggestions_url() && 75 TemplateURLRef::SameUrlRefs(url1->suggestions_url(),
76 url1->instant_url() == url2->instant_url() && 76 url2->suggestions_url()) &&
77 url1->favicon_url() == url2->favicon_url() && 77 url1->favicon_url() == url2->favicon_url() &&
78 url1->safe_for_autoreplace() == url2->safe_for_autoreplace() && 78 url1->safe_for_autoreplace() == url2->safe_for_autoreplace() &&
79 url1->show_in_default_list() == url2->show_in_default_list() && 79 url1->show_in_default_list() == url2->show_in_default_list() &&
80 url1->input_encodings() == url2->input_encodings(); 80 url1->input_encodings() == url2->input_encodings();
81 } 81 }
82 82
83 } // namespace 83 } // namespace
84 84
85 85
86 class TemplateURLService::LessWithPrefix { 86 class TemplateURLService::LessWithPrefix {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 DCHECK(t_url); 212 DCHECK(t_url);
213 UIThreadSearchTermsData search_terms_data; 213 UIThreadSearchTermsData search_terms_data;
214 return GenerateSearchURLUsingTermsData(t_url, search_terms_data); 214 return GenerateSearchURLUsingTermsData(t_url, search_terms_data);
215 } 215 }
216 216
217 // static 217 // static
218 GURL TemplateURLService::GenerateSearchURLUsingTermsData( 218 GURL TemplateURLService::GenerateSearchURLUsingTermsData(
219 const TemplateURL* t_url, 219 const TemplateURL* t_url,
220 const SearchTermsData& search_terms_data) { 220 const SearchTermsData& search_terms_data) {
221 DCHECK(t_url); 221 DCHECK(t_url);
222 const TemplateURLRef& search_ref = t_url->url_ref(); 222 const TemplateURLRef* search_ref = t_url->url();
223 // Extension keywords don't have host-based search URLs. 223 // Extension keywords don't have host-based search URLs.
224 if (!search_ref.IsValidUsingTermsData(search_terms_data) || 224 if (!search_ref || !search_ref->IsValidUsingTermsData(search_terms_data) ||
225 t_url->IsExtensionKeyword()) 225 t_url->IsExtensionKeyword())
226 return GURL(); 226 return GURL();
227 227
228 if (!search_ref.SupportsReplacementUsingTermsData(search_terms_data)) 228 if (!search_ref->SupportsReplacementUsingTermsData(search_terms_data))
229 return GURL(t_url->url()); 229 return GURL(search_ref->url());
230 230
231 return GURL(search_ref.ReplaceSearchTermsUsingTermsData( 231 return GURL(search_ref->ReplaceSearchTermsUsingTermsData(
232 ASCIIToUTF16(kReplacementTerm), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 232 ASCIIToUTF16(kReplacementTerm), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
233 string16(), search_terms_data)); 233 string16(), search_terms_data));
234 } 234 }
235 235
236 bool TemplateURLService::CanReplaceKeyword( 236 bool TemplateURLService::CanReplaceKeyword(
237 const string16& keyword, 237 const string16& keyword,
238 const GURL& url, 238 const GURL& url,
239 const TemplateURL** template_url_to_replace) { 239 const TemplateURL** template_url_to_replace) {
240 DCHECK(!keyword.empty()); // This should only be called for non-empty 240 DCHECK(!keyword.empty()); // This should only be called for non-empty
241 // keywords. If we need to support empty kewords 241 // keywords. If we need to support empty kewords
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 const std::pair<KeywordToTemplateMap::const_iterator, 278 const std::pair<KeywordToTemplateMap::const_iterator,
279 KeywordToTemplateMap::const_iterator> match_range( 279 KeywordToTemplateMap::const_iterator> match_range(
280 std::equal_range( 280 std::equal_range(
281 keyword_to_template_map_.begin(), keyword_to_template_map_.end(), 281 keyword_to_template_map_.begin(), keyword_to_template_map_.end(),
282 KeywordToTemplateMap::value_type(prefix, kNullTemplateURL), 282 KeywordToTemplateMap::value_type(prefix, kNullTemplateURL),
283 LessWithPrefix())); 283 LessWithPrefix()));
284 284
285 // Return vector of matching keywords. 285 // Return vector of matching keywords.
286 for (KeywordToTemplateMap::const_iterator i(match_range.first); 286 for (KeywordToTemplateMap::const_iterator i(match_range.first);
287 i != match_range.second; ++i) { 287 i != match_range.second; ++i) {
288 DCHECK(!i->second->url().empty()); 288 DCHECK(i->second->url());
289 if (!support_replacement_only || i->second->url_ref().SupportsReplacement()) 289 if (!support_replacement_only || i->second->url()->SupportsReplacement())
290 matches->push_back(i->first); 290 matches->push_back(i->first);
291 } 291 }
292 } 292 }
293 293
294 const TemplateURL* TemplateURLService::GetTemplateURLForKeyword( 294 const TemplateURL* TemplateURLService::GetTemplateURLForKeyword(
295 const string16& keyword) const { 295 const string16& keyword) const {
296 KeywordToTemplateMap::const_iterator elem( 296 KeywordToTemplateMap::const_iterator elem(
297 keyword_to_template_map_.find(keyword)); 297 keyword_to_template_map_.find(keyword));
298 return (elem == keyword_to_template_map_.end()) ? NULL : elem->second; 298 return (elem == keyword_to_template_map_.end()) ? NULL : elem->second;
299 } 299 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 const Extension* extension) { 391 const Extension* extension) {
392 const TemplateURL* url = GetTemplateURLForExtension(extension); 392 const TemplateURL* url = GetTemplateURLForExtension(extension);
393 if (url) 393 if (url)
394 Remove(url); 394 Remove(url);
395 } 395 }
396 396
397 const TemplateURL* TemplateURLService::GetTemplateURLForExtension( 397 const TemplateURL* TemplateURLService::GetTemplateURLForExtension(
398 const Extension* extension) const { 398 const Extension* extension) const {
399 for (TemplateURLVector::const_iterator i = template_urls_.begin(); 399 for (TemplateURLVector::const_iterator i = template_urls_.begin();
400 i != template_urls_.end(); ++i) { 400 i != template_urls_.end(); ++i) {
401 if ((*i)->IsExtensionKeyword() && 401 if ((*i)->IsExtensionKeyword() && (*i)->url()->GetHost() == extension->id())
402 ((*i)->url_ref().GetHost() == extension->id()))
403 return *i; 402 return *i;
404 } 403 }
405 404
406 return NULL; 405 return NULL;
407 } 406 }
408 407
409 std::vector<const TemplateURL*> TemplateURLService::GetTemplateURLs() const { 408 std::vector<const TemplateURL*> TemplateURLService::GetTemplateURLs() const {
410 return template_urls_; 409 return template_urls_;
411 } 410 }
412 411
413 void TemplateURLService::IncrementUsageCount(const TemplateURL* url) { 412 void TemplateURLService::IncrementUsageCount(const TemplateURL* url) {
414 DCHECK(url && std::find(template_urls_.begin(), template_urls_.end(), url) != 413 DCHECK(url && std::find(template_urls_.begin(), template_urls_.end(), url) !=
415 template_urls_.end()); 414 template_urls_.end());
416 const_cast<TemplateURL*>(url)->set_usage_count(url->usage_count() + 1); 415 const_cast<TemplateURL*>(url)->set_usage_count(url->usage_count() + 1);
417 if (service_.get()) 416 if (service_.get())
418 service_.get()->UpdateKeyword(*url); 417 service_.get()->UpdateKeyword(*url);
419 } 418 }
420 419
421 void TemplateURLService::ResetTemplateURL(const TemplateURL* url, 420 void TemplateURLService::ResetTemplateURL(const TemplateURL* url,
422 const string16& title, 421 const string16& title,
423 const string16& keyword, 422 const string16& keyword,
424 const std::string& search_url) { 423 const std::string& search_url) {
425 TemplateURL new_url(*url); 424 TemplateURL new_url(*url);
426 new_url.set_short_name(title); 425 new_url.set_short_name(title);
427 new_url.set_keyword(keyword); 426 new_url.set_keyword(keyword);
428 if (new_url.url() != search_url) { 427 if ((new_url.url() && search_url.empty()) ||
428 (!new_url.url() && !search_url.empty()) ||
429 (new_url.url() && new_url.url()->url() != search_url)) {
429 new_url.SetURL(search_url); 430 new_url.SetURL(search_url);
430 // The urls have changed, reset the favicon url. 431 // The urls have changed, reset the favicon url.
431 new_url.set_favicon_url(GURL()); 432 new_url.set_favicon_url(GURL());
432 } 433 }
433 new_url.set_safe_for_autoreplace(false); 434 new_url.set_safe_for_autoreplace(false);
434 new_url.set_last_modified(time_provider_()); 435 new_url.set_last_modified(time_provider_());
435 UpdateNoNotify(url, new_url); 436 UpdateNoNotify(url, new_url);
436 NotifyObservers(); 437 NotifyObservers();
437 } 438 }
438 439
439 bool TemplateURLService::CanMakeDefault(const TemplateURL* url) { 440 bool TemplateURLService::CanMakeDefault(const TemplateURL* url) {
440 return url != GetDefaultSearchProvider() && 441 return url != GetDefaultSearchProvider() &&
441 url->url_ref().SupportsReplacement() && !is_default_search_managed(); 442 url->url() &&
443 url->url()->SupportsReplacement() &&
444 !is_default_search_managed();
442 } 445 }
443 446
444 void TemplateURLService::SetDefaultSearchProvider(const TemplateURL* url) { 447 void TemplateURLService::SetDefaultSearchProvider(const TemplateURL* url) {
445 if (is_default_search_managed_) { 448 if (is_default_search_managed_) {
446 NOTREACHED(); 449 NOTREACHED();
447 return; 450 return;
448 } 451 }
449 // Always persist the setting in the database, that way if the backup 452 // Always persist the setting in the database, that way if the backup
450 // signature has changed out from under us it gets reset correctly. 453 // signature has changed out from under us it gets reset correctly.
451 SetDefaultSearchProviderNoNotify(url); 454 SetDefaultSearchProviderNoNotify(url);
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 970
968 // static 971 // static
969 SyncData TemplateURLService::CreateSyncDataFromTemplateURL( 972 SyncData TemplateURLService::CreateSyncDataFromTemplateURL(
970 const TemplateURL& turl) { 973 const TemplateURL& turl) {
971 sync_pb::EntitySpecifics specifics; 974 sync_pb::EntitySpecifics specifics;
972 sync_pb::SearchEngineSpecifics* se_specifics = 975 sync_pb::SearchEngineSpecifics* se_specifics =
973 specifics.mutable_search_engine(); 976 specifics.mutable_search_engine();
974 se_specifics->set_short_name(UTF16ToUTF8(turl.short_name())); 977 se_specifics->set_short_name(UTF16ToUTF8(turl.short_name()));
975 se_specifics->set_keyword(UTF16ToUTF8(turl.keyword())); 978 se_specifics->set_keyword(UTF16ToUTF8(turl.keyword()));
976 se_specifics->set_favicon_url(turl.favicon_url().spec()); 979 se_specifics->set_favicon_url(turl.favicon_url().spec());
977 se_specifics->set_url(turl.url()); 980 se_specifics->set_url(turl.url() ? turl.url()->url() : std::string());
978 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); 981 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace());
979 se_specifics->set_originating_url(turl.originating_url().spec()); 982 se_specifics->set_originating_url(turl.originating_url().spec());
980 se_specifics->set_date_created(turl.date_created().ToInternalValue()); 983 se_specifics->set_date_created(turl.date_created().ToInternalValue());
981 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); 984 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';'));
982 se_specifics->set_show_in_default_list(turl.show_in_default_list()); 985 se_specifics->set_show_in_default_list(turl.show_in_default_list());
983 se_specifics->set_suggestions_url(turl.suggestions_url()); 986 se_specifics->set_suggestions_url(turl.suggestions_url() ?
987 turl.suggestions_url()->url() : std::string());
984 se_specifics->set_prepopulate_id(turl.prepopulate_id()); 988 se_specifics->set_prepopulate_id(turl.prepopulate_id());
985 se_specifics->set_autogenerate_keyword(turl.autogenerate_keyword()); 989 se_specifics->set_autogenerate_keyword(turl.autogenerate_keyword());
986 se_specifics->set_instant_url(turl.instant_url()); 990 se_specifics->set_instant_url(turl.instant_url() ?
991 turl.instant_url()->url() : std::string());
987 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); 992 se_specifics->set_last_modified(turl.last_modified().ToInternalValue());
988 se_specifics->set_sync_guid(turl.sync_guid()); 993 se_specifics->set_sync_guid(turl.sync_guid());
989 return SyncData::CreateLocalData(se_specifics->sync_guid(), 994 return SyncData::CreateLocalData(se_specifics->sync_guid(),
990 se_specifics->keyword(), 995 se_specifics->keyword(),
991 specifics); 996 specifics);
992 } 997 }
993 998
994 // static 999 // static
995 TemplateURL* TemplateURLService::CreateTemplateURLFromSyncData( 1000 TemplateURL* TemplateURLService::CreateTemplateURLFromSyncData(
996 const SyncData& sync_data) { 1001 const SyncData& sync_data) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 template_url->SetURL(osd_url); 1068 template_url->SetURL(osd_url);
1064 AddNoNotify(template_url); 1069 AddNoNotify(template_url);
1065 } 1070 }
1066 } 1071 }
1067 1072
1068 // Initialize default search. 1073 // Initialize default search.
1069 UpdateDefaultSearch(); 1074 UpdateDefaultSearch();
1070 1075
1071 // Request a server check for the correct Google URL if Google is the 1076 // Request a server check for the correct Google URL if Google is the
1072 // default search engine, not in headless mode and not in Chrome Frame. 1077 // default search engine, not in headless mode and not in Chrome Frame.
1073 if (initial_default_search_provider_.get() && 1078 if (initial_default_search_provider_.get()) {
1074 initial_default_search_provider_->url_ref().HasGoogleBaseURLs()) { 1079 const TemplateURLRef* default_provider_ref =
1075 scoped_ptr<base::Environment> env(base::Environment::Create()); 1080 initial_default_search_provider_->url();
1076 if (!env->HasVar(env_vars::kHeadless) && 1081 if (default_provider_ref && default_provider_ref->HasGoogleBaseURLs()) {
1077 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) 1082 scoped_ptr<base::Environment> env(base::Environment::Create());
1078 GoogleURLTracker::RequestServerCheck(); 1083 if (!env->HasVar(env_vars::kHeadless) &&
1084 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame))
1085 GoogleURLTracker::RequestServerCheck();
1086 }
1079 } 1087 }
1080 } 1088 }
1081 1089
1082 void TemplateURLService::RemoveFromMaps(const TemplateURL* template_url) { 1090 void TemplateURLService::RemoveFromMaps(const TemplateURL* template_url) {
1083 if (!template_url->keyword().empty()) 1091 if (!template_url->keyword().empty())
1084 keyword_to_template_map_.erase(template_url->keyword()); 1092 keyword_to_template_map_.erase(template_url->keyword());
1085 if (!template_url->sync_guid().empty()) 1093 if (!template_url->sync_guid().empty())
1086 guid_to_template_map_.erase(template_url->sync_guid()); 1094 guid_to_template_map_.erase(template_url->sync_guid());
1087 if (loaded_) 1095 if (loaded_)
1088 provider_map_.Remove(template_url); 1096 provider_map_.Remove(template_url);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 std::string suggest_url; 1181 std::string suggest_url;
1174 std::string instant_url; 1182 std::string instant_url;
1175 std::string icon_url; 1183 std::string icon_url;
1176 std::string encodings; 1184 std::string encodings;
1177 std::string short_name; 1185 std::string short_name;
1178 std::string keyword; 1186 std::string keyword;
1179 std::string id_string; 1187 std::string id_string;
1180 std::string prepopulate_id; 1188 std::string prepopulate_id;
1181 if (t_url) { 1189 if (t_url) {
1182 enabled = true; 1190 enabled = true;
1183 search_url = t_url->url(); 1191 if (t_url->url())
1184 suggest_url = t_url->suggestions_url(); 1192 search_url = t_url->url()->url();
1185 instant_url = t_url->instant_url(); 1193 if (t_url->suggestions_url())
1194 suggest_url = t_url->suggestions_url()->url();
1195 if (t_url->instant_url())
1196 instant_url = t_url->instant_url()->url();
1186 GURL icon_gurl = t_url->favicon_url(); 1197 GURL icon_gurl = t_url->favicon_url();
1187 if (!icon_gurl.is_empty()) 1198 if (!icon_gurl.is_empty())
1188 icon_url = icon_gurl.spec(); 1199 icon_url = icon_gurl.spec();
1189 encodings = JoinString(t_url->input_encodings(), ';'); 1200 encodings = JoinString(t_url->input_encodings(), ';');
1190 short_name = UTF16ToUTF8(t_url->short_name()); 1201 short_name = UTF16ToUTF8(t_url->short_name());
1191 keyword = UTF16ToUTF8(t_url->keyword()); 1202 keyword = UTF16ToUTF8(t_url->keyword());
1192 id_string = base::Int64ToString(t_url->id()); 1203 id_string = base::Int64ToString(t_url->id());
1193 prepopulate_id = base::Int64ToString(t_url->prepopulate_id()); 1204 prepopulate_id = base::Int64ToString(t_url->prepopulate_id());
1194 } 1205 }
1195 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled); 1206 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 if (!urls_for_host) 1351 if (!urls_for_host)
1341 return; 1352 return;
1342 1353
1343 QueryTerms query_terms; 1354 QueryTerms query_terms;
1344 bool built_terms = false; // Most URLs won't match a TemplateURLs host; 1355 bool built_terms = false; // Most URLs won't match a TemplateURLs host;
1345 // so we lazily build the query_terms. 1356 // so we lazily build the query_terms.
1346 const std::string path = row.url().path(); 1357 const std::string path = row.url().path();
1347 1358
1348 for (TemplateURLSet::const_iterator i = urls_for_host->begin(); 1359 for (TemplateURLSet::const_iterator i = urls_for_host->begin();
1349 i != urls_for_host->end(); ++i) { 1360 i != urls_for_host->end(); ++i) {
1350 const TemplateURLRef& search_ref = (*i)->url_ref(); 1361 const TemplateURLRef* search_ref = (*i)->url();
1351 1362
1352 // Count the URL against a TemplateURL if the host and path of the 1363 // Count the URL against a TemplateURL if the host and path of the
1353 // visited URL match that of the TemplateURL as well as the search term's 1364 // visited URL match that of the TemplateURL as well as the search term's
1354 // key of the TemplateURL occurring in the visited url. 1365 // key of the TemplateURL occurring in the visited url.
1355 // 1366 //
1356 // NOTE: Even though we're iterating over TemplateURLs indexed by the host 1367 // NOTE: Even though we're iterating over TemplateURLs indexed by the host
1357 // of the URL we still need to call GetHost on the search_ref. In 1368 // of the URL we still need to call GetHost on the search_ref. In
1358 // particular, GetHost returns an empty string if search_ref doesn't support 1369 // particular, GetHost returns an empty string if search_ref doesn't support
1359 // replacement or isn't valid for use in keyword search terms. 1370 // replacement or isn't valid for use in keyword search terms.
1360 1371
1361 if (search_ref.GetHost() == row.url().host() && 1372 if (search_ref && search_ref->GetHost() == row.url().host() &&
1362 search_ref.GetPath() == path) { 1373 search_ref->GetPath() == path) {
1363 if (!built_terms && !BuildQueryTerms(row.url(), &query_terms)) { 1374 if (!built_terms && !BuildQueryTerms(row.url(), &query_terms)) {
1364 // No query terms. No need to continue with the rest of the 1375 // No query terms. No need to continue with the rest of the
1365 // TemplateURLs. 1376 // TemplateURLs.
1366 return; 1377 return;
1367 } 1378 }
1368 built_terms = true; 1379 built_terms = true;
1369 1380
1370 if (content::PageTransitionStripQualifier(details.transition) == 1381 if (content::PageTransitionStripQualifier(details.transition) ==
1371 content::PAGE_TRANSITION_KEYWORD) { 1382 content::PAGE_TRANSITION_KEYWORD) {
1372 // The visit is the result of the user entering a keyword, generate a 1383 // The visit is the result of the user entering a keyword, generate a
1373 // KEYWORD_GENERATED visit for the KEYWORD so that the keyword typed 1384 // KEYWORD_GENERATED visit for the KEYWORD so that the keyword typed
1374 // count is boosted. 1385 // count is boosted.
1375 AddTabToSearchVisit(**i); 1386 AddTabToSearchVisit(**i);
1376 } 1387 }
1377 1388
1378 QueryTerms::iterator terms_iterator = 1389 QueryTerms::iterator terms_iterator =
1379 query_terms.find(search_ref.GetSearchTermKey()); 1390 query_terms.find(search_ref->GetSearchTermKey());
1380 if (terms_iterator != query_terms.end() && 1391 if (terms_iterator != query_terms.end() &&
1381 !terms_iterator->second.empty()) { 1392 !terms_iterator->second.empty()) {
1382 SetKeywordSearchTermsForURL(*i, row.url(), 1393 SetKeywordSearchTermsForURL(*i, row.url(),
1383 search_ref.SearchTermToString16(terms_iterator->second)); 1394 search_ref->SearchTermToString16(terms_iterator->second));
1384 } 1395 }
1385 } 1396 }
1386 } 1397 }
1387 } 1398 }
1388 1399
1389 void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) { 1400 void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) {
1390 // Only add visits for entries the user hasn't modified. If the user modified 1401 // Only add visits for entries the user hasn't modified. If the user modified
1391 // the entry the keyword may no longer correspond to the host name. It may be 1402 // the entry the keyword may no longer correspond to the host name. It may be
1392 // possible to do something more sophisticated here, but it's so rare as to 1403 // possible to do something more sophisticated here, but it's so rare as to
1393 // not be worth it. 1404 // not be worth it.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 } 1454 }
1444 } 1455 }
1445 } 1456 }
1446 return (valid_term_count > 0); 1457 return (valid_term_count > 0);
1447 } 1458 }
1448 1459
1449 void TemplateURLService::GoogleBaseURLChanged() { 1460 void TemplateURLService::GoogleBaseURLChanged() {
1450 bool something_changed = false; 1461 bool something_changed = false;
1451 for (size_t i = 0; i < template_urls_.size(); ++i) { 1462 for (size_t i = 0; i < template_urls_.size(); ++i) {
1452 const TemplateURL* t_url = template_urls_[i]; 1463 const TemplateURL* t_url = template_urls_[i];
1453 if (t_url->url_ref().HasGoogleBaseURLs() || 1464 if ((t_url->url() && t_url->url()->HasGoogleBaseURLs()) ||
1454 t_url->suggestions_url_ref().HasGoogleBaseURLs()) { 1465 (t_url->suggestions_url() &&
1466 t_url->suggestions_url()->HasGoogleBaseURLs())) {
1455 RemoveFromKeywordMapByPointer(t_url); 1467 RemoveFromKeywordMapByPointer(t_url);
1456 t_url->InvalidateCachedValues(); 1468 t_url->InvalidateCachedValues();
1457 if (!t_url->keyword().empty()) 1469 if (!t_url->keyword().empty())
1458 keyword_to_template_map_[t_url->keyword()] = t_url; 1470 keyword_to_template_map_[t_url->keyword()] = t_url;
1459 something_changed = true; 1471 something_changed = true;
1460 } 1472 }
1461 } 1473 }
1462 1474
1463 if (something_changed && loaded_) { 1475 if (something_changed && loaded_) {
1464 UIThreadSearchTermsData search_terms_data; 1476 UIThreadSearchTermsData search_terms_data;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 default_search_provider_ = url; 1578 default_search_provider_ = url;
1567 1579
1568 if (url) { 1580 if (url) {
1569 TemplateURL* modifiable_url = const_cast<TemplateURL*>(url); 1581 TemplateURL* modifiable_url = const_cast<TemplateURL*>(url);
1570 // Don't mark the url as edited, otherwise we won't be able to rev the 1582 // Don't mark the url as edited, otherwise we won't be able to rev the
1571 // template urls we ship with. 1583 // template urls we ship with.
1572 modifiable_url->set_show_in_default_list(true); 1584 modifiable_url->set_show_in_default_list(true);
1573 if (service_.get()) 1585 if (service_.get())
1574 service_.get()->UpdateKeyword(*url); 1586 service_.get()->UpdateKeyword(*url);
1575 1587
1576 if (url->url_ref().HasGoogleBaseURLs()) { 1588 const TemplateURLRef* url_ref = url->url();
1589 if (url_ref && url_ref->HasGoogleBaseURLs()) {
1577 GoogleURLTracker::RequestServerCheck(); 1590 GoogleURLTracker::RequestServerCheck();
1578 #if defined(ENABLE_RLZ) 1591 #if defined(ENABLE_RLZ)
1579 // Needs to be evaluated. See http://crbug.com/62328. 1592 // Needs to be evaluated. See http://crbug.com/62328.
1580 base::ThreadRestrictions::ScopedAllowIO allow_io; 1593 base::ThreadRestrictions::ScopedAllowIO allow_io;
1581 RLZTracker::RecordProductEvent(rlz_lib::CHROME, 1594 RLZTracker::RecordProductEvent(rlz_lib::CHROME,
1582 rlz_lib::CHROME_OMNIBOX, 1595 rlz_lib::CHROME_OMNIBOX,
1583 rlz_lib::SET_TO_GOOGLE); 1596 rlz_lib::SET_TO_GOOGLE);
1584 #endif 1597 #endif
1585 } 1598 }
1586 } 1599 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 new_url.set_sync_guid(guid); 1735 new_url.set_sync_guid(guid);
1723 UpdateNoNotify(url, new_url); 1736 UpdateNoNotify(url, new_url);
1724 } 1737 }
1725 1738
1726 string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl) const { 1739 string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl) const {
1727 // Already unique. 1740 // Already unique.
1728 if (!GetTemplateURLForKeyword(turl.keyword())) 1741 if (!GetTemplateURLForKeyword(turl.keyword()))
1729 return turl.keyword(); 1742 return turl.keyword();
1730 1743
1731 // First, try to return the generated keyword for the TemplateURL. 1744 // First, try to return the generated keyword for the TemplateURL.
1732 GURL gurl(turl.url()); 1745 string16 keyword_candidate = GenerateKeyword(
1733 string16 keyword_candidate = GenerateKeyword(gurl, true); 1746 turl.url() ? GURL(turl.url()->url()) : GURL(), true);
1734 if (!GetTemplateURLForKeyword(keyword_candidate) && 1747 if (!GetTemplateURLForKeyword(keyword_candidate) &&
1735 !keyword_candidate.empty()) { 1748 !keyword_candidate.empty()) {
1736 return keyword_candidate; 1749 return keyword_candidate;
1737 } 1750 }
1738 1751
1739 // We try to uniquify the keyword by appending a special character to the end. 1752 // We try to uniquify the keyword by appending a special character to the end.
1740 // This is a best-effort approach where we try to preserve the original 1753 // This is a best-effort approach where we try to preserve the original
1741 // keyword and let the user do what they will after our attempt. 1754 // keyword and let the user do what they will after our attempt.
1742 keyword_candidate = turl.keyword(); 1755 keyword_candidate = turl.keyword();
1743 do { 1756 do {
1744 keyword_candidate.append(ASCIIToUTF16("_")); 1757 keyword_candidate.append(UTF8ToUTF16("_"));
1745 } while (GetTemplateURLForKeyword(keyword_candidate)); 1758 } while (GetTemplateURLForKeyword(keyword_candidate));
1746 1759
1747 return keyword_candidate; 1760 return keyword_candidate;
1748 } 1761 }
1749 1762
1750 bool TemplateURLService::ResolveSyncKeywordConflict( 1763 bool TemplateURLService::ResolveSyncKeywordConflict(
1751 TemplateURL* sync_turl, 1764 TemplateURL* sync_turl,
1752 SyncChangeList* change_list) { 1765 SyncChangeList* change_list) {
1753 DCHECK(sync_turl); 1766 DCHECK(sync_turl);
1754 DCHECK(change_list); 1767 DCHECK(change_list);
(...skipping 23 matching lines...) Expand all
1778 return true; 1791 return true;
1779 } 1792 }
1780 1793
1781 const TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL( 1794 const TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL(
1782 const TemplateURL& sync_turl) { 1795 const TemplateURL& sync_turl) {
1783 const TemplateURL* existing_turl = 1796 const TemplateURL* existing_turl =
1784 GetTemplateURLForKeyword(sync_turl.keyword()); 1797 GetTemplateURLForKeyword(sync_turl.keyword());
1785 if (!existing_turl) 1798 if (!existing_turl)
1786 return NULL; 1799 return NULL;
1787 1800
1788 if (!existing_turl->url().empty() && 1801 if (existing_turl->url() && sync_turl.url() &&
1789 existing_turl->url() == sync_turl.url()) { 1802 existing_turl->url()->url() == sync_turl.url()->url()) {
1790 return existing_turl; 1803 return existing_turl;
1791 } 1804 }
1792 return NULL; 1805 return NULL;
1793 } 1806 }
1794 1807
1795 void TemplateURLService::MergeSyncAndLocalURLDuplicates( 1808 void TemplateURLService::MergeSyncAndLocalURLDuplicates(
1796 TemplateURL* sync_turl, 1809 TemplateURL* sync_turl,
1797 TemplateURL* local_turl, 1810 TemplateURL* local_turl,
1798 SyncChangeList* change_list) { 1811 SyncChangeList* change_list) {
1799 DCHECK(sync_turl); 1812 DCHECK(sync_turl);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 dst->set_input_encodings(input_encodings); 1909 dst->set_input_encodings(input_encodings);
1897 dst->set_show_in_default_list(specifics.show_in_default_list()); 1910 dst->set_show_in_default_list(specifics.show_in_default_list());
1898 dst->SetSuggestionsURL(specifics.suggestions_url()); 1911 dst->SetSuggestionsURL(specifics.suggestions_url());
1899 dst->SetPrepopulateId(specifics.prepopulate_id()); 1912 dst->SetPrepopulateId(specifics.prepopulate_id());
1900 dst->set_autogenerate_keyword(specifics.autogenerate_keyword()); 1913 dst->set_autogenerate_keyword(specifics.autogenerate_keyword());
1901 dst->SetInstantURL(specifics.instant_url()); 1914 dst->SetInstantURL(specifics.instant_url());
1902 dst->set_last_modified( 1915 dst->set_last_modified(
1903 base::Time::FromInternalValue(specifics.last_modified())); 1916 base::Time::FromInternalValue(specifics.last_modified()));
1904 dst->set_sync_guid(specifics.sync_guid()); 1917 dst->set_sync_guid(specifics.sync_guid());
1905 } 1918 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698