diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-07 04:31:35 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-07 04:31:35 +0000 |
commit | b504899244b4264994d4daae2bee660706dba652 (patch) | |
tree | eda190cb35dfff7f700a4c636730ff2487cb35d8 /chrome/browser/importer/importer.h | |
parent | e562de106eeab2667eeb6922ddf2d771a0efa55d (diff) | |
download | chromium_src-b504899244b4264994d4daae2bee660706dba652.zip chromium_src-b504899244b4264994d4daae2bee660706dba652.tar.gz chromium_src-b504899244b4264994d4daae2bee660706dba652.tar.bz2 |
Adds import/export of bookmarks to bookmarks.html file.
BUG=1649
TEST=bring up bookmark manager and try out import/export from the
tools menu. Note that import ALWAYS creates a new folder under
the 'Other bookmarks folder' with the name of Imported (x). This
is by design.
Review URL: http://codereview.chromium.org/9471
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer/importer.h')
-rw-r--r-- | chrome/browser/importer/importer.h | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h index a597879..4e57b64 100644 --- a/chrome/browser/importer/importer.h +++ b/chrome/browser/importer/importer.h @@ -27,7 +27,9 @@ enum ProfileType { MS_IE = 0, FIREFOX2, FIREFOX3, - GOOGLE_TOOLBAR5 + GOOGLE_TOOLBAR5, + // Identifies a 'bookmarks.html' file. + BOOKMARKS_HTML }; // An enumeration of the type of data we want to import. @@ -57,6 +59,18 @@ class Importer; // This object must be invoked on UI thread. class ProfileWriter : public base::RefCounted<ProfileWriter> { public: + // Used to identify how the bookmarks are added. + enum BookmarkOptions { + // Indicates the bookmark should only be added if unique. Uniqueness + // is done by title, url and path. That is, if this is passed to + // AddBookmarkEntry the bookmark is added only if there is no other + // URL with the same url, path and title. + ADD_IF_UNIQUE = 1 << 0, + + // Indicates the bookmarks are being added during first run. + FIRST_RUN = 1 << 1 + }; + explicit ProfileWriter(Profile* profile) : profile_(profile) { } virtual ~ProfileWriter() { } @@ -86,9 +100,21 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> { virtual void AddIE7PasswordInfo(const IE7PasswordInfo& info); virtual void AddHistoryPage(const std::vector<history::URLRow>& page); virtual void AddHomepage(const GURL& homepage); - virtual void AddBookmarkEntry( - const std::vector<BookmarkEntry>& bookmark, - bool check_uniqueness); + // Adds the bookmarks to the BookmarkModel. + // |options| is a bitmask of BookmarkOptions and dictates how and + // which bookmarks are added. If the bitmask contains FIRST_RUN, + // then any entries with a value of true for in_toolbar are added to + // the bookmark bar. If the bitmask does not contain FIRST_RUN then + // the folder name the bookmarks are added to is uniqued based on + // |first_folder_name|. For example, if |first_folder_name| is 'foo' + // and a folder with the name 'foo' already exists in the other + // bookmarks folder, then the folder name 'foo 2' is used. + // If |options| contains ADD_IF_UNIQUE, then the bookmark is added only + // if another bookmarks does not exist with the same title, path and + // url. + virtual void AddBookmarkEntry(const std::vector<BookmarkEntry>& bookmark, + const std::wstring& first_folder_name, + int options); virtual void AddFavicons( const std::vector<history::ImportedFavIconUsage>& favicons); // Add the TemplateURLs in |template_urls| to the local store and make the @@ -111,6 +137,19 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> { Profile* GetProfile() const { return profile_; } private: + // Generates a unique folder name. If folder_name is not unique, then this + // repeatedly tests for '|folder_name| + (i)' until a unique name is found. + std::wstring GenerateUniqueFolderName(BookmarkModel* model, + const std::wstring& folder_name); + + // Returns true if a bookmark exists with the same url, title and path + // as |entry|. |first_folder_name| is the name to use for the first + // path entry if |first_run| is true. + bool DoesBookmarkExist(BookmarkModel* model, + const BookmarkEntry& entry, + const std::wstring& first_folder_name, + bool first_run); + Profile* profile_; DISALLOW_EVIL_CONSTRUCTORS(ProfileWriter); @@ -290,12 +329,15 @@ class Importer : public base::RefCounted<Importer> { void set_first_run(bool first_run) { first_run_ = first_run; } + bool cancelled() const { return cancelled_; } + protected: Importer() : main_loop_(MessageLoop::current()), delagate_loop_(NULL), importer_host_(NULL), - cancelled_(false) {} + cancelled_(false), + first_run_(false) {} // Notifies the coordinator that the collection of data for the specified // item has begun. @@ -329,8 +371,6 @@ class Importer : public base::RefCounted<Importer> { static bool ReencodeFavicon(const unsigned char* src_data, size_t src_len, std::vector<unsigned char>* png_data); - bool cancelled() const { return cancelled_; } - bool first_run() const { return first_run_; } // The importer should know the main thread so that ProfileWriter @@ -359,6 +399,7 @@ class ImportObserver { public: virtual ~ImportObserver() {} // The import operation was canceled by the user. + // TODO (4164): this is never invoked, either rip it out or invoke it. virtual void ImportCanceled() = 0; // The import operation was completed successfully. @@ -380,4 +421,3 @@ void StartImportingWithUI(HWND parent_window, bool first_run); #endif // CHROME_BROWSER_IMPORTER_IMPORTER_H_ - |