diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 01:07:08 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 01:07:08 +0000 |
commit | 4e40f59bb0a560ce5c606d9e9b31b462f86a8c3e (patch) | |
tree | 89f57076929ad36770aec4dc0cc7ee7e888f5bec /chrome/browser/importer | |
parent | b89852f5c5d3171a76ec2dee6e85c9fd0e078be6 (diff) | |
download | chromium_src-4e40f59bb0a560ce5c606d9e9b31b462f86a8c3e.zip chromium_src-4e40f59bb0a560ce5c606d9e9b31b462f86a8c3e.tar.gz chromium_src-4e40f59bb0a560ce5c606d9e9b31b462f86a8c3e.tar.bz2 |
Enforce that TemplateURLs' URLs cannot be empty.
This should already have been true in non-test code: the keyword editor, the importer, the extension system, and the search engine autodetection code all tried to ensure that the URLs are non-empty. However, because we've seen problems occur, this change tries to sanitize the pref, database, and sync inputs to expunge any bogus entries.
We also fix tests, add some more DCHECKs to make this assertion clearer in some of the TemplateURL-adding paths, and then remove conditionals that checked for empty URLs.
This also cleans up a silly design where TemplateURLService listened for changes to the default search provider prefs -- meaning that anyone who tried to write them wound up calling back to the observer as every single pref was written. This led to reading back bad state. Eliminating this ought to allow for some other cleanups in TemplateURLService, but I haven't tried to make them here.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10014033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132909 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer')
-rw-r--r-- | chrome/browser/importer/profile_writer.cc | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc index bf81c3bc..ee478a0 100644 --- a/chrome/browser/importer/profile_writer.cc +++ b/chrome/browser/importer/profile_writer.cc @@ -255,15 +255,13 @@ static std::string HostPathKeyForURL(const GURL& url) { // the TemplateURL is invalid. static std::string BuildHostPathKey(const TemplateURL* t_url, bool try_url_if_invalid) { - if (!t_url->url().empty()) { - if (try_url_if_invalid && !t_url->url_ref().IsValid()) - return HostPathKeyForURL(GURL(t_url->url())); - - if (t_url->url_ref().SupportsReplacement()) { - return HostPathKeyForURL(GURL( - t_url->url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()))); - } + if (try_url_if_invalid && !t_url->url_ref().IsValid()) + return HostPathKeyForURL(GURL(t_url->url())); + + if (t_url->url_ref().SupportsReplacement()) { + return HostPathKeyForURL(GURL( + t_url->url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"), + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()))); } return std::string(); } @@ -317,7 +315,7 @@ void ProfileWriter::AddKeywords(ScopedVector<TemplateURL> template_urls, continue; // Only add valid TemplateURLs to the model. - if (!(*i)->url().empty() && (*i)->url_ref().IsValid()) { + if ((*i)->url_ref().IsValid()) { model->Add(*i); // Takes ownership. *i = NULL; // Prevent the vector from deleting *i later. } |