Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/utility/importer/firefox_importer.h" | 5 #include "chrome/utility/importer/firefox_importer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| 11 #include "base/json/json_file_value_serializer.h" | |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/common/importer/firefox_importer_utils.h" | 17 #include "chrome/common/importer/firefox_importer_utils.h" |
| 17 #include "chrome/common/importer/firefox_importer_utils.h" | 18 #include "chrome/common/importer/firefox_importer_utils.h" |
| 18 #include "chrome/common/importer/imported_bookmark_entry.h" | 19 #include "chrome/common/importer/imported_bookmark_entry.h" |
| 19 #include "chrome/common/importer/imported_favicon_usage.h" | 20 #include "chrome/common/importer/imported_favicon_usage.h" |
| 20 #include "chrome/common/importer/importer_bridge.h" | 21 #include "chrome/common/importer/importer_bridge.h" |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 | 377 |
| 377 void FirefoxImporter::ImportHomepage() { | 378 void FirefoxImporter::ImportHomepage() { |
| 378 GURL home_page = GetHomepage(source_path_); | 379 GURL home_page = GetHomepage(source_path_); |
| 379 if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { | 380 if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { |
| 380 bridge_->AddHomePage(home_page); | 381 bridge_->AddHomePage(home_page); |
| 381 } | 382 } |
| 382 } | 383 } |
| 383 | 384 |
| 384 void FirefoxImporter::GetSearchEnginesXMLData( | 385 void FirefoxImporter::GetSearchEnginesXMLData( |
| 385 std::vector<std::string>* search_engine_data) { | 386 std::vector<std::string>* search_engine_data) { |
| 386 // TODO(mpawlowski): This may no longer work, search engines are stored in | |
| 387 // search.json since Firefox 3.5, not in search.sqlite. XML definitions are | |
| 388 // still necessary. http://crbug.com/329175 | |
| 389 base::FilePath file = source_path_.AppendASCII("search.sqlite"); | 387 base::FilePath file = source_path_.AppendASCII("search.sqlite"); |
| 390 if (!base::PathExists(file)) | 388 if (!base::PathExists(file)) { |
| 389 // since Firefox 3.5, search engines are no longer stored in search.sqlite. | |
|
Ilya Sherman
2014/04/23 04:56:01
nit: Please start the sentence with a capital lett
| |
| 390 // Instead, search.json is used for storing search engines. | |
| 391 | |
| 392 base::FilePath search_json_file = source_path_.AppendASCII("search.json"); | |
| 393 if (!base::PathExists(search_json_file)) | |
| 394 return; | |
| 395 | |
| 396 JSONFileValueSerializer serializer(search_json_file); | |
| 397 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | |
| 398 | |
| 399 if (!root.get()) | |
|
Ilya Sherman
2014/04/23 04:56:01
nit: No need for the ".get()".
| |
| 400 return; | |
| 401 | |
| 402 base::DictionaryValue* search_root = | |
| 403 static_cast<base::DictionaryValue*>(root.release()); | |
|
Ilya Sherman
2014/04/23 04:56:01
Please use GetAsDictionary() for a type-safe conve
Ilya Sherman
2014/04/23 04:56:01
Releasing the scoped_ptr here leaks memory. It's
| |
| 404 const std::string kDirectories("directories"); | |
| 405 const base::DictionaryValue* search_directories = NULL; | |
| 406 | |
| 407 if (!search_root->GetDictionary(kDirectories, &search_directories)) | |
| 408 return; | |
| 409 | |
| 410 // search engine list can be found from key <engines> of the dictionary. | |
|
Ilya Sherman
2014/04/23 04:56:01
nit: Please write this as a complete sentence, inc
| |
| 411 // key <engines> is a grandchild of key <directories>. | |
| 412 // However, key <engines> parent's key is dynamic which | |
| 413 // depends on operating systems. For example, | |
| 414 // Ubuntu: /usr/lib/firefox/distribution/searchplugins/locale/en-US | |
| 415 // Windows: C:\\Program Files (x86)\\Mozilla Firefox\\browser\\searchplugins | |
| 416 // Therefore, it needs to be retrieved by using iterator | |
| 417 | |
| 418 base::DictionaryValue::Iterator it(*search_directories); | |
| 419 const base::ListValue* search_engines = NULL; | |
|
Ilya Sherman
2014/04/23 04:56:01
nit: Please move this down even closer to where it
| |
| 420 const std::string kEngines(it.key() + ".engines"); | |
| 421 | |
| 422 if (search_directories->GetList(kEngines, &search_engines)) { | |
| 423 const std::string kFilePath("filePath"); | |
| 424 for (size_t i = 0; i < search_engines->GetSize(); ++i) { | |
| 425 const base::DictionaryValue* engine_info = NULL; | |
| 426 if (search_engines->GetDictionary(i, &engine_info)) { | |
| 427 std::string file_path; | |
| 428 if (engine_info->GetString(kFilePath, &file_path)) { | |
| 429 std::string file_data; | |
| 430 base::FilePath xml_file = base::FilePath::FromUTF8Unsafe(file_path); | |
| 431 base::ReadFileToString(xml_file, &file_data); | |
| 432 search_engine_data->push_back(file_data); | |
| 433 } | |
| 434 } | |
| 435 } | |
| 436 } | |
| 391 return; | 437 return; |
| 438 } | |
|
Ilya Sherman
2014/04/23 04:56:01
Please factor this code out into a separate method
| |
| 392 | 439 |
| 393 sql::Connection db; | 440 sql::Connection db; |
| 394 if (!db.Open(file)) | 441 if (!db.Open(file)) |
| 395 return; | 442 return; |
| 396 | 443 |
| 397 const char* query = "SELECT engineid FROM engine_data " | 444 const char* query = "SELECT engineid FROM engine_data " |
| 398 "WHERE engineid NOT IN " | 445 "WHERE engineid NOT IN " |
| 399 "(SELECT engineid FROM engine_data " | 446 "(SELECT engineid FROM engine_data " |
| 400 "WHERE name='hidden') " | 447 "WHERE name='hidden') " |
| 401 "ORDER BY value ASC"; | 448 "ORDER BY value ASC"; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 | 658 |
| 612 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 659 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
| 613 continue; // Unable to decode. | 660 continue; // Unable to decode. |
| 614 | 661 |
| 615 usage.urls = i->second; | 662 usage.urls = i->second; |
| 616 favicons->push_back(usage); | 663 favicons->push_back(usage); |
| 617 } | 664 } |
| 618 s.Reset(true); | 665 s.Reset(true); |
| 619 } | 666 } |
| 620 } | 667 } |
| OLD | NEW |