Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/browser/importer/in_process_importer_bridge.cc

Issue 616763002: Importing certain bookmarks from firefox and HTML file as search engines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed dependency issue. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/importer/in_process_importer_bridge.h ('k') | chrome/chrome_utility.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 TemplateURL creation fails, returns NULL.
95 // This function transfers ownership of the created TemplateURL to the caller. 96 // This function transfers ownership of the created TemplateURL to the caller.
96 TemplateURL* CreateTemplateURL(const base::string16& title, 97 TemplateURL* CreateTemplateURL(const base::string16& url,
97 const base::string16& keyword, 98 const base::string16& keyword,
98 const GURL& url) { 99 const base::string16& title) {
99 // Skip if the url is invalid. 100 if (url.empty() || keyword.empty())
100 if (!url.is_valid())
101 return NULL; 101 return NULL;
102
103 TemplateURLData data; 102 TemplateURLData data;
104 if (keyword.empty()) 103 data.SetKeyword(keyword);
105 data.SetKeyword(TemplateURL::GenerateKeyword(url));
106 else
107 data.SetKeyword(keyword);
108 // We set short name by using the title if it exists. 104 // We set short name by using the title if it exists.
109 // Otherwise, we use the shortcut. 105 // Otherwise, we use the shortcut.
110 data.short_name = title.empty() ? keyword : title; 106 data.short_name = title.empty() ? keyword : title;
111 data.SetURL( 107 data.SetURL(TemplateURLRef::DisplayURLToURLRef(url));
112 TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec())));
113 return new TemplateURL(data); 108 return new TemplateURL(data);
114 } 109 }
115 110
116 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| 111 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines|
117 // with the resulting TemplateURLs. 112 // with the resulting TemplateURLs.
118 void ParseSearchEnginesFromFirefoxXMLData( 113 void ParseSearchEnginesFromFirefoxXMLData(
119 const std::vector<std::string>& xml_data, 114 const std::vector<std::string>& xml_data,
120 std::vector<TemplateURL*>* search_engines) { 115 std::vector<TemplateURL*>* search_engines) {
121 DCHECK(search_engines); 116 DCHECK(search_engines);
122 117
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); 209 ConvertImporterVisitSourceToHistoryVisitSource(visit_source);
215 BrowserThread::PostTask(BrowserThread::UI, 210 BrowserThread::PostTask(BrowserThread::UI,
216 FROM_HERE, 211 FROM_HERE,
217 base::Bind(&ProfileWriter::AddHistoryPage, 212 base::Bind(&ProfileWriter::AddHistoryPage,
218 writer_, 213 writer_,
219 converted_rows, 214 converted_rows,
220 converted_visit_source)); 215 converted_visit_source));
221 } 216 }
222 217
223 void InProcessImporterBridge::SetKeywords( 218 void InProcessImporterBridge::SetKeywords(
224 const std::vector<importer::URLKeywordInfo>& url_keywords, 219 const std::vector<importer::SearchEngineInfo>& search_engines,
225 bool unique_on_host_and_path) { 220 bool unique_on_host_and_path) {
226 ScopedVector<TemplateURL> owned_template_urls; 221 ScopedVector<TemplateURL> owned_template_urls;
227 for (size_t i = 0; i < url_keywords.size(); ++i) { 222 for (const auto& search_engine : search_engines) {
228 owned_template_urls.push_back( 223 TemplateURL* owned_template_url =
229 CreateTemplateURL(url_keywords[i].display_name, 224 CreateTemplateURL(search_engine.url,
230 url_keywords[i].keyword, 225 search_engine.keyword,
231 url_keywords[i].url)); 226 search_engine.display_name);
227 if (owned_template_url)
228 owned_template_urls.push_back(owned_template_url);
232 } 229 }
233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 230 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
234 base::Bind(&ProfileWriter::AddKeywords, writer_, 231 base::Bind(&ProfileWriter::AddKeywords, writer_,
235 base::Passed(&owned_template_urls), unique_on_host_and_path)); 232 base::Passed(&owned_template_urls), unique_on_host_and_path));
236 } 233 }
237 234
238 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( 235 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData(
239 const std::vector<std::string>& search_engine_data) { 236 const std::vector<std::string>& search_engine_data) {
240 std::vector<TemplateURL*> search_engines; 237 std::vector<TemplateURL*> search_engines;
241 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); 238 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 BrowserThread::PostTask( 294 BrowserThread::PostTask(
298 BrowserThread::UI, FROM_HERE, 295 BrowserThread::UI, FROM_HERE,
299 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); 296 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_));
300 } 297 }
301 298
302 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { 299 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) {
303 return l10n_util::GetStringUTF16(message_id); 300 return l10n_util::GetStringUTF16(message_id);
304 } 301 }
305 302
306 InProcessImporterBridge::~InProcessImporterBridge() {} 303 InProcessImporterBridge::~InProcessImporterBridge() {}
OLDNEW
« no previous file with comments | « chrome/browser/importer/in_process_importer_bridge.h ('k') | chrome/chrome_utility.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698