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 | |
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')
50 files changed, 790 insertions, 837 deletions
diff --git a/chrome/SConscript.unit_tests b/chrome/SConscript.unit_tests index b87ff13..8cba2ef 100644 --- a/chrome/SConscript.unit_tests +++ b/chrome/SConscript.unit_tests @@ -108,7 +108,7 @@ unit_test_files = [ 'browser/autocomplete/keyword_provider_unittest.cc', 'browser/back_forward_menu_model_unittest.cc', 'browser/bookmark_bar_context_menu_controller_test.cc', - 'browser/bookmarks/bookmark_bar_model_unittest.cc', + 'browser/bookmarks/bookmark_bar_unittest.cc', 'browser/bookmarks/bookmark_drag_data_unittest.cc', 'browser/cache_manager_host_unittest.cc', 'browser/chrome_thread_unittest.cc', diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index 42b6d81..27a3e7b 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -11,7 +11,7 @@ #include "chrome/browser/autocomplete/history_contents_provider.h" #include "chrome/browser/autocomplete/keyword_provider.h" #include "chrome/browser/autocomplete/search_provider.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/external_protocol_handler.h" #include "chrome/browser/history_tab_ui.h" #include "chrome/browser/profile.h" @@ -394,12 +394,12 @@ void AutocompleteProvider::UpdateStarredStateOfMatches() { if (!profile_) return; - BookmarkBarModel* bookmark_bar_model = profile_->GetBookmarkBarModel(); - if (!bookmark_bar_model || !bookmark_bar_model->IsLoaded()) + BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); + if (!bookmark_model || !bookmark_model->IsLoaded()) return; for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) - i->starred = bookmark_bar_model->IsBookmarked(GURL(i->destination_url)); + i->starred = bookmark_model->IsBookmarked(GURL(i->destination_url)); } // AutocompleteResult --------------------------------------------------------- diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc index 2d03db9..d8c91e8 100644 --- a/chrome/browser/autocomplete/history_contents_provider.cc +++ b/chrome/browser/autocomplete/history_contents_provider.cc @@ -45,7 +45,7 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input, if (input.text().empty() || (input.type() == AutocompleteInput::INVALID) || // The history service or bookmark bar model must exist. !(profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) || - profile_->GetBookmarkBarModel())) { + profile_->GetBookmarkModel())) { Stop(); return; } @@ -191,8 +191,8 @@ AutocompleteMatch HistoryContentsProvider::ResultToMatch( ACMatchClassification(0, ACMatchClassification::URL)); match.description = result.title(); match.starred = - (profile_->GetBookmarkBarModel() && - profile_->GetBookmarkBarModel()->IsBookmarked(result.url())); + (profile_->GetBookmarkModel() && + profile_->GetBookmarkModel()->IsBookmarked(result.url())); ClassifyDescription(result, &match); return match; @@ -227,8 +227,8 @@ int HistoryContentsProvider::CalculateRelevance( const history::URLResult& result) { bool in_title = !!result.title_match_positions().size(); bool is_starred = - (profile_->GetBookmarkBarModel() && - profile_->GetBookmarkBarModel()->IsBookmarked(result.url())); + (profile_->GetBookmarkModel() && + profile_->GetBookmarkModel()->IsBookmarked(result.url())); switch (input_type_) { case AutocompleteInput::UNKNOWN: @@ -258,7 +258,7 @@ int HistoryContentsProvider::CalculateRelevance( } void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { - BookmarkBarModel* bookmark_model = profile_->GetBookmarkBarModel(); + BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); if (!bookmark_model) return; @@ -266,7 +266,7 @@ void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { // empty. TimeTicks start_time = TimeTicks::Now(); - std::vector<BookmarkBarModel::TitleMatch> matches; + std::vector<BookmarkModel::TitleMatch> matches; bookmark_model->GetBookmarksMatchingText(input.text(), kMaxMatchCount, &matches); for (size_t i = 0; i < matches.size(); ++i) @@ -276,7 +276,7 @@ void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { } void HistoryContentsProvider::AddBookmarkTitleMatchToResults( - const BookmarkBarModel::TitleMatch& match) { + const BookmarkModel::TitleMatch& match) { history::URLResult url_result(match.node->GetURL(), match.match_positions); url_result.set_title(match.node->GetTitle()); results_.AppendURLBySwapping(&url_result); diff --git a/chrome/browser/autocomplete/history_contents_provider.h b/chrome/browser/autocomplete/history_contents_provider.h index aded64d..f824480 100644 --- a/chrome/browser/autocomplete/history_contents_provider.h +++ b/chrome/browser/autocomplete/history_contents_provider.h @@ -6,7 +6,7 @@ #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_CONTENTS_PROVIDER_H__ #include "chrome/browser/autocomplete/autocomplete.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/history.h" // HistoryContentsProvider is an AutocompleteProvider that provides results from @@ -14,7 +14,7 @@ // HistoryContentsProvider gets results from two sources: // . HistoryService: this provides results for matches in the body/title of // previously viewed pages. This is asynchronous. -// . BookmarkBarModel: provides results for matches in the titles of bookmarks. +// . BookmarkModel: provides results for matches in the titles of bookmarks. // This is synchronous. class HistoryContentsProvider : public AutocompleteProvider { public: @@ -66,10 +66,9 @@ class HistoryContentsProvider : public AutocompleteProvider { // matches are added directly to results_. void QueryBookmarks(const AutocompleteInput& input); - // Converts a BookmarkBarModel::TitleMatch to a QueryResult and adds it - // to results_. - void AddBookmarkTitleMatchToResults( - const BookmarkBarModel::TitleMatch& match); + // Converts a BookmarkModel::TitleMatch to a QueryResult and adds it to + // results_. + void AddBookmarkTitleMatchToResults(const BookmarkModel::TitleMatch& match); CancelableRequestConsumerT<int, 0> request_consumer_; diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc index 5796f4d..5122071 100644 --- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc @@ -148,14 +148,14 @@ TEST_F(HistoryContentsProviderTest, MinimalChanges) { EXPECT_EQ(2, m3.size()); } -// Tests that the BookmarkBarModel is queried correctly. +// Tests that the BookmarkModel is queried correctly. TEST_F(HistoryContentsProviderTest, Bookmarks) { - profile()->CreateBookmarkBarModel(false); + profile()->CreateBookmarkModel(false); profile()->BlockUntilBookmarkModelLoaded(); // Add a bookmark. GURL bookmark_url("http://www.google.com/4"); - profile()->GetBookmarkBarModel()->SetURLStarred(bookmark_url, L"bar", true); + profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, L"bar", true); AutocompleteInput input(L"bar", std::wstring(), true); diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc index e1b8ee8..b2663e6 100644 --- a/chrome/browser/autocomplete/history_url_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc @@ -6,7 +6,7 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "chrome/browser/autocomplete/history_url_provider.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/history.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" @@ -114,7 +114,7 @@ void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { void HistoryURLProviderTest::SetUp() { profile_.reset(new TestingProfile()); - profile_->CreateBookmarkBarModel(true); + profile_->CreateBookmarkModel(true); profile_->CreateHistoryService(true); history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); @@ -144,7 +144,7 @@ void HistoryURLProviderTest::FillData() { cur.visit_count, cur.typed_count, visit_time, false); if (cur.starred) { - profile_->GetBookmarkBarModel()->SetURLStarred( + profile_->GetBookmarkModel()->SetURLStarred( current_url, std::wstring(), true); } } diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index e2be1a5..5ec75d2 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -6,7 +6,6 @@ #include "base/message_loop.h" #include "base/string_util.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/google_util.h" #include "chrome/browser/profile.h" diff --git a/chrome/browser/bookmark_bar_context_menu_controller.cc b/chrome/browser/bookmark_bar_context_menu_controller.cc index a21c130..0ba0348 100644 --- a/chrome/browser/bookmark_bar_context_menu_controller.cc +++ b/chrome/browser/bookmark_bar_context_menu_controller.cc @@ -4,7 +4,7 @@ #include "chrome/browser/bookmark_bar_context_menu_controller.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/page_navigator.h" @@ -24,7 +24,7 @@ namespace { // Returns true if the specified node is of type URL, or has a descendant // of type URL. -bool NodeHasURLs(BookmarkBarNode* node) { +bool NodeHasURLs(BookmarkNode* node) { if (node->GetType() == history::StarredEntry::URL) return true; @@ -40,7 +40,7 @@ bool NodeHasURLs(BookmarkBarNode* node) { // in a new window. navigator indicates the PageNavigator to use for // new tabs. It is reset if open_first_in_new_window is true. // opened_url is set to true the first time a new tab is opened. -void OpenAll(BookmarkBarNode* node, +void OpenAll(BookmarkNode* node, bool open_first_in_new_window, PageNavigator** navigator, bool* opened_url) { @@ -89,7 +89,7 @@ class EditFolderController : public InputWindowDelegate, public BookmarkBarView::ModelChangedListener { public: EditFolderController(BookmarkBarView* view, - BookmarkBarNode* node, + BookmarkNode* node, int visual_order, bool is_new) : view_(view), @@ -126,7 +126,7 @@ class EditFolderController : public InputWindowDelegate, virtual void InputAccepted(const std::wstring& text) { view_->ClearModelChangedListenerIfEquals(this); - BookmarkBarModel* model = view_->GetProfile()->GetBookmarkBarModel(); + BookmarkModel* model = view_->GetProfile()->GetBookmarkModel(); if (is_new_) model->AddGroup(node_, visual_order_, text); else @@ -156,7 +156,7 @@ class EditFolderController : public InputWindowDelegate, // If is_new is true, this is the parent to create the new node under. // Otherwise this is the node to change the title of. - BookmarkBarNode* node_; + BookmarkNode* node_; int visual_order_; bool is_new_; @@ -183,7 +183,7 @@ const int BookmarkBarContextMenuController::new_folder_id = 10; BookmarkBarContextMenuController::BookmarkBarContextMenuController( BookmarkBarView* view, - BookmarkBarNode* node) + BookmarkNode* node) : view_(view), node_(node), menu_(this) { @@ -208,7 +208,7 @@ BookmarkBarContextMenuController::BookmarkBarContextMenuController( menu_.AppendSeparator(); if (node->GetParent() != - view->GetProfile()->GetBookmarkBarModel()->root_node()) { + view->GetProfile()->GetBookmarkModel()->root_node()) { menu_.AppendMenuItemWithLabel(edit_bookmark_id, l10n_util::GetString(IDS_BOOKMARK_BAR_EDIT)); menu_.AppendMenuItemWithLabel( @@ -284,7 +284,7 @@ void BookmarkBarContextMenuController::ExecuteCommand(int id) { L"BookmarkBar_ContextMenu_OpenAllInNewWindow", profile); } - BookmarkBarNode* node = node_; + BookmarkNode* node = node_; PageNavigator* navigator = view_->GetPageNavigator(); bool opened_url = false; OpenAll(node, (id == open_all_bookmarks_in_new_window_id), &navigator, @@ -328,7 +328,7 @@ void BookmarkBarContextMenuController::ExecuteCommand(int id) { profile); int visual_order; - BookmarkBarNode* parent = + BookmarkNode* parent = GetParentAndVisualOrderForNewNode(&visual_order); GetParentAndVisualOrderForNewNode(&visual_order); // Controller deletes itself when done. @@ -361,7 +361,7 @@ bool BookmarkBarContextMenuController::IsCommandEnabled(int id) const { // Returns the parent node and visual_order to use when adding new // bookmarks/folders. -BookmarkBarNode* BookmarkBarContextMenuController:: +BookmarkNode* BookmarkBarContextMenuController:: GetParentAndVisualOrderForNewNode(int* visual_order) { if (node_->GetType() != history::StarredEntry::URL) { // Adding to a group always adds to the end. diff --git a/chrome/browser/bookmark_bar_context_menu_controller.h b/chrome/browser/bookmark_bar_context_menu_controller.h index 04bbac1..9332bca 100644 --- a/chrome/browser/bookmark_bar_context_menu_controller.h +++ b/chrome/browser/bookmark_bar_context_menu_controller.h @@ -8,7 +8,7 @@ #include "chrome/views/chrome_menu.h" #include "chrome/browser/views/bookmark_bar_view.h" -class BookmarkBarNode; +class BookmarkNode; class PageNavigator; // BookmarkBarContextMenuController manages the context menus shown for the @@ -18,7 +18,7 @@ class BookmarkBarContextMenuController : public ChromeViews::MenuDelegate, public BookmarkBarView::ModelChangedListener { public: BookmarkBarContextMenuController(BookmarkBarView* view, - BookmarkBarNode* node); + BookmarkNode* node); // Shows the menu at the specified place. void RunMenuAt(int x, int y); @@ -49,11 +49,11 @@ class BookmarkBarContextMenuController : public ChromeViews::MenuDelegate, private: // Returns the parent node and visual_order to use when adding new // bookmarks/folders. - BookmarkBarNode* GetParentAndVisualOrderForNewNode(int* visual_order); + BookmarkNode* GetParentAndVisualOrderForNewNode(int* visual_order); ChromeViews::MenuItemView menu_; BookmarkBarView* view_; - BookmarkBarNode* node_; + BookmarkNode* node_; DISALLOW_EVIL_CONSTRUCTORS(BookmarkBarContextMenuController); }; diff --git a/chrome/browser/bookmark_bar_context_menu_controller_test.cc b/chrome/browser/bookmark_bar_context_menu_controller_test.cc index 081e1f4..dd70601 100644 --- a/chrome/browser/bookmark_bar_context_menu_controller_test.cc +++ b/chrome/browser/bookmark_bar_context_menu_controller_test.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/bookmark_bar_context_menu_controller.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profile.h" #include "chrome/browser/views/bookmark_bar_view.h" #include "chrome/common/pref_names.h" @@ -39,9 +39,9 @@ class BookmarkBarContextMenuControllerTest : public testing::Test { profile_.reset(new TestingProfile()); profile_->set_has_history_service(true); - profile_->CreateBookmarkBarModel(true); + profile_->CreateBookmarkModel(true); - model_ = profile_->GetBookmarkBarModel(); + model_ = profile_->GetBookmarkModel(); bb_view_.reset(new BookmarkBarView(profile_.get(), NULL)); bb_view_->SetPageNavigator(&navigator_); @@ -59,7 +59,7 @@ class BookmarkBarContextMenuControllerTest : public testing::Test { protected: MessageLoopForUI message_loop_; scoped_ptr<TestingProfile> profile_; - BookmarkBarModel* model_; + BookmarkModel* model_; scoped_ptr<BookmarkBarView> bb_view_; TestingPageNavigator navigator_; @@ -76,10 +76,10 @@ class BookmarkBarContextMenuControllerTest : public testing::Test { model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a", GURL(test_base + "a")); - BookmarkBarNode* f1 = + BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1"); model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a")); - BookmarkBarNode* f11 = model_->AddGroup(f1, 1, L"F11"); + BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11"); model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a")); model_->AddGroup(model_->GetBookmarkBarNode(), 2, L"F2"); } @@ -116,7 +116,7 @@ TEST_F(BookmarkBarContextMenuControllerTest, OpenURL) { // Tests open all on a folder with a couple of bookmarks. TEST_F(BookmarkBarContextMenuControllerTest, OpenAll) { - BookmarkBarNode* folder = model_->GetBookmarkBarNode()->GetChild(1); + BookmarkNode* folder = model_->GetBookmarkBarNode()->GetChild(1); BookmarkBarContextMenuController controller(bb_view_.get(), folder); ASSERT_TRUE(controller.IsCommandEnabled( BookmarkBarContextMenuController::open_all_bookmarks_id)); @@ -134,7 +134,7 @@ TEST_F(BookmarkBarContextMenuControllerTest, OpenAll) { // Tests that menus are appropriately disabled for empty folders. TEST_F(BookmarkBarContextMenuControllerTest, DisableForEmptyFolder) { - BookmarkBarNode* folder = model_->GetBookmarkBarNode()->GetChild(2); + BookmarkNode* folder = model_->GetBookmarkBarNode()->GetChild(2); BookmarkBarContextMenuController controller(bb_view_.get(), folder); EXPECT_FALSE(controller.IsCommandEnabled( BookmarkBarContextMenuController::open_all_bookmarks_id)); 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_;
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 35cc2ce..c3ad1ba 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -810,11 +810,11 @@ > </File> <File - RelativePath=".\bookmarks\bookmark_bar_model.cc" + RelativePath=".\bookmarks\bookmark_model.cc" > </File> <File - RelativePath=".\bookmarks\bookmark_bar_model.h" + RelativePath=".\bookmarks\bookmark_model.h" > </File> <File diff --git a/chrome/browser/browser_commands.cc b/chrome/browser/browser_commands.cc index 6fe3593..5594f0e 100644 --- a/chrome/browser/browser_commands.cc +++ b/chrome/browser/browser_commands.cc @@ -810,7 +810,7 @@ void Browser::StarCurrentTabContents() { return; WebContents* rvh = tab->AsWebContents(); - BookmarkBarModel* model = tab->profile()->GetBookmarkBarModel(); + BookmarkModel* model = tab->profile()->GetBookmarkModel(); if (!model || !model->IsLoaded()) return; // Ignore requests until bookmarks are loaded. diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 187e25a..b5cdf52 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -508,7 +508,7 @@ RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() { void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) { if (!model_) { - model_ = dom_ui_host_->profile()->GetBookmarkBarModel(); + model_ = dom_ui_host_->profile()->GetBookmarkModel(); model_->AddObserver(this); } // If the model is loaded, synchronously send the bookmarks down. Otherwise @@ -518,11 +518,11 @@ void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) { } void RecentlyBookmarkedHandler::SendBookmarksToPage() { - std::vector<BookmarkBarNode*> recently_bookmarked; + std::vector<BookmarkNode*> recently_bookmarked; model_->GetMostRecentlyAddedEntries(kRecentBookmarks, &recently_bookmarked); ListValue list_value; for (size_t i = 0; i < recently_bookmarked.size(); ++i) { - BookmarkBarNode* node = recently_bookmarked[i]; + BookmarkNode* node = recently_bookmarked[i]; DictionaryValue* entry_value = new DictionaryValue; SetURLAndTitle(entry_value, node->GetTitle(), node->GetURL()); list_value.Append(entry_value); @@ -530,24 +530,24 @@ void RecentlyBookmarkedHandler::SendBookmarksToPage() { dom_ui_host_->CallJavascriptFunction(L"recentlyBookmarked", list_value); } -void RecentlyBookmarkedHandler::Loaded(BookmarkBarModel* model) { +void RecentlyBookmarkedHandler::Loaded(BookmarkModel* model) { SendBookmarksToPage(); } -void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkBarModel* model, - BookmarkBarNode* parent, +void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkModel* model, + BookmarkNode* parent, int index) { SendBookmarksToPage(); } -void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkBarModel* model, - BookmarkBarNode* parent, +void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkModel* model, + BookmarkNode* parent, int index) { SendBookmarksToPage(); } -void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkBarModel* model, - BookmarkBarNode* node) { +void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model, + BookmarkNode* node) { SendBookmarksToPage(); } diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h index 49dcf81..3584954 100644 --- a/chrome/browser/dom_ui/new_tab_ui.h +++ b/chrome/browser/dom_ui/new_tab_ui.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__ #define CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__ -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/dom_ui/dom_ui_host.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/history/history.h" @@ -179,7 +179,7 @@ class TemplateURLHandler : public DOMMessageHandler, }; class RecentlyBookmarkedHandler : public DOMMessageHandler, - public BookmarkBarModelObserver { + public BookmarkModelObserver { public: explicit RecentlyBookmarkedHandler(DOMUIHost* dom_ui_host); ~RecentlyBookmarkedHandler(); @@ -194,29 +194,29 @@ class RecentlyBookmarkedHandler : public DOMMessageHandler, private: void SendBookmarksToPage(); - // BookmarkBarModelObserver methods. These invoke SendBookmarksToPage. - virtual void Loaded(BookmarkBarModel* model); - virtual void BookmarkNodeAdded(BookmarkBarModel* model, - BookmarkBarNode* parent, + // BookmarkModelObserver methods. These invoke SendBookmarksToPage. + virtual void Loaded(BookmarkModel* model); + 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 BookmarkNodeChanged(BookmarkModel* model, + BookmarkNode* node); // These two won't effect what is shown, so they do nothing. - 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 BookmarkNodeFavIconLoaded(BookmarkBarModel* model, - BookmarkBarNode* node) {} + virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, + BookmarkNode* node) {} DOMUIHost* dom_ui_host_; // The model we're getting bookmarks from. The model is owned by the Profile. - BookmarkBarModel* model_; + BookmarkModel* model_; DISALLOW_EVIL_CONSTRUCTORS(RecentlyBookmarkedHandler); }; diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc index daaf43b..e067894 100644 --- a/chrome/browser/history/expire_history_backend_unittest.cc +++ b/chrome/browser/history/expire_history_backend_unittest.cc @@ -7,7 +7,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/scoped_ptr.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/archived_database.h" #include "chrome/browser/history/expire_history_backend.h" #include "chrome/browser/history/history_database.h" @@ -65,7 +65,7 @@ class ExpireHistoryTest : public testing::Test, static bool IsStringInFile(std::wstring& filename, const char* str); - BookmarkBarModel bookmark_model_; + BookmarkModel bookmark_model_; MessageLoop message_loop_; diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index 5f91019..3bbb716 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -5,7 +5,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/scoped_ptr.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/in_memory_history_backend.h" #include "chrome/browser/history/in_memory_database.h" @@ -69,7 +69,7 @@ class HistoryBackendTest : public testing::Test { backend_->AddPage(request); } - BookmarkBarModel bookmark_model_; + BookmarkModel bookmark_model_; protected: bool loaded_; @@ -315,7 +315,7 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { // Unstar row2. bookmark_model_.SetURLStarred(row2.url(), std::wstring(), false); // Tell the backend it was unstarred. We have to explicitly do this as - // BookmarkBarModel isn't wired up to the backend during testing. + // BookmarkModel isn't wired up to the backend during testing. std::set<GURL> unstarred_urls; unstarred_urls.insert(row2.url()); backend_->URLsNoLongerBookmarked(unstarred_urls); @@ -329,7 +329,7 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { // Unstar row 1. bookmark_model_.SetURLStarred(row1.url(), std::wstring(), false); // Tell the backend it was unstarred. We have to explicitly do this as - // BookmarkBarModel isn't wired up to the backend during testing. + // BookmarkModel isn't wired up to the backend during testing. unstarred_urls.clear(); unstarred_urls.insert(row1.url()); backend_->URLsNoLongerBookmarked(unstarred_urls); diff --git a/chrome/browser/history/starred_url_database.cc b/chrome/browser/history/starred_url_database.cc index 6b61f31..67baced 100644 --- a/chrome/browser/history/starred_url_database.cc +++ b/chrome/browser/history/starred_url_database.cc @@ -7,8 +7,8 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/json_writer.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/history/history.h" #include "chrome/browser/history/query_parser.h" #include "chrome/browser/meta_table_helper.h" @@ -541,14 +541,14 @@ bool StarredURLDatabase::MigrateBookmarksToFileImpl(const std::wstring& path) { // Create the bookmark bar and other folder nodes. history::StarredEntry entry; entry.type = history::StarredEntry::BOOKMARK_BAR; - BookmarkBarNode bookmark_bar_node(NULL, GURL()); + BookmarkNode bookmark_bar_node(NULL, GURL()); bookmark_bar_node.Reset(entry); entry.type = history::StarredEntry::OTHER; - BookmarkBarNode other_node(NULL, GURL()); + BookmarkNode other_node(NULL, GURL()); other_node.Reset(entry); std::map<history::UIStarID, history::StarID> group_id_to_id_map; - typedef std::map<history::StarID, BookmarkBarNode*> IDToNodeMap; + typedef std::map<history::StarID, BookmarkNode*> IDToNodeMap; IDToNodeMap id_to_node_map; history::UIStarID other_folder_group_id = 0; @@ -586,14 +586,14 @@ bool StarredURLDatabase::MigrateBookmarksToFileImpl(const std::wstring& path) { continue; } - BookmarkBarNode* node = id_to_node_map[i->id]; + BookmarkNode* node = id_to_node_map[i->id]; if (!node) { // Creating a node results in creating the parent. As such, it is // possible for the node representing a group to have been created before // encountering the details. // The created nodes are owned by the root node. - node = new BookmarkBarNode(NULL, i->url); + node = new BookmarkNode(NULL, i->url); id_to_node_map[i->id] = node; } node->Reset(*i); @@ -601,10 +601,10 @@ bool StarredURLDatabase::MigrateBookmarksToFileImpl(const std::wstring& path) { DCHECK(group_id_to_id_map.find(i->parent_group_id) != group_id_to_id_map.end()); history::StarID parent_id = group_id_to_id_map[i->parent_group_id]; - BookmarkBarNode* parent = id_to_node_map[parent_id]; + BookmarkNode* parent = id_to_node_map[parent_id]; if (!parent) { // Haven't encountered the parent yet, create it now. - parent = new BookmarkBarNode(NULL, GURL()); + parent = new BookmarkNode(NULL, GURL()); id_to_node_map[parent_id] = parent; } diff --git a/chrome/browser/history_model.cc b/chrome/browser/history_model.cc index 64baf0c..638000c 100644 --- a/chrome/browser/history_model.cc +++ b/chrome/browser/history_model.cc @@ -4,7 +4,7 @@ #include "chrome/browser/history_model.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profile.h" // The max number of results to retrieve when browsing user's history. @@ -61,8 +61,7 @@ history::URLID HistoryModel::GetURLID(int index) { bool HistoryModel::IsStarred(int index) { if (star_state_[index] == UNKNOWN) { - bool is_starred = - profile_->GetBookmarkBarModel()->IsBookmarked(GetURL(index)); + bool is_starred = profile_->GetBookmarkModel()->IsBookmarked(GetURL(index)); star_state_[index] = is_starred ? STARRED : NOT_STARRED; } return (star_state_[index] == STARRED); @@ -171,7 +170,7 @@ void HistoryModel::SetPageStarred(int index, bool state) { if (observer_) observer_->ModelChanged(false); - BookmarkBarModel* bb_model = profile_->GetBookmarkBarModel(); + BookmarkModel* bb_model = profile_->GetBookmarkModel(); if (bb_model) bb_model->SetURLStarred(result.url(), result.title(), state); } diff --git a/chrome/browser/history_model.h b/chrome/browser/history_model.h index 8f3e5db..07e69a3 100644 --- a/chrome/browser/history_model.h +++ b/chrome/browser/history_model.h @@ -67,8 +67,8 @@ class HistoryModel : public BaseHistoryModel, // Contents of the current query. history::QueryResults results_; - // We lazily ask the BookmarkBarModel for whether a URL is starred. This - // enum gives the state of a particular entry. + // We lazily ask the BookmarkModel for whether a URL is starred. This enum + // gives the state of a particular entry. enum StarState { UNKNOWN = 0, // Indicates we haven't determined the state yet. STARRED, diff --git a/chrome/browser/ie_importer.cc b/chrome/browser/ie_importer.cc index a65600c..374a34d 100644 --- a/chrome/browser/ie_importer.cc +++ b/chrome/browser/ie_importer.cc @@ -15,7 +15,7 @@ #include "base/string_util.h" #include "base/time.h" #include "base/win_util.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/ie7_password.h" #include "chrome/browser/template_url_model.h" #include "chrome/common/l10n_util.h" diff --git a/chrome/browser/importer.cc b/chrome/browser/importer.cc index 1fc4ae5..47eea2f 100644 --- a/chrome/browser/importer.cc +++ b/chrome/browser/importer.cc @@ -10,7 +10,7 @@ #include "base/gfx/image_operations.h" #include "base/gfx/png_encoder.h" #include "base/string_util.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/firefox2_importer.h" #include "chrome/browser/firefox3_importer.h" @@ -31,13 +31,12 @@ // ProfileWriter. -bool ProfileWriter::BookmarkBarModelIsLoaded() const { - return profile_->GetBookmarkBarModel()->IsLoaded(); +bool ProfileWriter::BookmarkModelIsLoaded() const { + return profile_->GetBookmarkModel()->IsLoaded(); } -void ProfileWriter::AddBookmarkBarModelObserver( - BookmarkBarModelObserver* observer) { - profile_->GetBookmarkBarModel()->AddObserver(observer); +void ProfileWriter::AddBookmarkModelObserver(BookmarkModelObserver* observer) { + profile_->GetBookmarkModel()->AddObserver(observer); } bool ProfileWriter::TemplateURLModelIsLoaded() const { @@ -77,28 +76,28 @@ void ProfileWriter::AddHomepage(const GURL& home_page) { void ProfileWriter::AddBookmarkEntry( const std::vector<BookmarkEntry>& bookmark) { - BookmarkBarModel* model = profile_->GetBookmarkBarModel(); + BookmarkModel* model = profile_->GetBookmarkModel(); DCHECK(model->IsLoaded()); bool show_bookmark_toolbar = false; - std::set<BookmarkBarNode*> groups_added_to; + std::set<BookmarkNode*> groups_added_to; for (std::vector<BookmarkEntry>::const_iterator it = bookmark.begin(); it != bookmark.end(); ++it) { // Don't insert this url if it exists in model or url is not valid. if (model->GetNodeByURL(it->url) != NULL || !it->url.is_valid()) continue; - // Set up groups in BookmarkBarModel in such a way that path[i] is + // Set up groups in BookmarkModel in such a way that path[i] is // the subgroup of path[i-1]. Finally they construct a path in the // model: // path[0] \ path[1] \ ... \ path[size() - 1] - BookmarkBarNode* parent = + BookmarkNode* parent = (it->in_toolbar ? model->GetBookmarkBarNode() : model->other_node()); for (std::vector<std::wstring>::const_iterator i = it->path.begin(); i != it->path.end(); ++i) { - BookmarkBarNode* child = NULL; + BookmarkNode* child = NULL; for (int index = 0; index < parent->GetChildCount(); ++index) { - BookmarkBarNode* node = parent->GetChild(index); + BookmarkNode* node = parent->GetChild(index); if ((node->GetType() == history::StarredEntry::BOOKMARK_BAR || node->GetType() == history::StarredEntry::USER_GROUP) && node->GetTitle() == *i) { @@ -123,7 +122,7 @@ void ProfileWriter::AddBookmarkEntry( // Reset the date modified time of the groups we added to. We do this to // make sure the 'recently added to' combobox in the bubble doesn't get random // groups. - for (std::set<BookmarkBarNode*>::const_iterator i = groups_added_to.begin(); + for (std::set<BookmarkNode*>::const_iterator i = groups_added_to.begin(); i != groups_added_to.end(); ++i) { model->ResetDateGroupModified(*i); } @@ -300,7 +299,7 @@ ImporterHost::~ImporterHost() { STLDeleteContainerPointers(source_profiles_.begin(), source_profiles_.end()); } -void ImporterHost::Loaded(BookmarkBarModel* model) { +void ImporterHost::Loaded(BookmarkModel* model) { model->RemoveObserver(this); waiting_for_bookmarkbar_model_ = false; InvokeTaskIfDone(); @@ -370,11 +369,10 @@ void ImporterHost::StartImportSettings(const ProfileInfo& profile_info, } } - // BookmarkBarModel should be loaded before adding IE favorites. So we - // observe the BookmarkBarModel if needed, and start the task after - // it has been loaded. - if ((items & FAVORITES) && !writer_->BookmarkBarModelIsLoaded()) { - writer_->AddBookmarkBarModelObserver(this); + // BookmarkModel should be loaded before adding IE favorites. So we observe + // the BookmarkModel if needed, and start the task after it has been loaded. + if ((items & FAVORITES) && !writer_->BookmarkModelIsLoaded()) { + writer_->AddBookmarkModelObserver(this); waiting_for_bookmarkbar_model_ = true; } diff --git a/chrome/browser/importer.h b/chrome/browser/importer.h index 598e39e..65ba842 100644 --- a/chrome/browser/importer.h +++ b/chrome/browser/importer.h @@ -11,7 +11,7 @@ #include "base/basictypes.h" #include "base/message_loop.h" #include "base/ref_counted.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/ie7_password.h" #include "chrome/browser/profile.h" @@ -57,10 +57,10 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> { explicit ProfileWriter(Profile* profile) : profile_(profile) { } virtual ~ProfileWriter() { } - // Methods for monitoring BookmarkBarModel status. - virtual bool BookmarkBarModelIsLoaded() const; - virtual void AddBookmarkBarModelObserver( - BookmarkBarModelObserver* observer); + // Methods for monitoring BookmarkModel status. + virtual bool BookmarkModelIsLoaded() const; + virtual void AddBookmarkModelObserver( + BookmarkModelObserver* observer); // Methods for monitoring TemplateURLModel status. virtual bool TemplateURLModelIsLoaded() const; @@ -113,7 +113,7 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> { // browsers dynamically, and controls the process of importing. When // the import process is done, ImporterHost deletes itself. class ImporterHost : public base::RefCounted<ImporterHost>, - public BookmarkBarModelObserver, + public BookmarkModelObserver, public NotificationObserver { public: ImporterHost(); @@ -123,23 +123,23 @@ class ImporterHost : public base::RefCounted<ImporterHost>, // exist. explicit ImporterHost(MessageLoop* file_loop); - // BookmarkBarModelObserver methods. - virtual void Loaded(BookmarkBarModel* model); - virtual void BookmarkNodeMoved(BookmarkBarModel* model, - BookmarkBarNode* old_parent, + // BookmarkModelObserver methods. + virtual void Loaded(BookmarkModel* model); + 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) {} // NotificationObserver method. Called when TemplateURLModel has been loaded. void Observe(NotificationType type, diff --git a/chrome/browser/importer_unittest.cc b/chrome/browser/importer_unittest.cc index 5dde26c..694632f 100644 --- a/chrome/browser/importer_unittest.cc +++ b/chrome/browser/importer_unittest.cc @@ -151,13 +151,12 @@ class TestObserver : public ProfileWriter, EXPECT_EQ(1, password_count_); } - virtual bool BookmarkBarModelIsLoaded() const { + virtual bool BookmarkModelIsLoaded() const { // Profile is ready for writing. return true; } - virtual void AddBookmarkBarModelObserver( - BookmarkBarModelObserver* observer) { + virtual void AddBookmarkModelObserver(BookmarkModelObserver* observer) { NOTREACHED(); } @@ -505,13 +504,12 @@ class FirefoxObserver : public ProfileWriter, default_keyword_url_); } - virtual bool BookmarkBarModelIsLoaded() const { + virtual bool BookmarkModelIsLoaded() const { // Profile is ready for writing. return true; } - virtual void AddBookmarkBarModelObserver( - BookmarkBarModelObserver* observer) { + virtual void AddBookmarkModelObserver(BookmarkModelObserver* observer) { NOTREACHED(); } @@ -696,13 +694,12 @@ class Firefox3Observer : public ProfileWriter, default_keyword_url_); } - virtual bool BookmarkBarModelIsLoaded() const { + virtual bool BookmarkModelIsLoaded() const { // Profile is ready for writing. return true; } - virtual void AddBookmarkBarModelObserver( - BookmarkBarModelObserver* observer) { + virtual void AddBookmarkModelObserver(BookmarkModelObserver* observer) { NOTREACHED(); } diff --git a/chrome/browser/metrics_service.cc b/chrome/browser/metrics_service.cc index aaec563..f01494b 100644 --- a/chrome/browser/metrics_service.cc +++ b/chrome/browser/metrics_service.cc @@ -162,7 +162,7 @@ #include "base/path_service.h" #include "base/string_util.h" #include "base/task.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" @@ -452,7 +452,7 @@ void MetricsService::Observe(NotificationType type, break; case NOTIFY_BOOKMARK_MODEL_LOADED: - LogBookmarks(Source<Profile>(source)->GetBookmarkBarModel()); + LogBookmarks(Source<Profile>(source)->GetBookmarkModel()); break; default: @@ -1301,9 +1301,7 @@ void MetricsService::LogPluginChange(NotificationType type, } // Recursively counts the number of bookmarks and folders in node. -static void CountBookmarks(BookmarkBarNode* node, - int* bookmarks, - int* folders) { +static void CountBookmarks(BookmarkNode* node, int* bookmarks, int* folders) { if (node->GetType() == history::StarredEntry::URL) (*bookmarks)++; else @@ -1312,7 +1310,7 @@ static void CountBookmarks(BookmarkBarNode* node, CountBookmarks(node->GetChild(i), bookmarks, folders); } -void MetricsService::LogBookmarks(BookmarkBarNode* node, +void MetricsService::LogBookmarks(BookmarkNode* node, const wchar_t* num_bookmarks_key, const wchar_t* num_folders_key) { DCHECK(node); @@ -1327,7 +1325,7 @@ void MetricsService::LogBookmarks(BookmarkBarNode* node, pref->SetInteger(num_folders_key, num_folders); } -void MetricsService::LogBookmarks(BookmarkBarModel* model) { +void MetricsService::LogBookmarks(BookmarkModel* model) { DCHECK(model); LogBookmarks(model->GetBookmarkBarNode(), prefs::kNumBookmarksOnBookmarkBar, diff --git a/chrome/browser/metrics_service.h b/chrome/browser/metrics_service.h index 246d476..bda5d1b 100644 --- a/chrome/browser/metrics_service.h +++ b/chrome/browser/metrics_service.h @@ -23,8 +23,8 @@ #include "chrome/common/notification_service.h" #include "webkit/glue/webplugin.h" -class BookmarkBarModel; -class BookmarkBarNode; +class BookmarkModel; +class BookmarkNode; class PrefService; class Profile; class TemplateURLModel; @@ -229,12 +229,12 @@ class MetricsService : public NotificationObserver, // Set the value in preferences for for the number of bookmarks and folders // in node. The pref key for the number of bookmarks in num_bookmarks_key and // the pref key for number of folders in num_folders_key. - void LogBookmarks(BookmarkBarNode* node, + void LogBookmarks(BookmarkNode* node, const wchar_t* num_bookmarks_key, const wchar_t* num_folders_key); // Sets preferences for the for the number of bookmarks in model. - void LogBookmarks(BookmarkBarModel* model); + void LogBookmarks(BookmarkModel* model); // Records a plugin-related notification. These are recorded to an in-object // buffer because these notifications are sent on page load, and we don't diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 1ca28fe..0ad41b6 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -11,7 +11,7 @@ #include "base/scoped_ptr.h" #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 "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/download_manager.h" @@ -465,12 +465,8 @@ class OffTheRecordProfileImpl : public Profile, return profile_->DidLastSessionExitCleanly(); } - virtual bool HasBookmarkBarModel() { - return profile_->HasBookmarkBarModel(); - } - - virtual BookmarkBarModel* GetBookmarkBarModel() { - return profile_->GetBookmarkBarModel(); + virtual BookmarkModel* GetBookmarkModel() { + return profile_->GetBookmarkModel(); } #ifdef CHROME_PERSONALIZATION @@ -610,11 +606,11 @@ ProfileImpl::~ProfileImpl() { request_context_ = NULL; } - // HistoryService may call into the BookmarkBarModel, as such we need to - // delete HistoryService before the BookmarkBarModel. The destructor for + // HistoryService may call into the BookmarkModel, as such we need to + // delete HistoryService before the BookmarkModel. The destructor for // HistoryService will join with HistoryService's backend thread so that // by the time the destructor has finished we're sure it will no longer call - // into the BookmarkBarModel. + // into the BookmarkModel. history_service_ = NULL; bookmark_bar_model_.reset(); @@ -724,7 +720,7 @@ HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { if (!history_service_created_) { history_service_created_ = true; scoped_refptr<HistoryService> history(new HistoryService(this)); - if (!history->Init(GetPath(), GetBookmarkBarModel())) + if (!history->Init(GetPath(), GetBookmarkModel())) return NULL; history_service_.swap(history); @@ -836,13 +832,9 @@ bool ProfileImpl::DidLastSessionExitCleanly() { return last_session_exited_cleanly_; } -bool ProfileImpl::HasBookmarkBarModel() { - return bookmark_bar_model_.get() != NULL; -} - -BookmarkBarModel* ProfileImpl::GetBookmarkBarModel() { +BookmarkModel* ProfileImpl::GetBookmarkModel() { if (!bookmark_bar_model_.get()) { - bookmark_bar_model_.reset(new BookmarkBarModel(this)); + bookmark_bar_model_.reset(new BookmarkModel(this)); bookmark_bar_model_->Load(); } return bookmark_bar_model_.get(); diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 9e5adf2..83dcdec 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -19,7 +19,7 @@ #include "chrome/personalization/personalization.h" #endif -class BookmarkBarModel; +class BookmarkModel; class DownloadManager; class HistoryService; class NavigationController; @@ -182,11 +182,8 @@ class Profile { // Returns true if the last time this profile was open it was exited cleanly. virtual bool DidLastSessionExitCleanly() = 0; - // Returns true if the BookmarkBarMOdel has been created. - virtual bool HasBookmarkBarModel() = 0; - - // Returns the BookmarkBarModel, creating if not yet created. - virtual BookmarkBarModel* GetBookmarkBarModel() = 0; + // Returns the BookmarkModel, creating if not yet created. + virtual BookmarkModel* GetBookmarkModel() = 0; #ifdef CHROME_PERSONALIZATION virtual ProfilePersonalization GetProfilePersonalization() = 0; @@ -263,8 +260,7 @@ class ProfileImpl : public Profile { virtual void UnregisterNavigationController(NavigationController* controller); virtual const Profile::ProfileControllerSet& GetNavigationControllers(); virtual bool DidLastSessionExitCleanly(); - virtual bool HasBookmarkBarModel(); - virtual BookmarkBarModel* GetBookmarkBarModel(); + virtual BookmarkModel* GetBookmarkModel(); virtual bool IsSameProfile(Profile* profile); virtual Time GetStartTime() const; virtual TabRestoreService* GetTabRestoreService(); @@ -297,7 +293,7 @@ class ProfileImpl : public Profile { scoped_ptr<PrefService> prefs_; scoped_ptr<TemplateURLFetcher> template_url_fetcher_; scoped_ptr<TemplateURLModel> template_url_model_; - scoped_ptr<BookmarkBarModel> bookmark_bar_model_; + scoped_ptr<BookmarkModel> bookmark_bar_model_; #ifdef CHROME_PERSONALIZATION ProfilePersonalization personalization_; diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index d7fbabf..9c26e82 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -193,7 +193,7 @@ static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc, } // Returns the drag operations for the specified node. -static int GetDragOperationsForNode(BookmarkBarNode* node) { +static int GetDragOperationsForNode(BookmarkNode* node) { if (node->GetType() == history::StarredEntry::URL) { return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE | DragDropTypes::DRAG_LINK; @@ -316,9 +316,7 @@ class MenuRunner : public ChromeViews::MenuDelegate, public: // start_child_index is the index of the first child in node to add to the // menu. - MenuRunner(BookmarkBarView* view, - BookmarkBarNode* node, - int start_child_index) + MenuRunner(BookmarkBarView* view, BookmarkNode* node, int start_child_index) : view_(view), node_(node), menu_(this) { @@ -328,7 +326,7 @@ class MenuRunner : public ChromeViews::MenuDelegate, } // Returns the node the menu is being run for. - BookmarkBarNode* GetNode() { + BookmarkNode* GetNode() { return node_; } @@ -346,7 +344,7 @@ class MenuRunner : public ChromeViews::MenuDelegate, // Notification that the favicon has finished loading. Reset the icon // of the menu item. - void FavIconLoaded(BookmarkBarNode* node) { + void FavIconLoaded(BookmarkNode* node) { if (node_to_menu_id_map_.find(node) != node_to_menu_id_map_.end()) { menu_.SetIcon(node->GetFavIcon(), node_to_menu_id_map_[node]); @@ -368,14 +366,14 @@ class MenuRunner : public ChromeViews::MenuDelegate, private: // Creates an entry in menu for each child node of parent starting at // start_child_index, recursively invoking this for any star groups. - void BuildMenu(BookmarkBarNode* parent, + void BuildMenu(BookmarkNode* parent, int start_child_index, MenuItemView* menu, int* next_menu_id) { DCHECK(!parent->GetChildCount() || start_child_index < parent->GetChildCount()); for (int i = start_child_index; i < parent->GetChildCount(); ++i) { - BookmarkBarNode* node = parent->GetChild(i); + BookmarkNode* node = parent->GetChild(i); int id = *next_menu_id; (*next_menu_id)++; @@ -428,17 +426,17 @@ class MenuRunner : public ChromeViews::MenuDelegate, } // Drag originated from same profile and is not a URL. Only accept it if // the dragged node is not a parent of the node menu represents. - BookmarkBarNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; + BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; DCHECK(drop_node); - BookmarkBarNode* drag_node = drop_data_.GetNode(view_->GetProfile()-> - GetBookmarkBarModel()); + BookmarkNode* drag_node = + drop_data_.GetNode(view_->GetProfile()->GetBookmarkModel()); if (!drag_node) { // Hmmm, can't find the dragged node. This is generally an error // condition and we won't try and do anything fancy. NOTREACHED(); return false; } - BookmarkBarNode* node = drop_node; + BookmarkNode* node = drop_node; while (drop_node && drop_node != drag_node) drop_node = drop_node->GetParent(); return (drop_node == NULL); @@ -448,8 +446,8 @@ class MenuRunner : public ChromeViews::MenuDelegate, const ChromeViews::DropTargetEvent& event, DropPosition* position) { DCHECK(drop_data_.is_valid); - BookmarkBarNode* node = menu_id_to_node_map_[item->GetCommand()]; - BookmarkBarNode* drop_parent = node->GetParent(); + BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()]; + BookmarkNode* drop_parent = node->GetParent(); int index_to_drop_at = drop_parent->IndexOfChild(node); if (*position == DROP_AFTER) { index_to_drop_at++; @@ -465,11 +463,11 @@ class MenuRunner : public ChromeViews::MenuDelegate, virtual int OnPerformDrop(MenuItemView* menu, DropPosition position, const DropTargetEvent& event) { - BookmarkBarNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; + BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; DCHECK(drop_node); - BookmarkBarModel* model = view_->GetModel(); + BookmarkModel* model = view_->GetModel(); DCHECK(model); - BookmarkBarNode* drop_parent = drop_node->GetParent(); + BookmarkNode* drop_parent = drop_node->GetParent(); DCHECK(drop_parent); int index_to_drop_at = drop_parent->IndexOfChild(drop_node); if (position == DROP_AFTER) { @@ -526,7 +524,7 @@ class MenuRunner : public ChromeViews::MenuDelegate, } // The node we're showing the contents of. - BookmarkBarNode* node_; + BookmarkNode* node_; // The view that created us. BookmarkBarView* view_; @@ -534,12 +532,12 @@ class MenuRunner : public ChromeViews::MenuDelegate, // The menu. MenuItemView menu_; - // Mapping from menu id to the BookmarkBarNode. - std::map<int, BookmarkBarNode*> menu_id_to_node_map_; + // Mapping from menu id to the BookmarkNode. + std::map<int, BookmarkNode*> menu_id_to_node_map_; // Mapping from node to menu id. This only contains entries for nodes of type // URL. - std::map<BookmarkBarNode*, int> node_to_menu_id_map_; + std::map<BookmarkNode*, int> node_to_menu_id_map_; // Data for the drop. BookmarkDragData drop_data_; @@ -678,12 +676,12 @@ void BookmarkBarView::SetProfile(Profile* profile) { ns->AddObserver(this, NOTIFY_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, NotificationService::AllSources()); - model_ = profile_->GetBookmarkBarModel(); + model_ = profile_->GetBookmarkModel(); model_->AddObserver(this); if (model_->IsLoaded()) Loaded(model_); - // else case: we'll receive notification back from the BookmarkBarModel when - // done loading, then we'll populate the bar. + // else case: we'll receive notification back from the BookmarkModel when done + // loading, then we'll populate the bar. } void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) { @@ -973,7 +971,7 @@ int BookmarkBarView::OnDragUpdated(const DropTargetEvent& event) { } if (drop_on || is_over_overflow || is_over_other) { - BookmarkBarNode* node; + BookmarkNode* node; if (is_over_other) node = model_->other_node(); else if (is_over_overflow) @@ -1009,9 +1007,8 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) { if (!drop_info_.get() || !drop_info_->drag_operation) return DragDropTypes::DRAG_NONE; - BookmarkBarNode* root = - drop_info_->is_over_other ? model_->other_node() : - model_->GetBookmarkBarNode(); + BookmarkNode* root = drop_info_->is_over_other ? model_->other_node() : + model_->GetBookmarkBarNode(); int index = drop_info_->drop_index; const bool drop_on = drop_info_->drop_on; const BookmarkDragData data = drop_info_->data; @@ -1024,7 +1021,7 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) { } drop_info_.reset(); - BookmarkBarNode* parent_node; + BookmarkNode* parent_node; if (is_over_other) { parent_node = root; index = parent_node->GetChildCount(); @@ -1155,8 +1152,8 @@ int BookmarkBarView::GetBookmarkButtonCount() { return GetChildViewCount() - 4; } -void BookmarkBarView::Loaded(BookmarkBarModel* model) { - BookmarkBarNode* node = model_->GetBookmarkBarNode(); +void BookmarkBarView::Loaded(BookmarkModel* model) { + BookmarkNode* node = model_->GetBookmarkBarNode(); DCHECK(node && model_->other_node()); // Create a button for each of the children on the bookmark bar. for (int i = 0; i < node->GetChildCount(); ++i) @@ -1166,7 +1163,7 @@ void BookmarkBarView::Loaded(BookmarkBarModel* model) { SchedulePaint(); } -void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkBarModel* model) { +void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { // The bookmark model should never be deleted before us. This code exists // to check for regressions in shutdown code and not crash. NOTREACHED(); @@ -1177,10 +1174,10 @@ void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkBarModel* model) { model_ = NULL; } -void BookmarkBarView::BookmarkNodeMoved(BookmarkBarModel* model, - BookmarkBarNode* old_parent, +void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, + BookmarkNode* old_parent, int old_index, - BookmarkBarNode* new_parent, + BookmarkNode* new_parent, int new_index) { StopThrobbing(true); BookmarkNodeRemovedImpl(model, old_parent, old_index); @@ -1188,16 +1185,16 @@ void BookmarkBarView::BookmarkNodeMoved(BookmarkBarModel* model, StartThrobbing(); } -void BookmarkBarView::BookmarkNodeAdded(BookmarkBarModel* model, - BookmarkBarNode* parent, +void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, + BookmarkNode* parent, int index) { StopThrobbing(true); BookmarkNodeAddedImpl(model, parent, index); StartThrobbing(); } -void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkBarModel* model, - BookmarkBarNode* parent, +void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, + BookmarkNode* parent, int index) { NotifyModelChanged(); if (parent != model_->GetBookmarkBarNode()) { @@ -1210,16 +1207,16 @@ void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkBarModel* model, SchedulePaint(); } -void BookmarkBarView::BookmarkNodeRemoved(BookmarkBarModel* model, - BookmarkBarNode* parent, +void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, + BookmarkNode* parent, int index) { StopThrobbing(true); BookmarkNodeRemovedImpl(model, parent, index); StartThrobbing(); } -void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkBarModel* model, - BookmarkBarNode* parent, +void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, + BookmarkNode* parent, int index) { NotifyModelChanged(); if (parent != model_->GetBookmarkBarNode()) { @@ -1234,14 +1231,14 @@ void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkBarModel* model, SchedulePaint(); } -void BookmarkBarView::BookmarkNodeChanged(BookmarkBarModel* model, - BookmarkBarNode* node) { +void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model, + BookmarkNode* node) { NotifyModelChanged(); BookmarkNodeChangedImpl(model, node); } -void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkBarModel* model, - BookmarkBarNode* node) { +void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, + BookmarkNode* node) { if (node->GetParent() != model_->GetBookmarkBarNode()) { // We only care about nodes on the bookmark bar. return; @@ -1262,8 +1259,8 @@ void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkBarModel* model, } } -void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkBarModel* model, - BookmarkBarNode* node) { +void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model, + BookmarkNode* node) { if (menu_runner_.get()) menu_runner_->FavIconLoaded(node); if (drop_menu_runner_.get()) @@ -1292,7 +1289,7 @@ void BookmarkBarView::WriteDragData(View* sender, NOTREACHED(); } -void BookmarkBarView::WriteDragData(BookmarkBarNode* node, +void BookmarkBarView::WriteDragData(BookmarkNode* node, OSExchangeData* data) { DCHECK(node && data); BookmarkDragData drag_data(node); @@ -1314,7 +1311,7 @@ int BookmarkBarView::GetDragOperations(View* sender, int x, int y) { void BookmarkBarView::RunMenu(ChromeViews::View* view, const CPoint& pt, HWND hwnd) { - BookmarkBarNode* node; + BookmarkNode* node; MenuItemView::AnchorPosition anchor_point = MenuItemView::TOPLEFT; // When we set the menu's position, we must take into account the mirrored @@ -1369,7 +1366,7 @@ void BookmarkBarView::RunMenu(ChromeViews::View* view, void BookmarkBarView::ButtonPressed(ChromeViews::BaseButton* sender) { int index = GetChildIndex(sender); DCHECK(index != -1); - BookmarkBarNode* node = model_->GetBookmarkBarNode()->GetChild(index); + BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(index); DCHECK(page_navigator_); page_navigator_->OpenURL( node->GetURL(), @@ -1387,7 +1384,7 @@ void BookmarkBarView::ShowContextMenu(View* source, return; } - BookmarkBarNode* node = model_->GetBookmarkBarNode(); + BookmarkNode* node = model_->GetBookmarkBarNode(); if (source == other_bookmarked_button_) { node = model_->other_node(); } else if (source != this) { @@ -1402,8 +1399,7 @@ void BookmarkBarView::ShowContextMenu(View* source, controller.RunMenuAt(x, y); } -ChromeViews::View* BookmarkBarView::CreateBookmarkButton( - BookmarkBarNode* node) { +ChromeViews::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) { if (node->GetType() == history::StarredEntry::URL) { BookmarkButton* button = new BookmarkButton(node->GetURL(), node->GetTitle(), @@ -1420,7 +1416,7 @@ ChromeViews::View* BookmarkBarView::CreateBookmarkButton( } } -void BookmarkBarView::ConfigureButton(BookmarkBarNode* node, +void BookmarkBarView::ConfigureButton(BookmarkNode* node, ChromeViews::TextButton* button) { button->SetText(node->GetTitle()); button->ClearMaxTextSize(); @@ -1484,7 +1480,7 @@ void BookmarkBarView::NotifyModelChanged() { model_changed_listener_->ModelChanged(); } -void BookmarkBarView::ShowDropFolderForNode(BookmarkBarNode* node) { +void BookmarkBarView::ShowDropFolderForNode(BookmarkNode* node) { if (drop_menu_runner_.get() && drop_menu_runner_->GetNode() == node) { // Already showing for the specified node. return; @@ -1542,7 +1538,7 @@ void BookmarkBarView::StopShowFolderDropMenuTimer() { show_folder_drop_menu_task_->Cancel(); } -void BookmarkBarView::StartShowFolderDropMenuTimer(BookmarkBarNode* node) { +void BookmarkBarView::StartShowFolderDropMenuTimer(BookmarkNode* node) { if (testing_) { // So that tests can run as fast as possible disable the delay during // testing. @@ -1608,7 +1604,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event, int button_w = button->GetWidth(); if (button_x < button_w) { found = true; - BookmarkBarNode* node = model_->GetBookmarkBarNode()->GetChild(i); + BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(i); if (node->GetType() != history::StarredEntry::URL) { if (button_x <= MenuItemView::kDropBetweenPixels) { *index = i; @@ -1653,7 +1649,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event, } if (*drop_on) { - BookmarkBarNode* parent = + BookmarkNode* parent = *is_over_other ? model_->other_node() : model_->GetBookmarkBarNode()->GetChild(*index); int operation = @@ -1673,14 +1669,14 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event, } int BookmarkBarView::CalculateDropOperation(const BookmarkDragData& data, - BookmarkBarNode* parent, + BookmarkNode* parent, int index) { if (!CanDropAt(data, parent, index)) return DragDropTypes::DRAG_NONE; if (data.is_url) { // User is dragging a URL. - BookmarkBarNode* node = model_->GetNodeByURL(data.url); + BookmarkNode* node = model_->GetNodeByURL(data.url); if (!node) { // We don't have a node with this url. return DragDropTypes::DRAG_COPY; @@ -1690,7 +1686,7 @@ int BookmarkBarView::CalculateDropOperation(const BookmarkDragData& data, return DragDropTypes::DRAG_MOVE | DragDropTypes::DRAG_COPY; } else if (data.profile_id == GetProfile()->GetID()) { // Dropping a group from the same profile results in a move. - BookmarkBarNode* node = data.GetNode(model_); + BookmarkNode* node = data.GetNode(model_); if (!node) { // Generally shouldn't get here, we originated the drag but couldn't // find the node. @@ -1704,11 +1700,11 @@ int BookmarkBarView::CalculateDropOperation(const BookmarkDragData& data, } bool BookmarkBarView::CanDropAt(const BookmarkDragData& data, - BookmarkBarNode* parent, + BookmarkNode* parent, int index) { DCHECK(data.is_valid); if (data.is_url) { - BookmarkBarNode* existing_node = model_->GetNodeByURL(data.url); + BookmarkNode* existing_node = model_->GetNodeByURL(data.url); if (existing_node && existing_node->GetParent() == parent) { const int existing_index = parent->IndexOfChild(existing_node); if (index == existing_index || existing_index + 1 == index) @@ -1716,7 +1712,7 @@ bool BookmarkBarView::CanDropAt(const BookmarkDragData& data, } return true; } else if (data.profile_id == profile_->GetID()) { - BookmarkBarNode* existing_node = data.GetNode(model_); + BookmarkNode* existing_node = data.GetNode(model_); if (existing_node) { if (existing_node->GetParent() == parent) { const int existing_index = parent->IndexOfChild(existing_node); @@ -1725,7 +1721,7 @@ bool BookmarkBarView::CanDropAt(const BookmarkDragData& data, } // Allow the drop only if the node we're going to drop on isn't a // descendant of the dragged node. - BookmarkBarNode* test_node = parent; + BookmarkNode* test_node = parent; while (test_node && test_node != existing_node) test_node = test_node->GetParent(); return (test_node == NULL); @@ -1736,11 +1732,11 @@ bool BookmarkBarView::CanDropAt(const BookmarkDragData& data, int BookmarkBarView::PerformDropImpl(const BookmarkDragData& data, - BookmarkBarNode* parent_node, + BookmarkNode* parent_node, int index) { if (data.is_url) { // User is dragging a URL. - BookmarkBarNode* node = model_->GetNodeByURL(data.url); + BookmarkNode* node = model_->GetNodeByURL(data.url); if (!node) { std::wstring title = data.title; if (title.empty()) { @@ -1755,7 +1751,7 @@ int BookmarkBarView::PerformDropImpl(const BookmarkDragData& data, model_->Move(node, parent_node, index); return DragDropTypes::DRAG_MOVE; } else if (data.profile_id == GetProfile()->GetID()) { - BookmarkBarNode* node = data.GetNode(model_); + BookmarkNode* node = data.GetNode(model_); if (!node) { // Generally shouldn't get here, we originated the drag but couldn't // find the node. Do nothing. @@ -1771,19 +1767,19 @@ int BookmarkBarView::PerformDropImpl(const BookmarkDragData& data, } void BookmarkBarView::CloneDragData(const BookmarkDragData& data, - BookmarkBarNode* parent, + BookmarkNode* parent, int index_to_add_at) { DCHECK(data.is_valid && model_); if (data.is_url) { - BookmarkBarNode* node = model_->GetNodeByURL(data.url); + BookmarkNode* node = model_->GetNodeByURL(data.url); if (node) { model_->Move(node, parent, index_to_add_at); } else { model_->AddURL(parent, index_to_add_at, data.title, data.url); } } else { - BookmarkBarNode* new_folder = model_->AddGroup(parent, index_to_add_at, - data.title); + BookmarkNode* new_folder = model_->AddGroup(parent, index_to_add_at, + data.title); for (int i = 0; i < static_cast<int>(data.children.size()); ++i) CloneDragData(data.children[i], new_folder, i); } @@ -1807,15 +1803,15 @@ void BookmarkBarView::StartThrobbing() { if (!GetViewContainer()) return; // We're not showing, don't do anything. - BookmarkBarNode* node = model_->GetNodeByURL(bubble_url_); + BookmarkNode* node = model_->GetNodeByURL(bubble_url_); if (!node) return; // Generally shouldn't happen. // Determine which visible button is showing the url (or is an ancestor of // the url). if (node->HasAncestor(model_->GetBookmarkBarNode())) { - BookmarkBarNode* bbn = model_->GetBookmarkBarNode(); - BookmarkBarNode* parent_on_bb = node; + BookmarkNode* bbn = model_->GetBookmarkBarNode(); + BookmarkNode* parent_on_bb = node; while (parent_on_bb->GetParent() != bbn) parent_on_bb = parent_on_bb->GetParent(); int index = bbn->IndexOfChild(parent_on_bb); diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h index 63dcacb..552dbaf 100644 --- a/chrome/browser/views/bookmark_bar_view.h +++ b/chrome/browser/views/bookmark_bar_view.h @@ -5,8 +5,8 @@ #ifndef CHROME_BROWSER_VIEWS_BOOKMARK_BAR_VIEW_H_ #define CHROME_BROWSER_VIEWS_BOOKMARK_BAR_VIEW_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/slide_animation.h" #include "chrome/views/label.h" #include "chrome/views/menu.h" @@ -28,16 +28,15 @@ namespace ChromeViews { class MenuItemView; } -// BookmarkBarView renders the BookmarkBarModel. Each starred entry -// on the BookmarkBar is rendered as a MenuButton. An additional -// MenuButton aligned to the right allows the user to quickly see -// recently starred entries. +// BookmarkBarView renders the BookmarkModel. Each starred entry on the +// BookmarkBar is rendered as a MenuButton. An additional MenuButton aligned to +// the right allows the user to quickly see recently starred entries. // // BookmarkBarView shows the bookmarks from a specific Profile. BookmarkBarView // waits until the HistoryService for the profile has been loaded before -// creating the BookmarkBarModel. +// creating the BookmarkModel. class BookmarkBarView : public ChromeViews::View, - public BookmarkBarModelObserver, + public BookmarkModelObserver, public ChromeViews::ViewMenuDelegate, public ChromeViews::BaseButton::ButtonListener, public Menu::Delegate, @@ -120,7 +119,7 @@ class BookmarkBarView : public ChromeViews::View, PageNavigator* GetPageNavigator() { return page_navigator_; } // Returns the model. - BookmarkBarModel* GetModel() { return model_; } + BookmarkModel* GetModel() { return model_; } // Toggles whether the bookmark bar is shown only on the new tab page or on // all tabs. @@ -174,8 +173,7 @@ class BookmarkBarView : public ChromeViews::View, // deletes itself once run. class ShowFolderDropMenuTask : public Task { public: - ShowFolderDropMenuTask(BookmarkBarView* view, - BookmarkBarNode* node) + ShowFolderDropMenuTask(BookmarkBarView* view, BookmarkNode* node) : view_(view), node_(node) { } @@ -195,7 +193,7 @@ class BookmarkBarView : public ChromeViews::View, private: BookmarkBarView* view_; - BookmarkBarNode* node_; + BookmarkNode* node_; DISALLOW_COPY_AND_ASSIGN(ShowFolderDropMenuTask); }; @@ -217,55 +215,55 @@ class BookmarkBarView : public ChromeViews::View, // Invoked when the bookmark bar model has finished loading. Creates a button // for each of the children of the root node from the model. - virtual void Loaded(BookmarkBarModel* model); + virtual void Loaded(BookmarkModel* model); // Invoked when the model is being deleted. - virtual void BookmarkModelBeingDeleted(BookmarkBarModel* model); + virtual void BookmarkModelBeingDeleted(BookmarkModel* model); // Invokes added followed by removed. - 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); // Notifies ModelChangeListener of change. // If the node was added to the root node, a button is created and added to // this bookmark bar view. - virtual void BookmarkNodeAdded(BookmarkBarModel* model, - BookmarkBarNode* parent, + virtual void BookmarkNodeAdded(BookmarkModel* model, + BookmarkNode* parent, int index); // Implementation for BookmarkNodeAddedImpl. - void BookmarkNodeAddedImpl(BookmarkBarModel* model, - BookmarkBarNode* parent, + void BookmarkNodeAddedImpl(BookmarkModel* model, + BookmarkNode* parent, int index); // Notifies ModelChangeListener of change. // If the node was a child of the root node, the button corresponding to it // is removed. - virtual void BookmarkNodeRemoved(BookmarkBarModel* model, - BookmarkBarNode* parent, + virtual void BookmarkNodeRemoved(BookmarkModel* model, + BookmarkNode* parent, int index); // Implementation for BookmarkNodeRemoved. - void BookmarkNodeRemovedImpl(BookmarkBarModel* model, - BookmarkBarNode* parent, + void BookmarkNodeRemovedImpl(BookmarkModel* model, + BookmarkNode* parent, int index); // Notifies ModelChangedListener and invokes BookmarkNodeChangedImpl. - virtual void BookmarkNodeChanged(BookmarkBarModel* model, - BookmarkBarNode* node); + virtual void BookmarkNodeChanged(BookmarkModel* model, + BookmarkNode* node); // If the node is a child of the root node, the button is updated // appropriately. - void BookmarkNodeChangedImpl(BookmarkBarModel* model, BookmarkBarNode* node); + void BookmarkNodeChangedImpl(BookmarkModel* model, BookmarkNode* node); // Invoked when the favicon is available. If the node is a child of the // root node, the appropriate button is updated. If a menu is showing, the // call is forwarded to the menu to allow for it to update the icon. - virtual void BookmarkNodeFavIconLoaded(BookmarkBarModel* model, - BookmarkBarNode* node); + virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, + BookmarkNode* node); // DragController method. Determines the node representing sender and invokes // WriteDragData to write the actual data. @@ -275,7 +273,7 @@ class BookmarkBarView : public ChromeViews::View, OSExchangeData* data); // Writes a BookmarkDragData for node to data. - void WriteDragData(BookmarkBarNode* node, OSExchangeData* data); + void WriteDragData(BookmarkNode* node, OSExchangeData* data); // Returns the drag operations for the specified button. virtual int GetDragOperations(ChromeViews::View* sender, int x, int y); @@ -300,11 +298,11 @@ class BookmarkBarView : public ChromeViews::View, bool is_mouse_gesture); // Creates the button for rendering the specified bookmark node. - ChromeViews::View* CreateBookmarkButton(BookmarkBarNode* node); + ChromeViews::View* CreateBookmarkButton(BookmarkNode* node); // COnfigures the button from the specified node. This sets the text, // and icon. - void ConfigureButton(BookmarkBarNode* node, ChromeViews::TextButton* button); + void ConfigureButton(BookmarkNode* node, ChromeViews::TextButton* button); // Used when showing the menu allowing the user to choose when the bar is // visible. Return value corresponds to the users preference for when the @@ -329,13 +327,13 @@ class BookmarkBarView : public ChromeViews::View, void NotifyModelChanged(); // Shows the menu used during drag and drop for the specified node. - void ShowDropFolderForNode(BookmarkBarNode* node); + void ShowDropFolderForNode(BookmarkNode* node); // Cancels the timer used to show a drop menu. void StopShowFolderDropMenuTimer(); // Stars the timer used to show a drop menu for node. - void StartShowFolderDropMenuTimer(BookmarkBarNode* node); + void StartShowFolderDropMenuTimer(BookmarkNode* node); // Returns the drop operation and index for the drop based on the event // and data. Returns DragDropTypes::DRAG_NONE if not a valid location. @@ -349,26 +347,26 @@ class BookmarkBarView : public ChromeViews::View, // Invokes CanDropAt to determine if this is a valid location for the data, // then returns the appropriate drag operation based on the data. int CalculateDropOperation(const BookmarkDragData& data, - BookmarkBarNode* parent, + BookmarkNode* parent, int index); // Returns true if the specified location is a valid drop location for // the supplied drag data. bool CanDropAt(const BookmarkDragData& data, - BookmarkBarNode* parent, + BookmarkNode* parent, int index); // Performs a drop of the specified data at the specified location. Returns // the result. int PerformDropImpl(const BookmarkDragData& data, - BookmarkBarNode* parent_node, + BookmarkNode* parent_node, int index); // Creates a new group/entry for data, and recursively invokes itself for // all children of data. This is used during drag and drop to clone a // group from another profile. void CloneDragData(const BookmarkDragData& data, - BookmarkBarNode* parent, + BookmarkNode* parent, int index_to_add_at); // Returns the index of the first hidden bookmark button. If all buttons are @@ -391,7 +389,7 @@ class BookmarkBarView : public ChromeViews::View, // Model providing details as to the starred entries/groups that should be // shown. This is owned by the Profile. - BookmarkBarModel* model_; + BookmarkModel* model_; // Used to manage showing a Menu: either for the most recently bookmarked // entries, or for the a starred group. diff --git a/chrome/browser/views/bookmark_bar_view_test.cc b/chrome/browser/views/bookmark_bar_view_test.cc index ffaa992..211d88d 100644 --- a/chrome/browser/views/bookmark_bar_view_test.cc +++ b/chrome/browser/views/bookmark_bar_view_test.cc @@ -4,7 +4,7 @@ #include "base/string_util.h" #include "chrome/browser/automation/ui_controls.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/page_navigator.h" #include "chrome/browser/profile.h" #include "chrome/browser/views/bookmark_bar_view.h" @@ -73,10 +73,10 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { profile_.reset(new TestingProfile()); profile_->set_has_history_service(true); - profile_->CreateBookmarkBarModel(true); + profile_->CreateBookmarkModel(true); profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); - model_ = profile_->GetBookmarkBarModel(); + model_ = profile_->GetBookmarkModel(); bb_view_ = new BookmarkBarView(profile_.get(), NULL); bb_view_->SetPageNavigator(&navigator_); @@ -129,7 +129,7 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { // See comment above class description for what this does. virtual bool CreateBigMenu() { return false; } - BookmarkBarModel* model_; + BookmarkModel* model_; BookmarkBarView* bb_view_; TestingPageNavigator navigator_; @@ -137,10 +137,9 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { void AddTestData(bool big_menu) { std::string test_base = "file:///c:/tmp/"; - BookmarkBarNode* f1 = - model_->AddGroup(model_->GetBookmarkBarNode(), 0, L"F1"); + BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 0, L"F1"); model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a")); - BookmarkBarNode* f11 = model_->AddGroup(f1, 1, L"F11"); + BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11"); model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a")); if (big_menu) { for (int i = 1; i <= 100; ++i) { @@ -157,10 +156,10 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { model_->AddURL(model_->GetBookmarkBarNode(), 4, L"d", GURL(test_base + "d")); model_->AddURL(model_->other_node(), 0, L"oa", GURL(test_base + "oa")); - BookmarkBarNode* of = model_->AddGroup(model_->other_node(), 1, L"OF"); + BookmarkNode* of = model_->AddGroup(model_->other_node(), 1, L"OF"); model_->AddURL(of, 0, L"ofa", GURL(test_base + "ofa")); model_->AddURL(of, 1, L"ofb", GURL(test_base + "ofb")); - BookmarkBarNode* of2 = model_->AddGroup(model_->other_node(), 2, L"OF2"); + BookmarkNode* of2 = model_->AddGroup(model_->other_node(), 2, L"OF2"); model_->AddURL(of2, 0, L"of2a", GURL(test_base + "of2a")); model_->AddURL(of2, 1, L"of2b", GURL(test_base + "of2b")); } diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc index 1734d01..476391e 100644 --- a/chrome/browser/views/bookmark_bubble_view.cc +++ b/chrome/browser/views/bookmark_bubble_view.cc @@ -6,7 +6,7 @@ #include "chrome/app/chrome_dll_resource.h" #include "chrome/app/theme/theme_resources.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profile.h" #include "chrome/browser/standard_layout.h" #include "chrome/browser/user_metrics.h" @@ -51,7 +51,7 @@ static SkBitmap* kCloseImage = NULL; // RecentlyUsedFoldersModel --------------------------------------------------- BookmarkBubbleView::RecentlyUsedFoldersModel::RecentlyUsedFoldersModel( - BookmarkBarModel* bb_model, BookmarkBarNode* node) + BookmarkModel* bb_model, BookmarkNode* node) // Use + 2 to account for bookmark bar and other node. : nodes_(bb_model->GetMostRecentlyModifiedGroups(kMaxMRUFolders + 2)), node_parent_index_(0) { @@ -93,14 +93,14 @@ std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt( return nodes_[index]->GetTitle(); } -BookmarkBarNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt( +BookmarkNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt( int index) { return nodes_[index]; } void BookmarkBubbleView::RecentlyUsedFoldersModel::RemoveNode( - BookmarkBarNode* node) { - std::vector<BookmarkBarNode*>::iterator i = + BookmarkNode* node) { + std::vector<BookmarkNode*>::iterator i = find(nodes_.begin(), nodes_.end(), node); if (i != nodes_.end()) nodes_.erase(i); @@ -163,8 +163,8 @@ BookmarkBubbleView::BookmarkBubbleView(InfoBubbleDelegate* delegate, profile_(profile), url_(url), newly_bookmarked_(newly_bookmarked), - parent_model_(profile_->GetBookmarkBarModel(), - profile_->GetBookmarkBarModel()->GetNodeByURL(url)) { + parent_model_(profile_->GetBookmarkModel(), + profile_->GetBookmarkModel()->GetNodeByURL(url)) { Init(); } @@ -254,8 +254,8 @@ void BookmarkBubbleView::Init() { } std::wstring BookmarkBubbleView::GetTitle() { - BookmarkBarModel* bookmark_model= profile_->GetBookmarkBarModel(); - BookmarkBarNode* node = bookmark_model->GetNodeByURL(url_); + BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); + BookmarkNode* node = bookmark_model->GetNodeByURL(url_); if (node) return node->GetTitle(); else @@ -288,10 +288,10 @@ void BookmarkBubbleView::ItemChanged(ComboBox* combo_box, ShowEditor(); return; } - BookmarkBarModel* model = profile_->GetBookmarkBarModel(); - BookmarkBarNode* node = model->GetNodeByURL(url_); + BookmarkModel* model = profile_->GetBookmarkModel(); + BookmarkNode* node = model->GetNodeByURL(url_); if (node) { - BookmarkBarNode* new_parent = parent_model_.GetNodeAt(new_index); + BookmarkNode* new_parent = parent_model_.GetNodeAt(new_index); if (new_parent != node->GetParent()) { UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_); model->Move(node, new_parent, new_parent->GetChildCount()); @@ -320,7 +320,7 @@ void BookmarkBubbleView::RemoveBookmark() { UserMetrics::RecordAction(L"BookmarkBubble_Unstar", profile_); GURL url = url_; - BookmarkBarModel* model = profile_->GetBookmarkBarModel(); + BookmarkModel* model = profile_->GetBookmarkModel(); // Close first, then notify the service. That way we know we won't be // visible and don't have to worry about some other window becoming // activated and deleting us before we invoke Close. @@ -352,8 +352,8 @@ void BookmarkBubbleView::ShowEditor() { } void BookmarkBubbleView::SetNodeTitleFromTextField() { - BookmarkBarModel* model = profile_->GetBookmarkBarModel(); - BookmarkBarNode* node = model->GetNodeByURL(url_); + BookmarkModel* model = profile_->GetBookmarkModel(); + BookmarkNode* node = model->GetNodeByURL(url_); if (node) { const std::wstring new_title = title_tf_->GetText(); if (new_title != node->GetTitle()) { diff --git a/chrome/browser/views/bookmark_bubble_view.h b/chrome/browser/views/bookmark_bubble_view.h index 17af49f..2b3fc9f 100644 --- a/chrome/browser/views/bookmark_bubble_view.h +++ b/chrome/browser/views/bookmark_bubble_view.h @@ -15,8 +15,8 @@ class Profile; -class BookmarkBarModel; -class BookmarkBarNode; +class BookmarkModel; +class BookmarkNode; namespace ChromeViews { class CheckBox; @@ -57,23 +57,23 @@ class BookmarkBubbleView : public ChromeViews::View, // also contains an extra item that shows the text 'Choose another folder...'. class RecentlyUsedFoldersModel : public ChromeViews::ComboBox::Model { public: - RecentlyUsedFoldersModel(BookmarkBarModel* bb_model, BookmarkBarNode* node); + RecentlyUsedFoldersModel(BookmarkModel* bb_model, BookmarkNode* node); // ComboBox::Model methods. Call through to nodes_. virtual int GetItemCount(ChromeViews::ComboBox* source); virtual std::wstring GetItemAt(ChromeViews::ComboBox* source, int index); // Returns the node at the specified index. - BookmarkBarNode* GetNodeAt(int index); + BookmarkNode* GetNodeAt(int index); // Returns the index of the original parent folder. int node_parent_index() const { return node_parent_index_; } private: // Removes node from nodes_. Does nothing if node is not in nodes_. - void RemoveNode(BookmarkBarNode* node); + void RemoveNode(BookmarkNode* node); - std::vector<BookmarkBarNode*> nodes_; + std::vector<BookmarkNode*> nodes_; int node_parent_index_; DISALLOW_EVIL_CONSTRUCTORS(RecentlyUsedFoldersModel); diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc index b8d4a11..549474c 100644 --- a/chrome/browser/views/bookmark_editor_view.cc +++ b/chrome/browser/views/bookmark_editor_view.cc @@ -149,7 +149,7 @@ void BookmarkEditorView::OnTreeViewSelectionChanged( bool BookmarkEditorView::CanEdit(ChromeViews::TreeView* tree_view, ChromeViews::TreeModelNode* node) { // Only allow editting of children of the bookmark bar node and other node. - BookmarkNode* bb_node = tree_model_->AsNode(node); + EditorNode* bb_node = tree_model_->AsNode(node); return (bb_node->GetParent() && bb_node->GetParent()->GetParent()); } @@ -223,7 +223,7 @@ void BookmarkEditorView::ShowContextMenu(View* source, void BookmarkEditorView::Init() { tree_view_.SetContextMenuController(this); - bb_model_ = profile_->GetBookmarkBarModel(); + bb_model_ = profile_->GetBookmarkModel(); DCHECK(bb_model_); bb_model_->AddObserver(this); @@ -295,32 +295,32 @@ void BookmarkEditorView::Init() { Loaded(bb_model_); } -void BookmarkEditorView::Loaded(BookmarkBarModel* model) { +void BookmarkEditorView::Loaded(BookmarkModel* model) { Reset(true); } -void BookmarkEditorView::BookmarkNodeMoved(BookmarkBarModel* model, - BookmarkBarNode* old_parent, - int old_index, - BookmarkBarNode* new_parent, - int new_index) { +void BookmarkEditorView::BookmarkNodeMoved(BookmarkModel* model, + BookmarkNode* old_parent, + int old_index, + BookmarkNode* new_parent, + int new_index) { Reset(false); } -void BookmarkEditorView::BookmarkNodeAdded(BookmarkBarModel* model, - BookmarkBarNode* parent, +void BookmarkEditorView::BookmarkNodeAdded(BookmarkModel* model, + BookmarkNode* parent, int index) { Reset(false); } -void BookmarkEditorView::BookmarkNodeRemoved(BookmarkBarModel* model, - BookmarkBarNode* parent, +void BookmarkEditorView::BookmarkNodeRemoved(BookmarkModel* model, + BookmarkNode* parent, int index) { Reset(false); } void BookmarkEditorView::Reset(bool first_time) { - BookmarkBarNode* node_editing = bb_model_->GetNodeByURL(url_); + BookmarkNode* node_editing = bb_model_->GetNodeByURL(url_); // If the title is empty we need to fetch it from the node. if (first_time && title_.empty()) { @@ -334,8 +334,8 @@ void BookmarkEditorView::Reset(bool first_time) { // tree_view will try to invoke something on the model we just deleted. tree_view_.SetModel(NULL); - BookmarkNode* root_node = CreateRootNode(); - tree_model_.reset(new BookmarkTreeModel(root_node)); + EditorNode* root_node = CreateRootNode(); + tree_model_.reset(new EditorTreeModel(root_node)); tree_view_.SetModel(tree_model_.get()); tree_view_.SetController(this); @@ -374,7 +374,7 @@ void BookmarkEditorView::UserInputChanged() { void BookmarkEditorView::NewGroup() { // Create a new entry parented to the selected item, or the bookmark // bar if nothing is selected. - BookmarkNode* parent = tree_model_->AsNode(tree_view_.GetSelectedNode()); + EditorNode* parent = tree_model_->AsNode(tree_view_.GetSelectedNode()); if (!parent) { NOTREACHED(); return; @@ -383,9 +383,9 @@ void BookmarkEditorView::NewGroup() { tree_view_.StartEditing(AddNewGroup(parent)); } -BookmarkEditorView::BookmarkNode* BookmarkEditorView::AddNewGroup( - BookmarkNode* parent) { - BookmarkNode* new_node = new BookmarkNode(); +BookmarkEditorView::EditorNode* BookmarkEditorView::AddNewGroup( + EditorNode* parent) { + EditorNode* new_node = new EditorNode(); new_node->SetTitle(l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)); new_node->value = 0; // new_node is now owned by parent. @@ -396,13 +396,13 @@ BookmarkEditorView::BookmarkNode* BookmarkEditorView::AddNewGroup( void BookmarkEditorView::ExpandAndSelect() { tree_view_.ExpandAll(); - BookmarkBarNode* to_select = bb_model_->GetNodeByURL(url_); + BookmarkNode* to_select = bb_model_->GetNodeByURL(url_); int group_id_to_select = to_select ? to_select->GetParent()->id() : bb_model_->GetParentForNewNodes()->id(); DCHECK(group_id_to_select); // GetMostRecentParent should never return NULL. - BookmarkNode* b_node = + EditorNode* b_node = FindNodeWithID(tree_model_->GetRoot(), group_id_to_select); if (!b_node) b_node = tree_model_->GetRoot()->GetChild(0); // Bookmark bar node. @@ -410,9 +410,9 @@ void BookmarkEditorView::ExpandAndSelect() { tree_view_.SetSelectedNode(b_node); } -BookmarkEditorView::BookmarkNode* BookmarkEditorView::CreateRootNode() { - BookmarkNode* root_node = new BookmarkNode(std::wstring(), 0); - BookmarkBarNode* bb_root_node = bb_model_->root_node(); +BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() { + EditorNode* root_node = new EditorNode(std::wstring(), 0); + BookmarkNode* bb_root_node = bb_model_->root_node(); CreateNodes(bb_root_node, root_node); DCHECK(root_node->GetChildCount() == 2); DCHECK(bb_root_node->GetChild(0)->GetType() == @@ -421,12 +421,12 @@ BookmarkEditorView::BookmarkNode* BookmarkEditorView::CreateRootNode() { return root_node; } -void BookmarkEditorView::CreateNodes(BookmarkBarNode* bb_node, - BookmarkEditorView::BookmarkNode* b_node) { +void BookmarkEditorView::CreateNodes(BookmarkNode* bb_node, + BookmarkEditorView::EditorNode* b_node) { for (int i = 0; i < bb_node->GetChildCount(); ++i) { - BookmarkBarNode* child_bb_node = bb_node->GetChild(i); + BookmarkNode* child_bb_node = bb_node->GetChild(i); if (child_bb_node->is_folder()) { - BookmarkNode* new_b_node = new BookmarkNode(child_bb_node->GetTitle(), + EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(), child_bb_node->id()); b_node->Add(b_node->GetChildCount(), new_b_node); CreateNodes(child_bb_node, new_b_node); @@ -434,13 +434,13 @@ void BookmarkEditorView::CreateNodes(BookmarkBarNode* bb_node, } } -BookmarkEditorView::BookmarkNode* BookmarkEditorView::FindNodeWithID( - BookmarkEditorView::BookmarkNode* node, +BookmarkEditorView::EditorNode* BookmarkEditorView::FindNodeWithID( + BookmarkEditorView::EditorNode* node, int id) { if (node->value == id) return node; for (int i = 0; i < node->GetChildCount(); ++i) { - BookmarkNode* result = FindNodeWithID(node->GetChild(i), id); + EditorNode* result = FindNodeWithID(node->GetChild(i), id); if (result) return result; } @@ -457,7 +457,7 @@ void BookmarkEditorView::ApplyEdits() { ApplyEdits(tree_model_->AsNode(tree_view_.GetSelectedNode())); } -void BookmarkEditorView::ApplyEdits(BookmarkNode* parent) { +void BookmarkEditorView::ApplyEdits(EditorNode* parent) { DCHECK(parent); // We're going to apply edits to the bookmark bar model, which will call us @@ -468,8 +468,8 @@ void BookmarkEditorView::ApplyEdits(BookmarkNode* parent) { GURL new_url(GetInputURL()); std::wstring new_title(GetInputTitle()); - BookmarkBarNode* old_node = bb_model_->GetNodeByURL(url_); - BookmarkBarNode* old_parent = old_node ? old_node->GetParent() : NULL; + BookmarkNode* old_node = bb_model_->GetNodeByURL(url_); + BookmarkNode* old_parent = old_node ? old_node->GetParent() : NULL; const int old_index = old_parent ? old_parent->IndexOfChild(old_node) : -1; if (url_ != new_url) { @@ -478,7 +478,7 @@ void BookmarkEditorView::ApplyEdits(BookmarkNode* parent) { } // Create the new groups and update the titles. - BookmarkBarNode* new_parent = NULL; + BookmarkNode* new_parent = NULL; ApplyNameChangesAndCreateNewGroups( bb_model_->root_node(), tree_model_->GetRoot(), parent, &new_parent); @@ -488,7 +488,7 @@ void BookmarkEditorView::ApplyEdits(BookmarkNode* parent) { return; } - BookmarkBarNode* current_node = bb_model_->GetNodeByURL(new_url); + BookmarkNode* current_node = bb_model_->GetNodeByURL(new_url); if (current_node) { // There's already a node with the URL. @@ -515,15 +515,15 @@ void BookmarkEditorView::ApplyEdits(BookmarkNode* parent) { } void BookmarkEditorView::ApplyNameChangesAndCreateNewGroups( - BookmarkBarNode* bb_node, - BookmarkEditorView::BookmarkNode* b_node, - BookmarkEditorView::BookmarkNode* parent_b_node, - BookmarkBarNode** parent_bb_node) { + BookmarkNode* bb_node, + BookmarkEditorView::EditorNode* b_node, + BookmarkEditorView::EditorNode* parent_b_node, + BookmarkNode** parent_bb_node) { if (parent_b_node == b_node) *parent_bb_node = bb_node; for (int i = 0; i < b_node->GetChildCount(); ++i) { - BookmarkNode* child_b_node = b_node->GetChild(i); - BookmarkBarNode* child_bb_node = NULL; + EditorNode* child_b_node = b_node->GetChild(i); + BookmarkNode* child_bb_node = NULL; if (child_b_node->value == 0) { // New group. child_bb_node = bb_model_->AddGroup(bb_node, @@ -532,7 +532,7 @@ void BookmarkEditorView::ApplyNameChangesAndCreateNewGroups( // Existing node, reset the title (BBModel ignores changes if the title // is the same). for (int j = 0; j < bb_node->GetChildCount(); ++j) { - BookmarkBarNode* node = bb_node->GetChild(j); + BookmarkNode* node = bb_node->GetChild(j); if (node->is_folder() && node->id() == child_b_node->value) { child_bb_node = node; break; diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h index 01158ef..b928dc9 100644 --- a/chrome/browser/views/bookmark_editor_view.h +++ b/chrome/browser/views/bookmark_editor_view.h @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H__ -#define CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H__ +#ifndef CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H_ +#define CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H_ #include <set> #include "chrome/views/tree_node_model.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/views/checkbox.h" #include "chrome/views/dialog_delegate.h" #include "chrome/views/menu.h" @@ -27,7 +27,7 @@ class Profile; // change the URL, title and where the bookmark appears as well as adding // new groups and changing the name of other groups. // -// Edits are applied to the BookmarkBarModel when the user presses 'OK'. +// Edits are applied to the BookmarkModel when the user presses 'OK'. // // To use BookmarkEditorView invoke the static show method. @@ -38,7 +38,7 @@ class BookmarkEditorView : public ChromeViews::View, public ChromeViews::TextField::Controller, public ChromeViews::ContextMenuController, public Menu::Delegate, - public BookmarkBarModelObserver { + public BookmarkModelObserver { FRIEND_TEST(BookmarkEditorViewTest, ChangeParent); FRIEND_TEST(BookmarkEditorViewTest, ChangeURLToExistingURL); FRIEND_TEST(BookmarkEditorViewTest, EditTitleKeepsPosition); @@ -110,14 +110,14 @@ class BookmarkEditorView : public ChromeViews::View, private: // Type of node in the tree. - typedef ChromeViews::TreeNodeWithValue<int> BookmarkNode; + typedef ChromeViews::TreeNodeWithValue<int> EditorNode; // Model for the TreeView. Trivial subclass that doesn't allow titles with // empty strings. - class BookmarkTreeModel : public ChromeViews::TreeNodeModel<BookmarkNode> { + class EditorTreeModel : public ChromeViews::TreeNodeModel<EditorNode> { public: - explicit BookmarkTreeModel(BookmarkNode* root) - : TreeNodeModel<BookmarkNode>(root) {} + explicit EditorTreeModel(EditorNode* root) + : TreeNodeModel<EditorNode>(root) {} virtual void SetTitle(ChromeViews::TreeModelNode* node, const std::wstring& title) { @@ -126,31 +126,31 @@ class BookmarkEditorView : public ChromeViews::View, } private: - DISALLOW_EVIL_CONSTRUCTORS(BookmarkTreeModel); + DISALLOW_COPY_AND_ASSIGN(EditorTreeModel); }; // Creates the necessary sub-views, configures them, adds them to the layout, // and requests the entries to display from the database. void Init(); - // BookmarkBarModel observer methods. Any structural change results in + // BookmarkModel observer methods. Any structural change results in // resetting the tree model. - virtual void Loaded(BookmarkBarModel* model); - virtual void BookmarkNodeMoved(BookmarkBarModel* model, - BookmarkBarNode* old_parent, + virtual void Loaded(BookmarkModel* model); + 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) {} // Resets the model of the tree and updates the various buttons appropriately. // If first_time is true, Reset is being invoked from the constructor or @@ -164,37 +164,36 @@ class BookmarkEditorView : public ChromeViews::View, // Creates a returns the new root node. This invokes CreateNodes to do // the real work. - BookmarkNode* CreateRootNode(); + EditorNode* CreateRootNode(); // Adds and creates a child node in b_node for all children of bb_node that // are groups. - void CreateNodes(BookmarkBarNode* bb_node, - BookmarkNode* b_node); + void CreateNodes(BookmarkNode* bb_node, EditorNode* b_node); // Returns the node with the specified id, or NULL if one can't be found. - BookmarkNode* FindNodeWithID(BookmarkEditorView::BookmarkNode* node, int id); + EditorNode* FindNodeWithID(BookmarkEditorView::EditorNode* node, int id); // Invokes ApplyEdits with the selected node. void ApplyEdits(); // Applies the edits done by the user. |parent| gives the parent of the URL // being edited. - void ApplyEdits(BookmarkNode* parent); + void ApplyEdits(EditorNode* parent); // Recursively adds newly created groups and sets the title of nodes to // match the user edited title. // - // bb_node gives the BookmarkBarNode the edits are to be applied to, - // with b_node the source of the edits. + // bb_node gives the BookmarkNode the edits are to be applied to, with b_node + // the source of the edits. // // If b_node == parent_b_node, parent_bb_node is set to bb_node. This is - // used to determine the new BookmarkBarNode parent based on the BookmarkNode + // used to determine the new BookmarkNode parent based on the EditorNode // parent. void ApplyNameChangesAndCreateNewGroups( - BookmarkBarNode* bb_node, - BookmarkEditorView::BookmarkNode* b_node, - BookmarkEditorView::BookmarkNode* parent_b_node, - BookmarkBarNode** parent_bb_node); + BookmarkNode* bb_node, + BookmarkEditorView::EditorNode* b_node, + BookmarkEditorView::EditorNode* parent_b_node, + BookmarkNode** parent_bb_node); // Returns the current url the user has input. GURL GetInputURL() const; @@ -211,16 +210,16 @@ class BookmarkEditorView : public ChromeViews::View, // editing on the new gorup as well. void NewGroup(); - // Creates a new BookmarkNode as the last child of parent. The new node is + // Creates a new EditorNode as the last child of parent. The new node is // added to the model and returned. This does NOT start editing. This is used // internally by NewGroup and broken into a separate method for testing. - BookmarkNode* AddNewGroup(BookmarkNode* parent); + EditorNode* AddNewGroup(EditorNode* parent); // Profile the entry is from. Profile* profile_; // Model driving the TreeView. - scoped_ptr<BookmarkTreeModel> tree_model_; + scoped_ptr<EditorTreeModel> tree_model_; // Displays star groups. ChromeViews::TreeView tree_view_; @@ -244,14 +243,13 @@ class BookmarkEditorView : public ChromeViews::View, std::wstring title_; // Mode used to create nodes from. - BookmarkBarModel* bb_model_; + BookmarkModel* bb_model_; // If true, we're running the menu for the bookmark bar or other bookmarks // nodes. bool running_menu_for_root_; - DISALLOW_EVIL_CONSTRUCTORS(BookmarkEditorView); + DISALLOW_COPY_AND_ASSIGN(BookmarkEditorView); }; -#endif // CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H__ - +#endif // CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H_ diff --git a/chrome/browser/views/bookmark_editor_view_unittest.cc b/chrome/browser/views/bookmark_editor_view_unittest.cc index 2f161a0..74baaf5 100644 --- a/chrome/browser/views/bookmark_editor_view_unittest.cc +++ b/chrome/browser/views/bookmark_editor_view_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/profile.h" #include "chrome/browser/views/bookmark_editor_view.h" #include "chrome/common/pref_names.h" @@ -11,8 +11,8 @@ #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" -// Base class for bookmark editor tests. Creates a BookmarkBarModel and -// populates it with test data. +// Base class for bookmark editor tests. Creates a BookmarkModel and populates +// it with test data. class BookmarkEditorViewTest : public testing::Test { public: BookmarkEditorViewTest() : model_(NULL) { @@ -21,9 +21,9 @@ class BookmarkEditorViewTest : public testing::Test { virtual void SetUp() { profile_.reset(new TestingProfile()); profile_->set_has_history_service(true); - profile_->CreateBookmarkBarModel(true); + profile_->CreateBookmarkModel(true); - model_ = profile_->GetBookmarkBarModel(); + model_ = profile_->GetBookmarkModel(); AddTestData(); } @@ -33,7 +33,7 @@ class BookmarkEditorViewTest : public testing::Test { protected: MessageLoopForUI message_loop_; - BookmarkBarModel* model_; + BookmarkModel* model_; scoped_ptr<TestingProfile> profile_; std::string base_path() const { return "file:///c:/tmp/"; } @@ -56,18 +56,16 @@ class BookmarkEditorViewTest : public testing::Test { model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a", GURL(test_base + "a")); - BookmarkBarNode* f1 = - model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1"); + BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1"); model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a")); - BookmarkBarNode* f11 = model_->AddGroup(f1, 1, L"F11"); + BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11"); model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a")); model_->AddGroup(model_->GetBookmarkBarNode(), 2, L"F2"); // Children of the other node. model_->AddURL(model_->other_node(), 0, L"oa", GURL(test_base + "oa")); - BookmarkBarNode* of1 = - model_->AddGroup(model_->other_node(), 1, L"OF1"); + BookmarkNode* of1 = model_->AddGroup(model_->other_node(), 1, L"OF1"); model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a")); } }; @@ -76,12 +74,12 @@ class BookmarkEditorViewTest : public testing::Test { TEST_F(BookmarkEditorViewTest, ModelsMatch) { BookmarkEditorView editor(profile_.get(), GURL(base_path() + "xxx"), L"xxx"); - BookmarkEditorView::BookmarkNode* editor_root = editor.tree_model_->GetRoot(); + BookmarkEditorView::EditorNode* editor_root = editor.tree_model_->GetRoot(); // The root should have two children, one for the bookmark bar node, // the other for the 'other bookmarks' folder. ASSERT_EQ(2, editor_root->GetChildCount()); - BookmarkEditorView::BookmarkNode* bb_node = editor_root->GetChild(0); + BookmarkEditorView::EditorNode* bb_node = editor_root->GetChild(0); // The root should have 2 nodes: folder F1 and F2. ASSERT_EQ(2, bb_node->GetChildCount()); ASSERT_EQ(L"F1", bb_node->GetChild(0)->GetTitle()); @@ -91,7 +89,7 @@ TEST_F(BookmarkEditorViewTest, ModelsMatch) { ASSERT_EQ(1, bb_node->GetChild(0)->GetChildCount()); ASSERT_EQ(L"F11", bb_node->GetChild(0)->GetChild(0)->GetTitle()); - BookmarkEditorView::BookmarkNode* other_node = editor_root->GetChild(1); + BookmarkEditorView::EditorNode* other_node = editor_root->GetChild(1); // Other node should have one child (OF1). ASSERT_EQ(1, other_node->GetChildCount()); ASSERT_EQ(L"OF1", other_node->GetChild(0)->GetTitle()); @@ -103,8 +101,7 @@ TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); - BookmarkBarNode* bb_node = - profile_->GetBookmarkBarModel()->GetBookmarkBarNode(); + BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode(); ASSERT_EQ(L"new_a", bb_node->GetChild(0)->GetTitle()); // The URL shouldn't have changed. ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->GetURL()); @@ -118,8 +115,7 @@ TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); - BookmarkBarNode* bb_node = - profile_->GetBookmarkBarModel()->GetBookmarkBarNode(); + BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode(); ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); // The URL should have changed. ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->GetURL()); @@ -131,7 +127,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParent) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(1)); - BookmarkBarNode* other_node = profile_->GetBookmarkBarModel()->other_node(); + BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->GetURL()); } @@ -145,8 +141,7 @@ TEST_F(BookmarkEditorViewTest, ChangeURLToExistingURL) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); // Position shouldn't have changed. - BookmarkBarNode* bb_node = - profile_->GetBookmarkBarModel()->GetBookmarkBarNode(); + BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode(); ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); // The URL should have changed. ASSERT_TRUE(GURL(base_path() + "f1a") == bb_node->GetChild(0)->GetURL()); @@ -161,19 +156,18 @@ TEST_F(BookmarkEditorViewTest, MoveToNewParent) { BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a"); // Create two nodes: "F21" as a child of "F2" and "F211" as a child of "F21". - BookmarkEditorView::BookmarkNode* f2 = + BookmarkEditorView::EditorNode* f2 = editor.tree_model_->GetRoot()->GetChild(0)->GetChild(1); - BookmarkEditorView::BookmarkNode* f21 = editor.AddNewGroup(f2); + BookmarkEditorView::EditorNode* f21 = editor.AddNewGroup(f2); f21->SetTitle(L"F21"); - BookmarkEditorView::BookmarkNode* f211 = editor.AddNewGroup(f21); + BookmarkEditorView::EditorNode* f211 = editor.AddNewGroup(f21); f211->SetTitle(L"F211"); // Parent the node to "F21". editor.ApplyEdits(f2); - BookmarkBarNode* bb_node = - profile_->GetBookmarkBarModel()->GetBookmarkBarNode(); - BookmarkBarNode* mf2 = bb_node->GetChild(1); + BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode(); + BookmarkNode* mf2 = bb_node->GetChild(1); // F2 in the model should have two children now: F21 and the node edited. ASSERT_EQ(2, mf2->GetChildCount()); @@ -183,7 +177,7 @@ TEST_F(BookmarkEditorViewTest, MoveToNewParent) { ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle()); // F21 should have one child, F211. - BookmarkBarNode* mf21 = mf2->GetChild(0); + BookmarkNode* mf21 = mf2->GetChild(0); ASSERT_EQ(1, mf21->GetChildCount()); ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle()); } diff --git a/chrome/browser/views/toolbar_star_toggle.cc b/chrome/browser/views/toolbar_star_toggle.cc index 52d2839..101d319 100644 --- a/chrome/browser/views/toolbar_star_toggle.cc +++ b/chrome/browser/views/toolbar_star_toggle.cc @@ -5,7 +5,7 @@ #include "chrome/browser/views/toolbar_star_toggle.h" #include "chrome/app/theme/theme_resources.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser.h" #include "chrome/browser/views/bookmark_bubble_view.h" #include "chrome/browser/views/toolbar_view.h" diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index de0a221..a1eced4 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -7,7 +7,7 @@ #include "base/command_line.h" #include "base/file_version_info.h" #include "chrome/app/locales/locale_settings.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser.h" #include "chrome/browser/cache_manager_host.h" #include "chrome/browser/character_encoding.h" @@ -746,8 +746,8 @@ void WebContents::Observe(NotificationType type, const NotificationDetails& details) { TabContents::Observe(type, source, details); switch (type) { - case NOTIFY_BOOKMARK_MODEL_LOADED: // BookmarkBarModel finished loading, - // fall through to update starred state. + case NOTIFY_BOOKMARK_MODEL_LOADED: // BookmarkModel finished loading, fall + // through to update starred state. case NOTIFY_URLS_STARRED: { // Somewhere, a URL has been starred. // Ignore notifications for profiles other than our current one. Profile* source_profile = Source<Profile>(source).ptr(); @@ -1460,7 +1460,7 @@ void WebContents::BroadcastProvisionalLoadCommit( } void WebContents::UpdateStarredStateForCurrentURL() { - BookmarkBarModel* model = profile()->GetBookmarkBarModel(); + BookmarkModel* model = profile()->GetBookmarkModel(); const bool old_state = is_starred_; is_starred_ = (model && model->GetNodeByURL(GetURL())); diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index ac7021d..59cf5a5 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -9,31 +9,31 @@ namespace { -// BookmarkLoadObserver is used when blocking until the BookmarkBarModel -// finishes loading. As soon as the BookmarkBarModel finishes loading the -// message loop is quit. -class BookmarkLoadObserver : public BookmarkBarModelObserver { +// BookmarkLoadObserver is used when blocking until the BookmarkModel +// finishes loading. As soon as the BookmarkModel finishes loading the message +// loop is quit. +class BookmarkLoadObserver : public BookmarkModelObserver { public: BookmarkLoadObserver() {} - virtual void Loaded(BookmarkBarModel* model) { + virtual void Loaded(BookmarkModel* model) { 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) {} private: DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver); @@ -90,7 +90,7 @@ void TestingProfile::DestroyHistoryService() { MessageLoop::current()->Run(); } -void TestingProfile::CreateBookmarkBarModel(bool delete_file) { +void TestingProfile::CreateBookmarkModel(bool delete_file) { // Nuke the model first, that way we're sure it's done writing to disk. bookmark_bar_model_.reset(NULL); @@ -99,7 +99,7 @@ void TestingProfile::CreateBookmarkBarModel(bool delete_file) { file_util::AppendToPath(&path, chrome::kBookmarksFileName); file_util::Delete(path, false); } - bookmark_bar_model_.reset(new BookmarkBarModel(this)); + bookmark_bar_model_.reset(new BookmarkModel(this)); if (history_service_.get()) { history_service_->history_backend_->bookmark_service_ = bookmark_bar_model_.get(); diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 8422934..c1f1190 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -8,7 +8,7 @@ #include "base/base_paths.h" #include "base/path_service.h" #include "base/file_util.h" -#include "chrome/browser/bookmarks/bookmark_bar_model.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_prefs.h" #include "chrome/browser/history/history.h" #include "chrome/browser/profile.h" @@ -30,14 +30,14 @@ class TestingProfile : public Profile { // NULL. If |delete_file| is true, the bookmarks file is deleted first, then // the model is created. As TestingProfile deletes the directory containing // the files used by HistoryService, the boolean only matters if you're - // recreating the BookmarkBarModel. + // recreating the BookmarkModel. // // NOTE: this does not block until the bookmarks are loaded. For that use // BlockUntilBookmarkModelLoaded. - void CreateBookmarkBarModel(bool delete_file); + void CreateBookmarkModel(bool delete_file); - // Blocks until the BookmarkBarModel finishes loaded. This is NOT invoked - // from CreateBookmarkBarModel. + // Blocks until the BookmarkModel finishes loaded. This is NOT invoked from + // CreateBookmarkModel. void BlockUntilBookmarkModelLoaded(); // Creates a TemplateURLModel. If not invoked the TemplateURLModel is NULL. @@ -130,10 +130,7 @@ class TestingProfile : public Profile { } virtual void MergeResourceBoolean(int message_id, bool* output_value) { } - virtual bool HasBookmarkBarModel() { - return (bookmark_bar_model_.get() != NULL); - } - virtual BookmarkBarModel* GetBookmarkBarModel() { + virtual BookmarkModel* GetBookmarkModel() { return bookmark_bar_model_.get(); } virtual bool Profile::IsSameProfile(Profile *p) { @@ -174,8 +171,8 @@ class TestingProfile : public Profile { // The history service. Only created if CreateHistoryService is invoked. scoped_refptr<HistoryService> history_service_; - // The BookmarkBarModel. Only created if CreateBookmarkBarModel is invoked. - scoped_ptr<BookmarkBarModel> bookmark_bar_model_; + // The BookmarkModel. Only created if CreateBookmarkModel is invoked. + scoped_ptr<BookmarkModel> bookmark_bar_model_; // The TemplateURLFetcher. Only created if CreateTemplateURLModel is invoked. scoped_ptr<TemplateURLModel> template_url_model_; diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index ea425b9..39bb9b2 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -614,7 +614,7 @@ Name="TestBookmarkBarModel" > <File - RelativePath="..\..\browser\bookmarks\bookmark_bar_model_unittest.cc" + RelativePath="..\..\browser\bookmarks\bookmark_model_unittest.cc" > </File> </Filter> |