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 // Creates a TemplateURL with the |keyword| and |url|. |url| must be non-empty. |
| 95 // |keyword| may be empty, provided that |url| can be converted to a valid GURL. | |
| 96 // If |url| contains replacement term(s) in host then it cannot be converted | |
|
Ilya Sherman
2014/11/07 00:22:34
nit: "in host" -> "in the host"
Tapu Ghose
2014/11/09 14:03:06
Done.
| |
| 97 // into a valid GURL. In such scenario, |keyword| can not be empty. |title| may | |
|
Ilya Sherman
2014/11/07 00:22:34
nit: "In such scenario" -> "In such a scenario"
Tapu Ghose
2014/11/09 14:03:06
Done.
| |
| 98 // be empty. | |
| 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 |
| 103 TemplateURLData data; | 106 TemplateURLData data; |
| 104 if (keyword.empty()) | 107 if (keyword.empty()) { |
| 105 data.SetKeyword(TemplateURL::GenerateKeyword(url)); | 108 GURL gurl = GURL(url); |
| 106 else | 109 if (!gurl.is_valid()) |
| 110 return NULL; | |
| 111 data.SetKeyword(TemplateURL::GenerateKeyword(gurl)); | |
| 112 } else { | |
| 107 data.SetKeyword(keyword); | 113 data.SetKeyword(keyword); |
| 114 } | |
| 115 | |
| 108 // We set short name by using the title if it exists. | 116 // We set short name by using the title if it exists. |
| 109 // Otherwise, we use the shortcut. | 117 // Otherwise, we use the shortcut. |
| 110 data.short_name = title.empty() ? keyword : title; | 118 data.short_name = title.empty() ? keyword : title; |
| 111 data.SetURL( | 119 data.SetURL( |
| 112 TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec()))); | 120 TemplateURLRef::DisplayURLToURLRef(url)); |
|
Ilya Sherman
2014/11/07 00:22:34
nit: Looks like you can un-wrap this line.
Tapu Ghose
2014/11/09 14:03:06
Done.
| |
| 113 return new TemplateURL(data); | 121 return new TemplateURL(data); |
| 114 } | 122 } |
| 115 | 123 |
| 116 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| | 124 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| |
| 117 // with the resulting TemplateURLs. | 125 // with the resulting TemplateURLs. |
| 118 void ParseSearchEnginesFromFirefoxXMLData( | 126 void ParseSearchEnginesFromFirefoxXMLData( |
| 119 const std::vector<std::string>& xml_data, | 127 const std::vector<std::string>& xml_data, |
| 120 std::vector<TemplateURL*>* search_engines) { | 128 std::vector<TemplateURL*>* search_engines) { |
| 121 DCHECK(search_engines); | 129 DCHECK(search_engines); |
| 122 | 130 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); | 222 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); |
| 215 BrowserThread::PostTask(BrowserThread::UI, | 223 BrowserThread::PostTask(BrowserThread::UI, |
| 216 FROM_HERE, | 224 FROM_HERE, |
| 217 base::Bind(&ProfileWriter::AddHistoryPage, | 225 base::Bind(&ProfileWriter::AddHistoryPage, |
| 218 writer_, | 226 writer_, |
| 219 converted_rows, | 227 converted_rows, |
| 220 converted_visit_source)); | 228 converted_visit_source)); |
| 221 } | 229 } |
| 222 | 230 |
| 223 void InProcessImporterBridge::SetKeywords( | 231 void InProcessImporterBridge::SetKeywords( |
| 224 const std::vector<importer::URLKeywordInfo>& url_keywords, | 232 const std::vector<importer::SearchEngineInfo>& search_engines, |
| 225 bool unique_on_host_and_path) { | 233 bool unique_on_host_and_path) { |
| 226 ScopedVector<TemplateURL> owned_template_urls; | 234 ScopedVector<TemplateURL> owned_template_urls; |
| 227 for (size_t i = 0; i < url_keywords.size(); ++i) { | 235 for (size_t i = 0; i < search_engines.size(); ++i) { |
| 228 owned_template_urls.push_back( | 236 owned_template_urls.push_back( |
| 229 CreateTemplateURL(url_keywords[i].display_name, | 237 CreateTemplateURL(search_engines[i].display_name, |
| 230 url_keywords[i].keyword, | 238 search_engines[i].keyword, |
| 231 url_keywords[i].url)); | 239 search_engines[i].url)); |
| 232 } | 240 } |
| 233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 241 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 234 base::Bind(&ProfileWriter::AddKeywords, writer_, | 242 base::Bind(&ProfileWriter::AddKeywords, writer_, |
| 235 base::Passed(&owned_template_urls), unique_on_host_and_path)); | 243 base::Passed(&owned_template_urls), unique_on_host_and_path)); |
| 236 } | 244 } |
| 237 | 245 |
| 238 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( | 246 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( |
| 239 const std::vector<std::string>& search_engine_data) { | 247 const std::vector<std::string>& search_engine_data) { |
| 240 std::vector<TemplateURL*> search_engines; | 248 std::vector<TemplateURL*> search_engines; |
| 241 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); | 249 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 BrowserThread::PostTask( | 305 BrowserThread::PostTask( |
| 298 BrowserThread::UI, FROM_HERE, | 306 BrowserThread::UI, FROM_HERE, |
| 299 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); | 307 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); |
| 300 } | 308 } |
| 301 | 309 |
| 302 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { | 310 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { |
| 303 return l10n_util::GetStringUTF16(message_id); | 311 return l10n_util::GetStringUTF16(message_id); |
| 304 } | 312 } |
| 305 | 313 |
| 306 InProcessImporterBridge::~InProcessImporterBridge() {} | 314 InProcessImporterBridge::~InProcessImporterBridge() {} |
| OLD | NEW |