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

Side by Side Diff: chrome/utility/importer/firefox_importer.cc

Issue 2296633002: Fix Firefox bookmarks import. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix Created 4 years 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 unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 9
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 void FirefoxImporter::ImportBookmarks() { 198 void FirefoxImporter::ImportBookmarks() {
199 base::FilePath file = source_path_.AppendASCII("places.sqlite"); 199 base::FilePath file = source_path_.AppendASCII("places.sqlite");
200 if (!base::PathExists(file)) 200 if (!base::PathExists(file))
201 return; 201 return;
202 202
203 sql::Connection db; 203 sql::Connection db;
204 if (!db.Open(file)) 204 if (!db.Open(file))
205 return; 205 return;
206 206
207 // Get the bookmark folders that we are interested in. 207 // Get the bookmark folders that we are interested in.
208 int toolbar_folder_id = -1; 208 int toolbar_folder_id = LoadNodeIDByGUID(&db, "toolbar_____");
209 int menu_folder_id = -1; 209 int menu_folder_id = LoadNodeIDByGUID(&db, "menu________");
210 int unsorted_folder_id = -1; 210 int unsorted_folder_id = LoadNodeIDByGUID(&db, "unfiled_____");
211 LoadRootNodeID(&db, &toolbar_folder_id, &menu_folder_id, &unsorted_folder_id);
212 211
213 // Load livemark IDs. 212 // Load livemark IDs.
214 std::set<int> livemark_id; 213 std::set<int> livemark_id;
215 LoadLivemarkIDs(&db, &livemark_id); 214 LoadLivemarkIDs(&db, &livemark_id);
216 215
217 // Load the default bookmarks. 216 // Load the default bookmarks.
218 std::set<GURL> default_urls; 217 std::set<GURL> default_urls;
219 LoadDefaultBookmarks(app_path_, &default_urls); 218 LoadDefaultBookmarks(app_path_, &default_urls);
220 219
221 BookmarkList list; 220 BookmarkList list;
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 size_t end_of_parent = file_data.find("</SearchPlugin>"); 635 size_t end_of_parent = file_data.find("</SearchPlugin>");
637 if (end_of_parent != std::string::npos && !alias.empty()) 636 if (end_of_parent != std::string::npos && !alias.empty())
638 file_data.insert(end_of_parent, "<Alias>" + alias + "</Alias> \n"); 637 file_data.insert(end_of_parent, "<Alias>" + alias + "</Alias> \n");
639 } 638 }
640 search_engine_data->push_back(file_data); 639 search_engine_data->push_back(file_data);
641 } 640 }
642 } 641 }
643 } 642 }
644 } 643 }
645 644
646 void FirefoxImporter::LoadRootNodeID(sql::Connection* db, 645 int FirefoxImporter::LoadNodeIDByGUID(sql::Connection* db,
647 int* toolbar_folder_id, 646 const std::string& GUID) {
648 int* menu_folder_id, 647 const char query[] =
649 int* unsorted_folder_id) { 648 "SELECT id "
650 static const char kToolbarFolderName[] = "toolbar"; 649 "FROM moz_bookmarks "
651 static const char kMenuFolderName[] = "menu"; 650 "WHERE guid == ?";
652 static const char kUnsortedFolderName[] = "unfiled"; 651 sql::Statement s(db->GetUniqueStatement(query));
652 s.BindString(0, GUID);
653 653
654 const char query[] = "SELECT root_name, folder_id FROM moz_bookmarks_roots"; 654 if (!s.Step())
655 sql::Statement s(db->GetUniqueStatement(query)); 655 return -1;
656 656 return s.ColumnInt(0);
657 while (s.Step()) {
658 std::string folder = s.ColumnString(0);
659 int id = s.ColumnInt(1);
660 if (folder == kToolbarFolderName)
661 *toolbar_folder_id = id;
662 else if (folder == kMenuFolderName)
663 *menu_folder_id = id;
664 else if (folder == kUnsortedFolderName)
665 *unsorted_folder_id = id;
666 }
667 } 657 }
668 658
669 void FirefoxImporter::LoadLivemarkIDs(sql::Connection* db, 659 void FirefoxImporter::LoadLivemarkIDs(sql::Connection* db,
670 std::set<int>* livemark) { 660 std::set<int>* livemark) {
671 static const char kFeedAnnotation[] = "livemark/feedURI"; 661 static const char kFeedAnnotation[] = "livemark/feedURI";
672 livemark->clear(); 662 livemark->clear();
673 663
674 const char query[] = 664 const char query[] =
675 "SELECT b.item_id " 665 "SELECT b.item_id "
676 "FROM moz_anno_attributes a " 666 "FROM moz_anno_attributes a "
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 772
783 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) 773 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data))
784 continue; // Unable to decode. 774 continue; // Unable to decode.
785 775
786 usage.urls = i->second; 776 usage.urls = i->second;
787 favicons->push_back(usage); 777 favicons->push_back(usage);
788 } 778 }
789 s.Reset(true); 779 s.Reset(true);
790 } 780 }
791 } 781 }
OLDNEW
« no previous file with comments | « chrome/utility/importer/firefox_importer.h ('k') | chrome/utility/importer/firefox_importer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698