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

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

Issue 1240183002: Update SplitString calls in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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/common/extensions/command.cc ('k') | chrome/common/pepper_flash.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/common/importer/firefox_importer_utils.h" 5 #include "chrome/common/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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 bool GetFirefoxVersionAndPathFromProfile(const base::FilePath& profile_path, 132 bool GetFirefoxVersionAndPathFromProfile(const base::FilePath& profile_path,
133 int* version, 133 int* version,
134 base::FilePath* app_path) { 134 base::FilePath* app_path) {
135 bool ret = false; 135 bool ret = false;
136 base::FilePath compatibility_file = 136 base::FilePath compatibility_file =
137 profile_path.AppendASCII("compatibility.ini"); 137 profile_path.AppendASCII("compatibility.ini");
138 std::string content; 138 std::string content;
139 base::ReadFileToString(compatibility_file, &content); 139 base::ReadFileToString(compatibility_file, &content);
140 base::ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); 140 base::ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n");
141 std::vector<std::string> lines;
142 base::SplitString(content, '\n', &lines);
143 141
144 for (size_t i = 0; i < lines.size(); ++i) { 142 for (const std::string& line : base::SplitString(
145 const std::string& line = lines[i]; 143 content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
146 if (line.empty() || line[0] == '#' || line[0] == ';') 144 if (line.empty() || line[0] == '#' || line[0] == ';')
147 continue; 145 continue;
148 size_t equal = line.find('='); 146 size_t equal = line.find('=');
149 if (equal != std::string::npos) { 147 if (equal != std::string::npos) {
150 std::string key = line.substr(0, equal); 148 std::string key = line.substr(0, equal);
151 if (key == "LastVersion") { 149 if (key == "LastVersion") {
152 base::StringToInt(line.substr(equal + 1), version); 150 base::StringToInt(line.substr(equal + 1), version);
153 ret = true; 151 ret = true;
154 } else if (key == "LastAppDir") { 152 } else if (key == "LastAppDir") {
155 // TODO(evanm): If the path in question isn't convertible to 153 // TODO(evanm): If the path in question isn't convertible to
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return false; 233 return false;
236 234
237 std::string default_homepages = 235 std::string default_homepages =
238 ReadBrowserConfigProp(app_path, "browser.startup.homepage"); 236 ReadBrowserConfigProp(app_path, "browser.startup.homepage");
239 237
240 size_t seperator = default_homepages.find_first_of('|'); 238 size_t seperator = default_homepages.find_first_of('|');
241 if (seperator == std::string::npos) 239 if (seperator == std::string::npos)
242 return homepage.spec() == GURL(default_homepages).spec(); 240 return homepage.spec() == GURL(default_homepages).spec();
243 241
244 // Crack the string into separate homepage urls. 242 // Crack the string into separate homepage urls.
245 std::vector<std::string> urls; 243 for (const std::string& url : base::SplitString(
246 base::SplitString(default_homepages, '|', &urls); 244 default_homepages, "|",
247 245 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
248 for (size_t i = 0; i < urls.size(); ++i) { 246 if (homepage.spec() == GURL(url).spec())
249 if (homepage.spec() == GURL(urls[i]).spec())
250 return true; 247 return true;
251 } 248 }
252 249
253 return false; 250 return false;
254 } 251 }
255 252
256 std::string GetPrefsJsValue(const std::string& content, 253 std::string GetPrefsJsValue(const std::string& content,
257 const std::string& pref_key) { 254 const std::string& pref_key) {
258 // This file has the syntax: user_pref("key", value); 255 // This file has the syntax: user_pref("key", value);
259 std::string search_for = std::string("user_pref(\"") + pref_key + 256 std::string search_for = std::string("user_pref(\"") + pref_key +
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // Copyright=Copyright (c) 1998 - 2010 mozilla.org 293 // Copyright=Copyright (c) 1998 - 2010 mozilla.org
297 // ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384} 294 // ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
298 // ......................................... 295 // .........................................
299 // In this example the function returns "Iceweasel" (or a localized equivalent). 296 // In this example the function returns "Iceweasel" (or a localized equivalent).
300 base::string16 GetFirefoxImporterName(const base::FilePath& app_path) { 297 base::string16 GetFirefoxImporterName(const base::FilePath& app_path) {
301 const base::FilePath app_ini_file = app_path.AppendASCII("application.ini"); 298 const base::FilePath app_ini_file = app_path.AppendASCII("application.ini");
302 std::string branding_name; 299 std::string branding_name;
303 if (base::PathExists(app_ini_file)) { 300 if (base::PathExists(app_ini_file)) {
304 std::string content; 301 std::string content;
305 base::ReadFileToString(app_ini_file, &content); 302 base::ReadFileToString(app_ini_file, &content);
306 std::vector<std::string> lines; 303
307 base::SplitString(content, '\n', &lines);
308 const std::string name_attr("Name="); 304 const std::string name_attr("Name=");
309 bool in_app_section = false; 305 bool in_app_section = false;
310 for (size_t i = 0; i < lines.size(); ++i) { 306 for (const base::StringPiece& line : base::SplitStringPiece(
311 base::TrimWhitespace(lines[i], base::TRIM_ALL, &lines[i]); 307 content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
312 if (lines[i] == "[App]") { 308 if (line == "[App]") {
313 in_app_section = true; 309 in_app_section = true;
314 } else if (in_app_section) { 310 } else if (in_app_section) {
315 if (lines[i].find(name_attr) == 0) { 311 if (line.find(name_attr) == 0) {
316 branding_name = lines[i].substr(name_attr.size()); 312 line.substr(name_attr.size()).CopyToString(&branding_name);
317 break; 313 break;
318 } else if (lines[i].length() > 0 && lines[i][0] == '[') { 314 } else if (line.length() > 0 && line[0] == '[') {
319 // No longer in the [App] section. 315 // No longer in the [App] section.
320 break; 316 break;
321 } 317 }
322 } 318 }
323 } 319 }
324 } 320 }
325 321
326 base::StringToLowerASCII(&branding_name); 322 base::StringToLowerASCII(&branding_name);
327 if (branding_name.find("iceweasel") != std::string::npos) 323 if (branding_name.find("iceweasel") != std::string::npos)
328 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL); 324 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL);
329 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX); 325 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX);
330 } 326 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/command.cc ('k') | chrome/common/pepper_flash.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698