Fix memory leak in Sync FakeServerEntity
[chromium-blink-merge.git] / chrome / utility / importer / bookmark_html_reader.h
blob274c9a272169ee622e9b8f1c64d395e3764ab045
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
3 // found in the LICENSE file.
5 #ifndef CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_
6 #define CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/strings/string16.h"
14 class GURL;
15 struct ImportedBookmarkEntry;
16 struct ImportedFaviconUsage;
18 namespace base {
19 class FilePath;
20 class Time;
23 namespace bookmark_html_reader {
25 // Imports the bookmarks from the specified file.
27 // |cancellation_callback| is polled to query if the import should be cancelled;
28 // if it returns |true| at any time the import will be cancelled. If
29 // |cancellation_callback| is a null callback the import will run to completion.
31 // |valid_url_callback| is called to determine if a specified URL is valid for
32 // import; it returns |true| if it is. If |valid_url_callback| is a null
33 // callback, all URLs are considered to be valid.
35 // |file_path| is the path of the file on disk to import.
37 // |bookmarks| is a pointer to a vector, which is filled with the imported
38 // bookmarks. It may not be NULL.
40 // |favicons| is a pointer to a vector, which is filled with the favicons of
41 // imported bookmarks. It may be NULL, in which case favicons are not imported.
42 void ImportBookmarksFile(
43 const base::Callback<bool(void)>& cancellation_callback,
44 const base::Callback<bool(const GURL&)>& valid_url_callback,
45 const base::FilePath& file_path,
46 std::vector<ImportedBookmarkEntry>* bookmarks,
47 std::vector<ImportedFaviconUsage>* favicons);
49 namespace internal {
51 // The file format that BookmarkHTMLReader parses starts with a heading
52 // tag, which contains its title. All bookmarks and sub-folders follow,
53 // bracketed by a <DL> tag:
54 // <DT><H3 PERSONAL_TOOLBAR_FOLDER="true" ...>title</H3>
55 // <DL><p>
56 // ... container ...
57 // </DL><p>
58 // And a bookmark is presented by a <A> tag:
59 // <DT><A HREF="url" SHORTCUTURL="shortcut" ADD_DATE="11213014"...>name</A>
60 // Reference: http://kb.mozillazine.org/Bookmarks.html
62 bool ParseCharsetFromLine(const std::string& line,
63 std::string* charset);
64 bool ParseFolderNameFromLine(const std::string& line,
65 const std::string& charset,
66 base::string16* folder_name,
67 bool* is_toolbar_folder,
68 base::Time* add_date);
69 // See above, this will also put the data: URL of the favicon into |*favicon|
70 // if there is a favicon given. |post_data| is set for POST base keywords to
71 // the contents of the actual POST (with %s for the search term).
72 bool ParseBookmarkFromLine(const std::string& line,
73 const std::string& charset,
74 base::string16* title,
75 GURL* url,
76 GURL* favicon,
77 base::string16* shortcut,
78 base::Time* add_date,
79 base::string16* post_data);
80 // Save bookmarks imported from browsers with Firefox 2 compatible bookmark
81 // systems such as Epiphany. This bookmark format is the same as that of the
82 // basic Firefox 2 bookmark, but it misses additional properties and uses
83 // lower-case tag:
84 // ...<h1>Bookmarks</h1><dl>
85 // <dt><a href="url">name</a></dt>
86 // <dt><a href="url">name</a></dt>
87 // </dl>
88 bool ParseMinimumBookmarkFromLine(const std::string& line,
89 const std::string& charset,
90 base::string16* title,
91 GURL* url);
93 } // namespace internal
95 } // namespace bookmark_html_reader
97 #endif // CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_