OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_IMPORTER_SAFARI_IMPORTER_H_ | |
6 #define CHROME_BROWSER_IMPORTER_SAFARI_IMPORTER_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <vector> | |
11 | |
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/browser/history/history_types.h" | |
17 #include "chrome/browser/importer/importer.h" | |
18 #include "chrome/common/importer/importer_url_row.h" | |
19 | |
20 #if __OBJC__ | |
21 @class NSDictionary; | |
22 @class NSString; | |
23 #else | |
24 class NSDictionary; | |
25 class NSString; | |
26 #endif | |
27 | |
28 class GURL; | |
29 struct ImportedBookmarkEntry; | |
30 struct ImportedFaviconUsage; | |
31 | |
32 namespace history { | |
33 class URLRow; | |
34 } | |
35 | |
36 namespace sql { | |
37 class Connection; | |
38 } | |
39 | |
40 // Importer for Safari on OS X. | |
41 class SafariImporter : public Importer { | |
42 public: | |
43 // |library_dir| is the full path to the ~/Library directory, | |
44 // We pass it in as a parameter for testing purposes. | |
45 explicit SafariImporter(const base::FilePath& library_dir); | |
46 | |
47 // Importer: | |
48 virtual void StartImport(const importer::SourceProfile& source_profile, | |
49 uint16 items, | |
50 ImporterBridge* bridge) OVERRIDE; | |
51 | |
52 // Does this user account have a Safari Profile and if so, what items | |
53 // are supported? | |
54 // in: library_dir - ~/Library or a standin for testing purposes. | |
55 // out: services_supported - the service supported for import. | |
56 // Returns true if we can import the Safari profile. | |
57 static bool CanImport(const base::FilePath& library_dir, | |
58 uint16* services_supported); | |
59 | |
60 private: | |
61 FRIEND_TEST_ALL_PREFIXES(SafariImporterTest, BookmarkImport); | |
62 FRIEND_TEST_ALL_PREFIXES(SafariImporterTest, FaviconImport); | |
63 FRIEND_TEST_ALL_PREFIXES(SafariImporterTest, HistoryImport); | |
64 | |
65 virtual ~SafariImporter(); | |
66 | |
67 // Multiple URLs can share the same favicon; this is a map | |
68 // of URLs -> IconIDs that we load as a temporary step before | |
69 // actually loading the icons. | |
70 typedef std::map<int64, std::set<GURL> > FaviconMap; | |
71 | |
72 void ImportBookmarks(); | |
73 void ImportPasswords(); | |
74 void ImportHistory(); | |
75 | |
76 // Parse Safari's stored bookmarks. | |
77 void ParseBookmarks(const string16& toolbar_name, | |
78 std::vector<ImportedBookmarkEntry>* bookmarks); | |
79 | |
80 // Function to recursively read Bookmarks out of Safari plist. | |
81 // |bookmark_folder| The dictionary containing a folder to parse. | |
82 // |parent_path_elements| Path elements up to this point. | |
83 // |is_in_toolbar| Is this folder in the toolbar. | |
84 // |out_bookmarks| BookMark element array to write into. | |
85 void RecursiveReadBookmarksFolder( | |
86 NSDictionary* bookmark_folder, | |
87 const std::vector<string16>& parent_path_elements, | |
88 bool is_in_toolbar, | |
89 const string16& toolbar_name, | |
90 std::vector<ImportedBookmarkEntry>* out_bookmarks); | |
91 | |
92 // Converts history time stored by Safari as a double serialized as a string, | |
93 // to seconds-since-UNIX-Ephoch-format used by Chrome. | |
94 double HistoryTimeToEpochTime(NSString* history_time); | |
95 | |
96 // Parses Safari's history and loads it into the input array. | |
97 void ParseHistoryItems(std::vector<ImporterURLRow>* history_items); | |
98 | |
99 // Opens the favicon database file. | |
100 bool OpenDatabase(sql::Connection* db); | |
101 | |
102 // Loads the urls associated with the favicons into favicon_map; | |
103 void ImportFaviconURLs(sql::Connection* db, FaviconMap* favicon_map); | |
104 | |
105 // Loads and reencodes the individual favicons. | |
106 void LoadFaviconData(sql::Connection* db, | |
107 const FaviconMap& favicon_map, | |
108 std::vector<ImportedFaviconUsage>* favicons); | |
109 | |
110 base::FilePath library_dir_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(SafariImporter); | |
113 }; | |
114 | |
115 #endif // CHROME_BROWSER_IMPORTER_SAFARI_IMPORTER_H_ | |
OLD | NEW |