diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-21 15:20:33 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-21 15:20:33 +0000 |
commit | f25387b62a3cccde48622d0b7fca57cd6fb16ab7 (patch) | |
tree | 06ac2c1972d6608fb65979c3a279a6d214fecc6c /chrome/browser/history/starred_url_database.h | |
parent | bcc682fc4f5050ac911635ab649fbd30002fc2b4 (diff) | |
download | chromium_src-f25387b62a3cccde48622d0b7fca57cd6fb16ab7.zip chromium_src-f25387b62a3cccde48622d0b7fca57cd6fb16ab7.tar.gz chromium_src-f25387b62a3cccde48622d0b7fca57cd6fb16ab7.tar.bz2 |
Moves bookmarks out of history into its own file (JSON).
Interesting points:
. Migration was a bit atypical. Here is the approach I took:
. If the URL db contains bookmarks it writes the bookmarks to a
temporary file.
. When the bookmark bar model is loaded it assumes bookmarks are
stored in a file. If the bookmarks file doesn't exist it then
attempts to load from history, after waiting for history to finish
processing tasks.
. I've broken having the omnibox query for starred only. This patch
was already too ginormous for me to contemplate this too. I'll return
to it after I land this.
. Similarly the history page isn't searching for starred titles
now. As we discussed with Glen, that is probably fine for now.
. I've converted NOTIFY_STARRED_FAVICON_CHANGED to
NOTIFY_FAVICON_CHANGED and it is notified ANY time a favicon
changes. I'm mildly concerned about the extra notifications, but
without having history know about starred it's the best I can do for
now.
. Autocomplete (specifically URLDatabase::AutocompleteForPrefix)
previously sorted by starred. It can no longer do this. I don't
think I can get this functionality back:( Luckily it only mattered
if you had a starred and non-starred URL with the same type count
that matched a query. Probably pretty rare.
What's left:
. Fix up HistoryContentsProvider to query for starred entries titles.
. Clean up the delete all case. I basically just made it compile; it
can be greatly simplified.
. Rename BookmarkBarModel to BookmarksModel.
BUG=1256202
TEST=this is a huge change to bookmarks. Thanfully it's pretty well
covered by tests, none-the-less make sure you exercise bookmarks
pretty heavily to make sure nothing is busted.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history/starred_url_database.h')
-rw-r--r-- | chrome/browser/history/starred_url_database.h | 151 |
1 files changed, 36 insertions, 115 deletions
diff --git a/chrome/browser/history/starred_url_database.h b/chrome/browser/history/starred_url_database.h index d58571d..e7a774f 100644 --- a/chrome/browser/history/starred_url_database.h +++ b/chrome/browser/history/starred_url_database.h @@ -44,12 +44,9 @@ class SqliteStatementCache; namespace history { -// Encapsulates a URL database plus starred information. -// -// WARNING: many of the following methods allow you to update, delete or -// insert starred entries specifying a visual order. These methods do NOT -// adjust the visual order of surrounding entries. You must explicitly do -// it yourself using AdjustStarredVisualOrder as appropriate. +// Bookmarks were originally part of the url database, they have since been +// moved to a separate file. This file exists purely for historical reasons and +// contains just enough to allow migration. class StarredURLDatabase : public URLDatabase { public: // Must call InitStarTable() AND any additional init functions provided by @@ -57,87 +54,22 @@ class StarredURLDatabase : public URLDatabase { StarredURLDatabase(); virtual ~StarredURLDatabase(); - // Returns the id of the starred entry. This does NOT return entry.id, - // rather the database is queried for the id based on entry.url or - // entry.group_id. - StarID GetStarIDForEntry(const StarredEntry& entry); - - // Returns the internal star ID for the externally-generated group ID. - StarID GetStarIDForGroupID(UIStarID group_id); - - // Gets the details for the specified star entry in entry. - bool GetStarredEntry(StarID star_id, StarredEntry* entry); - - // Creates a starred entry with the requested information. The structure will - // be updated with the ID of the newly created entry. The URL table will be - // updated to point to the entry. The URL row will be created if it doesn't - // exist. - // - // We currently only support one entry per URL. This URL should not already be - // starred when calling this function or it will fail and will return 0. - StarID CreateStarredEntry(StarredEntry* entry); - - // Returns starred entries. - // This returns three different result types: - // only_on_bookmark_bar == true: only those entries on the bookmark bar are - // returned. - // only_on_bookmark_bar == false and parent_id == 0: all starred - // entries/groups. - // otherwise only the direct children (groups and entries) of parent_id are - // returned. - bool GetStarredEntries(UIStarID parent_group_id, - std::vector<StarredEntry>* entries); - - // Deletes a starred entry. This adjusts the visual order of all siblings - // after the entry. The deleted entry(s) will be *appended* to - // |*deleted_entries| (so delete can be called more than once with the same - // list) and deleted URLs will additionally be added to the set. - // - // This function invokes DeleteStarredEntryImpl to do the actual work, which - // recurses. - void DeleteStarredEntry(StarID star_id, - std::set<GURL>* unstarred_urls, - std::vector<StarredEntry>* deleted_entries); - - // Implementation to update the database for UpdateStarredEntry. Returns true - // on success. If successful, the parent_id, url_id, id and date_added fields - // of the entry are reset from that of the database. - bool UpdateStarredEntry(StarredEntry* entry); - - // Gets up to max_count starred entries of type URL adding them to entries. - // The results are ordered by date added in descending order (most recent - // first). - void GetMostRecentStarredEntries(int max_count, - std::vector<StarredEntry>* entries); - - // Gets the URLIDs for all starred entries of type URL whose title matches - // the specified query. - void GetURLsForTitlesMatching(const std::wstring& query, - std::set<URLID>* ids); - - // Returns true if the starred table is in a sane state. If false, the starred - // table is likely corrupt and shouldn't be used. - bool is_starred_valid() const { return is_starred_valid_; } - - // Updates the URL ID for the given starred entry. This is used by the expirer - // when URL IDs change. It can't use UpdateStarredEntry since that doesn't - // set the URLID, and it does a bunch of other logic that we don't need. - bool UpdateURLIDForStar(StarID star_id, URLID new_url_id); - protected: // The unit tests poke our innards. friend class HistoryTest; + friend class StarredURLDatabaseTest; FRIEND_TEST(HistoryTest, CreateStarGroup); + // Writes bookmarks to the specified file. + bool MigrateBookmarksToFile(const std::wstring& path); + // Returns the database and statement cache for the functions in this // interface. The decendent of this class implements these functions to // return its objects. virtual sqlite3* GetDB() = 0; virtual SqliteStatementCache& GetStatementCache() = 0; - // Creates the starred tables if necessary. - bool InitStarTable(); - + private: // Makes sure the starred table is in a sane state. This does the following: // . Makes sure there is a bookmark bar and other nodes. If no bookmark bar // node is found, the table is dropped and recreated. @@ -155,17 +87,8 @@ class StarredURLDatabase : public URLDatabase { // This should be invoked after migration. bool EnsureStarredIntegrity(); - // Creates a starred entry with the specified parameters in the database. - // Returns the newly created id, or 0 on failure. - // - // WARNING: Does not update the visual order. - StarID CreateStarredEntryRow(URLID url_id, - UIStarID group_id, - UIStarID parent_group_id, - const std::wstring& title, - const Time& date_added, - int visual_order, - StarredEntry::Type type); + // Gets all the starred entries. + bool GetAllStarredEntries(std::vector<StarredEntry>* entries); // Sets the title, parent_id, parent_group_id, visual_order and date_modifed // of the specified star entry. @@ -185,26 +108,39 @@ class StarredURLDatabase : public URLDatabase { int start_visual_order, int delta); + // Creates a starred entry with the specified parameters in the database. + // Returns the newly created id, or 0 on failure. + // + // WARNING: Does not update the visual order. + StarID CreateStarredEntryRow(URLID url_id, + UIStarID group_id, + UIStarID parent_group_id, + const std::wstring& title, + const Time& date_added, + int visual_order, + StarredEntry::Type type); + // Deletes the entry from the starred database base on the starred id (NOT // the url id). // // WARNING: Does not update the visual order. bool DeleteStarredEntryRow(StarID star_id); - // Should the integrity of the starred table be checked on every mutation? - // Default is true. Set to false when running tests that need to allow the - // table to be in an invalid state while testing. - bool check_starred_integrity_on_mutation_; + // Gets the details for the specified star entry in entry. + bool GetStarredEntry(StarID star_id, StarredEntry* entry); + + // Creates a starred entry with the requested information. The structure will + // be updated with the ID of the newly created entry. The URL table will be + // updated to point to the entry. The URL row will be created if it doesn't + // exist. + // + // We currently only support one entry per URL. This URL should not already be + // starred when calling this function or it will fail and will return 0. + StarID CreateStarredEntry(StarredEntry* entry); - private: // Used when checking integrity of starred table. typedef ChromeViews::TreeNodeWithValue<history::StarredEntry> StarredNode; - // Implementation of DeleteStarredEntryImpl. - void DeleteStarredEntryImpl(StarID star_id, - std::set<GURL>* unstarred_urls, - std::vector<StarredEntry>* deleted_entries); - // Returns the max group id, or 0 if there is an error. UIStarID GetMaxGroupID(); @@ -262,24 +198,9 @@ class StarredURLDatabase : public URLDatabase { // needs to be moved. bool Move(StarredNode* source, StarredNode* new_parent); - // Drops and recreates the starred table as well as marking all URLs as - // unstarred. This is used as a last resort if the bookmarks table is - // totally corrupt. - bool RecreateStarredEntries(); - - // Iterates through the children of node make sure the visual order matches - // the order in node's children. DCHECKs if the order differs. This recurses. - void CheckVisualOrder(StarredNode* node); - - // Makes sure the starred table is in a sane state, if not this DCHECKs. - // This is invoked internally after any mutation to the starred table. - // - // This is a no-op in release builds. - void CheckStarredIntegrity(); - - // True if the starred table is valid. This is initialized in - // EnsureStarredIntegrityImpl. - bool is_starred_valid_; + // Does the work of migrating bookmarks to a temporary file that + // BookmarkStorage will read from. + bool MigrateBookmarksToFileImpl(const std::wstring& path); DISALLOW_EVIL_CONSTRUCTORS(StarredURLDatabase); }; |