diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-11 15:22:32 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-11 15:22:32 +0000 |
commit | d8e41ed4a55e60be60d47de5bbcb8a027e85a879 (patch) | |
tree | e0feaa030fe3834c0fc871de7564ef74e9595b05 /chrome/browser/bookmarks | |
parent | 7903e0262e2dda44eaa186d126cf88e2cc1470eb (diff) | |
download | chromium_src-d8e41ed4a55e60be60d47de5bbcb8a027e85a879.zip chromium_src-d8e41ed4a55e60be60d47de5bbcb8a027e85a879.tar.gz chromium_src-d8e41ed4a55e60be60d47de5bbcb8a027e85a879.tar.bz2 |
Renames BoomarkBarModel to BookmarkModel.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1912
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_codec.cc | 26 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_codec.h | 26 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_drag_data.cc | 8 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_drag_data.h | 10 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_drag_data_unittest.cc | 28 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.cc (renamed from chrome/browser/bookmarks/bookmark_bar_model.cc) | 193 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.h (renamed from chrome/browser/bookmarks/bookmark_bar_model.h) | 186 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model_unittest.cc (renamed from chrome/browser/bookmarks/bookmark_bar_model_unittest.cc) | 221 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_storage.cc | 4 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_storage.h | 11 |
10 files changed, 353 insertions, 360 deletions
diff --git a/chrome/browser/bookmarks/bookmark_codec.cc b/chrome/browser/bookmarks/bookmark_codec.cc index 93874f3..04acf49 100644 --- a/chrome/browser/bookmarks/bookmark_codec.cc +++ b/chrome/browser/bookmarks/bookmark_codec.cc @@ -6,7 +6,7 @@ #include "base/string_util.h" #include "base/values.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "googleurl/src/gurl.h" #include "generated_resources.h" @@ -30,12 +30,12 @@ static const wchar_t* kTypeFolder = L"folder"; // Current version of the file. static const int kCurrentVersion = 1; -Value* BookmarkCodec::Encode(BookmarkBarModel* model) { +Value* BookmarkCodec::Encode(BookmarkModel* model) { return Encode(model->GetBookmarkBarNode(), model->other_node()); } -Value* BookmarkCodec::Encode(BookmarkBarNode* bookmark_bar_node, - BookmarkBarNode* other_folder_node) { +Value* BookmarkCodec::Encode(BookmarkNode* bookmark_bar_node, + BookmarkNode* other_folder_node) { DictionaryValue* roots = new DictionaryValue(); roots->Set(kRootFolderNameKey, EncodeNode(bookmark_bar_node)); roots->Set(kOtherBookmarFolderNameKey, EncodeNode(other_folder_node)); @@ -46,7 +46,7 @@ Value* BookmarkCodec::Encode(BookmarkBarNode* bookmark_bar_node, return main; } -bool BookmarkCodec::Decode(BookmarkBarModel* model, const Value& value) { +bool BookmarkCodec::Decode(BookmarkModel* model, const Value& value) { if (value.GetType() != Value::TYPE_DICTIONARY) return false; // Unexpected type. @@ -88,7 +88,7 @@ bool BookmarkCodec::Decode(BookmarkBarModel* model, const Value& value) { return true; } -Value* BookmarkCodec::EncodeNode(BookmarkBarNode* node) { +Value* BookmarkCodec::EncodeNode(BookmarkNode* node) { DictionaryValue* value = new DictionaryValue(); value->SetString(kNameKey, node->GetTitle()); value->SetString(kDateAddedKey, @@ -111,9 +111,9 @@ Value* BookmarkCodec::EncodeNode(BookmarkBarNode* node) { return value; } -bool BookmarkCodec::DecodeChildren(BookmarkBarModel* model, +bool BookmarkCodec::DecodeChildren(BookmarkModel* model, const ListValue& child_value_list, - BookmarkBarNode* parent) { + BookmarkNode* parent) { for (size_t i = 0; i < child_value_list.GetSize(); ++i) { Value* child_value; if (!child_value_list.Get(i, &child_value)) @@ -130,10 +130,10 @@ bool BookmarkCodec::DecodeChildren(BookmarkBarModel* model, return true; } -bool BookmarkCodec::DecodeNode(BookmarkBarModel* model, +bool BookmarkCodec::DecodeNode(BookmarkModel* model, const DictionaryValue& value, - BookmarkBarNode* parent, - BookmarkBarNode* node) { + BookmarkNode* parent, + BookmarkNode* node) { bool created_node = (node == NULL); std::wstring title; if (!value.GetString(kNameKey, &title)) @@ -158,7 +158,7 @@ bool BookmarkCodec::DecodeNode(BookmarkBarModel* model, return false; // TODO(sky): this should ignore the node if not a valid URL. if (!node) - node = new BookmarkBarNode(model, GURL(url_string)); + node = new BookmarkNode(model, GURL(url_string)); if (parent) parent->Add(parent->GetChildCount(), node); node->type_ = history::StarredEntry::URL; @@ -175,7 +175,7 @@ bool BookmarkCodec::DecodeNode(BookmarkBarModel* model, return false; if (!node) - node = new BookmarkBarNode(model, GURL()); + node = new BookmarkNode(model, GURL()); node->type_ = history::StarredEntry::USER_GROUP; node->date_group_modified_ = Time::FromInternalValue(StringToInt64(last_modified_date)); diff --git a/chrome/browser/bookmarks/bookmark_codec.h b/chrome/browser/bookmarks/bookmark_codec.h index 1470f2c..2865514 100644 --- a/chrome/browser/bookmarks/bookmark_codec.h +++ b/chrome/browser/bookmarks/bookmark_codec.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// BookmarkCodec is responsible for encoding and decoding the BookmarkBarModel +// BookmarkCodec is responsible for encoding and decoding the BookmarkModel // into JSON values. The encoded values are written to disk via the // BookmarkService. @@ -11,8 +11,8 @@ #include "base/basictypes.h" -class BookmarkBarModel; -class BookmarkBarNode; +class BookmarkModel; +class BookmarkNode; class DictionaryValue; class ListValue; class Value; @@ -28,38 +28,38 @@ class BookmarkCodec { // returned object. This is invoked to encode the contents of the bookmark bar // model and is currently a convenience to invoking Encode that takes the // bookmark bar node and other folder node. - Value* Encode(BookmarkBarModel* model); + Value* Encode(BookmarkModel* model); // Encodes the bookmark bar and other folders returning the JSON value. It's // up to the caller to delete the returned object. // This method is public for use by StarredURLDatabase in migrating the // bookmarks out of the database. - Value* Encode(BookmarkBarNode* bookmark_bar_node, - BookmarkBarNode* other_folder_node); + Value* Encode(BookmarkNode* bookmark_bar_node, + BookmarkNode* other_folder_node); // Decodes the previously encoded value to the specified model. Returns true // on success, false otherwise. If there is an error (such as unexpected // version) all children are removed from the bookmark bar and other folder // nodes. - bool Decode(BookmarkBarModel* model, const Value& value); + bool Decode(BookmarkModel* model, const Value& value); private: // Encodes node and all its children into a Value object and returns it. // The caller takes ownership of the returned object. - Value* EncodeNode(BookmarkBarNode* node); + Value* EncodeNode(BookmarkNode* node); // Decodes the children of the specified node. Returns true on success. - bool DecodeChildren(BookmarkBarModel* model, + bool DecodeChildren(BookmarkModel* model, const ListValue& child_value_list, - BookmarkBarNode* parent); + BookmarkNode* parent); // Decodes the supplied node from the supplied value. Child nodes are // created appropriately by way of DecodeChildren. If node is NULL a new // node is created and added to parent, otherwise node is used. - bool DecodeNode(BookmarkBarModel* model, + bool DecodeNode(BookmarkModel* model, const DictionaryValue& value, - BookmarkBarNode* parent, - BookmarkBarNode* node); + BookmarkNode* parent, + BookmarkNode* node); DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); }; diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc index 61c9ccc..996470c 100644 --- a/chrome/browser/bookmarks/bookmark_drag_data.cc +++ b/chrome/browser/bookmarks/bookmark_drag_data.cc @@ -5,7 +5,7 @@ #include "chrome/browser/bookmarks/bookmark_drag_data.h" #include "base/pickle.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/common/os_exchange_data.h" static CLIPFORMAT clipboard_format = 0; @@ -20,7 +20,7 @@ static void RegisterFormat() { BookmarkDragData::BookmarkDragData() : is_url(false), is_valid(false) { } -BookmarkDragData::BookmarkDragData(BookmarkBarNode* node) +BookmarkDragData::BookmarkDragData(BookmarkNode* node) : is_url(node->GetType() == history::StarredEntry::URL), url(node->GetURL()), title(node->GetTitle()), @@ -62,7 +62,7 @@ bool BookmarkDragData::Read(const OSExchangeData& data) { return is_valid; } -BookmarkBarNode* BookmarkDragData::GetNode(BookmarkBarModel* model) const { +BookmarkNode* BookmarkDragData::GetNode(BookmarkModel* model) const { DCHECK(!is_url && id_ && is_valid); return model->GetNodeByID(id_); } @@ -111,7 +111,7 @@ bool BookmarkDragData::ReadFromPickle(Pickle* pickle, void** iterator) { return true; } -void BookmarkDragData::AddChildren(BookmarkBarNode* node) { +void BookmarkDragData::AddChildren(BookmarkNode* node) { for (int i = 0, max = node->GetChildCount(); i < max; ++i) children.push_back(BookmarkDragData(node->GetChild(i))); } diff --git a/chrome/browser/bookmarks/bookmark_drag_data.h b/chrome/browser/bookmarks/bookmark_drag_data.h index fd967eb..c7e1fed 100644 --- a/chrome/browser/bookmarks/bookmark_drag_data.h +++ b/chrome/browser/bookmarks/bookmark_drag_data.h @@ -10,8 +10,8 @@ #include "chrome/browser/history/history.h" #include "googleurl/src/gurl.h" -class BookmarkBarModel; -class BookmarkBarNode; +class BookmarkModel; +class BookmarkNode; class OSExchangeData; class Pickle; @@ -32,7 +32,7 @@ struct BookmarkDragData { BookmarkDragData(); // Created a BookmarkDragData populated from node. - explicit BookmarkDragData(BookmarkBarNode* node); + explicit BookmarkDragData(BookmarkNode* node); // Writes this BookmarkDragData to data. If BookmarkDragData is a URL, // this writes out the URL and URL title clipboard data as well. @@ -45,7 +45,7 @@ struct BookmarkDragData { // path can not be found, NULL is returned. // // This is only valid for groups. - BookmarkBarNode* BookmarkDragData::GetNode(BookmarkBarModel* model) const; + BookmarkNode* BookmarkDragData::GetNode(BookmarkModel* model) const; // If true, this entry represents a StarredEntry of type URL. bool is_url; @@ -72,7 +72,7 @@ struct BookmarkDragData { bool ReadFromPickle(Pickle* pickle, void** iterator); // Adds to children an entry for each child of node. - void AddChildren(BookmarkBarNode* node); + void AddChildren(BookmarkNode* node); // ID (node->id()) of the node this BookmarkDragData was created from. int id_; diff --git a/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc b/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc index 4ebe7b0..76f0f67 100644 --- a/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "base/scoped_ptr.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" #include "chrome/browser/bookmarks/bookmark_drag_data.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/common/os_exchange_data.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -25,12 +25,12 @@ TEST_F(BookmarkDragDataTest, BogusRead) { } TEST_F(BookmarkDragDataTest, URL) { - BookmarkBarModel model(NULL); - BookmarkBarNode* root = model.GetBookmarkBarNode(); + BookmarkModel model(NULL); + BookmarkNode* root = model.GetBookmarkBarNode(); GURL url(GURL("http://foo.com")); const std::wstring profile_id(L"blah"); const std::wstring title(L"blah"); - BookmarkBarNode* node = model.AddURL(root, 0, title, url); + BookmarkNode* node = model.AddURL(root, 0, title, url); BookmarkDragData drag_data(node); drag_data.profile_id = profile_id; EXPECT_TRUE(drag_data.url == url); @@ -58,11 +58,11 @@ TEST_F(BookmarkDragDataTest, URL) { } TEST_F(BookmarkDragDataTest, Group) { - BookmarkBarModel model(NULL); - BookmarkBarNode* root = model.GetBookmarkBarNode(); - BookmarkBarNode* g1 = model.AddGroup(root, 0, L"g1"); - BookmarkBarNode* g11 = model.AddGroup(g1, 0, L"g11"); - BookmarkBarNode* g12 = model.AddGroup(g1, 0, L"g12"); + BookmarkModel model(NULL); + BookmarkNode* root = model.GetBookmarkBarNode(); + BookmarkNode* g1 = model.AddGroup(root, 0, L"g1"); + BookmarkNode* g11 = model.AddGroup(g1, 0, L"g11"); + BookmarkNode* g12 = model.AddGroup(g1, 0, L"g12"); BookmarkDragData drag_data(g12); const std::wstring profile_id(L"blah"); @@ -82,14 +82,14 @@ TEST_F(BookmarkDragDataTest, Group) { EXPECT_TRUE(read_data.is_valid); EXPECT_FALSE(read_data.is_url); - BookmarkBarNode* r_g12 = read_data.GetNode(&model); + BookmarkNode* r_g12 = read_data.GetNode(&model); EXPECT_TRUE(g12 == r_g12); } TEST_F(BookmarkDragDataTest, GroupWithChild) { - BookmarkBarModel model(NULL); - BookmarkBarNode* root = model.GetBookmarkBarNode(); - BookmarkBarNode* group = model.AddGroup(root, 0, L"g1"); + BookmarkModel model(NULL); + BookmarkNode* root = model.GetBookmarkBarNode(); + BookmarkNode* group = model.AddGroup(root, 0, L"g1"); GURL url(GURL("http://foo.com")); const std::wstring profile_id(L"blah"); @@ -115,6 +115,6 @@ TEST_F(BookmarkDragDataTest, GroupWithChild) { EXPECT_TRUE(url == read_data.children[0].url); EXPECT_TRUE(read_data.children[0].is_url); - BookmarkBarNode* r_group = read_data.GetNode(&model); + BookmarkNode* r_group = read_data.GetNode(&model); EXPECT_TRUE(group == r_group); } diff --git a/chrome/browser/bookmarks/bookmark_bar_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index df35fe5..7ddae40 100644 --- a/chrome/browser/bookmarks/bookmark_bar_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "base/gfx/png_decoder.h" #include "chrome/browser/bookmarks/bookmark_storage.h" @@ -15,27 +15,27 @@ namespace { // Functions used for sorting. -bool MoreRecentlyModified(BookmarkBarNode* n1, BookmarkBarNode* n2) { +bool MoreRecentlyModified(BookmarkNode* n1, BookmarkNode* n2) { return n1->date_group_modified() > n2->date_group_modified(); } -bool MoreRecentlyAdded(BookmarkBarNode* n1, BookmarkBarNode* n2) { +bool MoreRecentlyAdded(BookmarkNode* n1, BookmarkNode* n2) { return n1->date_added() > n2->date_added(); } } // namespace -// BookmarkBarNode ------------------------------------------------------------ +// BookmarkNode --------------------------------------------------------------- namespace { -// ID for BookmarkBarNodes. +// ID for BookmarkNodes. // Various places assume an invalid id if == 0, for that reason we start with 1. int next_id_ = 1; } -const SkBitmap& BookmarkBarNode::GetFavIcon() { +const SkBitmap& BookmarkNode::GetFavIcon() { if (!loaded_favicon_) { loaded_favicon_ = true; model_->LoadFavIcon(this); @@ -43,7 +43,7 @@ const SkBitmap& BookmarkBarNode::GetFavIcon() { return favicon_; } -BookmarkBarNode::BookmarkBarNode(BookmarkBarModel* model, const GURL& url) +BookmarkNode::BookmarkNode(BookmarkModel* model, const GURL& url) : model_(model), id_(next_id_++), loaded_favicon_(false), @@ -54,7 +54,7 @@ BookmarkBarNode::BookmarkBarNode(BookmarkBarModel* model, const GURL& url) date_added_(Time::Now()) { } -void BookmarkBarNode::Reset(const history::StarredEntry& entry) { +void BookmarkNode::Reset(const history::StarredEntry& entry) { DCHECK(entry.type != history::StarredEntry::URL || entry.url == url_); @@ -65,9 +65,9 @@ void BookmarkBarNode::Reset(const history::StarredEntry& entry) { SetTitle(entry.title); } -// BookmarkBarModel ----------------------------------------------------------- +// BookmarkModel -------------------------------------------------------------- -BookmarkBarModel::BookmarkBarModel(Profile* profile) +BookmarkModel::BookmarkModel(Profile* profile) : profile_(profile), loaded_(false), #pragma warning(suppress: 4355) // Okay to pass "this" here. @@ -77,7 +77,7 @@ BookmarkBarModel::BookmarkBarModel(Profile* profile) waiting_for_history_load_(false), loaded_signal_(CreateEvent(NULL, TRUE, FALSE, NULL)) { // Create the bookmark bar and other bookmarks folders. These always exist. - CreateBookmarkBarNode(); + CreateBookmarkNode(); CreateOtherBookmarksNode(); // And add them to the root. @@ -93,7 +93,7 @@ BookmarkBarModel::BookmarkBarModel(Profile* profile) } } -BookmarkBarModel::~BookmarkBarModel() { +BookmarkModel::~BookmarkModel() { if (profile_ && store_.get()) { NotificationService::current()->RemoveObserver( this, NOTIFY_FAVICON_CHANGED, Source<Profile>(profile_)); @@ -104,7 +104,7 @@ BookmarkBarModel::~BookmarkBarModel() { this, NOTIFY_HISTORY_LOADED, Source<Profile>(profile_)); } - FOR_EACH_OBSERVER(BookmarkBarModelObserver, observers_, + FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, BookmarkModelBeingDeleted(this)); if (store_) { @@ -114,7 +114,7 @@ BookmarkBarModel::~BookmarkBarModel() { } } -void BookmarkBarModel::Load() { +void BookmarkModel::Load() { if (store_.get()) { // If the store is non-null, it means Load was already invoked. Load should // only be invoked once. @@ -132,16 +132,16 @@ void BookmarkBarModel::Load() { store_->LoadBookmarks(false); } -BookmarkBarNode* BookmarkBarModel::GetParentForNewNodes() { - std::vector<BookmarkBarNode*> nodes; +BookmarkNode* BookmarkModel::GetParentForNewNodes() { + std::vector<BookmarkNode*> nodes; GetMostRecentlyModifiedGroupNodes(&root_, 1, &nodes); return nodes.empty() ? bookmark_bar_node_ : nodes[0]; } -std::vector<BookmarkBarNode*> BookmarkBarModel::GetMostRecentlyModifiedGroups( +std::vector<BookmarkNode*> BookmarkModel::GetMostRecentlyModifiedGroups( size_t max_count) { - std::vector<BookmarkBarNode*> nodes; + std::vector<BookmarkNode*> nodes; GetMostRecentlyModifiedGroupNodes(&root_, max_count, &nodes); if (nodes.size() < max_count) { @@ -157,13 +157,13 @@ std::vector<BookmarkBarNode*> BookmarkBarModel::GetMostRecentlyModifiedGroups( return nodes; } -void BookmarkBarModel::GetMostRecentlyAddedEntries( +void BookmarkModel::GetMostRecentlyAddedEntries( size_t count, - std::vector<BookmarkBarNode*>* nodes) { + std::vector<BookmarkNode*>* nodes) { AutoLock url_lock(url_lock_); for (NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.begin(); i != nodes_ordered_by_url_set_.end(); ++i) { - std::vector<BookmarkBarNode*>::iterator insert_position = + std::vector<BookmarkNode*>::iterator insert_position = std::upper_bound(nodes->begin(), nodes->end(), *i, &MoreRecentlyAdded); if (nodes->size() < count || insert_position != nodes->end()) { nodes->insert(insert_position, *i); @@ -173,7 +173,7 @@ void BookmarkBarModel::GetMostRecentlyAddedEntries( } } -void BookmarkBarModel::GetBookmarksMatchingText( +void BookmarkModel::GetBookmarksMatchingText( const std::wstring& text, size_t max_count, std::vector<TitleMatch>* matches) { @@ -198,7 +198,7 @@ void BookmarkBarModel::GetBookmarksMatchingText( } } -void BookmarkBarModel::Remove(BookmarkBarNode* parent, int index) { +void BookmarkModel::Remove(BookmarkNode* parent, int index) { if (!loaded_ || !IsValidIndex(parent, index, false) || parent == &root_) { NOTREACHED(); return; @@ -206,9 +206,9 @@ void BookmarkBarModel::Remove(BookmarkBarNode* parent, int index) { RemoveAndDeleteNode(parent->GetChild(index)); } -void BookmarkBarModel::Move(BookmarkBarNode* node, - BookmarkBarNode* new_parent, - int index) { +void BookmarkModel::Move(BookmarkNode* node, + BookmarkNode* new_parent, + int index) { if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) || new_parent == &root_ || node == &root_ || node == bookmark_bar_node_ || node == other_node_) { @@ -224,7 +224,7 @@ void BookmarkBarModel::Move(BookmarkBarNode* node, SetDateGroupModified(new_parent, Time::Now()); - BookmarkBarNode* old_parent = node->GetParent(); + BookmarkNode* old_parent = node->GetParent(); int old_index = old_parent->IndexOfChild(node); if (old_parent == new_parent && @@ -240,13 +240,13 @@ void BookmarkBarModel::Move(BookmarkBarNode* node, if (store_.get()) store_->ScheduleSave(); - FOR_EACH_OBSERVER(BookmarkBarModelObserver, observers_, + FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, BookmarkNodeMoved(this, old_parent, old_index, new_parent, index)); } -void BookmarkBarModel::SetTitle(BookmarkBarNode* node, - const std::wstring& title) { +void BookmarkModel::SetTitle(BookmarkNode* node, + const std::wstring& title) { if (!node) { NOTREACHED(); return; @@ -259,18 +259,18 @@ void BookmarkBarModel::SetTitle(BookmarkBarNode* node, if (store_.get()) store_->ScheduleSave(); - FOR_EACH_OBSERVER(BookmarkBarModelObserver, observers_, + FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, BookmarkNodeChanged(this, node)); } -BookmarkBarNode* BookmarkBarModel::GetNodeByURL(const GURL& url) { +BookmarkNode* BookmarkModel::GetNodeByURL(const GURL& url) { AutoLock url_lock(url_lock_); - BookmarkBarNode tmp_node(this, url); + BookmarkNode tmp_node(this, url); NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.find(&tmp_node); return (i != nodes_ordered_by_url_set_.end()) ? *i : NULL; } -void BookmarkBarModel::GetBookmarks(std::vector<GURL>* urls) { +void BookmarkModel::GetBookmarks(std::vector<GURL>* urls) { AutoLock url_lock(url_lock_); for (NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.begin(); i != nodes_ordered_by_url_set_.end(); ++i) { @@ -278,13 +278,13 @@ void BookmarkBarModel::GetBookmarks(std::vector<GURL>* urls) { } } -BookmarkBarNode* BookmarkBarModel::GetNodeByID(int id) { +BookmarkNode* BookmarkModel::GetNodeByID(int id) { // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. return GetNodeByID(&root_, id); } -BookmarkBarNode* BookmarkBarModel::AddGroup( - BookmarkBarNode* parent, +BookmarkNode* BookmarkModel::AddGroup( + BookmarkNode* parent, int index, const std::wstring& title) { if (!loaded_ || parent == &root_ || !IsValidIndex(parent, index, true)) { @@ -293,22 +293,22 @@ BookmarkBarNode* BookmarkBarModel::AddGroup( return NULL; } - BookmarkBarNode* new_node = new BookmarkBarNode(this, GURL()); + BookmarkNode* new_node = new BookmarkNode(this, GURL()); new_node->SetTitle(title); new_node->type_ = history::StarredEntry::USER_GROUP; return AddNode(parent, index, new_node); } -BookmarkBarNode* BookmarkBarModel::AddURL(BookmarkBarNode* parent, - int index, - const std::wstring& title, - const GURL& url) { +BookmarkNode* BookmarkModel::AddURL(BookmarkNode* parent, + int index, + const std::wstring& title, + const GURL& url) { return AddURLWithCreationTime(parent, index, title, url, Time::Now()); } -BookmarkBarNode* BookmarkBarModel::AddURLWithCreationTime( - BookmarkBarNode* parent, +BookmarkNode* BookmarkModel::AddURLWithCreationTime( + BookmarkNode* parent, int index, const std::wstring& title, const GURL& url, @@ -319,7 +319,7 @@ BookmarkBarNode* BookmarkBarModel::AddURLWithCreationTime( return NULL; } - BookmarkBarNode* existing_node = GetNodeByURL(url); + BookmarkNode* existing_node = GetNodeByURL(url); if (existing_node) { Move(existing_node, parent, index); SetTitle(existing_node, title); @@ -328,7 +328,7 @@ BookmarkBarNode* BookmarkBarModel::AddURLWithCreationTime( SetDateGroupModified(parent, creation_time); - BookmarkBarNode* new_node = new BookmarkBarNode(this, url); + BookmarkNode* new_node = new BookmarkNode(this, url); new_node->SetTitle(title); new_node->date_added_ = creation_time; new_node->type_ = history::StarredEntry::URL; @@ -339,31 +339,31 @@ BookmarkBarNode* BookmarkBarModel::AddURLWithCreationTime( return AddNode(parent, index, new_node); } -void BookmarkBarModel::SetURLStarred(const GURL& url, - const std::wstring& title, - bool is_starred) { - BookmarkBarNode* node = GetNodeByURL(url); +void BookmarkModel::SetURLStarred(const GURL& url, + const std::wstring& title, + bool is_starred) { + BookmarkNode* node = GetNodeByURL(url); if (is_starred && !node) { // Add the url. - BookmarkBarNode* parent = GetParentForNewNodes(); + BookmarkNode* parent = GetParentForNewNodes(); AddURL(parent, parent->GetChildCount(), title, url); } else if (!is_starred && node) { Remove(node->GetParent(), node->GetParent()->IndexOfChild(node)); } } -void BookmarkBarModel::ResetDateGroupModified(BookmarkBarNode* node) { +void BookmarkModel::ResetDateGroupModified(BookmarkNode* node) { SetDateGroupModified(node, Time()); } -void BookmarkBarModel::FavIconLoaded(BookmarkBarNode* node) { +void BookmarkModel::FavIconLoaded(BookmarkNode* node) { // Send out notification to the observer. - FOR_EACH_OBSERVER(BookmarkBarModelObserver, observers_, + FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, BookmarkNodeFavIconLoaded(this, node)); } -void BookmarkBarModel::RemoveNode(BookmarkBarNode* node, - std::set<GURL>* removed_urls) { +void BookmarkModel::RemoveNode(BookmarkNode* node, + std::set<GURL>* removed_urls) { if (!loaded_ || !node || node == &root_ || node == bookmark_bar_node_ || node == other_node_) { NOTREACHED(); @@ -386,7 +386,7 @@ void BookmarkBarModel::RemoveNode(BookmarkBarNode* node, RemoveNode(node->GetChild(i), removed_urls); } -void BookmarkBarModel::OnBookmarkStorageLoadedBookmarks( +void BookmarkModel::OnBookmarkStorageLoadedBookmarks( bool file_exists, bool loaded_from_history) { if (loaded_) { @@ -426,7 +426,7 @@ void BookmarkBarModel::OnBookmarkStorageLoadedBookmarks( } } -void BookmarkBarModel::OnHistoryDone() { +void BookmarkModel::OnHistoryDone() { if (loaded_) { NOTREACHED(); return; @@ -437,7 +437,7 @@ void BookmarkBarModel::OnHistoryDone() { store_->LoadBookmarks(true); } -void BookmarkBarModel::DoneLoading() { +void BookmarkModel::DoneLoading() { { AutoLock url_lock(url_lock_); // Update nodes_ordered_by_url_set_ from the nodes. @@ -451,7 +451,7 @@ void BookmarkBarModel::DoneLoading() { // Notify our direct observers. - FOR_EACH_OBSERVER(BookmarkBarModelObserver, observers_, Loaded(this)); + FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, Loaded(this)); // And generic notification. NotificationService::current()->Notify( @@ -460,10 +460,10 @@ void BookmarkBarModel::DoneLoading() { NotificationService::NoDetails()); } -void BookmarkBarModel::RemoveAndDeleteNode(BookmarkBarNode* delete_me) { - scoped_ptr<BookmarkBarNode> node(delete_me); +void BookmarkModel::RemoveAndDeleteNode(BookmarkNode* delete_me) { + scoped_ptr<BookmarkNode> node(delete_me); - BookmarkBarNode* parent = node->GetParent(); + BookmarkNode* parent = node->GetParent(); DCHECK(parent); int index = parent->IndexOfChild(node.get()); parent->Remove(index); @@ -476,7 +476,7 @@ void BookmarkBarModel::RemoveAndDeleteNode(BookmarkBarNode* delete_me) { if (store_.get()) store_->ScheduleSave(); - FOR_EACH_OBSERVER(BookmarkBarModelObserver, observers_, + FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, BookmarkNodeRemoved(this, parent, index)); if (profile_) { @@ -491,15 +491,15 @@ void BookmarkBarModel::RemoveAndDeleteNode(BookmarkBarNode* delete_me) { Details<history::URLsStarredDetails>(&details)); } -BookmarkBarNode* BookmarkBarModel::AddNode(BookmarkBarNode* parent, - int index, - BookmarkBarNode* node) { +BookmarkNode* BookmarkModel::AddNode(BookmarkNode* parent, + int index, + BookmarkNode* node) { parent->Add(index, node); if (store_.get()) store_->ScheduleSave(); - FOR_EACH_OBSERVER(BookmarkBarModelObserver, observers_, + FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, BookmarkNodeAdded(this, parent, index)); if (node->GetType() == history::StarredEntry::URL) { @@ -512,34 +512,33 @@ BookmarkBarNode* BookmarkBarModel::AddNode(BookmarkBarNode* parent, return node; } -void BookmarkBarModel::BlockTillLoaded() { +void BookmarkModel::BlockTillLoaded() { if (loaded_signal_.Get()) WaitForSingleObject(loaded_signal_.Get(), INFINITE); } -BookmarkBarNode* BookmarkBarModel::GetNodeByID(BookmarkBarNode* node, - int id) { +BookmarkNode* BookmarkModel::GetNodeByID(BookmarkNode* node, int id) { if (node->id() == id) return node; for (int i = 0; i < node->GetChildCount(); ++i) { - BookmarkBarNode* result = GetNodeByID(node->GetChild(i), id); + BookmarkNode* result = GetNodeByID(node->GetChild(i), id); if (result) return result; } return NULL; } -bool BookmarkBarModel::IsValidIndex(BookmarkBarNode* parent, - int index, - bool allow_end) { +bool BookmarkModel::IsValidIndex(BookmarkNode* parent, + int index, + bool allow_end) { return (parent && (index >= 0 && (index < parent->GetChildCount() || (allow_end && index == parent->GetChildCount())))); } -void BookmarkBarModel::SetDateGroupModified(BookmarkBarNode* parent, - const Time time) { +void BookmarkModel::SetDateGroupModified(BookmarkNode* parent, + const Time time) { DCHECK(parent); parent->date_group_modified_ = time; @@ -547,23 +546,23 @@ void BookmarkBarModel::SetDateGroupModified(BookmarkBarNode* parent, store_->ScheduleSave(); } -void BookmarkBarModel::CreateBookmarkBarNode() { +void BookmarkModel::CreateBookmarkNode() { history::StarredEntry entry; entry.type = history::StarredEntry::BOOKMARK_BAR; bookmark_bar_node_ = CreateRootNodeFromStarredEntry(entry); } -void BookmarkBarModel::CreateOtherBookmarksNode() { +void BookmarkModel::CreateOtherBookmarksNode() { history::StarredEntry entry; entry.type = history::StarredEntry::OTHER; other_node_ = CreateRootNodeFromStarredEntry(entry); } -BookmarkBarNode* BookmarkBarModel::CreateRootNodeFromStarredEntry( +BookmarkNode* BookmarkModel::CreateRootNodeFromStarredEntry( const history::StarredEntry& entry) { DCHECK(entry.type == history::StarredEntry::BOOKMARK_BAR || entry.type == history::StarredEntry::OTHER); - BookmarkBarNode* node = new BookmarkBarNode(this, GURL()); + BookmarkNode* node = new BookmarkNode(this, GURL()); node->Reset(entry); if (entry.type == history::StarredEntry::BOOKMARK_BAR) node->SetTitle(l10n_util::GetString(IDS_BOOMARK_BAR_FOLDER_NAME)); @@ -572,14 +571,14 @@ BookmarkBarNode* BookmarkBarModel::CreateRootNodeFromStarredEntry( return node; } -void BookmarkBarModel::OnFavIconDataAvailable( +void BookmarkModel::OnFavIconDataAvailable( HistoryService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, GURL icon_url) { SkBitmap fav_icon; - BookmarkBarNode* node = + BookmarkNode* node = load_consumer_.GetClientData( profile_->GetHistoryService(Profile::EXPLICIT_ACCESS), handle); DCHECK(node); @@ -591,7 +590,7 @@ void BookmarkBarModel::OnFavIconDataAvailable( } } -void BookmarkBarModel::LoadFavIcon(BookmarkBarNode* node) { +void BookmarkModel::LoadFavIcon(BookmarkNode* node) { if (node->GetType() != history::StarredEntry::URL) return; @@ -603,12 +602,12 @@ void BookmarkBarModel::LoadFavIcon(BookmarkBarNode* node) { HistoryService::Handle handle = history_service->GetFavIconForURL( node->GetURL(), &load_consumer_, - NewCallback(this, &BookmarkBarModel::OnFavIconDataAvailable)); + NewCallback(this, &BookmarkModel::OnFavIconDataAvailable)); load_consumer_.SetClientData(history_service, handle, node); node->favicon_load_handle_ = handle; } -void BookmarkBarModel::CancelPendingFavIconLoadRequests(BookmarkBarNode* node) { +void BookmarkModel::CancelPendingFavIconLoadRequests(BookmarkNode* node) { if (node->favicon_load_handle_) { HistoryService* history = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); @@ -618,16 +617,16 @@ void BookmarkBarModel::CancelPendingFavIconLoadRequests(BookmarkBarNode* node) { } } -void BookmarkBarModel::GetMostRecentlyModifiedGroupNodes( - BookmarkBarNode* parent, +void BookmarkModel::GetMostRecentlyModifiedGroupNodes( + BookmarkNode* parent, size_t count, - std::vector<BookmarkBarNode*>* nodes) { + std::vector<BookmarkNode*>* nodes) { if (parent != &root_ && parent->is_folder() && parent->date_group_modified() > Time()) { if (count == 0) { nodes->push_back(parent); } else { - std::vector<BookmarkBarNode*>::iterator i = + std::vector<BookmarkNode*>::iterator i = std::upper_bound(nodes->begin(), nodes->end(), parent, &MoreRecentlyModified); if (nodes->size() < count || i != nodes->end()) { @@ -639,27 +638,27 @@ void BookmarkBarModel::GetMostRecentlyModifiedGroupNodes( } // else case, the root node, which we don't care about or imported nodes // (which have a time of 0). for (int i = 0; i < parent->GetChildCount(); ++i) { - BookmarkBarNode* child = parent->GetChild(i); + BookmarkNode* child = parent->GetChild(i); if (child->is_folder()) GetMostRecentlyModifiedGroupNodes(child, count, nodes); } } -void BookmarkBarModel::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { +void BookmarkModel::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { switch (type) { case NOTIFY_FAVICON_CHANGED: { // Prevent the observers from getting confused for multiple favicon loads. Details<history::FavIconChangeDetails> favicon_details(details); for (std::set<GURL>::const_iterator i = favicon_details->urls.begin(); i != favicon_details->urls.end(); ++i) { - BookmarkBarNode* node = GetNodeByURL(*i); + BookmarkNode* node = GetNodeByURL(*i); if (node) { // Got an updated favicon, for a URL, do a new request. node->InvalidateFavicon(); CancelPendingFavIconLoadRequests(node); - FOR_EACH_OBSERVER(BookmarkBarModelObserver, observers_, + FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, BookmarkNodeChanged(this, node)); } } @@ -684,7 +683,7 @@ void BookmarkBarModel::Observe(NotificationType type, } } -void BookmarkBarModel::PopulateNodesByURL(BookmarkBarNode* node) { +void BookmarkModel::PopulateNodesByURL(BookmarkNode* node) { // NOTE: this is called with url_lock_ already held. As such, this doesn't // explicitly grab the lock. if (node->is_url()) diff --git a/chrome/browser/bookmarks/bookmark_bar_model.h b/chrome/browser/bookmarks/bookmark_model.h index 25c19ad..e20349d 100644 --- a/chrome/browser/bookmarks/bookmark_bar_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -18,7 +18,7 @@ #include "googleurl/src/gurl.h" #include "skia/include/SkBitmap.h" -class BookmarkBarModel; +class BookmarkModel; class BookmarkCodec; class Profile; @@ -26,21 +26,20 @@ namespace history { class StarredURLDatabase; } -// BookmarkBarNode ------------------------------------------------------------ +// BookmarkNode --------------------------------------------------------------- -// BookmarkBarNode contains information about a starred entry: title, URL, -// favicon, star id and type. BookmarkBarNodes are returned from a -// BookmarkBarModel. +// BookmarkNode contains information about a starred entry: title, URL, favicon, +// star id and type. BookmarkNodes are returned from a BookmarkModel. // -class BookmarkBarNode : public ChromeViews::TreeNode<BookmarkBarNode> { - friend class BookmarkBarModel; +class BookmarkNode : public ChromeViews::TreeNode<BookmarkNode> { + friend class BookmarkModel; friend class BookmarkCodec; friend class history::StarredURLDatabase; - FRIEND_TEST(BookmarkBarModelTest, MostRecentlyAddedEntries); + FRIEND_TEST(BookmarkModelTest, MostRecentlyAddedEntries); public: - BookmarkBarNode(BookmarkBarModel* model, const GURL& url); - virtual ~BookmarkBarNode() {} + BookmarkNode(BookmarkModel* model, const GURL& url); + virtual ~BookmarkNode() {} // Returns the favicon for the this node. If the favicon has not yet been // loaded it is loaded and the observer of the model notified when done. @@ -86,7 +85,7 @@ class BookmarkBarNode : public ChromeViews::TreeNode<BookmarkBarNode> { void Reset(const history::StarredEntry& entry); // The model. This is NULL when created by StarredURLDatabase for migration. - BookmarkBarModel* model_; + BookmarkModel* model_; // Unique identifier for this node. const int id_; @@ -101,7 +100,7 @@ class BookmarkBarNode : public ChromeViews::TreeNode<BookmarkBarNode> { // from the HistoryService. HistoryService::Handle favicon_load_handle_; - // The URL. BookmarkBarModel maintains maps off this URL, it is important that + // The URL. BookmarkModel maintains maps off this URL, it is important that // it not change once the node has been created. const GURL url_; @@ -115,102 +114,101 @@ class BookmarkBarNode : public ChromeViews::TreeNode<BookmarkBarNode> { // Time last modified. Only used for groups. Time date_group_modified_; - DISALLOW_EVIL_CONSTRUCTORS(BookmarkBarNode); + DISALLOW_EVIL_CONSTRUCTORS(BookmarkNode); }; +// BookmarkModelObserver ------------------------------------------------------ -// BookmarkBarModelObserver --------------------------------------------------- - -// Observer for the BookmarkBarModel. +// Observer for the BookmarkModel. // -class BookmarkBarModelObserver { +class BookmarkModelObserver { public: // Invoked when the model has finished loading. - virtual void Loaded(BookmarkBarModel* model) = 0; + virtual void Loaded(BookmarkModel* model) = 0; - // Invoked from the destructor of the BookmarkBarModel. - virtual void BookmarkModelBeingDeleted(BookmarkBarModel* model) { } + // Invoked from the destructor of the BookmarkModel. + virtual void BookmarkModelBeingDeleted(BookmarkModel* model) { } // Invoked when a node has moved. - virtual void BookmarkNodeMoved(BookmarkBarModel* model, - BookmarkBarNode* old_parent, + virtual void BookmarkNodeMoved(BookmarkModel* model, + BookmarkNode* old_parent, int old_index, - BookmarkBarNode* new_parent, + BookmarkNode* new_parent, int new_index) = 0; // Invoked when a node has been added. - virtual void BookmarkNodeAdded(BookmarkBarModel* model, - BookmarkBarNode* parent, + virtual void BookmarkNodeAdded(BookmarkModel* model, + BookmarkNode* parent, int index) = 0; // Invoked when a node has been removed, the item may still be starred though. - virtual void BookmarkNodeRemoved(BookmarkBarModel* model, - BookmarkBarNode* parent, + virtual void BookmarkNodeRemoved(BookmarkModel* model, + BookmarkNode* parent, int index) = 0; // Invoked when the title or favicon of a node has changed. - virtual void BookmarkNodeChanged(BookmarkBarModel* model, - BookmarkBarNode* node) = 0; + virtual void BookmarkNodeChanged(BookmarkModel* model, + BookmarkNode* node) = 0; // Invoked when a favicon has finished loading. - virtual void BookmarkNodeFavIconLoaded(BookmarkBarModel* model, - BookmarkBarNode* node) = 0; + virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, + BookmarkNode* node) = 0; }; -// BookmarkBarModel ----------------------------------------------------------- +// BookmarkModel -------------------------------------------------------------- -// BookmarkBarModel provides a directed acyclic graph of the starred entries +// BookmarkModel provides a directed acyclic graph of the starred entries // and groups. Two graphs are provided for the two entry points: those on // the bookmark bar, and those in the other folder. // -// The methods of BookmarkBarModel update the internal structure immediately +// The methods of BookmarkModel update the internal structure immediately // and update the backend in the background. // // An observer may be attached to observer relevant events. // -// You should NOT directly create a BookmarkBarModel, instead go through the +// You should NOT directly create a BookmarkModel, instead go through the // Profile. // TODO(sky): rename to BookmarkModel. -class BookmarkBarModel : public NotificationObserver, public BookmarkService { - friend class BookmarkBarNode; - friend class BookmarkBarModelTest; +class BookmarkModel : public NotificationObserver, public BookmarkService { + friend class BookmarkNode; + friend class BookmarkModelTest; friend class BookmarkStorage; public: - explicit BookmarkBarModel(Profile* profile); - virtual ~BookmarkBarModel(); + explicit BookmarkModel(Profile* profile); + virtual ~BookmarkModel(); // Loads the bookmarks. This is called by Profile upon creation of the - // BookmarkBarModel. You need not invoke this directly. + // BookmarkModel. You need not invoke this directly. void Load(); // Returns the root node. The bookmark bar node and other node are children of // the root node. - BookmarkBarNode* root_node() { return &root_; } + BookmarkNode* root_node() { return &root_; } // Returns the bookmark bar node. - BookmarkBarNode* GetBookmarkBarNode() { return bookmark_bar_node_; } + BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; } // Returns the 'other' node. - BookmarkBarNode* other_node() { return other_node_; } + BookmarkNode* other_node() { return other_node_; } // Returns the parent the last node was added to. This never returns NULL // (as long as the model is loaded). - BookmarkBarNode* GetParentForNewNodes(); + BookmarkNode* GetParentForNewNodes(); // Returns a vector containing up to |max_count| of the most recently // modified groups. This never returns an empty vector. - std::vector<BookmarkBarNode*> GetMostRecentlyModifiedGroups(size_t max_count); + std::vector<BookmarkNode*> GetMostRecentlyModifiedGroups(size_t max_count); // Returns the most recently added bookmarks. void GetMostRecentlyAddedEntries(size_t count, - std::vector<BookmarkBarNode*>* nodes); + std::vector<BookmarkNode*>* nodes); // Used by GetBookmarksMatchingText to return a matching node and the location // of the match in the title. struct TitleMatch { - BookmarkBarNode* node; + BookmarkNode* node; // Location of the matching words in the title of the node. Snippet::MatchPositions match_positions; @@ -222,30 +220,30 @@ class BookmarkBarModel : public NotificationObserver, public BookmarkService { size_t max_count, std::vector<TitleMatch>* matches); - void AddObserver(BookmarkBarModelObserver* observer) { + void AddObserver(BookmarkModelObserver* observer) { observers_.AddObserver(observer); } - void RemoveObserver(BookmarkBarModelObserver* observer) { + void RemoveObserver(BookmarkModelObserver* observer) { observers_.RemoveObserver(observer); } // Unstars or deletes the specified entry. Removing a group entry recursively // unstars all nodes. Observers are notified immediately. - void Remove(BookmarkBarNode* parent, int index); + void Remove(BookmarkNode* parent, int index); // Moves the specified entry to a new location. - void Move(BookmarkBarNode* node, BookmarkBarNode* new_parent, int index); + void Move(BookmarkNode* node, BookmarkNode* new_parent, int index); // Sets the title of the specified node. - void SetTitle(BookmarkBarNode* node, const std::wstring& title); + void SetTitle(BookmarkNode* node, const std::wstring& title); // Returns true if the model finished loading. bool IsLoaded() { return loaded_; } // Returns the node with the specified URL, or NULL if there is no node with // the specified URL. This method is thread safe. - BookmarkBarNode* GetNodeByURL(const GURL& url); + BookmarkNode* GetNodeByURL(const GURL& url); // Returns all the bookmarked urls. This method is thread safe. virtual void GetBookmarks(std::vector<GURL>* urls); @@ -262,26 +260,26 @@ class BookmarkBarModel : public NotificationObserver, public BookmarkService { // Returns the node with the specified id, or NULL if there is no node with // the specified id. - BookmarkBarNode* GetNodeByID(int id); + BookmarkNode* GetNodeByID(int id); // Adds a new group node at the specified position. - BookmarkBarNode* AddGroup(BookmarkBarNode* parent, - int index, - const std::wstring& title); + BookmarkNode* AddGroup(BookmarkNode* parent, + int index, + const std::wstring& title); // Adds a url at the specified position. If there is already a node with the // specified URL, it is moved to the new position. - BookmarkBarNode* AddURL(BookmarkBarNode* parent, - int index, - const std::wstring& title, - const GURL& url); + BookmarkNode* AddURL(BookmarkNode* parent, + int index, + const std::wstring& title, + const GURL& url); // Adds a url with a specific creation date. - BookmarkBarNode* AddURLWithCreationTime(BookmarkBarNode* parent, - int index, - const std::wstring& title, - const GURL& url, - const Time& creation_time); + BookmarkNode* AddURLWithCreationTime(BookmarkNode* parent, + int index, + const std::wstring& title, + const GURL& url, + const Time& creation_time); // This is the convenience that makes sure the url is starred or not // starred. If the URL is not currently starred, it is added to the @@ -293,28 +291,28 @@ class BookmarkBarModel : public NotificationObserver, public BookmarkService { // Resets the 'date modified' time of the node to 0. This is used during // importing to exclude the newly created groups from showing up in the // combobox of most recently modified groups. - void ResetDateGroupModified(BookmarkBarNode* node); + void ResetDateGroupModified(BookmarkNode* node); private: - // Used to order BookmarkBarNodes by URL. + // Used to order BookmarkNodes by URL. class NodeURLComparator { public: - bool operator()(BookmarkBarNode* n1, BookmarkBarNode* n2) const { + bool operator()(BookmarkNode* n1, BookmarkNode* n2) const { return n1->GetURL() < n2->GetURL(); } }; // Overriden to notify the observer the favicon has been loaded. - void FavIconLoaded(BookmarkBarNode* node); + void FavIconLoaded(BookmarkNode* node); // Removes the node from internal maps and recurces through all children. If // the node is a url, its url is added to removed_urls. // // This does NOT delete the node. - void RemoveNode(BookmarkBarNode* node, std::set<GURL>* removed_urls); + void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls); // Callback from BookmarkStorage that it has finished loading. This method - // may be hit twice. In particular, on construction BookmarkBarModel asks + // may be hit twice. In particular, on construction BookmarkModel asks // BookmarkStorage to load the bookmarks. BookmarkStorage invokes this method // with loaded_from_history false and file_exists indicating whether the // bookmarks file exists. If the file doesn't exist, we query history. When @@ -335,34 +333,34 @@ class BookmarkBarModel : public NotificationObserver, public BookmarkService { void DoneLoading(); // Populates nodes_ordered_by_url_set_ from root. - void PopulateNodesByURL(BookmarkBarNode* node); + void PopulateNodesByURL(BookmarkNode* node); // Removes the node from its parent, sends notification, and deletes it. // type specifies how the node should be removed. - void RemoveAndDeleteNode(BookmarkBarNode* delete_me); + void RemoveAndDeleteNode(BookmarkNode* delete_me); // Adds the node at the specified position, and sends notification. - BookmarkBarNode* AddNode(BookmarkBarNode* parent, - int index, - BookmarkBarNode* node); + BookmarkNode* AddNode(BookmarkNode* parent, + int index, + BookmarkNode* node); // Implementation of GetNodeByID. - BookmarkBarNode* GetNodeByID(BookmarkBarNode* node, int id); + BookmarkNode* GetNodeByID(BookmarkNode* node, int id); // Returns true if the parent and index are valid. - bool IsValidIndex(BookmarkBarNode* parent, int index, bool allow_end); + bool IsValidIndex(BookmarkNode* parent, int index, bool allow_end); // Sets the date modified time of the specified node. - void SetDateGroupModified(BookmarkBarNode* parent, const Time time); + void SetDateGroupModified(BookmarkNode* parent, const Time time); // Creates the bookmark bar/other nodes. These call into // CreateRootNodeFromStarredEntry. - void CreateBookmarkBarNode(); + void CreateBookmarkNode(); void CreateOtherBookmarksNode(); // Creates a root node (either the bookmark bar node or other node) from the // specified starred entry. - BookmarkBarNode* CreateRootNodeFromStarredEntry( + BookmarkNode* CreateRootNodeFromStarredEntry( const history::StarredEntry& entry); // Notification that a favicon has finished loading. If we can decode the @@ -376,16 +374,16 @@ class BookmarkBarModel : public NotificationObserver, public BookmarkService { // Invoked from the node to load the favicon. Requests the favicon from the // history service. - void LoadFavIcon(BookmarkBarNode* node); + void LoadFavIcon(BookmarkNode* node); // If we're waiting on a favicon for node, the load request is canceled. - void CancelPendingFavIconLoadRequests(BookmarkBarNode* node); + void CancelPendingFavIconLoadRequests(BookmarkNode* node); // Returns up to count of the most recently modified groups. This may not // add anything. - void GetMostRecentlyModifiedGroupNodes(BookmarkBarNode* parent, + void GetMostRecentlyModifiedGroupNodes(BookmarkNode* parent, size_t count, - std::vector<BookmarkBarNode*>* nodes); + std::vector<BookmarkNode*>* nodes); // NotificationObserver. virtual void Observe(NotificationType type, @@ -399,24 +397,24 @@ class BookmarkBarModel : public NotificationObserver, public BookmarkService { // The root node. This contains the bookmark bar node and the 'other' node as // children. - BookmarkBarNode root_; + BookmarkNode root_; - BookmarkBarNode* bookmark_bar_node_; - BookmarkBarNode* other_node_; + BookmarkNode* bookmark_bar_node_; + BookmarkNode* other_node_; // The observers. - ObserverList<BookmarkBarModelObserver> observers_; + ObserverList<BookmarkModelObserver> observers_; // Set of nodes ordered by URL. This is not a map to avoid copying the // urls. // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As // such, be sure and wrap all usage of it around url_lock_. - typedef std::set<BookmarkBarNode*,NodeURLComparator> NodesOrderedByURLSet; + typedef std::set<BookmarkNode*,NodeURLComparator> NodesOrderedByURLSet; NodesOrderedByURLSet nodes_ordered_by_url_set_; Lock url_lock_; // Used for loading favicons and the empty history request. - CancelableRequestConsumerT<BookmarkBarNode*, NULL> load_consumer_; + CancelableRequestConsumerT<BookmarkNode*, NULL> load_consumer_; // Reads/writes bookmarks to disk. scoped_refptr<BookmarkStorage> store_; @@ -429,7 +427,7 @@ class BookmarkBarModel : public NotificationObserver, public BookmarkService { // Handle to event signaled when loading is done. ScopedHandle loaded_signal_; - DISALLOW_COPY_AND_ASSIGN(BookmarkBarModel); + DISALLOW_COPY_AND_ASSIGN(BookmarkModel); }; #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_ diff --git a/chrome/browser/bookmarks/bookmark_bar_model_unittest.cc b/chrome/browser/bookmarks/bookmark_model_unittest.cc index f6d4b2d..04c08d3 100644 --- a/chrome/browser/bookmarks/bookmark_bar_model_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_model_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/string_util.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_codec.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" @@ -11,16 +11,15 @@ #include "chrome/views/tree_node_model.h" #include "testing/gtest/include/gtest/gtest.h" -class BookmarkBarModelTest : public testing::Test, - public BookmarkBarModelObserver { +class BookmarkModelTest : public testing::Test, public BookmarkModelObserver { public: struct ObserverDetails { ObserverDetails() { Set(NULL, NULL, -1, -1); } - void Set(BookmarkBarNode* node1, - BookmarkBarNode* node2, + void Set(BookmarkNode* node1, + BookmarkNode* node2, int index1, int index2) { this->node1 = node1; @@ -29,8 +28,8 @@ class BookmarkBarModelTest : public testing::Test, this->index2 = index2; } - void AssertEquals(BookmarkBarNode* node1, - BookmarkBarNode* node2, + void AssertEquals(BookmarkNode* node1, + BookmarkNode* node2, int index1, int index2) { ASSERT_TRUE(this->node1 == node1); @@ -39,54 +38,54 @@ class BookmarkBarModelTest : public testing::Test, ASSERT_EQ(index2, this->index2); } - BookmarkBarNode* node1; - BookmarkBarNode* node2; + BookmarkNode* node1; + BookmarkNode* node2; int index1; int index2; }; - BookmarkBarModelTest() : model(NULL) { + BookmarkModelTest() : model(NULL) { model.AddObserver(this); ClearCounts(); } - void Loaded(BookmarkBarModel* model) { + void Loaded(BookmarkModel* model) { // We never load from the db, so that this should never get invoked. NOTREACHED(); } - virtual void BookmarkNodeMoved(BookmarkBarModel* model, - BookmarkBarNode* old_parent, + virtual void BookmarkNodeMoved(BookmarkModel* model, + BookmarkNode* old_parent, int old_index, - BookmarkBarNode* new_parent, + BookmarkNode* new_parent, int new_index) { moved_count++; observer_details.Set(old_parent, new_parent, old_index, new_index); } - virtual void BookmarkNodeAdded(BookmarkBarModel* model, - BookmarkBarNode* parent, + virtual void BookmarkNodeAdded(BookmarkModel* model, + BookmarkNode* parent, int index) { added_count++; observer_details.Set(parent, NULL, index, -1); } - virtual void BookmarkNodeRemoved(BookmarkBarModel* model, - BookmarkBarNode* parent, + virtual void BookmarkNodeRemoved(BookmarkModel* model, + BookmarkNode* parent, int index) { removed_count++; observer_details.Set(parent, NULL, index, -1); } - virtual void BookmarkNodeChanged(BookmarkBarModel* model, - BookmarkBarNode* node) { + virtual void BookmarkNodeChanged(BookmarkModel* model, + BookmarkNode* node) { changed_count++; observer_details.Set(node, NULL, -1, -1); } - virtual void BookmarkNodeFavIconLoaded(BookmarkBarModel* model, - BookmarkBarNode* node) { + virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, + BookmarkNode* node) { // We never attempt to load favicons, so that this method never // gets invoked. } @@ -105,7 +104,7 @@ class BookmarkBarModelTest : public testing::Test, ASSERT_EQ(changed_count, this->changed_count); } - void AssertNodesEqual(BookmarkBarNode* expected, BookmarkBarNode* actual) { + void AssertNodesEqual(BookmarkNode* expected, BookmarkNode* actual) { ASSERT_TRUE(expected); ASSERT_TRUE(actual); EXPECT_EQ(expected->GetTitle(), actual->GetTitle()); @@ -122,15 +121,15 @@ class BookmarkBarModelTest : public testing::Test, } } - void AssertModelsEqual(BookmarkBarModel* expected, - BookmarkBarModel* actual) { + void AssertModelsEqual(BookmarkModel* expected, + BookmarkModel* actual) { AssertNodesEqual(expected->GetBookmarkBarNode(), actual->GetBookmarkBarNode()); AssertNodesEqual(expected->other_node(), actual->other_node()); } - BookmarkBarModel model; + BookmarkModel model; int moved_count; @@ -143,13 +142,13 @@ class BookmarkBarModelTest : public testing::Test, ObserverDetails observer_details; }; -TEST_F(BookmarkBarModelTest, InitialState) { - BookmarkBarNode* bb_node = model.GetBookmarkBarNode(); +TEST_F(BookmarkModelTest, InitialState) { + BookmarkNode* bb_node = model.GetBookmarkBarNode(); ASSERT_TRUE(bb_node != NULL); EXPECT_EQ(0, bb_node->GetChildCount()); EXPECT_EQ(history::StarredEntry::BOOKMARK_BAR, bb_node->GetType()); - BookmarkBarNode* other_node = model.other_node(); + BookmarkNode* other_node = model.other_node(); ASSERT_TRUE(other_node != NULL); EXPECT_EQ(0, other_node->GetChildCount()); EXPECT_EQ(history::StarredEntry::OTHER, other_node->GetType()); @@ -157,12 +156,12 @@ TEST_F(BookmarkBarModelTest, InitialState) { EXPECT_TRUE(bb_node->id() != other_node->id()); } -TEST_F(BookmarkBarModelTest, AddURL) { - BookmarkBarNode* root = model.GetBookmarkBarNode(); +TEST_F(BookmarkModelTest, AddURL) { + BookmarkNode* root = model.GetBookmarkBarNode(); const std::wstring title(L"foo"); const GURL url("http://foo.com"); - BookmarkBarNode* new_node = model.AddURL(root, 0, title, url); + BookmarkNode* new_node = model.AddURL(root, 0, title, url); AssertObserverCount(1, 0, 0, 0); observer_details.AssertEquals(root, NULL, 0, -1); @@ -176,11 +175,11 @@ TEST_F(BookmarkBarModelTest, AddURL) { new_node->id() != model.other_node()->id()); } -TEST_F(BookmarkBarModelTest, AddGroup) { - BookmarkBarNode* root = model.GetBookmarkBarNode(); +TEST_F(BookmarkModelTest, AddGroup) { + BookmarkNode* root = model.GetBookmarkBarNode(); const std::wstring title(L"foo"); - BookmarkBarNode* new_node = model.AddGroup(root, 0, title); + BookmarkNode* new_node = model.AddGroup(root, 0, title); AssertObserverCount(1, 0, 0, 0); observer_details.AssertEquals(root, NULL, 0, -1); @@ -193,16 +192,16 @@ TEST_F(BookmarkBarModelTest, AddGroup) { // Add another group, just to make sure group_ids are incremented correctly. ClearCounts(); - BookmarkBarNode* new_node2 = model.AddGroup(root, 0, title); + BookmarkNode* new_node2 = model.AddGroup(root, 0, title); AssertObserverCount(1, 0, 0, 0); observer_details.AssertEquals(root, NULL, 0, -1); } -TEST_F(BookmarkBarModelTest, RemoveURL) { - BookmarkBarNode* root = model.GetBookmarkBarNode(); +TEST_F(BookmarkModelTest, RemoveURL) { + BookmarkNode* root = model.GetBookmarkBarNode(); const std::wstring title(L"foo"); const GURL url("http://foo.com"); - BookmarkBarNode* new_node = model.AddURL(root, 0, title, url); + BookmarkNode* new_node = model.AddURL(root, 0, title, url); ClearCounts(); model.Remove(root, 0); @@ -214,16 +213,16 @@ TEST_F(BookmarkBarModelTest, RemoveURL) { ASSERT_TRUE(model.GetNodeByURL(url) == NULL); } -TEST_F(BookmarkBarModelTest, RemoveGroup) { - BookmarkBarNode* root = model.GetBookmarkBarNode(); - BookmarkBarNode* group = model.AddGroup(root, 0, L"foo"); +TEST_F(BookmarkModelTest, RemoveGroup) { + BookmarkNode* root = model.GetBookmarkBarNode(); + BookmarkNode* group = model.AddGroup(root, 0, L"foo"); ClearCounts(); // Add a URL as a child. const std::wstring title(L"foo"); const GURL url("http://foo.com"); - BookmarkBarNode* new_node = model.AddURL(group, 0, title, url); + BookmarkNode* new_node = model.AddURL(group, 0, title, url); ClearCounts(); @@ -237,11 +236,11 @@ TEST_F(BookmarkBarModelTest, RemoveGroup) { ASSERT_TRUE(model.GetNodeByURL(url) == NULL); } -TEST_F(BookmarkBarModelTest, SetTitle) { - BookmarkBarNode* root = model.GetBookmarkBarNode(); +TEST_F(BookmarkModelTest, SetTitle) { + BookmarkNode* root = model.GetBookmarkBarNode(); std::wstring title(L"foo"); const GURL url("http://foo.com"); - BookmarkBarNode* node = model.AddURL(root, 0, title, url); + BookmarkNode* node = model.AddURL(root, 0, title, url); ClearCounts(); @@ -252,12 +251,12 @@ TEST_F(BookmarkBarModelTest, SetTitle) { EXPECT_EQ(title, node->GetTitle()); } -TEST_F(BookmarkBarModelTest, Move) { - BookmarkBarNode* root = model.GetBookmarkBarNode(); +TEST_F(BookmarkModelTest, Move) { + BookmarkNode* root = model.GetBookmarkBarNode(); std::wstring title(L"foo"); const GURL url("http://foo.com"); - BookmarkBarNode* node = model.AddURL(root, 0, title, url); - BookmarkBarNode* group1 = model.AddGroup(root, 0, L"foo"); + BookmarkNode* node = model.AddURL(root, 0, title, url); + BookmarkNode* group1 = model.AddGroup(root, 0, L"foo"); ClearCounts(); model.Move(node, group1, 0); @@ -280,27 +279,26 @@ TEST_F(BookmarkBarModelTest, Move) { } // Tests that adding a URL to a folder updates the last modified time. -TEST_F(BookmarkBarModelTest, ParentForNewNodes) { +TEST_F(BookmarkModelTest, ParentForNewNodes) { ASSERT_EQ(model.GetBookmarkBarNode(), model.GetParentForNewNodes()); const std::wstring title(L"foo"); const GURL url("http://foo.com"); - BookmarkBarNode* new_node = - model.AddURL(model.other_node(), 0, title, url); + BookmarkNode* new_node = model.AddURL(model.other_node(), 0, title, url); ASSERT_EQ(model.other_node(), model.GetParentForNewNodes()); } // Make sure recently modified stays in sync when adding a URL. -TEST_F(BookmarkBarModelTest, MostRecentlyModifiedGroups) { +TEST_F(BookmarkModelTest, MostRecentlyModifiedGroups) { // Add a group. - BookmarkBarNode* group = model.AddGroup(model.other_node(), 0, L"foo"); + BookmarkNode* group = model.AddGroup(model.other_node(), 0, L"foo"); // Add a URL to it. model.AddURL(group, 0, L"blah", GURL("http://foo.com")); // Make sure group is in the most recently modified. - std::vector<BookmarkBarNode*> most_recent_groups = + std::vector<BookmarkNode*> most_recent_groups = model.GetMostRecentlyModifiedGroups(1); ASSERT_EQ(1, most_recent_groups.size()); ASSERT_EQ(group, most_recent_groups[0]); @@ -314,17 +312,17 @@ TEST_F(BookmarkBarModelTest, MostRecentlyModifiedGroups) { } // Make sure MostRecentlyAddedEntries stays in sync. -TEST_F(BookmarkBarModelTest, MostRecentlyAddedEntries) { +TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { // Add a couple of nodes such that the following holds for the time of the // nodes: n1 > n2 > n3 > n4. Time base_time = Time::Now(); - BookmarkBarNode* n1 = model.AddURL( + BookmarkNode* n1 = model.AddURL( model.GetBookmarkBarNode(), 0, L"blah", GURL("http://foo.com/0")); - BookmarkBarNode* n2 = model.AddURL( + BookmarkNode* n2 = model.AddURL( model.GetBookmarkBarNode(), 1, L"blah", GURL("http://foo.com/1")); - BookmarkBarNode* n3 = model.AddURL( + BookmarkNode* n3 = model.AddURL( model.GetBookmarkBarNode(), 2, L"blah", GURL("http://foo.com/2")); - BookmarkBarNode* n4 = model.AddURL( + BookmarkNode* n4 = model.AddURL( model.GetBookmarkBarNode(), 3, L"blah", GURL("http://foo.com/3")); n1->date_added_ = base_time + TimeDelta::FromDays(4); n2->date_added_ = base_time + TimeDelta::FromDays(3); @@ -332,7 +330,7 @@ TEST_F(BookmarkBarModelTest, MostRecentlyAddedEntries) { n4->date_added_ = base_time + TimeDelta::FromDays(1); // Make sure order is honored. - std::vector<BookmarkBarNode*> recently_added; + std::vector<BookmarkNode*> recently_added; model.GetMostRecentlyAddedEntries(2, &recently_added); ASSERT_EQ(2, recently_added.size()); ASSERT_TRUE(n1 == recently_added[0]); @@ -350,17 +348,17 @@ TEST_F(BookmarkBarModelTest, MostRecentlyAddedEntries) { } // Makes sure GetBookmarksMatchingText works. -TEST_F(BookmarkBarModelTest, GetBookmarksMatchingText) { +TEST_F(BookmarkModelTest, GetBookmarksMatchingText) { // Add two urls with titles 'blah' and 'x' and one folder with the title // 'blah'. - BookmarkBarNode* n1 = model.AddURL( + BookmarkNode* n1 = model.AddURL( model.GetBookmarkBarNode(), 0, L"blah", GURL("http://foo.com/0")); - BookmarkBarNode* n2 = model.AddURL( + BookmarkNode* n2 = model.AddURL( model.GetBookmarkBarNode(), 1, L"x", GURL("http://foo.com/1")); model.AddGroup(model.GetBookmarkBarNode(), 2, L"blah"); // Make sure we don't get back the folder. - std::vector<BookmarkBarModel::TitleMatch> results; + std::vector<BookmarkModel::TitleMatch> results; model.GetBookmarksMatchingText(L"blah", 2, &results); ASSERT_EQ(1U, results.size()); EXPECT_EQ(n1, results[0].node); @@ -436,16 +434,16 @@ static void PopulateNodeFromString(const std::wstring& description, PopulateNodeImpl(elements, &index, parent); } -// Populates the BookmarkBarNode with the children of parent. -static void PopulateBookmarkBarNode(TestNode* parent, - BookmarkBarModel* model, - BookmarkBarNode* bb_node) { +// Populates the BookmarkNode with the children of parent. +static void PopulateBookmarkNode(TestNode* parent, + BookmarkModel* model, + BookmarkNode* bb_node) { for (int i = 0; i < parent->GetChildCount(); ++i) { TestNode* child = parent->GetChild(i); if (child->value == history::StarredEntry::USER_GROUP) { - BookmarkBarNode* new_bb_node = + BookmarkNode* new_bb_node = model->AddGroup(bb_node, i, child->GetTitle()); - PopulateBookmarkBarNode(child, model, new_bb_node); + PopulateBookmarkNode(child, model, new_bb_node); } else { model->AddURL(bb_node, i, child->GetTitle(), GURL("http://" + WideToASCII(child->GetTitle()))); @@ -455,9 +453,9 @@ static void PopulateBookmarkBarNode(TestNode* parent, } // namespace -// Test class that creates a BookmarkBarModel with a real history backend. -class BookmarkBarModelTestWithProfile : public testing::Test, - public BookmarkBarModelObserver { +// Test class that creates a BookmarkModel with a real history backend. +class BookmarkModelTestWithProfile : public testing::Test, + public BookmarkModelObserver { public: virtual void SetUp() { } @@ -472,11 +470,11 @@ class BookmarkBarModelTestWithProfile : public testing::Test, protected: // Verifies the contents of the bookmark bar node match the contents of the // TestNode. - void VerifyModelMatchesNode(TestNode* expected, BookmarkBarNode* actual) { + void VerifyModelMatchesNode(TestNode* expected, BookmarkNode* actual) { ASSERT_EQ(expected->GetChildCount(), actual->GetChildCount()); for (int i = 0; i < expected->GetChildCount(); ++i) { TestNode* expected_child = expected->GetChild(i); - BookmarkBarNode* actual_child = actual->GetChild(i); + BookmarkNode* actual_child = actual->GetChild(i); ASSERT_EQ(expected_child->GetTitle(), actual_child->GetTitle()); if (expected_child->value == history::StarredEntry::USER_GROUP) { ASSERT_TRUE(actual_child->GetType() == @@ -494,7 +492,7 @@ class BookmarkBarModelTestWithProfile : public testing::Test, } void BlockTillBookmarkModelLoaded() { - bb_model_ = profile_->GetBookmarkBarModel(); + bb_model_ = profile_->GetBookmarkModel(); if (!bb_model_->IsLoaded()) BlockTillLoaded(bb_model_); else @@ -510,35 +508,35 @@ class BookmarkBarModelTestWithProfile : public testing::Test, profile_->CreateHistoryService(true); } - BookmarkBarModel* bb_model_; + BookmarkModel* bb_model_; private: - // Blocks until the BookmarkBarModel has finished loading. - void BlockTillLoaded(BookmarkBarModel* model) { + // Blocks until the BookmarkModel has finished loading. + void BlockTillLoaded(BookmarkModel* model) { model->AddObserver(this); MessageLoop::current()->Run(); } - // BookmarkBarModelObserver methods. - virtual void Loaded(BookmarkBarModel* model) { + // BookmarkModelObserver methods. + virtual void Loaded(BookmarkModel* model) { // Balances the call in BlockTillLoaded. MessageLoop::current()->Quit(); } - virtual void BookmarkNodeMoved(BookmarkBarModel* model, - BookmarkBarNode* old_parent, + virtual void BookmarkNodeMoved(BookmarkModel* model, + BookmarkNode* old_parent, int old_index, - BookmarkBarNode* new_parent, + BookmarkNode* new_parent, int new_index) {} - virtual void BookmarkNodeAdded(BookmarkBarModel* model, - BookmarkBarNode* parent, + virtual void BookmarkNodeAdded(BookmarkModel* model, + BookmarkNode* parent, int index) {} - virtual void BookmarkNodeRemoved(BookmarkBarModel* model, - BookmarkBarNode* parent, + virtual void BookmarkNodeRemoved(BookmarkModel* model, + BookmarkNode* parent, int index) {} - virtual void BookmarkNodeChanged(BookmarkBarModel* model, - BookmarkBarNode* node) {} - virtual void BookmarkNodeFavIconLoaded(BookmarkBarModel* model, - BookmarkBarNode* node) {} + virtual void BookmarkNodeChanged(BookmarkModel* model, + BookmarkNode* node) {} + virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, + BookmarkNode* node) {} MessageLoopForUI message_loop_; }; @@ -546,7 +544,7 @@ class BookmarkBarModelTestWithProfile : public testing::Test, // Creates a set of nodes in the bookmark bar model, then recreates the // bookmark bar model which triggers loading from the db and checks the loaded // structure to make sure it is what we first created. -TEST_F(BookmarkBarModelTestWithProfile, CreateAndRestore) { +TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) { struct TestData { // Structure of the children of the bookmark bar model node. const std::wstring bbn_contents; @@ -567,19 +565,19 @@ TEST_F(BookmarkBarModelTestWithProfile, CreateAndRestore) { // delete them. profile_.reset(NULL); profile_.reset(new TestingProfile()); - profile_->CreateBookmarkBarModel(true); + profile_->CreateBookmarkModel(true); profile_->CreateHistoryService(true); BlockTillBookmarkModelLoaded(); TestNode bbn; PopulateNodeFromString(data[i].bbn_contents, &bbn); - PopulateBookmarkBarNode(&bbn, bb_model_, bb_model_->GetBookmarkBarNode()); + PopulateBookmarkNode(&bbn, bb_model_, bb_model_->GetBookmarkBarNode()); TestNode other; PopulateNodeFromString(data[i].other_contents, &other); - PopulateBookmarkBarNode(&other, bb_model_, bb_model_->other_node()); + PopulateBookmarkNode(&other, bb_model_, bb_model_->other_node()); - profile_->CreateBookmarkBarModel(false); + profile_->CreateBookmarkModel(false); BlockTillBookmarkModelLoaded(); VerifyModelMatchesNode(&bbn, bb_model_->GetBookmarkBarNode()); @@ -587,9 +585,8 @@ TEST_F(BookmarkBarModelTestWithProfile, CreateAndRestore) { } } -// Test class that creates a BookmarkBarModel with a real history backend. -class BookmarkBarModelTestWithProfile2 : - public BookmarkBarModelTestWithProfile { +// Test class that creates a BookmarkModel with a real history backend. +class BookmarkModelTestWithProfile2 : public BookmarkModelTestWithProfile { public: virtual void SetUp() { profile_.reset(new TestingProfile()); @@ -609,10 +606,10 @@ class BookmarkBarModelTestWithProfile2 : // other // OF1 // http://www.google.com/intl/en/about.html - About Google - BookmarkBarNode* bbn = bb_model_->GetBookmarkBarNode(); + BookmarkNode* bbn = bb_model_->GetBookmarkBarNode(); ASSERT_EQ(2, bbn->GetChildCount()); - BookmarkBarNode* child = bbn->GetChild(0); + BookmarkNode* child = bbn->GetChild(0); ASSERT_EQ(history::StarredEntry::URL, child->GetType()); ASSERT_EQ(L"Google", child->GetTitle()); ASSERT_TRUE(child->GetURL() == GURL("http://www.google.com")); @@ -622,7 +619,7 @@ class BookmarkBarModelTestWithProfile2 : ASSERT_EQ(L"F1", child->GetTitle()); ASSERT_EQ(2, child->GetChildCount()); - BookmarkBarNode* parent = child; + BookmarkNode* parent = child; child = parent->GetChild(0); ASSERT_EQ(history::StarredEntry::URL, child->GetType()); ASSERT_EQ(L"Google Advertising", child->GetTitle()); @@ -660,7 +657,7 @@ class BookmarkBarModelTestWithProfile2 : // Tests migrating bookmarks from db into file. This copies an old history db // file containing bookmarks and make sure they are loaded correctly and // persisted correctly. -TEST_F(BookmarkBarModelTestWithProfile2, MigrateFromDBToFileTest) { +TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) { // Copy db file over that contains starred table. std::wstring old_history_path; PathService::Get(chrome::DIR_TEST_DATA, &old_history_path); @@ -675,7 +672,7 @@ TEST_F(BookmarkBarModelTestWithProfile2, MigrateFromDBToFileTest) { // Create the history service making sure it doesn't blow away the file we // just copied. profile_->CreateHistoryService(false); - profile_->CreateBookmarkBarModel(true); + profile_->CreateBookmarkModel(true); BlockTillBookmarkModelLoaded(); // Make sure we loaded OK. @@ -684,7 +681,7 @@ TEST_F(BookmarkBarModelTestWithProfile2, MigrateFromDBToFileTest) { return; // Create again. This time we shouldn't load from history at all. - profile_->CreateBookmarkBarModel(false); + profile_->CreateBookmarkModel(false); BlockTillBookmarkModelLoaded(); // Make sure we loaded OK. @@ -695,16 +692,16 @@ TEST_F(BookmarkBarModelTestWithProfile2, MigrateFromDBToFileTest) { // Recreate the history service (with a clean db). Do this just to make sure // we're loading correctly from the bookmarks file. profile_->CreateHistoryService(true); - profile_->CreateBookmarkBarModel(false); + profile_->CreateBookmarkModel(false); BlockTillBookmarkModelLoaded(); VerifyExpectedState(); } // Simple test that removes a bookmark. This test exercises the code paths in // History that block till bookmark bar model is loaded. -TEST_F(BookmarkBarModelTestWithProfile2, RemoveNotification) { +TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) { profile_->CreateHistoryService(false); - profile_->CreateBookmarkBarModel(true); + profile_->CreateBookmarkModel(true); BlockTillBookmarkModelLoaded(); // Add a URL. @@ -716,6 +713,6 @@ TEST_F(BookmarkBarModelTestWithProfile2, RemoveNotification) { HistoryService::RedirectList()); // This won't actually delete the URL, rather it'll empty out the visits. - // This triggers blocking on the BookmarkBarModel. + // This triggers blocking on the BookmarkModel. profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->DeleteURL(url); } diff --git a/chrome/browser/bookmarks/bookmark_storage.cc b/chrome/browser/bookmarks/bookmark_storage.cc index 712b573..b46b092 100644 --- a/chrome/browser/bookmarks/bookmark_storage.cc +++ b/chrome/browser/bookmarks/bookmark_storage.cc @@ -7,8 +7,8 @@ #include "base/file_util.h" #include "base/json_writer.h" #include "base/message_loop.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" #include "chrome/browser/bookmarks/bookmark_codec.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/json_value_serializer.h" @@ -29,7 +29,7 @@ const int kSaveDelayMS = 2500; // BookmarkStorage ------------------------------------------------------------- -BookmarkStorage::BookmarkStorage(Profile* profile, BookmarkBarModel* model) +BookmarkStorage::BookmarkStorage(Profile* profile, BookmarkModel* model) : model_(model), #pragma warning(suppress: 4355) // Okay to pass "this" here. save_factory_(this), diff --git a/chrome/browser/bookmarks/bookmark_storage.h b/chrome/browser/bookmarks/bookmark_storage.h index cf2c3a9..6ec4184 100644 --- a/chrome/browser/bookmarks/bookmark_storage.h +++ b/chrome/browser/bookmarks/bookmark_storage.h @@ -9,14 +9,13 @@ #include "base/task.h"
#include "chrome/browser/browser_process.h"
-class BookmarkBarModel;
+class BookmarkModel;
class Profile;
class Value;
// BookmarkStorage handles reading/write the bookmark bar model. The
-// BookmarkBarModel uses the BookmarkStorage to load bookmarks from
-// disk, as well as notifying the BookmarkStorage every time the model
-// changes.
+// BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well
+// as notifying the BookmarkStorage every time the model changes.
//
// Internally BookmarkStorage uses BookmarkCodec to do the actual read/write.
@@ -25,7 +24,7 @@ class BookmarkStorage : public base::RefCountedThreadSafe<BookmarkStorage> { public:
// Creates a BookmarkStorage for the specified model
- BookmarkStorage(Profile* profile, BookmarkBarModel* model);
+ BookmarkStorage(Profile* profile, BookmarkModel* model);
// Loads the bookmarks into the model, notifying the model when done. If
// load_from_history is true, the bookmarks are loaded from the file written
@@ -52,7 +51,7 @@ class BookmarkStorage : public base::RefCountedThreadSafe<BookmarkStorage> { base::Thread* backend_thread() const { return backend_thread_; }
// The model. The model is NULL once BookmarkModelDeleted has been invoked.
- BookmarkBarModel* model_;
+ BookmarkModel* model_;
// Used to delay saves.
ScopedRunnableMethodFactory<BookmarkStorage> save_factory_;
|