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

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

Issue 9982018: Move most TemplateURL data members to a new struct, TemplateURLData. This allows us to eliminate t… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | « chrome/browser/importer/firefox2_importer.cc ('k') | chrome/browser/importer/ie_importer.cc » ('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/firefox_importer_utils.h" 5 #include "chrome/browser/importer/firefox_importer_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 typedef std::map<std::string, TemplateURL*> SearchEnginesMap; 193 typedef std::map<std::string, TemplateURL*> SearchEnginesMap;
194 SearchEnginesMap search_engine_for_url; 194 SearchEnginesMap search_engine_for_url;
195 std::string content; 195 std::string content;
196 // The first XML file represents the default search engine in Firefox 3, so we 196 // The first XML file represents the default search engine in Firefox 3, so we
197 // need to keep it on top of the list. 197 // need to keep it on top of the list.
198 SearchEnginesMap::const_iterator default_turl = search_engine_for_url.end(); 198 SearchEnginesMap::const_iterator default_turl = search_engine_for_url.end();
199 for (std::vector<FilePath>::const_iterator file_iter = xml_files.begin(); 199 for (std::vector<FilePath>::const_iterator file_iter = xml_files.begin();
200 file_iter != xml_files.end(); ++file_iter) { 200 file_iter != xml_files.end(); ++file_iter) {
201 file_util::ReadFileToString(*file_iter, &content); 201 file_util::ReadFileToString(*file_iter, &content);
202 FirefoxURLParameterFilter param_filter; 202 FirefoxURLParameterFilter param_filter;
203 TemplateURL* template_url = TemplateURLParser::Parse(NULL, content.data(), 203 TemplateURL* template_url = TemplateURLParser::Parse(NULL, true,
204 content.length(), &param_filter); 204 content.data(), content.length(), &param_filter);
205 if (template_url) { 205 if (template_url) {
206 SearchEnginesMap::iterator iter = 206 SearchEnginesMap::iterator iter =
207 search_engine_for_url.find(template_url->url()); 207 search_engine_for_url.find(template_url->url());
208 if (iter == search_engine_for_url.end()) { 208 if (iter == search_engine_for_url.end()) {
209 iter = search_engine_for_url.insert( 209 iter = search_engine_for_url.insert(
210 std::make_pair(template_url->url(), template_url)).first; 210 std::make_pair(template_url->url(), template_url)).first;
211 } else { 211 } else {
212 // We have already found a search engine with the same URL. We give 212 // We have already found a search engine with the same URL. We give
213 // priority to the latest one found, as GetSearchEnginesXMLFiles() 213 // priority to the latest one found, as GetSearchEnginesXMLFiles()
214 // returns a vector with first Firefox default search engines and then 214 // returns a vector with first Firefox default search engines and then
215 // the user's ones. We want to give priority to the user ones. 215 // the user's ones. We want to give priority to the user ones.
216 delete iter->second; 216 delete iter->second;
217 iter->second = template_url; 217 iter->second = template_url;
218 } 218 }
219 iter->second->set_show_in_default_list(true);
220 if (default_turl == search_engine_for_url.end()) 219 if (default_turl == search_engine_for_url.end())
221 default_turl = iter; 220 default_turl = iter;
222 } 221 }
223 content.clear(); 222 content.clear();
224 } 223 }
225 224
226 // Put the results in the |search_engines| vector. 225 // Put the results in the |search_engines| vector.
227 for (SearchEnginesMap::iterator t_iter = search_engine_for_url.begin(); 226 for (SearchEnginesMap::iterator t_iter = search_engine_for_url.begin();
228 t_iter != search_engine_for_url.end(); ++t_iter) { 227 t_iter != search_engine_for_url.end(); ++t_iter) {
229 if (t_iter == default_turl) 228 if (t_iter == default_turl)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 410 }
412 411
413 // String values have double quotes we don't need to return to the caller. 412 // String values have double quotes we don't need to return to the caller.
414 if (content[start] == '\"' && content[stop - 1] == '\"') { 413 if (content[start] == '\"' && content[stop - 1] == '\"') {
415 ++start; 414 ++start;
416 --stop; 415 --stop;
417 } 416 }
418 417
419 return content.substr(start, stop - start); 418 return content.substr(start, stop - start);
420 } 419 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox2_importer.cc ('k') | chrome/browser/importer/ie_importer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698