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" |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 for (base::FilePath engine_path = engines.Next(); | 473 for (base::FilePath engine_path = engines.Next(); |
474 !engine_path.value().empty(); engine_path = engines.Next()) { | 474 !engine_path.value().empty(); engine_path = engines.Next()) { |
475 std::string file_data; | 475 std::string file_data; |
476 base::ReadFileToString(file, &file_data); | 476 base::ReadFileToString(file, &file_data); |
477 search_engine_data->push_back(file_data); | 477 search_engine_data->push_back(file_data); |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
481 void FirefoxImporter::GetSearchEnginesXMLDataFromJSON( | 481 void FirefoxImporter::GetSearchEnginesXMLDataFromJSON( |
482 std::vector<std::string>* search_engine_data) { | 482 std::vector<std::string>* search_engine_data) { |
483 // search-metadata.json contains keywords for search engines. This | |
484 // file exists only if user has set keywords for search engines. | |
Ilya Sherman
2014/07/28 22:18:45
nit: "exists only if user has set" -> "exists only
Nikhil
2014/07/29 08:29:21
Done.
| |
485 base::FilePath search_metadata_json_file = | |
486 source_path_.AppendASCII("search-metadata.json"); | |
487 bool search_metadata_available = false; | |
488 if (base::PathExists(search_metadata_json_file)) | |
489 search_metadata_available = true; | |
Ilya Sherman
2014/07/28 22:18:45
nit: These three lines can be condensed to
bool s
Nikhil
2014/07/29 08:29:21
I've removed this boolean as check for search_meta
| |
490 | |
491 const base::DictionaryValue* search_metadata_root = NULL; | |
Ilya Sherman
2014/07/28 22:18:45
nit: Please move this down a few lines, to be just
Peter Kasting
2014/07/28 22:48:31
FWIW I prefer the line 503-507 formatting, as the
Nikhil
2014/07/29 08:29:21
Done.
| |
492 JSONFileValueSerializer metadata_serializer(search_metadata_json_file); | |
Ilya Sherman
2014/07/28 22:18:45
Why do this if search_metadata_available is false?
Nikhil
2014/07/29 08:29:21
Removed search_metadata_available as it's not requ
| |
493 scoped_ptr<base::Value> metadata_root( | |
494 metadata_serializer.Deserialize(NULL, NULL)); | |
495 if (metadata_root) | |
496 metadata_root->GetAsDictionary(&search_metadata_root); | |
497 | |
498 // search.json contains information about search engines to import. | |
483 base::FilePath search_json_file = source_path_.AppendASCII("search.json"); | 499 base::FilePath search_json_file = source_path_.AppendASCII("search.json"); |
484 if (!base::PathExists(search_json_file)) | 500 if (!base::PathExists(search_json_file)) |
485 return; | 501 return; |
486 | 502 |
487 JSONFileValueSerializer serializer(search_json_file); | 503 JSONFileValueSerializer serializer(search_json_file); |
488 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | 504 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); |
489 const base::DictionaryValue* search_root = NULL; | 505 const base::DictionaryValue* search_root = NULL; |
490 if (!root || !root->GetAsDictionary(&search_root)) | 506 if (!root || !root->GetAsDictionary(&search_root)) |
491 return; | 507 return; |
492 | 508 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 file_path.substr(index + kAppPrefix.length())); | 565 file_path.substr(index + kAppPrefix.length())); |
550 } else if ((index = file_path.find(kProfilePrefix)) != | 566 } else if ((index = file_path.find(kProfilePrefix)) != |
551 std::string::npos) { | 567 std::string::npos) { |
552 // Replace '[profile]/' with actual profile path. | 568 // Replace '[profile]/' with actual profile path. |
553 xml_file = source_path_.AppendASCII("searchplugins").AppendASCII( | 569 xml_file = source_path_.AppendASCII("searchplugins").AppendASCII( |
554 file_path.substr(index + kProfilePrefix.length())); | 570 file_path.substr(index + kProfilePrefix.length())); |
555 } | 571 } |
556 | 572 |
557 std::string file_data; | 573 std::string file_data; |
558 base::ReadFileToString(xml_file, &file_data); | 574 base::ReadFileToString(xml_file, &file_data); |
575 | |
576 // If keyword is mentioned for this search engine, then add | |
Peter Kasting
2014/07/28 22:48:31
Nit: keyword -> a keyword
Nikhil
2014/07/29 08:29:21
Done.
| |
577 // it in xml string as <Alias> element and use this updated | |
Ilya Sherman
2014/07/28 22:18:45
nit: "add it in xml string as <Alias> element" ->
Nikhil
2014/07/29 08:29:21
Done.
| |
578 // string. | |
579 if (search_metadata_available && search_metadata_root && | |
580 search_metadata_root->HasKey(file_path)) { | |
581 // Keyword is stored in field named as "alias". | |
Peter Kasting
2014/07/28 22:48:31
Nit: This comment is redundant.
Nikhil
2014/07/29 08:29:21
Done.
| |
582 const base::DictionaryValue* search_xml_path = NULL; | |
583 if (search_metadata_root->GetDictionaryWithoutPathExpansion( | |
584 file_path, &search_xml_path)) { | |
Peter Kasting
2014/07/28 22:48:31
Nit: Indent 4, not 8
Nikhil
2014/07/29 08:29:21
This was actually done by clang-format. I've now m
Ilya Sherman
2014/07/29 17:24:55
FWIW, I agree with clang-format, and disagree with
Peter Kasting
2014/07/29 18:33:31
I'm not convinced the codebase is, in fact, moving
| |
585 std::string alias; | |
586 search_xml_path->GetString("alias", &alias); | |
587 | |
588 // Add it as last child element. | |
Peter Kasting
2014/07/28 22:48:31
Nit: it -> the alias element; last -> the last
Nikhil
2014/07/29 08:29:21
Done.
| |
589 size_t end_of_parent = file_data.find("</SearchPlugin>"); | |
590 if (end_of_parent != std::string::npos) { | |
591 std::string& updated_file_data = file_data.insert( | |
592 end_of_parent, "<Alias>" + alias + "</Alias> \n"); | |
593 search_engine_data->push_back(updated_file_data); | |
594 continue; | |
Ilya Sherman
2014/07/28 22:18:45
IMO it would be better to simply update |file_data
Nikhil
2014/07/29 08:29:21
Done.
| |
595 } | |
596 } | |
597 } | |
598 | |
599 // No keyword is mentioned for this search-engine. | |
559 search_engine_data->push_back(file_data); | 600 search_engine_data->push_back(file_data); |
560 } | 601 } |
561 } | 602 } |
562 } | 603 } |
563 } | 604 } |
564 | 605 |
565 void FirefoxImporter::LoadRootNodeID(sql::Connection* db, | 606 void FirefoxImporter::LoadRootNodeID(sql::Connection* db, |
566 int* toolbar_folder_id, | 607 int* toolbar_folder_id, |
567 int* menu_folder_id, | 608 int* menu_folder_id, |
568 int* unsorted_folder_id) { | 609 int* unsorted_folder_id) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 | 738 |
698 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 739 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
699 continue; // Unable to decode. | 740 continue; // Unable to decode. |
700 | 741 |
701 usage.urls = i->second; | 742 usage.urls = i->second; |
702 favicons->push_back(usage); | 743 favicons->push_back(usage); |
703 } | 744 } |
704 s.Reset(true); | 745 s.Reset(true); |
705 } | 746 } |
706 } | 747 } |
OLD | NEW |