OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 low_value.find("moz:") != std::string::npos ) | 33 low_value.find("moz:") != std::string::npos ) |
34 return false; | 34 return false; |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 private: | 38 private: |
39 DISALLOW_EVIL_CONSTRUCTORS(FirefoxURLParameterFilter); | 39 DISALLOW_EVIL_CONSTRUCTORS(FirefoxURLParameterFilter); |
40 }; | 40 }; |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path, | 43 bool GetFirefoxVersionAndPathFromProfile(const FilePath& profile_path, |
44 int* version, | 44 int* version, |
45 std::wstring* app_path) { | 45 FilePath* app_path) { |
46 bool ret = false; | 46 bool ret = false; |
47 std::wstring compatibility_file(profile_path); | 47 FilePath compatibility_file = profile_path.AppendASCII("compatibility.ini"); |
48 file_util::AppendToPath(&compatibility_file, L"compatibility.ini"); | |
49 std::string content; | 48 std::string content; |
50 file_util::ReadFileToString(compatibility_file, &content); | 49 file_util::ReadFileToString(compatibility_file, &content); |
51 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); | 50 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); |
52 std::vector<std::string> lines; | 51 std::vector<std::string> lines; |
53 SplitString(content, '\n', &lines); | 52 SplitString(content, '\n', &lines); |
54 | 53 |
55 for (size_t i = 0; i < lines.size(); ++i) { | 54 for (size_t i = 0; i < lines.size(); ++i) { |
56 const std::string& line = lines[i]; | 55 const std::string& line = lines[i]; |
57 if (line.empty() || line[0] == '#' || line[0] == ';') | 56 if (line.empty() || line[0] == '#' || line[0] == ';') |
58 continue; | 57 continue; |
59 size_t equal = line.find('='); | 58 size_t equal = line.find('='); |
60 if (equal != std::string::npos) { | 59 if (equal != std::string::npos) { |
61 std::string key = line.substr(0, equal); | 60 std::string key = line.substr(0, equal); |
62 if (key == "LastVersion") { | 61 if (key == "LastVersion") { |
63 *version = line.substr(equal + 1)[0] - '0'; | 62 *version = line.substr(equal + 1)[0] - '0'; |
64 ret = true; | 63 ret = true; |
65 } else if (key == "LastAppDir") { | 64 } else if (key == "LastAppDir") { |
66 *app_path = UTF8ToWide(line.substr(equal + 1)); | 65 // TODO(evanm): If the path in question isn't convertible to |
| 66 // UTF-8, what does Firefox do? If it puts raw bytes in the |
| 67 // file, we could go straight from bytes -> filepath; |
| 68 // otherwise, we're out of luck here. |
| 69 *app_path = FilePath::FromWStringHack( |
| 70 UTF8ToWide(line.substr(equal + 1))); |
67 } | 71 } |
68 } | 72 } |
69 } | 73 } |
70 return ret; | 74 return ret; |
71 } | 75 } |
72 | 76 |
73 void ParseProfileINI(std::wstring file, DictionaryValue* root) { | 77 void ParseProfileINI(const FilePath& file, DictionaryValue* root) { |
74 // Reads the whole INI file. | 78 // Reads the whole INI file. |
75 std::string content; | 79 std::string content; |
76 file_util::ReadFileToString(file, &content); | 80 file_util::ReadFileToString(file, &content); |
77 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); | 81 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); |
78 std::vector<std::string> lines; | 82 std::vector<std::string> lines; |
79 SplitString(content, '\n', &lines); | 83 SplitString(content, '\n', &lines); |
80 | 84 |
81 // Parses the file. | 85 // Parses the file. |
82 root->Clear(); | 86 root->Clear(); |
83 std::wstring current_section; | 87 std::wstring current_section; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 std::vector<std::string> urls; | 327 std::vector<std::string> urls; |
324 SplitString(default_homepages, '|', &urls); | 328 SplitString(default_homepages, '|', &urls); |
325 | 329 |
326 for (size_t i = 0; i < urls.size(); ++i) { | 330 for (size_t i = 0; i < urls.size(); ++i) { |
327 if (homepage.spec() == GURL(urls[i]).spec()) | 331 if (homepage.spec() == GURL(urls[i]).spec()) |
328 return true; | 332 return true; |
329 } | 333 } |
330 | 334 |
331 return false; | 335 return false; |
332 } | 336 } |
OLD | NEW |