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

Unified Diff: chrome/utility/importer/firefox_importer.cc

Issue 247223003: Parsed search.json for importing search engine settings from FireFox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test coverage and addressed feedback Created 6 years, 8 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/utility/importer/firefox_importer.cc
diff --git a/chrome/utility/importer/firefox_importer.cc b/chrome/utility/importer/firefox_importer.cc
index c74947b685e91f288f07952175711e58a8890a2b..4beb9a3fa83064d21c50fd9fee0cce668094d3e3 100644
--- a/chrome/utility/importer/firefox_importer.cc
+++ b/chrome/utility/importer/firefox_importer.cc
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
+#include "base/json/json_file_value_serializer.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
@@ -383,12 +384,13 @@ void FirefoxImporter::ImportHomepage() {
void FirefoxImporter::GetSearchEnginesXMLData(
std::vector<std::string>* search_engine_data) {
- // TODO(mpawlowski): This may no longer work, search engines are stored in
- // search.json since Firefox 3.5, not in search.sqlite. XML definitions are
- // still necessary. http://crbug.com/329175
base::FilePath file = source_path_.AppendASCII("search.sqlite");
- if (!base::PathExists(file))
+ if (!base::PathExists(file)) {
+ // Since Firefox 3.5, search engines are no longer stored in search.sqlite.
+ // Instead, search.json is used for storing search engines.
+ GetSearchEnginesXMLDataFromJSON(search_engine_data);
return;
+ }
sql::Connection db;
if (!db.Open(file))
@@ -476,6 +478,55 @@ void FirefoxImporter::GetSearchEnginesXMLData(
}
}
+void FirefoxImporter::GetSearchEnginesXMLDataFromJSON(
+ std::vector<std::string>* search_engine_data) {
+ base::FilePath search_json_file = source_path_.AppendASCII("search.json");
+ if (!base::PathExists(search_json_file))
+ return;
+
+ JSONFileValueSerializer serializer(search_json_file);
+ scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL));
+ const base::DictionaryValue* search_root = NULL;
+
Ilya Sherman 2014/05/01 21:37:02 nit: I'd omit this blank line.
+ if (!root || !root->GetAsDictionary(&search_root))
+ return;
+
+ const std::string kDirectories("directories");
+ const base::DictionaryValue* search_directories = NULL;
+
Ilya Sherman 2014/05/01 21:37:02 nit: I'd omit this blank line.
+ if (!search_root->GetDictionary(kDirectories, &search_directories))
+ return;
+
+ // Dictionary "search_directories" contains a list of search engines.
Ilya Sherman 2014/05/01 21:37:02 nit: Rather than using quotation marks to denote v
+ // The list can be found from key <engines> of the dictionary.
+ // Key <engines> is a grandchild of key <directories>.
+ // However, key <engines> parent's key is dynamic which
+ // depends on operating systems. For example,
+ // Ubuntu: /usr/lib/firefox/distribution/searchplugins/locale/en-US
+ // Windows: C:\\Program Files (x86)\\Mozilla Firefox\\browser\\searchplugins
+ // Therefore, it needs to be retrieved by using iterator
Ilya Sherman 2014/05/01 21:37:02 nit: "by using iterator" -> "by searching."
+
+ base::DictionaryValue::Iterator it(*search_directories);
+ const std::string kEngines(it.key() + ".engines");
+ const base::ListValue* search_engines = NULL;
+
+ if (search_directories->GetList(kEngines, &search_engines)) {
Ilya Sherman 2014/05/01 21:37:02 nit: I'd suggest reversing this condition and usin
+ const std::string kFilePath("filePath");
+ for (size_t i = 0; i < search_engines->GetSize(); ++i) {
+ const base::DictionaryValue* engine_info = NULL;
+ if (search_engines->GetDictionary(i, &engine_info)) {
+ std::string file_path;
+ if (engine_info->GetString(kFilePath, &file_path)) {
+ std::string file_data;
+ base::FilePath xml_file = base::FilePath::FromUTF8Unsafe(file_path);
+ base::ReadFileToString(xml_file, &file_data);
+ search_engine_data->push_back(file_data);
+ }
+ }
+ }
+ }
+}
+
void FirefoxImporter::LoadRootNodeID(sql::Connection* db,
int* toolbar_folder_id,
int* menu_folder_id,

Powered by Google App Engine
This is Rietveld 408576698