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/util.h" | 5 #include "chrome/browser/search_engines/util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 27 matching lines...) Expand all Loading... |
38 return GURL(); | 38 return GURL(); |
39 const TemplateURLRef& search_url = default_provider->url_ref(); | 39 const TemplateURLRef& search_url = default_provider->url_ref(); |
40 DCHECK(search_url.SupportsReplacement(service->search_terms_data())); | 40 DCHECK(search_url.SupportsReplacement(service->search_terms_data())); |
41 TemplateURLRef::SearchTermsArgs search_terms_args(terms); | 41 TemplateURLRef::SearchTermsArgs search_terms_args(terms); |
42 search_terms_args.append_extra_query_params = true; | 42 search_terms_args.append_extra_query_params = true; |
43 return GURL(search_url.ReplaceSearchTerms(search_terms_args, | 43 return GURL(search_url.ReplaceSearchTerms(search_terms_args, |
44 service->search_terms_data())); | 44 service->search_terms_data())); |
45 } | 45 } |
46 | 46 |
47 void RemoveDuplicatePrepopulateIDs( | 47 void RemoveDuplicatePrepopulateIDs( |
48 WebDataService* service, | 48 KeywordWebDataService* service, |
49 const ScopedVector<TemplateURLData>& prepopulated_urls, | 49 const ScopedVector<TemplateURLData>& prepopulated_urls, |
50 TemplateURL* default_search_provider, | 50 TemplateURL* default_search_provider, |
51 TemplateURLService::TemplateURLVector* template_urls, | 51 TemplateURLService::TemplateURLVector* template_urls, |
52 const SearchTermsData& search_terms_data, | 52 const SearchTermsData& search_terms_data, |
53 std::set<std::string>* removed_keyword_guids) { | 53 std::set<std::string>* removed_keyword_guids) { |
54 DCHECK(template_urls); | 54 DCHECK(template_urls); |
55 | 55 |
56 // For convenience construct an ID->TemplateURL* map from |prepopulated_urls|. | 56 // For convenience construct an ID->TemplateURL* map from |prepopulated_urls|. |
57 typedef std::map<int, TemplateURLData*> PrepopulatedURLMap; | 57 typedef std::map<int, TemplateURLData*> PrepopulatedURLMap; |
58 PrepopulatedURLMap prepopulated_url_map; | 58 PrepopulatedURLMap prepopulated_url_map; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 ActionsFromPrepopulateData::ActionsFromPrepopulateData() {} | 180 ActionsFromPrepopulateData::ActionsFromPrepopulateData() {} |
181 | 181 |
182 ActionsFromPrepopulateData::~ActionsFromPrepopulateData() {} | 182 ActionsFromPrepopulateData::~ActionsFromPrepopulateData() {} |
183 | 183 |
184 // This is invoked when the version of the prepopulate data changes. | 184 // This is invoked when the version of the prepopulate data changes. |
185 // If |removed_keyword_guids| is not NULL, the Sync GUID of each item removed | 185 // If |removed_keyword_guids| is not NULL, the Sync GUID of each item removed |
186 // from the DB will be added to it. Note that this function will take | 186 // from the DB will be added to it. Note that this function will take |
187 // ownership of |prepopulated_urls| and will clear the vector. | 187 // ownership of |prepopulated_urls| and will clear the vector. |
188 void MergeEnginesFromPrepopulateData( | 188 void MergeEnginesFromPrepopulateData( |
189 WebDataService* service, | 189 KeywordWebDataService* service, |
190 ScopedVector<TemplateURLData>* prepopulated_urls, | 190 ScopedVector<TemplateURLData>* prepopulated_urls, |
191 size_t default_search_index, | 191 size_t default_search_index, |
192 TemplateURLService::TemplateURLVector* template_urls, | 192 TemplateURLService::TemplateURLVector* template_urls, |
193 TemplateURL* default_search_provider, | 193 TemplateURL* default_search_provider, |
194 std::set<std::string>* removed_keyword_guids) { | 194 std::set<std::string>* removed_keyword_guids) { |
195 DCHECK(prepopulated_urls); | 195 DCHECK(prepopulated_urls); |
196 DCHECK(template_urls); | 196 DCHECK(template_urls); |
197 | 197 |
198 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( | 198 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( |
199 prepopulated_urls, *template_urls, default_search_provider)); | 199 prepopulated_urls, *template_urls, default_search_provider)); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 default_search_provider->prepopulate_id()) || | 300 default_search_provider->prepopulate_id()) || |
301 (template_url->keyword() != default_search_provider->keyword()))) | 301 (template_url->keyword() != default_search_provider->keyword()))) |
302 actions.removed_engines.push_back(template_url); | 302 actions.removed_engines.push_back(template_url); |
303 } | 303 } |
304 | 304 |
305 return actions; | 305 return actions; |
306 } | 306 } |
307 | 307 |
308 void GetSearchProvidersUsingKeywordResult( | 308 void GetSearchProvidersUsingKeywordResult( |
309 const WDTypedResult& result, | 309 const WDTypedResult& result, |
310 WebDataService* service, | 310 KeywordWebDataService* service, |
311 PrefService* prefs, | 311 PrefService* prefs, |
312 TemplateURLService::TemplateURLVector* template_urls, | 312 TemplateURLService::TemplateURLVector* template_urls, |
313 TemplateURL* default_search_provider, | 313 TemplateURL* default_search_provider, |
314 const SearchTermsData& search_terms_data, | 314 const SearchTermsData& search_terms_data, |
315 int* new_resource_keyword_version, | 315 int* new_resource_keyword_version, |
316 std::set<std::string>* removed_keyword_guids) { | 316 std::set<std::string>* removed_keyword_guids) { |
317 DCHECK(template_urls); | 317 DCHECK(template_urls); |
318 DCHECK(template_urls->empty()); | 318 DCHECK(template_urls->empty()); |
319 DCHECK_EQ(KEYWORDS_RESULT, result.GetType()); | 319 DCHECK_EQ(KEYWORDS_RESULT, result.GetType()); |
320 DCHECK(new_resource_keyword_version); | 320 DCHECK(new_resource_keyword_version); |
(...skipping 19 matching lines...) Expand all Loading... |
340 | 340 |
341 *new_resource_keyword_version = keyword_result.builtin_keyword_version; | 341 *new_resource_keyword_version = keyword_result.builtin_keyword_version; |
342 GetSearchProvidersUsingLoadedEngines(service, prefs, template_urls, | 342 GetSearchProvidersUsingLoadedEngines(service, prefs, template_urls, |
343 default_search_provider, | 343 default_search_provider, |
344 search_terms_data, | 344 search_terms_data, |
345 new_resource_keyword_version, | 345 new_resource_keyword_version, |
346 removed_keyword_guids); | 346 removed_keyword_guids); |
347 } | 347 } |
348 | 348 |
349 void GetSearchProvidersUsingLoadedEngines( | 349 void GetSearchProvidersUsingLoadedEngines( |
350 WebDataService* service, | 350 KeywordWebDataService* service, |
351 PrefService* prefs, | 351 PrefService* prefs, |
352 TemplateURLService::TemplateURLVector* template_urls, | 352 TemplateURLService::TemplateURLVector* template_urls, |
353 TemplateURL* default_search_provider, | 353 TemplateURL* default_search_provider, |
354 const SearchTermsData& search_terms_data, | 354 const SearchTermsData& search_terms_data, |
355 int* resource_keyword_version, | 355 int* resource_keyword_version, |
356 std::set<std::string>* removed_keyword_guids) { | 356 std::set<std::string>* removed_keyword_guids) { |
357 DCHECK(template_urls); | 357 DCHECK(template_urls); |
358 DCHECK(resource_keyword_version); | 358 DCHECK(resource_keyword_version); |
359 size_t default_search_index; | 359 size_t default_search_index; |
360 ScopedVector<TemplateURLData> prepopulated_urls = | 360 ScopedVector<TemplateURLData> prepopulated_urls = |
(...skipping 19 matching lines...) Expand all Loading... |
380 std::vector<std::string> deduped_encodings; | 380 std::vector<std::string> deduped_encodings; |
381 std::set<std::string> encoding_set; | 381 std::set<std::string> encoding_set; |
382 for (std::vector<std::string>::const_iterator i(encodings->begin()); | 382 for (std::vector<std::string>::const_iterator i(encodings->begin()); |
383 i != encodings->end(); ++i) { | 383 i != encodings->end(); ++i) { |
384 if (encoding_set.insert(*i).second) | 384 if (encoding_set.insert(*i).second) |
385 deduped_encodings.push_back(*i); | 385 deduped_encodings.push_back(*i); |
386 } | 386 } |
387 encodings->swap(deduped_encodings); | 387 encodings->swap(deduped_encodings); |
388 return encodings->size() != deduped_encodings.size(); | 388 return encodings->size() != deduped_encodings.size(); |
389 } | 389 } |
OLD | NEW |