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

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: Removed references to firefox_places.{cc,h} Created 4 years, 1 month 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 size_t end_of_parent = file_data.find("</SearchPlugin>"); 639 size_t end_of_parent = file_data.find("</SearchPlugin>");
641 if (end_of_parent != std::string::npos && !alias.empty()) 640 if (end_of_parent != std::string::npos && !alias.empty())
642 file_data.insert(end_of_parent, "<Alias>" + alias + "</Alias> \n"); 641 file_data.insert(end_of_parent, "<Alias>" + alias + "</Alias> \n");
643 } 642 }
644 search_engine_data->push_back(file_data); 643 search_engine_data->push_back(file_data);
645 } 644 }
646 } 645 }
647 } 646 }
648 } 647 }
649 648
650 void FirefoxImporter::LoadRootNodeID(sql::Connection* db, 649 int FirefoxImporter::LoadNodeIDByGUID(sql::Connection* db,
651 int* toolbar_folder_id, 650 const std::string& GUID) {
652 int* menu_folder_id, 651 const char query[] =
653 int* unsorted_folder_id) { 652 "SELECT id "
654 static const char kToolbarFolderName[] = "toolbar"; 653 "FROM moz_bookmarks "
655 static const char kMenuFolderName[] = "menu"; 654 "WHERE guid == ?";
656 static const char kUnsortedFolderName[] = "unfiled"; 655 sql::Statement s(db->GetUniqueStatement(query));
656 s.BindString(0, GUID);
657 657
658 const char query[] = "SELECT root_name, folder_id FROM moz_bookmarks_roots"; 658 if (!s.Step())
659 sql::Statement s(db->GetUniqueStatement(query)); 659 return -1;
660 660 return s.ColumnInt(0);
661 while (s.Step()) {
662 std::string folder = s.ColumnString(0);
663 int id = s.ColumnInt(1);
664 if (folder == kToolbarFolderName)
665 *toolbar_folder_id = id;
666 else if (folder == kMenuFolderName)
667 *menu_folder_id = id;
668 else if (folder == kUnsortedFolderName)
669 *unsorted_folder_id = id;
670 }
671 } 661 }
672 662
673 void FirefoxImporter::LoadLivemarkIDs(sql::Connection* db, 663 void FirefoxImporter::LoadLivemarkIDs(sql::Connection* db,
674 std::set<int>* livemark) { 664 std::set<int>* livemark) {
675 static const char kFeedAnnotation[] = "livemark/feedURI"; 665 static const char kFeedAnnotation[] = "livemark/feedURI";
676 livemark->clear(); 666 livemark->clear();
677 667
678 const char query[] = 668 const char query[] =
679 "SELECT b.item_id " 669 "SELECT b.item_id "
680 "FROM moz_anno_attributes a " 670 "FROM moz_anno_attributes a "
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 775
786 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) 776 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data))
787 continue; // Unable to decode. 777 continue; // Unable to decode.
788 778
789 usage.urls = i->second; 779 usage.urls = i->second;
790 favicons->push_back(usage); 780 favicons->push_back(usage);
791 } 781 }
792 s.Reset(true); 782 s.Reset(true);
793 } 783 }
794 } 784 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698