diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 13:32:16 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 13:32:16 +0000 |
commit | 9430e4bae7a8faa17b353f66ed572b72cf393c05 (patch) | |
tree | f19b02c0477d30aaf70203872739607afec657a2 | |
parent | 76b24b56f8c5d78bc5c32fbdd81102ba9ed82dcb (diff) | |
download | chromium_src-9430e4bae7a8faa17b353f66ed572b72cf393c05.zip chromium_src-9430e4bae7a8faa17b353f66ed572b72cf393c05.tar.gz chromium_src-9430e4bae7a8faa17b353f66ed572b72cf393c05.tar.bz2 |
importer: use FilePath instead of wstring in some places
Added API to DictionaryValue to use ASCII where appropriate.
BUG=24672
TEST=profile import still got my bookmarks
Review URL: http://codereview.chromium.org/647016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39441 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/values.cc | 24 | ||||
-rw-r--r-- | base/values.h | 7 | ||||
-rw-r--r-- | chrome/browser/importer/firefox_importer_utils.cc | 16 | ||||
-rw-r--r-- | chrome/browser/importer/firefox_importer_utils.h | 6 | ||||
-rw-r--r-- | chrome/browser/importer/importer_list.cc | 38 |
5 files changed, 63 insertions, 28 deletions
diff --git a/base/values.cc b/base/values.cc index 7e55739..f78f474 100644 --- a/base/values.cc +++ b/base/values.cc @@ -354,6 +354,10 @@ bool DictionaryValue::HasKey(const std::wstring& key) const { return current_entry != dictionary_.end(); } +bool DictionaryValue::HasKeyASCII(const std::string& key) const { + return HasKey(ASCIIToWide(key)); +} + void DictionaryValue::Clear() { ValueMap::iterator dict_iterator = dictionary_.begin(); while (dict_iterator != dictionary_.end()) { @@ -471,6 +475,26 @@ bool DictionaryValue::GetReal(const std::wstring& path, return value->GetAsReal(out_value); } +bool DictionaryValue::GetString(const std::string& path, + string16* out_value) const { + return GetStringAsUTF16(ASCIIToWide(path), out_value); +} + +bool DictionaryValue::GetStringASCII(const std::string& path, + std::string* out_value) const { + std::string out; + if (!GetString(ASCIIToWide(path), &out)) + return false; + + if (!IsStringASCII(out)) { + NOTREACHED(); + return false; + } + + out_value->assign(out); + return true; +} + bool DictionaryValue::GetString(const std::wstring& path, std::string* out_value) const { Value* value; diff --git a/base/values.h b/base/values.h index e000508..ac6307a 100644 --- a/base/values.h +++ b/base/values.h @@ -214,6 +214,9 @@ class DictionaryValue : public Value { virtual bool Equals(const Value* other) const; // Returns true if the current dictionary has a value for the given key. + bool HasKeyASCII(const std::string& key) const; + // Deprecated version of the above. TODO: add a string16 version for Unicode. + // http://code.google.com/p/chromium/issues/detail?id=23581 bool HasKey(const std::wstring& key) const; // Returns the number of Values in this dictionary. @@ -264,6 +267,10 @@ class DictionaryValue : public Value { bool GetBoolean(const std::wstring& path, bool* out_value) const; bool GetInteger(const std::wstring& path, int* out_value) const; bool GetReal(const std::wstring& path, double* out_value) const; + bool GetString(const std::string& path, string16* out_value) const; + bool GetStringASCII(const std::string& path, std::string* out_value) const; + // TODO: deprecate wstring accessors. + // http://code.google.com/p/chromium/issues/detail?id=23581 bool GetString(const std::wstring& path, std::string* out_value) const; bool GetString(const std::wstring& path, std::wstring* out_value) const; bool GetStringAsUTF16(const std::wstring& path, string16* out_value) const; diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc index 624a4e9..36a3741 100644 --- a/chrome/browser/importer/firefox_importer_utils.cc +++ b/chrome/browser/importer/firefox_importer_utils.cc @@ -40,12 +40,11 @@ class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { }; } // namespace -bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path, +bool GetFirefoxVersionAndPathFromProfile(const FilePath& profile_path, int* version, - std::wstring* app_path) { + FilePath* app_path) { bool ret = false; - std::wstring compatibility_file(profile_path); - file_util::AppendToPath(&compatibility_file, L"compatibility.ini"); + FilePath compatibility_file = profile_path.AppendASCII("compatibility.ini"); std::string content; file_util::ReadFileToString(compatibility_file, &content); ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); @@ -63,14 +62,19 @@ bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path, *version = line.substr(equal + 1)[0] - '0'; ret = true; } else if (key == "LastAppDir") { - *app_path = UTF8ToWide(line.substr(equal + 1)); + // TODO(evanm): If the path in question isn't convertible to + // UTF-8, what does Firefox do? If it puts raw bytes in the + // file, we could go straight from bytes -> filepath; + // otherwise, we're out of luck here. + *app_path = FilePath::FromWStringHack( + UTF8ToWide(line.substr(equal + 1))); } } } return ret; } -void ParseProfileINI(std::wstring file, DictionaryValue* root) { +void ParseProfileINI(const FilePath& file, DictionaryValue* root) { // Reads the whole INI file. std::string content; file_util::ReadFileToString(file, &content); diff --git a/chrome/browser/importer/firefox_importer_utils.h b/chrome/browser/importer/firefox_importer_utils.h index fa7e50b..8927af0 100644 --- a/chrome/browser/importer/firefox_importer_utils.h +++ b/chrome/browser/importer/firefox_importer_utils.h @@ -37,9 +37,9 @@ FilePath GetFirefoxDylibPath(); #endif // OS_MACOSX // Detects version of Firefox and installation path from given Firefox profile -bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path, +bool GetFirefoxVersionAndPathFromProfile(const FilePath& profile_path, int* version, - std::wstring* app_path); + FilePath* app_path); // Gets the full path of the profiles.ini file. This file records // the profiles that can be used by Firefox. Returns an empty @@ -58,7 +58,7 @@ FilePath GetProfilesINI(); // Path=Profiles/abcdefeg.default // We set "[value]" in path "<Section>.<Key>". For example, the path // "Genenral.StartWithLastProfile" has the value "1". -void ParseProfileINI(std::wstring file, DictionaryValue* root); +void ParseProfileINI(const FilePath& file, DictionaryValue* root); // Returns true if we want to add the URL to the history. We filter // out the URL with a unsupported scheme. diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc index fe8ecb7..935cc3e 100644 --- a/chrome/browser/importer/importer_list.cc +++ b/chrome/browser/importer/importer_list.cc @@ -118,33 +118,33 @@ void ImporterList::DetectIEProfiles() { void ImporterList::DetectFirefoxProfiles() { DictionaryValue root; - std::wstring ini_file = GetProfilesINI().ToWStringHack(); + FilePath ini_file = GetProfilesINI(); ParseProfileINI(ini_file, &root); - std::wstring source_path; + FilePath source_path; for (int i = 0; ; ++i) { - std::wstring current_profile = L"Profile" + IntToWString(i); - if (!root.HasKey(current_profile)) { + std::string current_profile = "Profile" + IntToString(i); + if (!root.HasKeyASCII(current_profile)) { // Profiles are continuously numbered. So we exit when we can't // find the i-th one. break; } - std::wstring is_relative, path, profile_path; - if (root.GetString(current_profile + L".IsRelative", &is_relative) && - root.GetString(current_profile + L".Path", &path)) { + std::string is_relative; + string16 path16; + FilePath profile_path; + if (root.GetStringASCII(current_profile + ".IsRelative", &is_relative) && + root.GetString(current_profile + ".Path", &path16)) { #if defined(OS_WIN) - string16 path16 = WideToUTF16Hack(path); ReplaceSubstringsAfterOffset( &path16, 0, ASCIIToUTF16("/"), ASCIIToUTF16("\\")); - path.assign(UTF16ToWideHack(path16)); #endif + FilePath path = FilePath::FromWStringHack(UTF16ToWide(path16)); // IsRelative=1 means the folder path would be relative to the // path of profiles.ini. IsRelative=0 refers to a custom profile // location. - if (is_relative == L"1") { - profile_path = file_util::GetDirectoryFromPath(ini_file); - file_util::AppendToPath(&profile_path, path); + if (is_relative == "1") { + profile_path = ini_file.DirName().Append(path); } else { profile_path = path; } @@ -152,12 +152,12 @@ void ImporterList::DetectFirefoxProfiles() { // We only import the default profile when multiple profiles exist, // since the other profiles are used mostly by developers for testing. // Otherwise, Profile0 will be imported. - std::wstring is_default; - if ((root.GetString(current_profile + L".Default", &is_default) && - is_default == L"1") || i == 0) { + std::string is_default; + if ((root.GetStringASCII(current_profile + ".Default", &is_default) && + is_default == "1") || i == 0) { source_path = profile_path; // We break out of the loop when we have found the default profile. - if (is_default == L"1") + if (is_default == "1") break; } } @@ -165,7 +165,7 @@ void ImporterList::DetectFirefoxProfiles() { // Detects which version of Firefox is installed. ProfileType firefox_type; - std::wstring app_path; + FilePath app_path; int version = 0; #if defined(OS_WIN) version = GetCurrentFirefoxMajorVersionFromRegistry(); @@ -186,12 +186,12 @@ void ImporterList::DetectFirefoxProfiles() { ProfileInfo* firefox = new ProfileInfo(); firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX); firefox->browser_type = firefox_type; - firefox->source_path = source_path; + firefox->source_path = source_path.ToWStringHack(); #if defined(OS_WIN) firefox->app_path = GetFirefoxInstallPathFromRegistry(); #endif if (firefox->app_path.empty()) - firefox->app_path = app_path; + firefox->app_path = app_path.ToWStringHack(); firefox->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS | SEARCH_ENGINES; source_profiles_.push_back(firefox); |