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

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

Issue 28200: Revert change made in http://codereview.chromium.org/10925.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/firefox_importer_utils.h" 5 #include "chrome/browser/importer/firefox_importer_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 return true; 189 return true;
190 } 190 }
191 191
192 void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files, 192 void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files,
193 std::vector<TemplateURL*>* search_engines) { 193 std::vector<TemplateURL*>* search_engines) {
194 DCHECK(search_engines); 194 DCHECK(search_engines);
195 195
196 std::map<std::wstring, TemplateURL*> search_engine_for_url; 196 std::map<std::wstring, TemplateURL*> search_engine_for_url;
197 std::string content; 197 std::string content;
198 bool need_to_increment_iter;
199 // The first XML file represents the default search engine in Firefox 3, so we 198 // The first XML file represents the default search engine in Firefox 3, so we
200 // need to keep it on top of the list. 199 // need to keep it on top of the list.
201 TemplateURL* default_turl = NULL; 200 TemplateURL* default_turl = NULL;
202 for (std::vector<std::wstring>::const_iterator iter = xml_files.begin(); 201 for (std::vector<std::wstring>::const_iterator file_iter = xml_files.begin();
203 iter != xml_files.end();) { 202 file_iter != xml_files.end(); ++file_iter) {
204 need_to_increment_iter = true; 203 file_util::ReadFileToString(*file_iter, &content);
205 file_util::ReadFileToString(*iter, &content);
206 TemplateURL* template_url = new TemplateURL(); 204 TemplateURL* template_url = new TemplateURL();
207 FirefoxURLParameterFilter param_filter; 205 FirefoxURLParameterFilter param_filter;
208 if (TemplateURLParser::Parse( 206 if (TemplateURLParser::Parse(
209 reinterpret_cast<const unsigned char*>(content.data()), 207 reinterpret_cast<const unsigned char*>(content.data()),
210 content.length(), &param_filter, template_url) && 208 content.length(), &param_filter, template_url) &&
211 template_url->url()) { 209 template_url->url()) {
212 std::wstring url = template_url->url()->url(); 210 std::wstring url = template_url->url()->url();
213 std::map<std::wstring, TemplateURL*>::iterator iter = 211 std::map<std::wstring, TemplateURL*>::iterator iter =
214 search_engine_for_url.find(url); 212 search_engine_for_url.find(url);
215 if (iter != search_engine_for_url.end()) { 213 if (iter != search_engine_for_url.end()) {
216 // We have already found a search engine with the same URL. We give 214 // We have already found a search engine with the same URL. We give
217 // priority to the latest one found, as GetSearchEnginesXMLFiles() 215 // priority to the latest one found, as GetSearchEnginesXMLFiles()
218 // returns a vector with first Firefox default search engines and then 216 // returns a vector with first Firefox default search engines and then
219 // the user's ones. We want to give priority to the user ones. 217 // the user's ones. We want to give priority to the user ones.
220 delete iter->second; 218 delete iter->second;
221 iter = search_engine_for_url.erase(iter); 219 search_engine_for_url.erase(iter);
222 need_to_increment_iter = false;
223 } 220 }
224 // Give this a keyword to facilitate tab-to-search, if possible. 221 // Give this a keyword to facilitate tab-to-search, if possible.
225 template_url->set_keyword(TemplateURLModel::GenerateKeyword(GURL(url), 222 template_url->set_keyword(TemplateURLModel::GenerateKeyword(GURL(url),
226 false)); 223 false));
227 template_url->set_show_in_default_list(true); 224 template_url->set_show_in_default_list(true);
228 search_engine_for_url[url] = template_url; 225 search_engine_for_url[url] = template_url;
229 if (!default_turl) 226 if (!default_turl)
230 default_turl = template_url; 227 default_turl = template_url;
231 } else { 228 } else {
232 delete template_url; 229 delete template_url;
233 } 230 }
234 content.clear(); 231 content.clear();
235 if (need_to_increment_iter)
236 ++iter;
237 } 232 }
238 233
239 // Put the results in the |search_engines| vector. 234 // Put the results in the |search_engines| vector.
240 std::map<std::wstring, TemplateURL*>::iterator t_iter; 235 std::map<std::wstring, TemplateURL*>::iterator t_iter;
241 for (t_iter = search_engine_for_url.begin(); 236 for (t_iter = search_engine_for_url.begin();
242 t_iter != search_engine_for_url.end(); ++t_iter) { 237 t_iter != search_engine_for_url.end(); ++t_iter) {
243 if (t_iter->second == default_turl) 238 if (t_iter->second == default_turl)
244 search_engines->insert(search_engines->begin(), default_turl); 239 search_engines->insert(search_engines->begin(), default_turl);
245 else 240 else
246 search_engines->push_back(t_iter->second); 241 search_engines->push_back(t_iter->second);
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 // Version 3 has an extra line for further use. 728 // Version 3 has an extra line for further use.
734 if (version == 3) { 729 if (version == 3) {
735 ++begin; 730 ++begin;
736 } 731 }
737 732
738 forms->push_back(form); 733 forms->push_back(form);
739 } 734 }
740 } 735 }
741 } 736 }
742 737
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698