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