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

Unified Diff: chrome/browser/importer/firefox_importer_utils.cc

Issue 3221007: Fix a couple of firefox search engine import bugs. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: added test, TODO Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/importer/firefox_importer_utils.cc
diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc
index 8f8aee16f8c1ca0811608783e116ece8eff62d92..0ec9109cc7cba82454477280b67e7cf37303f5c1 100644
--- a/chrome/browser/importer/firefox_importer_utils.cc
+++ b/chrome/browser/importer/firefox_importer_utils.cc
@@ -282,30 +282,7 @@ std::string ReadPrefsJsValue(const FilePath& profile_path,
if (!ReadPrefFile(profile_path.AppendASCII("prefs.js"), &content))
return "";
- // This file has the syntax: user_pref("key", value);
- std::string search_for = std::string("user_pref(\"") + pref_key +
- std::string("\", ");
- size_t prop_index = content.find(search_for);
- if (prop_index == std::string::npos)
- return "";
-
- size_t start = prop_index + search_for.length();
- size_t stop = std::string::npos;
- if (start != std::string::npos)
- stop = content.find(")", start + 1);
-
- if (start == std::string::npos || stop == std::string::npos) {
- NOTREACHED() << "Firefox property " << pref_key << " could not be parsed.";
- return "";
- }
-
- // String values have double quotes we don't need to return to the caller.
- if (content[start] == '\"' && content[stop - 1] == '\"') {
- ++start;
- --stop;
- }
-
- return content.substr(start, stop - start);
+ return GetPrefsJsValue(content, pref_key);
}
int GetFirefoxDefaultSearchEngineIndex(
@@ -317,8 +294,8 @@ int GetFirefoxDefaultSearchEngineIndex(
if (search_engines.empty())
return -1;
- std::wstring default_se_name = UTF8ToWide(
- ReadPrefsJsValue(profile_path, "browser.search.selectedEngine"));
+ std::string default_se_name =
+ ReadPrefsJsValue(profile_path, "browser.search.selectedEngine");
if (default_se_name.empty()) {
// browser.search.selectedEngine does not exist if the user has not changed
@@ -331,7 +308,7 @@ int GetFirefoxDefaultSearchEngineIndex(
int default_se_index = -1;
for (std::vector<TemplateURL*>::const_iterator iter = search_engines.begin();
iter != search_engines.end(); ++iter) {
- if (default_se_name == (*iter)->short_name()) {
+ if (default_se_name == WideToUTF8((*iter)->short_name())) {
default_se_index = static_cast<int>(iter - search_engines.begin());
break;
}
@@ -449,3 +426,35 @@ bool ParsePrefFile(const FilePath& pref_file, DictionaryValue* prefs) {
}
return true;
}
+
+std::string GetPrefsJsValue(const std::string& content,
+ const std::string& pref_key) {
+ // This file has the syntax: user_pref("key", value);
+ std::string search_for = std::string("user_pref(\"") + pref_key +
+ std::string("\", ");
+ size_t prop_index = content.find(search_for);
+ if (prop_index == std::string::npos)
+ return "";
+
+ size_t start = prop_index + search_for.length();
+ size_t stop = std::string::npos;
+ if (start != std::string::npos) {
+ // Stop at the last ')' on this line.
+ stop = content.find("\n", start + 1);
+ stop = content.rfind(")", stop);
+ }
+
+ if (start == std::string::npos || stop == std::string::npos ||
+ stop < start) {
+ LOG(WARNING) << "Firefox property " << pref_key << " could not be parsed.";
+ return "";
+ }
+
+ // String values have double quotes we don't need to return to the caller.
+ if (content[start] == '\"' && content[stop - 1] == '\"') {
+ ++start;
+ --stop;
+ }
+
+ return content.substr(start, stop - start);
+}
« no previous file with comments | « chrome/browser/importer/firefox_importer_utils.h ('k') | chrome/browser/importer/firefox_importer_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698