Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / utility / importer / safari_importer.h
blobe063b757947ce774f51b6a58f7cef48ce6ab20a9
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_UTILITY_IMPORTER_SAFARI_IMPORTER_H_
6 #define CHROME_UTILITY_IMPORTER_SAFARI_IMPORTER_H_
8 #include <map>
9 #include <set>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h"
15 #include "base/gtest_prod_util.h"
16 #include "chrome/common/importer/importer_url_row.h"
17 #include "chrome/utility/importer/importer.h"
18 #include "components/favicon_base/favicon_usage_data.h"
20 #if __OBJC__
21 @class NSDictionary;
22 @class NSString;
23 #else
24 class NSDictionary;
25 class NSString;
26 #endif
28 class GURL;
29 struct ImportedBookmarkEntry;
31 namespace sql {
32 class Connection;
35 // Importer for Safari on OS X.
36 class SafariImporter : public Importer {
37 public:
38 // |library_dir| is the full path to the ~/Library directory,
39 // We pass it in as a parameter for testing purposes.
40 explicit SafariImporter(const base::FilePath& library_dir);
42 // Importer:
43 void StartImport(const importer::SourceProfile& source_profile,
44 uint16 items,
45 ImporterBridge* bridge) override;
47 private:
48 FRIEND_TEST_ALL_PREFIXES(SafariImporterTest, BookmarkImport);
49 FRIEND_TEST_ALL_PREFIXES(SafariImporterTest,
50 BookmarkImportWithEmptyBookmarksMenu);
51 FRIEND_TEST_ALL_PREFIXES(SafariImporterTest, FaviconImport);
52 FRIEND_TEST_ALL_PREFIXES(SafariImporterTest, HistoryImport);
54 ~SafariImporter() override;
56 // Multiple URLs can share the same favicon; this is a map
57 // of URLs -> IconIDs that we load as a temporary step before
58 // actually loading the icons.
59 typedef std::map<int64, std::set<GURL> > FaviconMap;
61 void ImportBookmarks();
62 void ImportPasswords();
63 void ImportHistory();
65 // Parse Safari's stored bookmarks.
66 void ParseBookmarks(const base::string16& toolbar_name,
67 std::vector<ImportedBookmarkEntry>* bookmarks);
69 // Function to recursively read Bookmarks out of Safari plist.
70 // |bookmark_folder| The dictionary containing a folder to parse.
71 // |parent_path_elements| Path elements up to this point.
72 // |is_in_toolbar| Is this folder in the toolbar.
73 // |out_bookmarks| BookMark element array to write into.
74 void RecursiveReadBookmarksFolder(
75 NSDictionary* bookmark_folder,
76 const std::vector<base::string16>& parent_path_elements,
77 bool is_in_toolbar,
78 const base::string16& toolbar_name,
79 std::vector<ImportedBookmarkEntry>* out_bookmarks);
81 // Converts history time stored by Safari as a double serialized as a string,
82 // to seconds-since-UNIX-Ephoch-format used by Chrome.
83 double HistoryTimeToEpochTime(NSString* history_time);
85 // Parses Safari's history and loads it into the input array.
86 void ParseHistoryItems(std::vector<ImporterURLRow>* history_items);
88 // Opens the favicon database file.
89 bool OpenDatabase(sql::Connection* db);
91 // Loads the urls associated with the favicons into favicon_map;
92 void ImportFaviconURLs(sql::Connection* db, FaviconMap* favicon_map);
94 // Loads and reencodes the individual favicons.
95 void LoadFaviconData(sql::Connection* db,
96 const FaviconMap& favicon_map,
97 favicon_base::FaviconUsageDataList* favicons);
99 base::FilePath library_dir_;
101 DISALLOW_COPY_AND_ASSIGN(SafariImporter);
104 #endif // CHROME_UTILITY_IMPORTER_SAFARI_IMPORTER_H_