Chromium Code Reviews| Index: chrome/browser/importer/bookmarks_file_importer.h |
| diff --git a/chrome/browser/importer/bookmarks_file_importer.h b/chrome/browser/importer/bookmarks_file_importer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..80e402ce9c2273bffeb0522ffe113964bea4cb0a |
| --- /dev/null |
| +++ b/chrome/browser/importer/bookmarks_file_importer.h |
| @@ -0,0 +1,101 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_IMPORTER_BOOKMARKS_FILE_IMPORTER_H_ |
| +#define CHROME_BROWSER_IMPORTER_BOOKMARKS_FILE_IMPORTER_H_ |
| + |
| +#include <set> |
|
tfarina
2013/05/07 01:03:19
looks like you can remove this include.
Avi (use Gerrit)
2013/05/07 03:11:28
Yes! Good catch.
|
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/callback_forward.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "chrome/browser/importer/importer.h" |
| +#include "chrome/browser/importer/profile_writer.h" |
| + |
| +class GURL; |
| + |
| +namespace base { |
| +class FilePath; |
| +} |
| + |
| +namespace history { |
| +struct ImportedFaviconUsage; |
| +} |
| + |
| +// Importer for bookmarks files. |
| +class BookmarksFileImporter : public Importer { |
| + public: |
| + BookmarksFileImporter(); |
| + |
| + // Importer: |
| + virtual void StartImport(const importer::SourceProfile& source_profile, |
| + uint16 items, |
| + ImporterBridge* bridge) OVERRIDE; |
| + |
| + // Imports the bookmarks from the specified file. |favicons| may be null, in |
| + // which case favicons are not parsed. |cancellation_callback| is polled to |
| + // query if the import should be cancelled; if it returns |true| at any time |
| + // the import will be cancelled. If |cancellation_callback| is NULL the |
| + // import will run to completion. |
| + static void ImportBookmarksFile( |
| + const base::FilePath& file_path, |
| + base::Callback<bool(void)>* cancellation_callback, |
| + std::vector<ProfileWriter::BookmarkEntry>* bookmarks, |
| + std::vector<history::ImportedFaviconUsage>* favicons); |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(BookmarksFileImporterTest, ParseTests); |
| + |
| + virtual ~BookmarksFileImporter(); |
| + |
| + // Helper methods exposed for testing. |
| + |
| + // The file format that BookmarksFileImporter parses starts with a heading |
| + // tag, which contains its title. All bookmarks and sub-folders follow, |
| + // bracketed by a <DL> tag: |
| + // <DT><H3 PERSONAL_TOOLBAR_FOLDER="true" ...>title</H3> |
| + // <DL><p> |
| + // ... container ... |
| + // </DL><p> |
| + // And a bookmark is presented by a <A> tag: |
| + // <DT><A HREF="url" SHORTCUTURL="shortcut" ADD_DATE="11213014"...>name</A> |
| + // Reference: http://kb.mozillazine.org/Bookmarks.html |
| + |
| + static bool ParseCharsetFromLine(const std::string& line, |
| + std::string* charset); |
| + static bool ParseFolderNameFromLine(const std::string& line, |
| + const std::string& charset, |
| + string16* folder_name, |
| + bool* is_toolbar_folder, |
| + base::Time* add_date); |
| + // See above, this will also put the data: URL of the favicon into |*favicon| |
| + // if there is a favicon given. |post_data| is set for POST base keywords to |
| + // the contents of the actual POST (with %s for the search term). |
| + static bool ParseBookmarkFromLine(const std::string& line, |
| + const std::string& charset, |
| + string16* title, |
| + GURL* url, |
| + GURL* favicon, |
| + string16* shortcut, |
| + base::Time* add_date, |
| + string16* post_data); |
| + // Save bookmarks imported from browsers with Firefox 2 compatible bookmark |
| + // systems such as Epiphany. This bookmark format is the same as that of the |
| + // basic Firefox 2 bookmark, but it misses additional properties and uses |
| + // lower-case tag: |
| + // ...<h1>Bookmarks</h1><dl> |
| + // <dt><a href="url">name</a></dt> |
| + // <dt><a href="url">name</a></dt> |
| + // </dl> |
| + static bool ParseMinimumBookmarkFromLine(const std::string& line, |
| + const std::string& charset, |
| + string16* title, |
| + GURL* url); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BookmarksFileImporter); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_IMPORTER_BOOKMARKS_FILE_IMPORTER_H_ |