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/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 |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/common/ini_parser.h" | |
| 19 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
| 20 #include "chrome/browser/search_engines/template_url_parser.h" | 21 #include "chrome/browser/search_engines/template_url_parser.h" |
| 21 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 22 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 22 #include "chrome/browser/search_engines/template_url_service.h" | 23 #include "chrome/browser/search_engines/template_url_service.h" |
| 23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 43 return false; | 44 return false; |
| 44 return true; | 45 return true; |
| 45 } | 46 } |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); | 49 DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); |
| 49 }; | 50 }; |
| 50 } // namespace | 51 } // namespace |
| 51 | 52 |
| 52 base::FilePath GetFirefoxProfilePath() { | 53 base::FilePath GetFirefoxProfilePath() { |
| 53 DictionaryValue root; | |
| 54 base::FilePath ini_file = GetProfilesINI(); | 54 base::FilePath ini_file = GetProfilesINI(); |
| 55 ParseProfileINI(ini_file, &root); | 55 std::string content; |
| 56 file_util::ReadFileToString(ini_file, &content); | |
| 57 DictionaryValueINIParser ini_parser; | |
| 58 ini_parser.Parse(content); | |
| 59 const DictionaryValue& root = ini_parser.root(); | |
| 56 | 60 |
| 57 base::FilePath source_path; | 61 base::FilePath source_path; |
| 58 for (int i = 0; ; ++i) { | 62 for (int i = 0; ; ++i) { |
| 59 std::string current_profile = base::StringPrintf("Profile%d", i); | 63 std::string current_profile = base::StringPrintf("Profile%d", i); |
| 60 if (!root.HasKey(current_profile)) { | 64 if (!root.HasKey(current_profile)) { |
| 61 // Profiles are continuously numbered. So we exit when we can't | 65 // Profiles are continuously numbered. So we exit when we can't |
| 62 // find the i-th one. | 66 // find the i-th one. |
| 63 break; | 67 break; |
| 64 } | 68 } |
| 65 std::string is_relative; | 69 std::string is_relative; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 // file, we could go straight from bytes -> filepath; | 127 // file, we could go straight from bytes -> filepath; |
| 124 // otherwise, we're out of luck here. | 128 // otherwise, we're out of luck here. |
| 125 *app_path = base::FilePath::FromWStringHack( | 129 *app_path = base::FilePath::FromWStringHack( |
| 126 UTF8ToWide(line.substr(equal + 1))); | 130 UTF8ToWide(line.substr(equal + 1))); |
| 127 } | 131 } |
| 128 } | 132 } |
| 129 } | 133 } |
| 130 return ret; | 134 return ret; |
| 131 } | 135 } |
| 132 | 136 |
| 133 void ParseProfileINI(const base::FilePath& file, DictionaryValue* root) { | 137 void ParseProfileINI(const base::FilePath& file, DictionaryValue* root) { |
|
Lei Zhang
2013/06/13 21:04:30
Don't you also need to delete this code since it's
tommycli
2013/06/13 23:02:03
That's correct. I thought I deleted it, but I must
| |
| 134 // Reads the whole INI file. | 138 // Reads the whole INI file. |
| 135 std::string content; | 139 std::string content; |
| 136 file_util::ReadFileToString(file, &content); | 140 file_util::ReadFileToString(file, &content); |
| 137 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); | 141 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); |
| 138 std::vector<std::string> lines; | 142 std::vector<std::string> lines; |
| 139 base::SplitString(content, '\n', &lines); | 143 base::SplitString(content, '\n', &lines); |
| 140 | 144 |
| 141 // Parses the file. | 145 // Parses the file. |
| 142 root->Clear(); | 146 root->Clear(); |
| 143 std::string current_section; | 147 std::string current_section; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 } | 463 } |
| 460 } | 464 } |
| 461 } | 465 } |
| 462 } | 466 } |
| 463 | 467 |
| 464 StringToLowerASCII(&branding_name); | 468 StringToLowerASCII(&branding_name); |
| 465 if (branding_name.find("iceweasel") != std::string::npos) | 469 if (branding_name.find("iceweasel") != std::string::npos) |
| 466 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL); | 470 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL); |
| 467 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX); | 471 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX); |
| 468 } | 472 } |
| OLD | NEW |