Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 182 |
| 183 // Remove leading "www.". | 183 // Remove leading "www.". |
| 184 result = net::StripWWW(result); | 184 result = net::StripWWW(result); |
| 185 | 185 |
| 186 // Remove trailing "/". | 186 // Remove trailing "/". |
| 187 return (result.length() > 0 && result[result.length() - 1] == '/') ? | 187 return (result.length() > 0 && result[result.length() - 1] == '/') ? |
| 188 result.substr(0, result.length() - 1) : result; | 188 result.substr(0, result.length() - 1) : result; |
| 189 } | 189 } |
| 190 | 190 |
| 191 // static | 191 // static |
| 192 GURL TemplateURLService::GenerateSearchURL(const TemplateURL* t_url) { | 192 GURL TemplateURLService::GenerateSearchURL(const TemplateURL* t_url, |
| 193 Profile* profile) { | |
|
Peter Kasting
2011/08/10 20:54:06
You don't actually need this, because none of the
| |
| 193 DCHECK(t_url); | 194 DCHECK(t_url); |
| 194 UIThreadSearchTermsData search_terms_data; | 195 UIThreadSearchTermsData search_terms_data(profile); |
| 195 return GenerateSearchURLUsingTermsData(t_url, search_terms_data); | 196 return GenerateSearchURLUsingTermsData(t_url, search_terms_data); |
| 196 } | 197 } |
| 197 | 198 |
| 198 // static | 199 // static |
| 199 GURL TemplateURLService::GenerateSearchURLUsingTermsData( | 200 GURL TemplateURLService::GenerateSearchURLUsingTermsData( |
| 200 const TemplateURL* t_url, | 201 const TemplateURL* t_url, |
| 201 const SearchTermsData& search_terms_data) { | 202 const SearchTermsData& search_terms_data) { |
| 202 DCHECK(t_url); | 203 DCHECK(t_url); |
| 203 const TemplateURLRef* search_ref = t_url->url(); | 204 const TemplateURLRef* search_ref = t_url->url(); |
| 204 // Extension keywords don't have host-based search URLs. | 205 // Extension keywords don't have host-based search URLs. |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) | 708 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) |
| 708 GoogleURLTracker::RequestServerCheck(); | 709 GoogleURLTracker::RequestServerCheck(); |
| 709 } | 710 } |
| 710 } | 711 } |
| 711 } | 712 } |
| 712 | 713 |
| 713 void TemplateURLService::RemoveFromMaps(const TemplateURL* template_url) { | 714 void TemplateURLService::RemoveFromMaps(const TemplateURL* template_url) { |
| 714 if (!template_url->keyword().empty()) | 715 if (!template_url->keyword().empty()) |
| 715 keyword_to_template_map_.erase(template_url->keyword()); | 716 keyword_to_template_map_.erase(template_url->keyword()); |
| 716 if (loaded_) | 717 if (loaded_) |
| 717 provider_map_.Remove(template_url); | 718 provider_map_.Remove(template_url, profile_); |
| 718 } | 719 } |
| 719 | 720 |
| 720 void TemplateURLService::RemoveFromKeywordMapByPointer( | 721 void TemplateURLService::RemoveFromKeywordMapByPointer( |
| 721 const TemplateURL* template_url) { | 722 const TemplateURL* template_url) { |
| 722 DCHECK(template_url); | 723 DCHECK(template_url); |
| 723 for (KeywordToTemplateMap::iterator i = keyword_to_template_map_.begin(); | 724 for (KeywordToTemplateMap::iterator i = keyword_to_template_map_.begin(); |
| 724 i != keyword_to_template_map_.end(); ++i) { | 725 i != keyword_to_template_map_.end(); ++i) { |
| 725 if (i->second == template_url) { | 726 if (i->second == template_url) { |
| 726 keyword_to_template_map_.erase(i); | 727 keyword_to_template_map_.erase(i); |
| 727 // A given TemplateURL only occurs once in the map. As soon as we find the | 728 // A given TemplateURL only occurs once in the map. As soon as we find the |
| 728 // entry, stop. | 729 // entry, stop. |
| 729 break; | 730 break; |
| 730 } | 731 } |
| 731 } | 732 } |
| 732 } | 733 } |
| 733 | 734 |
| 734 void TemplateURLService::AddToMaps(const TemplateURL* template_url) { | 735 void TemplateURLService::AddToMaps(const TemplateURL* template_url) { |
| 735 if (!template_url->keyword().empty()) | 736 if (!template_url->keyword().empty()) |
| 736 keyword_to_template_map_[template_url->keyword()] = template_url; | 737 keyword_to_template_map_[template_url->keyword()] = template_url; |
| 737 if (loaded_) { | 738 if (loaded_) { |
| 738 UIThreadSearchTermsData search_terms_data; | 739 UIThreadSearchTermsData search_terms_data(profile_); |
| 739 provider_map_.Add(template_url, search_terms_data); | 740 provider_map_.Add(template_url, search_terms_data); |
| 740 } | 741 } |
| 741 } | 742 } |
| 742 | 743 |
| 743 void TemplateURLService::SetTemplateURLs( | 744 void TemplateURLService::SetTemplateURLs( |
| 744 const std::vector<TemplateURL*>& urls) { | 745 const std::vector<TemplateURL*>& urls) { |
| 745 // Add mappings for the new items. | 746 // Add mappings for the new items. |
| 746 | 747 |
| 747 // First, add the items that already have id's, so that the next_id_ | 748 // First, add the items that already have id's, so that the next_id_ |
| 748 // gets properly set. | 749 // gets properly set. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 762 ++i) { | 763 ++i) { |
| 763 if ((*i)->id() != 0) | 764 if ((*i)->id() != 0) |
| 764 continue; | 765 continue; |
| 765 AddNoNotify(*i); | 766 AddNoNotify(*i); |
| 766 } | 767 } |
| 767 } | 768 } |
| 768 | 769 |
| 769 void TemplateURLService::ChangeToLoadedState() { | 770 void TemplateURLService::ChangeToLoadedState() { |
| 770 DCHECK(!loaded_); | 771 DCHECK(!loaded_); |
| 771 | 772 |
| 772 UIThreadSearchTermsData search_terms_data; | 773 UIThreadSearchTermsData search_terms_data(profile_); |
| 773 provider_map_.Init(template_urls_, search_terms_data); | 774 provider_map_.Init(template_urls_, search_terms_data); |
| 774 loaded_ = true; | 775 loaded_ = true; |
| 775 } | 776 } |
| 776 | 777 |
| 777 void TemplateURLService::NotifyLoaded() { | 778 void TemplateURLService::NotifyLoaded() { |
| 778 NotificationService::current()->Notify( | 779 NotificationService::current()->Notify( |
| 779 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 780 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 780 Source<TemplateURLService>(this), | 781 Source<TemplateURLService>(this), |
| 781 NotificationService::NoDetails()); | 782 NotificationService::NoDetails()); |
| 782 | 783 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 const TemplateURL& new_values) { | 929 const TemplateURL& new_values) { |
| 929 DCHECK(loaded_); | 930 DCHECK(loaded_); |
| 930 DCHECK(existing_turl); | 931 DCHECK(existing_turl); |
| 931 DCHECK(find(template_urls_.begin(), template_urls_.end(), existing_turl) != | 932 DCHECK(find(template_urls_.begin(), template_urls_.end(), existing_turl) != |
| 932 template_urls_.end()); | 933 template_urls_.end()); |
| 933 | 934 |
| 934 if (!existing_turl->keyword().empty()) | 935 if (!existing_turl->keyword().empty()) |
| 935 keyword_to_template_map_.erase(existing_turl->keyword()); | 936 keyword_to_template_map_.erase(existing_turl->keyword()); |
| 936 | 937 |
| 937 // This call handles copying over the values (while retaining the id). | 938 // This call handles copying over the values (while retaining the id). |
| 938 UIThreadSearchTermsData search_terms_data; | 939 UIThreadSearchTermsData search_terms_data(profile_); |
| 939 provider_map_.Update(existing_turl, new_values, search_terms_data); | 940 provider_map_.Update(existing_turl, new_values, search_terms_data, profile_); |
| 940 | 941 |
| 941 if (!existing_turl->keyword().empty()) | 942 if (!existing_turl->keyword().empty()) |
| 942 keyword_to_template_map_[existing_turl->keyword()] = existing_turl; | 943 keyword_to_template_map_[existing_turl->keyword()] = existing_turl; |
| 943 | 944 |
| 944 if (service_.get()) | 945 if (service_.get()) |
| 945 service_->UpdateKeyword(*existing_turl); | 946 service_->UpdateKeyword(*existing_turl); |
| 946 | 947 |
| 947 if (default_search_provider_ == existing_turl) | 948 if (default_search_provider_ == existing_turl) |
| 948 SetDefaultSearchProviderNoNotify(existing_turl); | 949 SetDefaultSearchProviderNoNotify(existing_turl); |
| 949 } | 950 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 t_url->suggestions_url()->HasGoogleBaseURLs())) { | 1082 t_url->suggestions_url()->HasGoogleBaseURLs())) { |
| 1082 RemoveFromKeywordMapByPointer(t_url); | 1083 RemoveFromKeywordMapByPointer(t_url); |
| 1083 t_url->InvalidateCachedValues(); | 1084 t_url->InvalidateCachedValues(); |
| 1084 if (!t_url->keyword().empty()) | 1085 if (!t_url->keyword().empty()) |
| 1085 keyword_to_template_map_[t_url->keyword()] = t_url; | 1086 keyword_to_template_map_[t_url->keyword()] = t_url; |
| 1086 something_changed = true; | 1087 something_changed = true; |
| 1087 } | 1088 } |
| 1088 } | 1089 } |
| 1089 | 1090 |
| 1090 if (something_changed && loaded_) { | 1091 if (something_changed && loaded_) { |
| 1091 UIThreadSearchTermsData search_terms_data; | 1092 UIThreadSearchTermsData search_terms_data(profile_); |
| 1092 provider_map_.UpdateGoogleBaseURLs(search_terms_data); | 1093 provider_map_.UpdateGoogleBaseURLs(search_terms_data); |
| 1093 NotifyObservers(); | 1094 NotifyObservers(); |
| 1094 } | 1095 } |
| 1095 } | 1096 } |
| 1096 | 1097 |
| 1097 void TemplateURLService::UpdateDefaultSearch() { | 1098 void TemplateURLService::UpdateDefaultSearch() { |
| 1098 if (!loaded_) { | 1099 if (!loaded_) { |
| 1099 // Set |initial_default_search_provider_| from the preferences. We use this | 1100 // Set |initial_default_search_provider_| from the preferences. We use this |
| 1100 // value for default search provider until the database has been loaded. | 1101 // value for default search provider until the database has been loaded. |
| 1101 if (!LoadDefaultSearchProviderFromPrefs(&initial_default_search_provider_, | 1102 if (!LoadDefaultSearchProviderFromPrefs(&initial_default_search_provider_, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1323 | 1324 |
| 1324 i = template_urls->erase(i); | 1325 i = template_urls->erase(i); |
| 1325 if (service_.get()) | 1326 if (service_.get()) |
| 1326 service_->RemoveKeyword(*template_url); | 1327 service_->RemoveKeyword(*template_url); |
| 1327 delete template_url; | 1328 delete template_url; |
| 1328 } else { | 1329 } else { |
| 1329 ++i; | 1330 ++i; |
| 1330 } | 1331 } |
| 1331 } | 1332 } |
| 1332 } | 1333 } |
| OLD | NEW |