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 21 matching lines...) Expand all Loading... |
32 GetDefaultSearchProvider(); | 32 GetDefaultSearchProvider(); |
33 if (!default_provider) { | 33 if (!default_provider) { |
34 // TODO(cpu): bug 1187517. It is possible to have no default provider. | 34 // TODO(cpu): bug 1187517. It is possible to have no default provider. |
35 // returning an empty string is a stopgap measure for the crash | 35 // returning an empty string is a stopgap measure for the crash |
36 // http://code.google.com/p/chromium/issues/detail?id=2573 | 36 // http://code.google.com/p/chromium/issues/detail?id=2573 |
37 return string16(); | 37 return string16(); |
38 } | 38 } |
39 return default_provider->short_name(); | 39 return default_provider->short_name(); |
40 } | 40 } |
41 | 41 |
| 42 GURL GetDefaultSearchURLForSearchTerms(Profile* profile, |
| 43 const string16& terms) { |
| 44 DCHECK(profile); |
| 45 const TemplateURL* default_provider = |
| 46 TemplateURLServiceFactory::GetForProfile(profile)-> |
| 47 GetDefaultSearchProvider(); |
| 48 if (!default_provider) |
| 49 return GURL(); |
| 50 const TemplateURLRef& search_url = default_provider->url_ref(); |
| 51 DCHECK(search_url.SupportsReplacement()); |
| 52 TemplateURLRef::SearchTermsArgs search_terms_args(terms); |
| 53 search_terms_args.append_extra_query_params = true; |
| 54 return GURL(search_url.ReplaceSearchTerms(search_terms_args)); |
| 55 } |
| 56 |
42 void RemoveDuplicatePrepopulateIDs( | 57 void RemoveDuplicatePrepopulateIDs( |
43 WebDataService* service, | 58 WebDataService* service, |
44 const ScopedVector<TemplateURL>& prepopulated_urls, | 59 const ScopedVector<TemplateURL>& prepopulated_urls, |
45 TemplateURL* default_search_provider, | 60 TemplateURL* default_search_provider, |
46 TemplateURLService::TemplateURLVector* template_urls, | 61 TemplateURLService::TemplateURLVector* template_urls, |
47 std::set<std::string>* removed_keyword_guids) { | 62 std::set<std::string>* removed_keyword_guids) { |
48 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); |
49 DCHECK(template_urls); | 64 DCHECK(template_urls); |
50 | 65 |
51 // For convenience construct an ID->TemplateURL* map from |prepopulated_urls|. | 66 // For convenience construct an ID->TemplateURL* map from |prepopulated_urls|. |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 std::vector<std::string> deduped_encodings; | 346 std::vector<std::string> deduped_encodings; |
332 std::set<std::string> encoding_set; | 347 std::set<std::string> encoding_set; |
333 for (std::vector<std::string>::const_iterator i(encodings->begin()); | 348 for (std::vector<std::string>::const_iterator i(encodings->begin()); |
334 i != encodings->end(); ++i) { | 349 i != encodings->end(); ++i) { |
335 if (encoding_set.insert(*i).second) | 350 if (encoding_set.insert(*i).second) |
336 deduped_encodings.push_back(*i); | 351 deduped_encodings.push_back(*i); |
337 } | 352 } |
338 encodings->swap(deduped_encodings); | 353 encodings->swap(deduped_encodings); |
339 return encodings->size() != deduped_encodings.size(); | 354 return encodings->size() != deduped_encodings.size(); |
340 } | 355 } |
OLD | NEW |