Chromium Code Reviews| 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/importer/in_process_importer_bridge.h" | 5 #include "chrome/browser/importer/in_process_importer_bridge.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 low_value.find("moz:") != std::string::npos) { | 84 low_value.find("moz:") != std::string::npos) { |
| 85 return false; | 85 return false; |
| 86 } | 86 } |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); | 91 DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // Creates a TemplateURL with the |keyword| and |url|. |title| may be empty. | 94 // Attempts to create a TemplateURL from the provided data. |title| is optional. |
| 95 // If |keyword| is not specified, the function will attempt to generate the | |
| 96 // keyword from |url|, which in that case must be a valid GURL. This can fail if | |
| 97 // e.g. the replacement term is in the host. If TemplateURL creation fails, | |
| 98 // returns NULL. | |
| 95 // This function transfers ownership of the created TemplateURL to the caller. | 99 // This function transfers ownership of the created TemplateURL to the caller. |
| 96 TemplateURL* CreateTemplateURL(const base::string16& title, | 100 TemplateURL* CreateTemplateURL(const base::string16& title, |
| 97 const base::string16& keyword, | 101 const base::string16& keyword, |
| 98 const GURL& url) { | 102 const base::string16& url) { |
| 99 // Skip if the url is invalid. | 103 if (url.empty()) |
| 100 if (!url.is_valid()) | |
| 101 return NULL; | 104 return NULL; |
| 102 | 105 |
| 106 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
| |
| 103 TemplateURLData data; | 107 TemplateURLData data; |
| 104 if (keyword.empty()) | 108 if (keyword.empty()) { |
| 105 data.SetKeyword(TemplateURL::GenerateKeyword(url)); | 109 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.
| |
| 106 else | 110 if (!gurl.is_valid()) |
| 111 return NULL; | |
| 112 generated_keyword = TemplateURL::GenerateKeyword(gurl); | |
| 113 data.SetKeyword(generated_keyword); | |
| 114 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.
| |
| 115 } else { | |
| 107 data.SetKeyword(keyword); | 116 data.SetKeyword(keyword); |
| 108 // We set short name by using the title if it exists. | 117 // We set short name by using the title if it exists. |
| 109 // Otherwise, we use the shortcut. | 118 // Otherwise, we use the shortcut. |
| 110 data.short_name = title.empty() ? keyword : title; | 119 data.short_name = title.empty() ? keyword : title; |
| 111 data.SetURL( | 120 } |
| 112 TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec()))); | 121 |
| 122 data.SetURL(TemplateURLRef::DisplayURLToURLRef(url)); | |
| 113 return new TemplateURL(data); | 123 return new TemplateURL(data); |
| 114 } | 124 } |
| 115 | 125 |
| 116 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| | 126 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| |
| 117 // with the resulting TemplateURLs. | 127 // with the resulting TemplateURLs. |
| 118 void ParseSearchEnginesFromFirefoxXMLData( | 128 void ParseSearchEnginesFromFirefoxXMLData( |
| 119 const std::vector<std::string>& xml_data, | 129 const std::vector<std::string>& xml_data, |
| 120 std::vector<TemplateURL*>* search_engines) { | 130 std::vector<TemplateURL*>* search_engines) { |
| 121 DCHECK(search_engines); | 131 DCHECK(search_engines); |
| 122 | 132 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); | 224 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); |
| 215 BrowserThread::PostTask(BrowserThread::UI, | 225 BrowserThread::PostTask(BrowserThread::UI, |
| 216 FROM_HERE, | 226 FROM_HERE, |
| 217 base::Bind(&ProfileWriter::AddHistoryPage, | 227 base::Bind(&ProfileWriter::AddHistoryPage, |
| 218 writer_, | 228 writer_, |
| 219 converted_rows, | 229 converted_rows, |
| 220 converted_visit_source)); | 230 converted_visit_source)); |
| 221 } | 231 } |
| 222 | 232 |
| 223 void InProcessImporterBridge::SetKeywords( | 233 void InProcessImporterBridge::SetKeywords( |
| 224 const std::vector<importer::URLKeywordInfo>& url_keywords, | 234 const std::vector<importer::SearchEngineInfo>& search_engines, |
| 225 bool unique_on_host_and_path) { | 235 bool unique_on_host_and_path) { |
| 226 ScopedVector<TemplateURL> owned_template_urls; | 236 ScopedVector<TemplateURL> owned_template_urls; |
| 227 for (size_t i = 0; i < url_keywords.size(); ++i) { | 237 for (const auto& search_engine : search_engines) { |
| 228 owned_template_urls.push_back( | 238 owned_template_urls.push_back( |
| 229 CreateTemplateURL(url_keywords[i].display_name, | 239 CreateTemplateURL(search_engine.display_name, |
| 230 url_keywords[i].keyword, | 240 search_engine.keyword, |
| 231 url_keywords[i].url)); | 241 search_engine.url)); |
| 232 } | 242 } |
| 233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 243 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 234 base::Bind(&ProfileWriter::AddKeywords, writer_, | 244 base::Bind(&ProfileWriter::AddKeywords, writer_, |
| 235 base::Passed(&owned_template_urls), unique_on_host_and_path)); | 245 base::Passed(&owned_template_urls), unique_on_host_and_path)); |
| 236 } | 246 } |
| 237 | 247 |
| 238 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( | 248 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( |
| 239 const std::vector<std::string>& search_engine_data) { | 249 const std::vector<std::string>& search_engine_data) { |
| 240 std::vector<TemplateURL*> search_engines; | 250 std::vector<TemplateURL*> search_engines; |
| 241 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); | 251 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 BrowserThread::PostTask( | 307 BrowserThread::PostTask( |
| 298 BrowserThread::UI, FROM_HERE, | 308 BrowserThread::UI, FROM_HERE, |
| 299 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); | 309 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); |
| 300 } | 310 } |
| 301 | 311 |
| 302 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { | 312 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { |
| 303 return l10n_util::GetStringUTF16(message_id); | 313 return l10n_util::GetStringUTF16(message_id); |
| 304 } | 314 } |
| 305 | 315 |
| 306 InProcessImporterBridge::~InProcessImporterBridge() {} | 316 InProcessImporterBridge::~InProcessImporterBridge() {} |
| OLD | NEW |