Make prepopulated-TemplateURL-de-duper heuristic smarter. Instead of blindly preserving the first URL we get back from the keyword table, use the default search engine, or the URL that matches the prepopulate keyword, only after that falling back to using the lowest ID.

BUG=128216
TEST=unit_tests TemplateURLServiceUtilTest.*


Review URL: https://chromiumcodereview.appspot.com/10409002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139300 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/search_engines/util.h b/chrome/browser/search_engines/util.h
index c480f53..0e96ae971 100644
--- a/chrome/browser/search_engines/util.h
+++ b/chrome/browser/search_engines/util.h
@@ -13,6 +13,7 @@
 
 #include "base/memory/scoped_ptr.h"
 #include "base/string16.h"
+#include "chrome/browser/search_engines/template_url_service.h"
 
 class Profile;
 class TemplateURL;
@@ -40,7 +41,7 @@
     const WDTypedResult& result,
     WebDataService* service,
     Profile* profile,
-    std::vector<TemplateURL*>* template_urls,
+    TemplateURLService::TemplateURLVector* template_urls,
     TemplateURL** default_search_provider,
     int* new_resource_keyword_version,
     std::set<std::string>* removed_keyword_guids);
@@ -54,4 +55,16 @@
     Profile* profile,
     scoped_ptr<TemplateURL>* backup_default_search_provider);
 
+// Removes (and deletes) TemplateURLs from |template_urls| and |service| if they
+// have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the
+// Sync GUID of each item removed from the DB will be added to it. This is a
+// helper used by GetSearchProvidersUsingKeywordResult(), but is declared here
+// so it's accessible by unittests.
+void RemoveDuplicatePrepopulateIDs(
+    WebDataService* service,
+    const ScopedVector<TemplateURL>& prepopulated_urls,
+    TemplateURL* default_search_provider,
+    TemplateURLService::TemplateURLVector* template_urls,
+    std::set<std::string>* removed_keyword_guids);
+
 #endif  // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_