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 | |
| 103 TemplateURLData data; | 105 TemplateURLData data; |
| 104 if (keyword.empty()) | 106 if (keyword.empty()) { |
| 105 data.SetKeyword(TemplateURL::GenerateKeyword(url)); | 107 GURL gurl(url); |
| 106 else | 108 if (!gurl.is_valid()) |
| 109 return NULL; | |
| 110 data.SetKeyword(TemplateURL::GenerateKeyword(gurl)); | |
| 111 } else { | |
| 107 data.SetKeyword(keyword); | 112 data.SetKeyword(keyword); |
| 113 } | |
| 108 // We set short name by using the title if it exists. | 114 // We set short name by using the title if it exists. |
| 109 // Otherwise, we use the shortcut. | 115 // Otherwise, we use the shortcut. |
| 110 data.short_name = title.empty() ? keyword : title; | 116 data.short_name = title.empty() ? keyword : title; |
|
Peter Kasting
2014/12/09 23:10:19
I think this should be "keyword()" instead of "key
Tapu Ghose
2014/12/10 04:41:55
Made use of "data.keyword()" instead of "keyword".
Peter Kasting
2014/12/10 17:41:16
Well, where else is this called from? You should
Tapu Ghose
2014/12/11 03:12:21
Looks like this is called while importing bookmark
| |
| 111 data.SetURL( | 117 data.SetURL(TemplateURLRef::DisplayURLToURLRef(url)); |
| 112 TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec()))); | |
| 113 return new TemplateURL(data); | 118 return new TemplateURL(data); |
| 114 } | 119 } |
| 115 | 120 |
| 116 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| | 121 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| |
| 117 // with the resulting TemplateURLs. | 122 // with the resulting TemplateURLs. |
| 118 void ParseSearchEnginesFromFirefoxXMLData( | 123 void ParseSearchEnginesFromFirefoxXMLData( |
| 119 const std::vector<std::string>& xml_data, | 124 const std::vector<std::string>& xml_data, |
| 120 std::vector<TemplateURL*>* search_engines) { | 125 std::vector<TemplateURL*>* search_engines) { |
| 121 DCHECK(search_engines); | 126 DCHECK(search_engines); |
| 122 | 127 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); | 219 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); |
| 215 BrowserThread::PostTask(BrowserThread::UI, | 220 BrowserThread::PostTask(BrowserThread::UI, |
| 216 FROM_HERE, | 221 FROM_HERE, |
| 217 base::Bind(&ProfileWriter::AddHistoryPage, | 222 base::Bind(&ProfileWriter::AddHistoryPage, |
| 218 writer_, | 223 writer_, |
| 219 converted_rows, | 224 converted_rows, |
| 220 converted_visit_source)); | 225 converted_visit_source)); |
| 221 } | 226 } |
| 222 | 227 |
| 223 void InProcessImporterBridge::SetKeywords( | 228 void InProcessImporterBridge::SetKeywords( |
| 224 const std::vector<importer::URLKeywordInfo>& url_keywords, | 229 const std::vector<importer::SearchEngineInfo>& search_engines, |
| 225 bool unique_on_host_and_path) { | 230 bool unique_on_host_and_path) { |
| 226 ScopedVector<TemplateURL> owned_template_urls; | 231 ScopedVector<TemplateURL> owned_template_urls; |
| 227 for (size_t i = 0; i < url_keywords.size(); ++i) { | 232 TemplateURL* owned_template_url; |
|
Peter Kasting
2014/12/09 23:10:19
Nit: Declare this where it's defined, in the loop
Tapu Ghose
2014/12/10 04:41:55
Agreed.
| |
| 228 owned_template_urls.push_back( | 233 for (const auto& search_engine : search_engines) { |
| 229 CreateTemplateURL(url_keywords[i].display_name, | 234 owned_template_url = CreateTemplateURL(search_engine.display_name, |
| 230 url_keywords[i].keyword, | 235 search_engine.keyword, |
| 231 url_keywords[i].url)); | 236 search_engine.url); |
| 237 if (owned_template_url) | |
| 238 owned_template_urls.push_back(owned_template_url); | |
| 232 } | 239 } |
| 233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 240 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 234 base::Bind(&ProfileWriter::AddKeywords, writer_, | 241 base::Bind(&ProfileWriter::AddKeywords, writer_, |
| 235 base::Passed(&owned_template_urls), unique_on_host_and_path)); | 242 base::Passed(&owned_template_urls), unique_on_host_and_path)); |
| 236 } | 243 } |
| 237 | 244 |
| 238 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( | 245 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( |
| 239 const std::vector<std::string>& search_engine_data) { | 246 const std::vector<std::string>& search_engine_data) { |
| 240 std::vector<TemplateURL*> search_engines; | 247 std::vector<TemplateURL*> search_engines; |
| 241 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); | 248 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 BrowserThread::PostTask( | 304 BrowserThread::PostTask( |
| 298 BrowserThread::UI, FROM_HERE, | 305 BrowserThread::UI, FROM_HERE, |
| 299 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); | 306 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); |
| 300 } | 307 } |
| 301 | 308 |
| 302 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { | 309 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { |
| 303 return l10n_util::GetStringUTF16(message_id); | 310 return l10n_util::GetStringUTF16(message_id); |
| 304 } | 311 } |
| 305 | 312 |
| 306 InProcessImporterBridge::~InProcessImporterBridge() {} | 313 InProcessImporterBridge::~InProcessImporterBridge() {} |
| OLD | NEW |