Chromium Code Reviews| Index: chrome/browser/importer/in_process_importer_bridge.cc |
| diff --git a/chrome/browser/importer/in_process_importer_bridge.cc b/chrome/browser/importer/in_process_importer_bridge.cc |
| index 3bd1fde5be8c905e1ea3b3014adf69bb691b80f0..6e540cfd809305a519332af9ca6be2119a288bd4 100644 |
| --- a/chrome/browser/importer/in_process_importer_bridge.cc |
| +++ b/chrome/browser/importer/in_process_importer_bridge.cc |
| @@ -91,25 +91,32 @@ class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { |
| DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); |
| }; |
| -// Creates a TemplateURL with the |keyword| and |url|. |title| may be empty. |
| +// Creates a TemplateURL with the |keyword| and |url|. |url| must be non-empty. |
| +// |keyword| may be empty, provided that |url| can be converted to a valid GURL. |
| +// If |url| contains replacement term(s) in the host then it cannot be converted |
| +// into a valid GURL. In such a scenario, |keyword| can not be empty. |title| |
| +// may be empty. |
|
Peter Kasting
2014/11/11 22:42:11
Nit: How about this slight tweak:
Attempts to cre
Tapu Ghose
2014/11/15 05:22:19
Rephrased comment as you suggested.
|
| // This function transfers ownership of the created TemplateURL to the caller. |
| TemplateURL* CreateTemplateURL(const base::string16& title, |
| const base::string16& keyword, |
| - const GURL& url) { |
| - // Skip if the url is invalid. |
| - if (!url.is_valid()) |
| + const base::string16& url) { |
| + if (url.empty()) |
| return NULL; |
| TemplateURLData data; |
| - if (keyword.empty()) |
| - data.SetKeyword(TemplateURL::GenerateKeyword(url)); |
| - else |
| + if (keyword.empty()) { |
| + GURL gurl = GURL(url); |
| + if (!gurl.is_valid()) |
| + return NULL; |
| + data.SetKeyword(TemplateURL::GenerateKeyword(gurl)); |
| + } else { |
| data.SetKeyword(keyword); |
| + } |
| + |
| // We set short name by using the title if it exists. |
| // Otherwise, we use the shortcut. |
| data.short_name = title.empty() ? keyword : title; |
| - data.SetURL( |
| - TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec()))); |
| + data.SetURL(TemplateURLRef::DisplayURLToURLRef(url)); |
| return new TemplateURL(data); |
| } |
| @@ -221,14 +228,14 @@ void InProcessImporterBridge::SetHistoryItems( |
| } |
| void InProcessImporterBridge::SetKeywords( |
| - const std::vector<importer::URLKeywordInfo>& url_keywords, |
| + const std::vector<importer::SearchEngineInfo>& search_engines, |
| bool unique_on_host_and_path) { |
| ScopedVector<TemplateURL> owned_template_urls; |
| - for (size_t i = 0; i < url_keywords.size(); ++i) { |
| + for (size_t i = 0; i < search_engines.size(); ++i) { |
|
Peter Kasting
2014/11/11 22:42:11
Nit: C++11:
for (const auto& search_engine : se
Tapu Ghose
2014/11/15 05:22:19
I like this range-based for loop. Since the existi
|
| owned_template_urls.push_back( |
| - CreateTemplateURL(url_keywords[i].display_name, |
| - url_keywords[i].keyword, |
| - url_keywords[i].url)); |
| + CreateTemplateURL(search_engines[i].display_name, |
|
Peter Kasting
2014/11/11 22:42:11
Shouldn't we check for NULL before blindly pushing
Tapu Ghose
2014/11/15 05:22:19
Updated CreateTemplateURL to make use that either
Peter Kasting
2014/11/17 21:30:35
That's fine, but that's not what I meant by this c
Tapu Ghose
2014/12/07 02:49:54
Got it. Checked NULL before pushing onto |owned_te
|
| + search_engines[i].keyword, |
| + search_engines[i].url)); |
| } |
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| base::Bind(&ProfileWriter::AddKeywords, writer_, |