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..8ff9a70760a8741d310a7d3b5d1cdf3a2d6621d2 100644 |
| --- a/chrome/browser/importer/in_process_importer_bridge.cc |
| +++ b/chrome/browser/importer/in_process_importer_bridge.cc |
| @@ -91,25 +91,35 @@ class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { |
| DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); |
| }; |
| -// Creates a TemplateURL with the |keyword| and |url|. |title| may be empty. |
| +// Attempts to create a TemplateURL from the provided data. |title| is optional. |
| +// If |keyword| is not specified, the function will attempt to generate the |
| +// keyword from |url|, which in that case must be a valid GURL. This can fail if |
| +// e.g. the replacement term is in the host. If TemplateURL creation fails, |
| +// returns NULL. |
| // 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; |
| + base::string16 generated_keyword; |
|
Peter Kasting
2014/11/17 21:30:35
Nit: Declare this where it's actually defined
Tapu Ghose
2014/12/07 02:49:54
Reverted all changes made in this function for gen
|
| TemplateURLData data; |
| - if (keyword.empty()) |
| - data.SetKeyword(TemplateURL::GenerateKeyword(url)); |
| - else |
| + if (keyword.empty()) { |
| + GURL gurl = GURL(url); |
|
Peter Kasting
2014/11/17 21:30:35
Nit: Shorter: GURL gurl(url);
Tapu Ghose
2014/12/07 02:49:54
Done.
|
| + if (!gurl.is_valid()) |
| + return NULL; |
| + generated_keyword = TemplateURL::GenerateKeyword(gurl); |
| + data.SetKeyword(generated_keyword); |
| + data.short_name = title.empty() ? generated_keyword : title; |
|
Peter Kasting
2014/11/17 21:30:35
Nit: Factor this out of both branches and use keyw
Tapu Ghose
2014/12/07 02:49:54
Acknowledged.
|
| + } 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()))); |
| + // 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(url)); |
| return new TemplateURL(data); |
| } |
| @@ -221,14 +231,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 (const auto& search_engine : search_engines) { |
| owned_template_urls.push_back( |
| - CreateTemplateURL(url_keywords[i].display_name, |
| - url_keywords[i].keyword, |
| - url_keywords[i].url)); |
| + CreateTemplateURL(search_engine.display_name, |
| + search_engine.keyword, |
| + search_engine.url)); |
| } |
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| base::Bind(&ProfileWriter::AddKeywords, writer_, |