Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 base::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 std::string& line = lines[i]; |
|
jeremy
2014/01/07 12:37:27
maintain const and work on a copy of the string be
| |
| 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) { |
| 114 std::string key = line.substr(0, equal); | 114 std::string key = line.substr(0, equal); |
| 115 if (key == "LastVersion") { | 115 if (key == "LastVersion") { |
| 116 base::StringToInt(line.substr(equal + 1), version); | 116 base::StringToInt(line.substr(equal + 1), version); |
| 117 ret = true; | 117 ret = true; |
| 118 } else if (key == "LastAppDir") { | 118 } else if (key == "LastPlatformDir") { |
|
jeremy
2014/01/07 12:37:27
Why are we changing this? This code is cross-platf
| |
| 119 // TODO(evanm): If the path in question isn't convertible to | 119 // TODO(evanm): If the path in question isn't convertible to |
| 120 // UTF-8, what does Firefox do? If it puts raw bytes in the | 120 // UTF-8, what does Firefox do? If it puts raw bytes in the |
| 121 // file, we could go straight from bytes -> filepath; | 121 // file, we could go straight from bytes -> filepath; |
| 122 // otherwise, we're out of luck here. | 122 // otherwise, we're out of luck here. |
| 123 #if defined (OS_MACOSX) | |
|
jeremy
2014/01/07 12:37:27
s/defined (/defined(/
| |
| 124 // Find the "*.app" component of the path and build up from there. | |
| 125 // The resulting path will be .../Firefox.app/Contents/MacOS. | |
| 126 // We do this because we don't trust LastPlatformDir to always be | |
| 127 // this particular path, without any subdirs, and we want to make | |
| 128 // our assumption about Firefox's root being in that path explicit. | |
| 129 const std::string dot_app(".app"); | |
| 130 const size_t pos = line.find(dot_app); | |
|
jeremy
2014/01/07 12:37:27
Recommend manipulating as a FilePath:
* Split usi
| |
| 131 if (pos == std::string::npos) { | |
| 132 LOG(ERROR) << line << " doesn't look like a valid Firefox " | |
| 133 << "installation path: missing /*.app/ directory."; | |
| 134 return false; | |
| 135 } | |
| 136 // Replace everything after .app with /Contents/MacOS. | |
| 137 line.replace(pos + dot_app.length(), | |
| 138 std::string::npos, | |
| 139 "/Contents/MacOS"); | |
| 140 #endif | |
|
jeremy
2014/01/07 12:37:27
#endif // OS_MACOSX
| |
| 123 *app_path = base::FilePath::FromUTF8Unsafe(line.substr(equal + 1)); | 141 *app_path = base::FilePath::FromUTF8Unsafe(line.substr(equal + 1)); |
| 124 } | 142 } |
| 125 } | 143 } |
| 126 } | 144 } |
| 127 return ret; | 145 return ret; |
| 128 } | 146 } |
| 129 | 147 |
| 130 bool ReadPrefFile(const base::FilePath& path, std::string* content) { | 148 bool ReadPrefFile(const base::FilePath& path, std::string* content) { |
| 131 if (content == NULL) | 149 if (content == NULL) |
| 132 return false; | 150 return false; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 } | 295 } |
| 278 } | 296 } |
| 279 } | 297 } |
| 280 } | 298 } |
| 281 | 299 |
| 282 StringToLowerASCII(&branding_name); | 300 StringToLowerASCII(&branding_name); |
| 283 if (branding_name.find("iceweasel") != std::string::npos) | 301 if (branding_name.find("iceweasel") != std::string::npos) |
| 284 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL); | 302 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL); |
| 285 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX); | 303 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX); |
| 286 } | 304 } |
| OLD | NEW |