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

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

Issue 19579005: Move ReadFileToString to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 std::string is_default; 52 std::string is_default;
53 root.GetStringASCII(profile_name + ".Default", &is_default); 53 root.GetStringASCII(profile_name + ".Default", &is_default);
54 return is_default == "1"; 54 return is_default == "1";
55 } 55 }
56 56
57 } // namespace 57 } // namespace
58 58
59 base::FilePath GetFirefoxProfilePath() { 59 base::FilePath GetFirefoxProfilePath() {
60 base::FilePath ini_file = GetProfilesINI(); 60 base::FilePath ini_file = GetProfilesINI();
61 std::string content; 61 std::string content;
62 file_util::ReadFileToString(ini_file, &content); 62 base::ReadFileToString(ini_file, &content);
63 base::DictionaryValueINIParser ini_parser; 63 base::DictionaryValueINIParser ini_parser;
64 ini_parser.Parse(content); 64 ini_parser.Parse(content);
65 return GetFirefoxProfilePathFromDictionary(ini_parser.root()); 65 return GetFirefoxProfilePathFromDictionary(ini_parser.root());
66 } 66 }
67 67
68 base::FilePath GetFirefoxProfilePathFromDictionary( 68 base::FilePath GetFirefoxProfilePathFromDictionary(
69 const DictionaryValue& root) { 69 const DictionaryValue& root) {
70 std::vector<std::string> profiles; 70 std::vector<std::string> profiles;
71 for (int i = 0; ; ++i) { 71 for (int i = 0; ; ++i) {
72 std::string current_profile = base::StringPrintf("Profile%d", i); 72 std::string current_profile = base::StringPrintf("Profile%d", i);
(...skipping 20 matching lines...) Expand all
93 return GetProfilePath(root, profiles.front()); 93 return GetProfilePath(root, profiles.front());
94 } 94 }
95 95
96 bool GetFirefoxVersionAndPathFromProfile(const base::FilePath& profile_path, 96 bool GetFirefoxVersionAndPathFromProfile(const base::FilePath& profile_path,
97 int* version, 97 int* version,
98 base::FilePath* app_path) { 98 base::FilePath* app_path) {
99 bool ret = false; 99 bool ret = false;
100 base::FilePath compatibility_file = 100 base::FilePath compatibility_file =
101 profile_path.AppendASCII("compatibility.ini"); 101 profile_path.AppendASCII("compatibility.ini");
102 std::string content; 102 std::string content;
103 file_util::ReadFileToString(compatibility_file, &content); 103 base::ReadFileToString(compatibility_file, &content);
104 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); 104 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n");
105 std::vector<std::string> lines; 105 std::vector<std::string> lines;
106 base::SplitString(content, '\n', &lines); 106 base::SplitString(content, '\n', &lines);
107 107
108 for (size_t i = 0; i < lines.size(); ++i) { 108 for (size_t i = 0; i < lines.size(); ++i) {
109 const std::string& line = lines[i]; 109 const std::string& line = lines[i];
110 if (line.empty() || line[0] == '#' || line[0] == ';') 110 if (line.empty() || line[0] == '#' || line[0] == ';')
111 continue; 111 continue;
112 size_t equal = line.find('='); 112 size_t equal = line.find('=');
113 if (equal != std::string::npos) { 113 if (equal != std::string::npos) {
(...skipping 11 matching lines...) Expand all
125 } 125 }
126 } 126 }
127 } 127 }
128 return ret; 128 return ret;
129 } 129 }
130 130
131 bool ReadPrefFile(const base::FilePath& path, std::string* content) { 131 bool ReadPrefFile(const base::FilePath& path, std::string* content) {
132 if (content == NULL) 132 if (content == NULL)
133 return false; 133 return false;
134 134
135 file_util::ReadFileToString(path, content); 135 base::ReadFileToString(path, content);
136 136
137 if (content->empty()) { 137 if (content->empty()) {
138 LOG(WARNING) << "Firefox preference file " << path.value() << " is empty."; 138 LOG(WARNING) << "Firefox preference file " << path.value() << " is empty.";
139 return false; 139 return false;
140 } 140 }
141 141
142 return true; 142 return true;
143 } 143 }
144 144
145 std::string ReadBrowserConfigProp(const base::FilePath& app_path, 145 std::string ReadBrowserConfigProp(const base::FilePath& app_path,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // BuildID=20120421070307 252 // BuildID=20120421070307
253 // Copyright=Copyright (c) 1998 - 2010 mozilla.org 253 // Copyright=Copyright (c) 1998 - 2010 mozilla.org
254 // ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384} 254 // ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
255 // ......................................... 255 // .........................................
256 // In this example the function returns "Iceweasel" (or a localized equivalent). 256 // In this example the function returns "Iceweasel" (or a localized equivalent).
257 string16 GetFirefoxImporterName(const base::FilePath& app_path) { 257 string16 GetFirefoxImporterName(const base::FilePath& app_path) {
258 const base::FilePath app_ini_file = app_path.AppendASCII("application.ini"); 258 const base::FilePath app_ini_file = app_path.AppendASCII("application.ini");
259 std::string branding_name; 259 std::string branding_name;
260 if (base::PathExists(app_ini_file)) { 260 if (base::PathExists(app_ini_file)) {
261 std::string content; 261 std::string content;
262 file_util::ReadFileToString(app_ini_file, &content); 262 base::ReadFileToString(app_ini_file, &content);
263 std::vector<std::string> lines; 263 std::vector<std::string> lines;
264 base::SplitString(content, '\n', &lines); 264 base::SplitString(content, '\n', &lines);
265 const std::string name_attr("Name="); 265 const std::string name_attr("Name=");
266 bool in_app_section = false; 266 bool in_app_section = false;
267 for (size_t i = 0; i < lines.size(); ++i) { 267 for (size_t i = 0; i < lines.size(); ++i) {
268 TrimWhitespace(lines[i], TRIM_ALL, &lines[i]); 268 TrimWhitespace(lines[i], TRIM_ALL, &lines[i]);
269 if (lines[i] == "[App]") { 269 if (lines[i] == "[App]") {
270 in_app_section = true; 270 in_app_section = true;
271 } else if (in_app_section) { 271 } else if (in_app_section) {
272 if (lines[i].find(name_attr) == 0) { 272 if (lines[i].find(name_attr) == 0) {
273 branding_name = lines[i].substr(name_attr.size()); 273 branding_name = lines[i].substr(name_attr.size());
274 break; 274 break;
275 } else if (lines[i].length() > 0 && lines[i][0] == '[') { 275 } else if (lines[i].length() > 0 && lines[i][0] == '[') {
276 // No longer in the [App] section. 276 // No longer in the [App] section.
277 break; 277 break;
278 } 278 }
279 } 279 }
280 } 280 }
281 } 281 }
282 282
283 StringToLowerASCII(&branding_name); 283 StringToLowerASCII(&branding_name);
284 if (branding_name.find("iceweasel") != std::string::npos) 284 if (branding_name.find("iceweasel") != std::string::npos)
285 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL); 285 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL);
286 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX); 286 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX);
287 } 287 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_handlers/content_scripts_handler.cc ('k') | chrome/installer/setup/install_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698