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