| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 DCHECK(t_url); | 193 DCHECK(t_url); |
| 194 UIThreadSearchTermsData search_terms_data; | 194 UIThreadSearchTermsData search_terms_data(NULL); |
| 195 return GenerateSearchURLUsingTermsData(t_url, search_terms_data); | 195 return GenerateSearchURLUsingTermsData(t_url, search_terms_data); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // static | 198 // static |
| 199 GURL TemplateURLService::GenerateSearchURLUsingTermsData( | 199 GURL TemplateURLService::GenerateSearchURLUsingTermsData( |
| 200 const TemplateURL* t_url, | 200 const TemplateURL* t_url, |
| 201 const SearchTermsData& search_terms_data) { | 201 const SearchTermsData& search_terms_data) { |
| 202 DCHECK(t_url); | 202 DCHECK(t_url); |
| 203 const TemplateURLRef* search_ref = t_url->url(); | 203 const TemplateURLRef* search_ref = t_url->url(); |
| 204 // Extension keywords don't have host-based search URLs. | 204 // Extension keywords don't have host-based search URLs. |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 // entry, stop. | 728 // entry, stop. |
| 729 break; | 729 break; |
| 730 } | 730 } |
| 731 } | 731 } |
| 732 } | 732 } |
| 733 | 733 |
| 734 void TemplateURLService::AddToMaps(const TemplateURL* template_url) { | 734 void TemplateURLService::AddToMaps(const TemplateURL* template_url) { |
| 735 if (!template_url->keyword().empty()) | 735 if (!template_url->keyword().empty()) |
| 736 keyword_to_template_map_[template_url->keyword()] = template_url; | 736 keyword_to_template_map_[template_url->keyword()] = template_url; |
| 737 if (loaded_) { | 737 if (loaded_) { |
| 738 UIThreadSearchTermsData search_terms_data; | 738 UIThreadSearchTermsData search_terms_data(NULL); |
| 739 provider_map_.Add(template_url, search_terms_data); | 739 provider_map_.Add(template_url, search_terms_data); |
| 740 } | 740 } |
| 741 } | 741 } |
| 742 | 742 |
| 743 void TemplateURLService::SetTemplateURLs( | 743 void TemplateURLService::SetTemplateURLs( |
| 744 const std::vector<TemplateURL*>& urls) { | 744 const std::vector<TemplateURL*>& urls) { |
| 745 // Add mappings for the new items. | 745 // Add mappings for the new items. |
| 746 | 746 |
| 747 // First, add the items that already have id's, so that the next_id_ | 747 // First, add the items that already have id's, so that the next_id_ |
| 748 // gets properly set. | 748 // gets properly set. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 762 ++i) { | 762 ++i) { |
| 763 if ((*i)->id() != 0) | 763 if ((*i)->id() != 0) |
| 764 continue; | 764 continue; |
| 765 AddNoNotify(*i); | 765 AddNoNotify(*i); |
| 766 } | 766 } |
| 767 } | 767 } |
| 768 | 768 |
| 769 void TemplateURLService::ChangeToLoadedState() { | 769 void TemplateURLService::ChangeToLoadedState() { |
| 770 DCHECK(!loaded_); | 770 DCHECK(!loaded_); |
| 771 | 771 |
| 772 UIThreadSearchTermsData search_terms_data; | 772 UIThreadSearchTermsData search_terms_data(NULL); |
| 773 provider_map_.Init(template_urls_, search_terms_data); | 773 provider_map_.Init(template_urls_, search_terms_data); |
| 774 loaded_ = true; | 774 loaded_ = true; |
| 775 } | 775 } |
| 776 | 776 |
| 777 void TemplateURLService::NotifyLoaded() { | 777 void TemplateURLService::NotifyLoaded() { |
| 778 NotificationService::current()->Notify( | 778 NotificationService::current()->Notify( |
| 779 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 779 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 780 Source<TemplateURLService>(this), | 780 Source<TemplateURLService>(this), |
| 781 NotificationService::NoDetails()); | 781 NotificationService::NoDetails()); |
| 782 | 782 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 const TemplateURL& new_values) { | 928 const TemplateURL& new_values) { |
| 929 DCHECK(loaded_); | 929 DCHECK(loaded_); |
| 930 DCHECK(existing_turl); | 930 DCHECK(existing_turl); |
| 931 DCHECK(find(template_urls_.begin(), template_urls_.end(), existing_turl) != | 931 DCHECK(find(template_urls_.begin(), template_urls_.end(), existing_turl) != |
| 932 template_urls_.end()); | 932 template_urls_.end()); |
| 933 | 933 |
| 934 if (!existing_turl->keyword().empty()) | 934 if (!existing_turl->keyword().empty()) |
| 935 keyword_to_template_map_.erase(existing_turl->keyword()); | 935 keyword_to_template_map_.erase(existing_turl->keyword()); |
| 936 | 936 |
| 937 // This call handles copying over the values (while retaining the id). | 937 // This call handles copying over the values (while retaining the id). |
| 938 UIThreadSearchTermsData search_terms_data; | 938 UIThreadSearchTermsData search_terms_data(NULL); |
| 939 provider_map_.Update(existing_turl, new_values, search_terms_data); | 939 provider_map_.Update(existing_turl, new_values, search_terms_data); |
| 940 | 940 |
| 941 if (!existing_turl->keyword().empty()) | 941 if (!existing_turl->keyword().empty()) |
| 942 keyword_to_template_map_[existing_turl->keyword()] = existing_turl; | 942 keyword_to_template_map_[existing_turl->keyword()] = existing_turl; |
| 943 | 943 |
| 944 if (service_.get()) | 944 if (service_.get()) |
| 945 service_->UpdateKeyword(*existing_turl); | 945 service_->UpdateKeyword(*existing_turl); |
| 946 | 946 |
| 947 if (default_search_provider_ == existing_turl) | 947 if (default_search_provider_ == existing_turl) |
| 948 SetDefaultSearchProviderNoNotify(existing_turl); | 948 SetDefaultSearchProviderNoNotify(existing_turl); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 t_url->suggestions_url()->HasGoogleBaseURLs())) { | 1081 t_url->suggestions_url()->HasGoogleBaseURLs())) { |
| 1082 RemoveFromKeywordMapByPointer(t_url); | 1082 RemoveFromKeywordMapByPointer(t_url); |
| 1083 t_url->InvalidateCachedValues(); | 1083 t_url->InvalidateCachedValues(); |
| 1084 if (!t_url->keyword().empty()) | 1084 if (!t_url->keyword().empty()) |
| 1085 keyword_to_template_map_[t_url->keyword()] = t_url; | 1085 keyword_to_template_map_[t_url->keyword()] = t_url; |
| 1086 something_changed = true; | 1086 something_changed = true; |
| 1087 } | 1087 } |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 if (something_changed && loaded_) { | 1090 if (something_changed && loaded_) { |
| 1091 UIThreadSearchTermsData search_terms_data; | 1091 UIThreadSearchTermsData search_terms_data(NULL); |
| 1092 provider_map_.UpdateGoogleBaseURLs(search_terms_data); | 1092 provider_map_.UpdateGoogleBaseURLs(search_terms_data); |
| 1093 NotifyObservers(); | 1093 NotifyObservers(); |
| 1094 } | 1094 } |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 void TemplateURLService::UpdateDefaultSearch() { | 1097 void TemplateURLService::UpdateDefaultSearch() { |
| 1098 if (!loaded_) { | 1098 if (!loaded_) { |
| 1099 // Set |initial_default_search_provider_| from the preferences. We use this | 1099 // Set |initial_default_search_provider_| from the preferences. We use this |
| 1100 // value for default search provider until the database has been loaded. | 1100 // value for default search provider until the database has been loaded. |
| 1101 if (!LoadDefaultSearchProviderFromPrefs(&initial_default_search_provider_, | 1101 if (!LoadDefaultSearchProviderFromPrefs(&initial_default_search_provider_, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 | 1323 |
| 1324 i = template_urls->erase(i); | 1324 i = template_urls->erase(i); |
| 1325 if (service_.get()) | 1325 if (service_.get()) |
| 1326 service_->RemoveKeyword(*template_url); | 1326 service_->RemoveKeyword(*template_url); |
| 1327 delete template_url; | 1327 delete template_url; |
| 1328 } else { | 1328 } else { |
| 1329 ++i; | 1329 ++i; |
| 1330 } | 1330 } |
| 1331 } | 1331 } |
| 1332 } | 1332 } |
| OLD | NEW |