OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_UTILITY_IMPORTER_FIREFOX_PLACES_FACTORY_H_ |
| 6 #define CHROME_UTILITY_IMPORTER_FIREFOX_PLACES_FACTORY_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/files/file_enumerator.h" |
| 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" |
| 15 #include "chrome/common/importer/importer_url_row.h" |
| 16 #include "components/favicon_base/favicon_usage_data.h" |
| 17 #include "sql/connection.h" |
| 18 #include "sql/statement.h" |
| 19 |
| 20 // Original definition is in http://mxr.mozilla.org/firefox/source/toolkit/ |
| 21 // components/places/public/nsINavBookmarksService.idl |
| 22 enum BookmarkItemType { |
| 23 TYPE_BOOKMARK = 1, |
| 24 TYPE_FOLDER = 2, |
| 25 TYPE_SEPARATOR = 3, |
| 26 TYPE_DYNAMIC_CONTAINER = 4 |
| 27 }; |
| 28 |
| 29 // The struct stores the information about a bookmark item. |
| 30 struct BookmarkItem { |
| 31 int parent; |
| 32 int id; |
| 33 GURL url; |
| 34 base::string16 title; |
| 35 BookmarkItemType type; |
| 36 std::string keyword; |
| 37 base::Time date_added; |
| 38 int64_t favicon; |
| 39 bool empty_folder; |
| 40 }; |
| 41 |
| 42 typedef std::vector<BookmarkItem*> BookmarkList; |
| 43 typedef std::set<int> PostKeywordIds; |
| 44 typedef std::set<int> LivemarkIds; |
| 45 typedef std::map<int64_t, std::set<GURL>> FaviconMap; |
| 46 |
| 47 class FirefoxPlaces { |
| 48 public: |
| 49 enum class FolderType { ROOT, MENU, TOOLBAR, TAGS, UNSORTED }; |
| 50 FirefoxPlaces(const base::FilePath& places_path); |
| 51 virtual bool LoadBookmarks(BookmarkList* bookmarks); |
| 52 virtual bool LoadHistory(std::vector<ImporterURLRow>* history); |
| 53 virtual bool LoadPostKeywordIds(PostKeywordIds* post_keyword_ids); |
| 54 virtual bool LoadLivemarkIds(LivemarkIds* livemark_ids); |
| 55 virtual int GetFolderId(FolderType folder_type); |
| 56 |
| 57 // Loads the favicons given in the map from the database, loads the data, |
| 58 // and converts it into FaviconUsage structures. |
| 59 virtual bool LoadFavicons(const FaviconMap& favicon_map, |
| 60 favicon_base::FaviconUsageDataList* favicons); |
| 61 |
| 62 virtual ~FirefoxPlaces() {} |
| 63 |
| 64 protected: |
| 65 base::FilePath places_path_; |
| 66 sql::Connection db_; |
| 67 |
| 68 // Gets the bookmark folder with given ID, and adds the entry in |list| |
| 69 // if successful. |
| 70 virtual void GetTopBookmarkFolder(int folder_id, BookmarkList* list); |
| 71 |
| 72 // Loads all children of the given folder, and appends them to the |list|. |
| 73 virtual void GetWholeBookmarkFolder(BookmarkList* list, |
| 74 size_t position, |
| 75 bool* empty_folder); |
| 76 }; |
| 77 |
| 78 class FirefoxPlacesV11 : public FirefoxPlaces { |
| 79 public: |
| 80 FirefoxPlacesV11(const base::FilePath& places_path); |
| 81 int GetFolderId(FolderType folder_type) override; |
| 82 |
| 83 private: |
| 84 // Gets the specific ID of a root node with given name from |db|. |
| 85 // Returns -1 if not found. |
| 86 int FirefoxPlacesV11::LoadNodeIDByName(const std::string& name); |
| 87 }; |
| 88 class FirefoxPlacesV25 : public FirefoxPlaces { |
| 89 public: |
| 90 FirefoxPlacesV25(const base::FilePath& places_path); |
| 91 int GetFolderId(FolderType folder_type) override; |
| 92 |
| 93 private: |
| 94 // Gets the specific ID of a bookmark node with given GUID from |db|. |
| 95 // Returns -1 if not found. |
| 96 int LoadNodeIDByGUID(const std::string& GUID); |
| 97 }; |
| 98 |
| 99 class FirefoxPlacesFactory { |
| 100 public: |
| 101 static std::unique_ptr<FirefoxPlaces> GetForProfile( |
| 102 const base::FilePath& profile_path); |
| 103 }; |
| 104 |
| 105 #endif CHROME_UTILITY_IMPORTER_FIREFOX_PLACES_FACTORY_H_ |
OLD | NEW |