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

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 comments Created 6 years, 2 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
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/debug/dump_without_crashing.h" 8 #include "base/debug/dump_without_crashing.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 low_value.find("moz:") != std::string::npos) { 94 low_value.find("moz:") != std::string::npos) {
95 return false; 95 return false;
96 } 96 }
97 return true; 97 return true;
98 } 98 }
99 99
100 private: 100 private:
101 DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); 101 DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter);
102 }; 102 };
103 103
104 // Creates a TemplateURL with the |keyword| and |url|. |title| may be empty. 104 // Creates a TemplateURL with the |keyword| and |raw_url|. |title| may be empty.
Peter Kasting 2014/10/07 23:17:38 This comment should probably also talk about what
Tapu Ghose 2014/10/12 00:58:20 Done.
105 // This function transfers ownership of the created TemplateURL to the caller. 105 // This function transfers ownership of the created TemplateURL to the caller.
106 TemplateURL* CreateTemplateURL(const base::string16& title, 106 TemplateURL* CreateTemplateURL(const base::string16& title,
107 const base::string16& keyword, 107 const base::string16& keyword,
108 const GURL& url) { 108 const base::string16& raw_url) {
Ilya Sherman 2014/10/07 22:08:22 nit: You might as well drop the "raw" prefix at th
Tapu Ghose 2014/10/12 00:58:20 Dropped "raw" prefix. Here, the url can be either
109 // Skip if the url is invalid. 109 // Skip if the |raw_url| is empty.
Peter Kasting 2014/10/07 23:17:38 This comment just restates the code. Instead, if
Tapu Ghose 2014/10/12 00:58:20 Agree with you.
110 if (!url.is_valid()) 110 if (raw_url.empty())
111 return NULL; 111 return NULL;
112 112
113 TemplateURLData data; 113 TemplateURLData data;
114 if (keyword.empty()) 114 if (keyword.empty())
115 data.SetKeyword(TemplateURL::GenerateKeyword(url)); 115 data.SetKeyword(TemplateURL::GenerateKeyword(GURL(raw_url)));
Peter Kasting 2014/10/07 23:17:38 This assumes that |raw_url| will construct a valid
Tapu Ghose 2014/10/12 00:58:20 The assumption is not guaranteed. Updated logic so
116 else 116 else
117 data.SetKeyword(keyword); 117 data.SetKeyword(keyword);
118 // We set short name by using the title if it exists. 118 // We set short name by using the title if it exists.
119 // Otherwise, we use the shortcut. 119 // Otherwise, we use the shortcut.
120 data.short_name = title.empty() ? keyword : title; 120 data.short_name = title.empty() ? keyword : title;
121 data.SetURL( 121 data.SetURL(TemplateURLRef::DisplayURLToURLRef(raw_url));
122 TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec())));
123 return new TemplateURL(data); 122 return new TemplateURL(data);
124 } 123 }
125 124
126 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| 125 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines|
127 // with the resulting TemplateURLs. 126 // with the resulting TemplateURLs.
128 void ParseSearchEnginesFromFirefoxXMLData( 127 void ParseSearchEnginesFromFirefoxXMLData(
129 const std::vector<std::string>& xml_data, 128 const std::vector<std::string>& xml_data,
130 std::vector<TemplateURL*>* search_engines) { 129 std::vector<TemplateURL*>* search_engines) {
131 DCHECK(search_engines); 130 DCHECK(search_engines);
132 131
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 230 }
232 231
233 void InProcessImporterBridge::SetKeywords( 232 void InProcessImporterBridge::SetKeywords(
234 const std::vector<importer::URLKeywordInfo>& url_keywords, 233 const std::vector<importer::URLKeywordInfo>& url_keywords,
235 bool unique_on_host_and_path) { 234 bool unique_on_host_and_path) {
236 ScopedVector<TemplateURL> owned_template_urls; 235 ScopedVector<TemplateURL> owned_template_urls;
237 for (size_t i = 0; i < url_keywords.size(); ++i) { 236 for (size_t i = 0; i < url_keywords.size(); ++i) {
238 owned_template_urls.push_back( 237 owned_template_urls.push_back(
239 CreateTemplateURL(url_keywords[i].display_name, 238 CreateTemplateURL(url_keywords[i].display_name,
240 url_keywords[i].keyword, 239 url_keywords[i].keyword,
241 url_keywords[i].url)); 240 url_keywords[i].raw_url));
242 } 241 }
243 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 242 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
244 base::Bind(&ProfileWriter::AddKeywords, writer_, 243 base::Bind(&ProfileWriter::AddKeywords, writer_,
245 base::Passed(&owned_template_urls), unique_on_host_and_path)); 244 base::Passed(&owned_template_urls), unique_on_host_and_path));
246 } 245 }
247 246
248 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( 247 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData(
249 const std::vector<std::string>& search_engine_data) { 248 const std::vector<std::string>& search_engine_data) {
250 std::vector<TemplateURL*> search_engines; 249 std::vector<TemplateURL*> search_engines;
251 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); 250 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 BrowserThread::PostTask( 307 BrowserThread::PostTask(
309 BrowserThread::UI, FROM_HERE, 308 BrowserThread::UI, FROM_HERE,
310 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); 309 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_));
311 } 310 }
312 311
313 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { 312 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) {
314 return l10n_util::GetStringUTF16(message_id); 313 return l10n_util::GetStringUTF16(message_id);
315 } 314 }
316 315
317 InProcessImporterBridge::~InProcessImporterBridge() {} 316 InProcessImporterBridge::~InProcessImporterBridge() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698