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 the host then it cannot be converted | |
| 97 // into a valid GURL. In such a scenario, |keyword| can not be empty. |title| | |
| 98 // 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.
| |
| 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(TemplateURLRef::DisplayURLToURLRef(url)); |
| 112 TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec()))); | |
| 113 return new TemplateURL(data); | 120 return new TemplateURL(data); |
| 114 } | 121 } |
| 115 | 122 |
| 116 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| | 123 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| |
| 117 // with the resulting TemplateURLs. | 124 // with the resulting TemplateURLs. |
| 118 void ParseSearchEnginesFromFirefoxXMLData( | 125 void ParseSearchEnginesFromFirefoxXMLData( |
| 119 const std::vector<std::string>& xml_data, | 126 const std::vector<std::string>& xml_data, |
| 120 std::vector<TemplateURL*>* search_engines) { | 127 std::vector<TemplateURL*>* search_engines) { |
| 121 DCHECK(search_engines); | 128 DCHECK(search_engines); |
| 122 | 129 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); | 221 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); |
| 215 BrowserThread::PostTask(BrowserThread::UI, | 222 BrowserThread::PostTask(BrowserThread::UI, |
| 216 FROM_HERE, | 223 FROM_HERE, |
| 217 base::Bind(&ProfileWriter::AddHistoryPage, | 224 base::Bind(&ProfileWriter::AddHistoryPage, |
| 218 writer_, | 225 writer_, |
| 219 converted_rows, | 226 converted_rows, |
| 220 converted_visit_source)); | 227 converted_visit_source)); |
| 221 } | 228 } |
| 222 | 229 |
| 223 void InProcessImporterBridge::SetKeywords( | 230 void InProcessImporterBridge::SetKeywords( |
| 224 const std::vector<importer::URLKeywordInfo>& url_keywords, | 231 const std::vector<importer::SearchEngineInfo>& search_engines, |
| 225 bool unique_on_host_and_path) { | 232 bool unique_on_host_and_path) { |
| 226 ScopedVector<TemplateURL> owned_template_urls; | 233 ScopedVector<TemplateURL> owned_template_urls; |
| 227 for (size_t i = 0; i < url_keywords.size(); ++i) { | 234 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
| |
| 228 owned_template_urls.push_back( | 235 owned_template_urls.push_back( |
| 229 CreateTemplateURL(url_keywords[i].display_name, | 236 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
| |
| 230 url_keywords[i].keyword, | 237 search_engines[i].keyword, |
| 231 url_keywords[i].url)); | 238 search_engines[i].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 |