summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/bookmarks/base_bookmark_model_observer.h14
-rw-r--r--chrome/browser/bookmarks/bookmark_codec.cc22
-rw-r--r--chrome/browser/bookmarks/bookmark_codec.h6
-rw-r--r--chrome/browser/bookmarks/bookmark_codec_unittest.cc26
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.cc18
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.h10
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data_unittest.cc30
-rw-r--r--chrome/browser/bookmarks/bookmark_editor.h6
-rw-r--r--chrome/browser/bookmarks/bookmark_folder_tree_model.cc39
-rw-r--r--chrome/browser/bookmarks/bookmark_folder_tree_model.h28
-rw-r--r--chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc10
-rw-r--r--chrome/browser/bookmarks/bookmark_html_writer_unittest.cc9
-rw-r--r--chrome/browser/bookmarks/bookmark_index.cc8
-rw-r--r--chrome/browser/bookmarks/bookmark_index.h10
-rw-r--r--chrome/browser/bookmarks/bookmark_index_unittest.cc4
-rw-r--r--chrome/browser/bookmarks/bookmark_manager.h2
-rw-r--r--chrome/browser/bookmarks/bookmark_model.cc146
-rw-r--r--chrome/browser/bookmarks/bookmark_model.h170
-rw-r--r--chrome/browser/bookmarks/bookmark_model_test_utils.cc4
-rw-r--r--chrome/browser/bookmarks/bookmark_model_test_utils.h4
-rw-r--r--chrome/browser/bookmarks/bookmark_model_unittest.cc169
-rw-r--r--chrome/browser/bookmarks/bookmark_table_model.cc61
-rw-r--r--chrome/browser/bookmarks/bookmark_table_model.h10
-rw-r--r--chrome/browser/bookmarks/bookmark_table_model_unittest.cc20
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc98
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.h42
-rw-r--r--chrome/browser/bookmarks/bookmark_utils_unittest.cc10
-rw-r--r--chrome/browser/cocoa/bookmark_bar_bridge.h12
-rw-r--r--chrome/browser/cocoa/bookmark_bar_bridge.mm14
-rw-r--r--chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm12
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.h12
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.mm27
-rw-r--r--chrome/browser/cocoa/bookmark_menu_bridge.h14
-rw-r--r--chrome/browser/cocoa/bookmark_menu_bridge.mm18
-rw-r--r--chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm8
-rw-r--r--chrome/browser/cocoa/bookmark_menu_cocoa_controller.h4
-rw-r--r--chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm6
-rw-r--r--chrome/browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm8
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc24
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.cc73
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.h18
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.cc56
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.h32
-rw-r--r--chrome/browser/gtk/bookmark_bubble_gtk.cc29
-rw-r--r--chrome/browser/gtk/bookmark_bubble_gtk.h2
-rw-r--r--chrome/browser/gtk/bookmark_context_menu.cc51
-rw-r--r--chrome/browser/gtk/bookmark_context_menu.h26
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk.cc25
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk.h24
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk_unittest.cc46
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.cc65
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.h26
-rw-r--r--chrome/browser/gtk/bookmark_menu_controller_gtk.cc30
-rw-r--r--chrome/browser/gtk/bookmark_menu_controller_gtk.h10
-rw-r--r--chrome/browser/gtk/bookmark_tree_model.cc24
-rw-r--r--chrome/browser/gtk/bookmark_tree_model.h4
-rw-r--r--chrome/browser/gtk/bookmark_utils_gtk.cc12
-rw-r--r--chrome/browser/gtk/bookmark_utils_gtk.h8
-rw-r--r--chrome/browser/importer/importer.cc23
-rw-r--r--chrome/browser/importer/importer.h14
-rw-r--r--chrome/browser/metrics/metrics_service.cc6
-rw-r--r--chrome/browser/metrics/metrics_service.h2
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc62
-rw-r--r--chrome/browser/views/bookmark_bar_view.h34
-rw-r--r--chrome/browser/views/bookmark_bar_view_test.cc9
-rw-r--r--chrome/browser/views/bookmark_bubble_view.cc19
-rw-r--r--chrome/browser/views/bookmark_bubble_view.h8
-rw-r--r--chrome/browser/views/bookmark_context_menu.cc51
-rw-r--r--chrome/browser/views/bookmark_context_menu.h26
-rw-r--r--chrome/browser/views/bookmark_context_menu_test.cc29
-rw-r--r--chrome/browser/views/bookmark_editor_view.cc40
-rw-r--r--chrome/browser/views/bookmark_editor_view.h30
-rw-r--r--chrome/browser/views/bookmark_editor_view_unittest.cc48
-rw-r--r--chrome/browser/views/bookmark_folder_tree_view.cc16
-rw-r--r--chrome/browser/views/bookmark_folder_tree_view.h6
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc50
-rw-r--r--chrome/browser/views/bookmark_manager_view.h28
-rw-r--r--chrome/browser/views/bookmark_menu_button.cc2
-rw-r--r--chrome/browser/views/bookmark_menu_controller_views.cc28
-rw-r--r--chrome/browser/views/bookmark_menu_controller_views.h14
-rw-r--r--chrome/browser/views/bookmark_table_view.cc15
-rw-r--r--chrome/browser/views/bookmark_table_view.h8
-rw-r--r--chrome/browser/views/toolbar_view.cc2
83 files changed, 1189 insertions, 1077 deletions
diff --git a/chrome/browser/bookmarks/base_bookmark_model_observer.h b/chrome/browser/bookmarks/base_bookmark_model_observer.h
index 34d755f..045afb9 100644
--- a/chrome/browser/bookmarks/base_bookmark_model_observer.h
+++ b/chrome/browser/bookmarks/base_bookmark_model_observer.h
@@ -22,31 +22,31 @@ class BaseBookmarkModelObserver : public BookmarkModelObserver {
BookmarkModelChanged();
}
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
BookmarkModelChanged();
}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
BookmarkModelChanged();
}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
BookmarkModelChanged();
}
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
BookmarkModelChanged();
}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
BookmarkModelChanged();
}
diff --git a/chrome/browser/bookmarks/bookmark_codec.cc b/chrome/browser/bookmarks/bookmark_codec.cc
index 03b7028..c9c8366 100644
--- a/chrome/browser/bookmarks/bookmark_codec.cc
+++ b/chrome/browser/bookmarks/bookmark_codec.cc
@@ -96,8 +96,8 @@ Value* BookmarkCodec::Encode(BookmarkModel* model) {
return Encode(model->GetBookmarkBarNode(), model->other_node());
}
-Value* BookmarkCodec::Encode(BookmarkNode* bookmark_bar_node,
- BookmarkNode* other_folder_node) {
+Value* BookmarkCodec::Encode(const BookmarkNode* bookmark_bar_node,
+ const BookmarkNode* other_folder_node) {
InitializeChecksum();
DictionaryValue* roots = new DictionaryValue();
roots->Set(kRootFolderNameKey, EncodeNode(bookmark_bar_node));
@@ -127,7 +127,7 @@ bool BookmarkCodec::Decode(BookmarkNode* bb_node,
return success;
}
-Value* BookmarkCodec::EncodeNode(BookmarkNode* node) {
+Value* BookmarkCodec::EncodeNode(const BookmarkNode* node) {
DictionaryValue* value = new DictionaryValue();
std::string id;
if (persist_ids_) {
@@ -203,8 +203,8 @@ bool BookmarkCodec::DecodeHelper(BookmarkNode* bb_node,
// Need to reset the type as decoding resets the type to FOLDER. Similarly
// we need to reset the title as the title is persisted and restored from
// the file.
- bb_node->type_ = history::StarredEntry::BOOKMARK_BAR;
- other_folder_node->type_ = history::StarredEntry::OTHER;
+ bb_node->SetType(history::StarredEntry::BOOKMARK_BAR);
+ other_folder_node->SetType(history::StarredEntry::OTHER);
bb_node->SetTitle(l10n_util::GetString(IDS_BOOMARK_BAR_FOLDER_NAME));
other_folder_node->SetTitle(
l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME));
@@ -266,7 +266,7 @@ bool BookmarkCodec::DecodeNode(const DictionaryValue& value,
if (parent)
parent->Add(parent->GetChildCount(), node);
- node->type_ = history::StarredEntry::URL;
+ node->SetType(history::StarredEntry::URL);
UpdateChecksumWithUrlNode(id_string, title, url_string);
} else {
std::wstring last_modified_date;
@@ -288,9 +288,9 @@ bool BookmarkCodec::DecodeNode(const DictionaryValue& value,
node->set_id(id);
}
- node->type_ = history::StarredEntry::USER_GROUP;
- node->date_group_modified_ = Time::FromInternalValue(
- StringToInt64(WideToUTF16Hack(last_modified_date)));
+ node->SetType(history::StarredEntry::USER_GROUP);
+ node->set_date_group_modified(Time::FromInternalValue(
+ StringToInt64(WideToUTF16Hack(last_modified_date))));
if (parent)
parent->Add(parent->GetChildCount(), node);
@@ -301,8 +301,8 @@ bool BookmarkCodec::DecodeNode(const DictionaryValue& value,
}
node->SetTitle(title);
- node->date_added_ = Time::FromInternalValue(
- StringToInt64(WideToUTF16Hack(date_added_string)));
+ node->set_date_added(Time::FromInternalValue(
+ StringToInt64(WideToUTF16Hack(date_added_string))));
return true;
}
diff --git a/chrome/browser/bookmarks/bookmark_codec.h b/chrome/browser/bookmarks/bookmark_codec.h
index 6631ec5..e6292a8 100644
--- a/chrome/browser/bookmarks/bookmark_codec.h
+++ b/chrome/browser/bookmarks/bookmark_codec.h
@@ -78,8 +78,8 @@ class BookmarkCodec {
// 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(BookmarkNode* bookmark_bar_node,
- BookmarkNode* other_folder_node);
+ Value* Encode(const BookmarkNode* bookmark_bar_node,
+ const BookmarkNode* other_folder_node);
// Decodes the previously encoded value to the specified nodes as well as
// setting |max_node_id| to the greatest node id. Returns true on success,
@@ -122,7 +122,7 @@ class BookmarkCodec {
private:
// Encodes node and all its children into a Value object and returns it.
// The caller takes ownership of the returned object.
- Value* EncodeNode(BookmarkNode* node);
+ Value* EncodeNode(const BookmarkNode* node);
// Helper to perform decoding.
bool DecodeHelper(BookmarkNode* bb_node,
diff --git a/chrome/browser/bookmarks/bookmark_codec_unittest.cc b/chrome/browser/bookmarks/bookmark_codec_unittest.cc
index 83df11d..d6a3424 100644
--- a/chrome/browser/bookmarks/bookmark_codec_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_codec_unittest.cc
@@ -24,29 +24,34 @@ const wchar_t kUrl4Url[] = L"http://www.url4.com";
const wchar_t kGroup1Title[] = L"group1";
const wchar_t kGroup2Title[] = L"group2";
+// Helper to get a mutable bookmark node.
+static BookmarkNode* AsMutable(const BookmarkNode* node) {
+ return const_cast<BookmarkNode*>(node);
}
+} // anonymous namespace
+
class BookmarkCodecTest : public testing::Test {
protected:
// Helpers to create bookmark models with different data.
BookmarkModel* CreateTestModel1() {
scoped_ptr<BookmarkModel> model(new BookmarkModel(NULL));
- BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
+ const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
model->AddURL(bookmark_bar, 0, kUrl1Title, GURL(kUrl1Url));
return model.release();
}
BookmarkModel* CreateTestModel2() {
scoped_ptr<BookmarkModel> model(new BookmarkModel(NULL));
- BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
+ const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
model->AddURL(bookmark_bar, 0, kUrl1Title, GURL(kUrl1Url));
model->AddURL(bookmark_bar, 1, kUrl2Title, GURL(kUrl2Url));
return model.release();
}
BookmarkModel* CreateTestModel3() {
scoped_ptr<BookmarkModel> model(new BookmarkModel(NULL));
- BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
+ const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
model->AddURL(bookmark_bar, 0, kUrl1Title, GURL(kUrl1Url));
- BookmarkNode* group1 = model->AddGroup(bookmark_bar, 1, kGroup1Title);
+ const BookmarkNode* group1 = model->AddGroup(bookmark_bar, 1, kGroup1Title);
model->AddURL(group1, 0, kUrl2Title, GURL(kUrl2Url));
return model.release();
}
@@ -90,7 +95,7 @@ class BookmarkCodecTest : public testing::Test {
scoped_ptr<Value> value(encoder.Encode(model));
const std::string& computed_checksum = encoder.computed_checksum();
const std::string& stored_checksum = encoder.stored_checksum();
-
+
// Computed and stored checksums should not be empty and should be equal.
EXPECT_FALSE(computed_checksum.empty());
EXPECT_FALSE(stored_checksum.empty());
@@ -102,8 +107,9 @@ class BookmarkCodecTest : public testing::Test {
bool Decode(BookmarkCodec* codec, BookmarkModel* model, const Value& value) {
int max_id;
- bool result = codec->Decode(model->GetBookmarkBarNode(),
- model->other_node(), &max_id, value);
+ bool result = codec->Decode(AsMutable(model->GetBookmarkBarNode()),
+ AsMutable(model->other_node()),
+ &max_id, value);
model->set_next_node_id(max_id);
return result;
}
@@ -122,7 +128,7 @@ class BookmarkCodecTest : public testing::Test {
*computed_checksum = decoder.computed_checksum();
const std::string& stored_checksum = decoder.stored_checksum();
-
+
// Computed and stored checksums should not be empty.
EXPECT_FALSE(computed_checksum->empty());
EXPECT_FALSE(stored_checksum.empty());
@@ -207,10 +213,10 @@ TEST_F(BookmarkCodecTest, PersistIDsTest) {
// Add a couple of more items to the decoded bookmark model and make sure
// ID persistence is working properly.
- BookmarkNode* bookmark_bar = decoded_model.GetBookmarkBarNode();
+ const BookmarkNode* bookmark_bar = decoded_model.GetBookmarkBarNode();
decoded_model.AddURL(
bookmark_bar, bookmark_bar->GetChildCount(), kUrl3Title, GURL(kUrl3Url));
- BookmarkNode* group2_node = decoded_model.AddGroup(
+ const BookmarkNode* group2_node = decoded_model.AddGroup(
bookmark_bar, bookmark_bar->GetChildCount(), kGroup2Title);
decoded_model.AddURL(group2_node, 0, kUrl4Title, GURL(kUrl4Url));
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc
index a6ae333..732d119 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data.cc
+++ b/chrome/browser/bookmarks/bookmark_drag_data.cc
@@ -28,7 +28,7 @@ static void RegisterFormat() {
}
#endif
-BookmarkDragData::Element::Element(BookmarkNode* node)
+BookmarkDragData::Element::Element(const BookmarkNode* node)
: is_url(node->is_url()),
url(node->GetURL()),
title(node->GetTitle()),
@@ -76,11 +76,12 @@ bool BookmarkDragData::Element::ReadFromPickle(Pickle* pickle,
return true;
}
-BookmarkDragData::BookmarkDragData(BookmarkNode* node) {
+BookmarkDragData::BookmarkDragData(const BookmarkNode* node) {
elements.push_back(Element(node));
}
-BookmarkDragData::BookmarkDragData(const std::vector<BookmarkNode*>& nodes) {
+BookmarkDragData::BookmarkDragData(
+ const std::vector<const BookmarkNode*>& nodes) {
for (size_t i = 0; i < nodes.size(); ++i)
elements.push_back(Element(nodes[i]));
}
@@ -185,14 +186,15 @@ bool BookmarkDragData::ReadFromPickle(Pickle* pickle) {
return true;
}
-std::vector<BookmarkNode*> BookmarkDragData::GetNodes(Profile* profile) const {
- std::vector<BookmarkNode*> nodes;
+std::vector<const BookmarkNode*> BookmarkDragData::GetNodes(
+ Profile* profile) const {
+ std::vector<const BookmarkNode*> nodes;
if (!IsFromProfile(profile))
return nodes;
for (size_t i = 0; i < elements.size(); ++i) {
- BookmarkNode* node =
+ const BookmarkNode* node =
profile->GetBookmarkModel()->GetNodeByID(elements[i].id_);
if (!node) {
nodes.clear();
@@ -203,8 +205,8 @@ std::vector<BookmarkNode*> BookmarkDragData::GetNodes(Profile* profile) const {
return nodes;
}
-BookmarkNode* BookmarkDragData::GetFirstNode(Profile* profile) const {
- std::vector<BookmarkNode*> nodes = GetNodes(profile);
+const BookmarkNode* BookmarkDragData::GetFirstNode(Profile* profile) const {
+ std::vector<const BookmarkNode*> nodes = GetNodes(profile);
return nodes.size() == 1 ? nodes[0] : NULL;
}
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.h b/chrome/browser/bookmarks/bookmark_drag_data.h
index 5e8db56..88cb6d4 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data.h
+++ b/chrome/browser/bookmarks/bookmark_drag_data.h
@@ -38,7 +38,7 @@ class Profile;
struct BookmarkDragData {
// Element represents a single node.
struct Element {
- explicit Element(BookmarkNode* node);
+ explicit Element(const BookmarkNode* node);
Element() : is_url(false), id_(0) {}
@@ -68,8 +68,8 @@ struct BookmarkDragData {
BookmarkDragData() { }
// Created a BookmarkDragData populated from the arguments.
- explicit BookmarkDragData(BookmarkNode* node);
- explicit BookmarkDragData(const std::vector<BookmarkNode*>& nodes);
+ explicit BookmarkDragData(const BookmarkNode* node);
+ explicit BookmarkDragData(const std::vector<const BookmarkNode*>& nodes);
#if defined(TOOLKIT_VIEWS)
// Writes elements to data. If there is only one element and it is a URL
@@ -93,11 +93,11 @@ struct BookmarkDragData {
// created from the same profile then the nodes from the model are returned.
// If the nodes can't be found (may have been deleted), an empty vector is
// returned.
- std::vector<BookmarkNode*> GetNodes(Profile* profile) const;
+ std::vector<const BookmarkNode*> GetNodes(Profile* profile) const;
// Convenience for getting the first node. Returns NULL if the data doesn't
// match any nodes or there is more than one node.
- BookmarkNode* GetFirstNode(Profile* profile) const;
+ const BookmarkNode* GetFirstNode(Profile* profile) const;
// Do we contain valid data?
bool is_valid() const { return !elements.empty(); }
diff --git a/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc b/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
index 9507196..02b2016 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
@@ -51,10 +51,10 @@ TEST_F(BookmarkDragDataTest, URL) {
profile.CreateBookmarkModel(false);
profile.SetID(L"id");
BookmarkModel* model = profile.GetBookmarkModel();
- BookmarkNode* root = model->GetBookmarkBarNode();
+ const BookmarkNode* root = model->GetBookmarkBarNode();
GURL url(GURL("http://foo.com"));
const std::wstring title(L"blah");
- BookmarkNode* node = model->AddURL(root, 0, title, url);
+ const BookmarkNode* node = model->AddURL(root, 0, title, url);
BookmarkDragData drag_data(node);
EXPECT_TRUE(drag_data.is_valid());
ASSERT_EQ(1, drag_data.elements.size());
@@ -93,10 +93,10 @@ TEST_F(BookmarkDragDataTest, Group) {
profile.CreateBookmarkModel(false);
profile.SetID(L"id");
BookmarkModel* model = profile.GetBookmarkModel();
- 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");
+ const BookmarkNode* root = model->GetBookmarkBarNode();
+ const BookmarkNode* g1 = model->AddGroup(root, 0, L"g1");
+ const BookmarkNode* g11 = model->AddGroup(g1, 0, L"g11");
+ const BookmarkNode* g12 = model->AddGroup(g1, 0, L"g12");
BookmarkDragData drag_data(g12);
EXPECT_TRUE(drag_data.is_valid());
@@ -117,7 +117,7 @@ TEST_F(BookmarkDragDataTest, Group) {
EXPECT_FALSE(read_data.elements[0].is_url);
// We should get back the same node when asking for the same profile.
- BookmarkNode* r_g12 = read_data.GetFirstNode(&profile);
+ const BookmarkNode* r_g12 = read_data.GetFirstNode(&profile);
EXPECT_TRUE(g12 == r_g12);
// A different profile should return NULL for the node.
@@ -131,8 +131,8 @@ TEST_F(BookmarkDragDataTest, GroupWithChild) {
profile.SetID(L"id");
profile.CreateBookmarkModel(false);
BookmarkModel* model = profile.GetBookmarkModel();
- BookmarkNode* root = model->GetBookmarkBarNode();
- BookmarkNode* group = model->AddGroup(root, 0, L"g1");
+ const BookmarkNode* root = model->GetBookmarkBarNode();
+ const BookmarkNode* group = model->AddGroup(root, 0, L"g1");
GURL url(GURL("http://foo.com"));
const std::wstring title(L"blah2");
@@ -159,7 +159,7 @@ TEST_F(BookmarkDragDataTest, GroupWithChild) {
EXPECT_TRUE(read_child.is_url);
// And make sure we get the node back.
- BookmarkNode* r_group = read_data.GetFirstNode(&profile);
+ const BookmarkNode* r_group = read_data.GetFirstNode(&profile);
EXPECT_TRUE(group == r_group);
}
@@ -169,16 +169,16 @@ TEST_F(BookmarkDragDataTest, MultipleNodes) {
profile.SetID(L"id");
profile.CreateBookmarkModel(false);
BookmarkModel* model = profile.GetBookmarkModel();
- BookmarkNode* root = model->GetBookmarkBarNode();
- BookmarkNode* group = model->AddGroup(root, 0, L"g1");
+ const BookmarkNode* root = model->GetBookmarkBarNode();
+ const BookmarkNode* group = model->AddGroup(root, 0, L"g1");
GURL url(GURL("http://foo.com"));
const std::wstring title(L"blah2");
- BookmarkNode* url_node = model->AddURL(group, 0, title, url);
+ const BookmarkNode* url_node = model->AddURL(group, 0, title, url);
// Write the nodes to the clipboard.
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(group);
nodes.push_back(url_node);
BookmarkDragData drag_data(nodes);
@@ -204,7 +204,7 @@ TEST_F(BookmarkDragDataTest, MultipleNodes) {
EXPECT_EQ(0, read_url.children.size());
// And make sure we get the node back.
- std::vector<BookmarkNode*> read_nodes = read_data.GetNodes(&profile);
+ std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile);
ASSERT_EQ(2, read_nodes.size());
EXPECT_TRUE(read_nodes[0] == group);
EXPECT_TRUE(read_nodes[1] == url_node);
diff --git a/chrome/browser/bookmarks/bookmark_editor.h b/chrome/browser/bookmarks/bookmark_editor.h
index 54996db..b7dc15b 100644
--- a/chrome/browser/bookmarks/bookmark_editor.h
+++ b/chrome/browser/bookmarks/bookmark_editor.h
@@ -19,7 +19,7 @@ class BookmarkEditor {
class Handler {
public:
virtual ~Handler() {}
- virtual void NodeCreated(BookmarkNode* new_node) = 0;
+ virtual void NodeCreated(const BookmarkNode* new_node) = 0;
};
// An enumeration of the possible configurations offered.
@@ -35,8 +35,8 @@ class BookmarkEditor {
// null. See description of Handler for details.
static void Show(gfx::NativeView parent_window,
Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
Configuration configuration,
Handler* handler);
};
diff --git a/chrome/browser/bookmarks/bookmark_folder_tree_model.cc b/chrome/browser/bookmarks/bookmark_folder_tree_model.cc
index ad03b61..b04379a 100644
--- a/chrome/browser/bookmarks/bookmark_folder_tree_model.cc
+++ b/chrome/browser/bookmarks/bookmark_folder_tree_model.cc
@@ -40,14 +40,14 @@ BookmarkFolderTreeModel::NodeType BookmarkFolderTreeModel::GetNodeType(
}
FolderNode* BookmarkFolderTreeModel::GetFolderNodeForBookmarkNode(
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (!node->is_folder())
return NULL;
return GetFolderNodeForBookmarkNode(AsNode(GetRoot()), node);
}
-BookmarkNode* BookmarkFolderTreeModel::TreeNodeAsBookmarkNode(
+const BookmarkNode* BookmarkFolderTreeModel::TreeNodeAsBookmarkNode(
TreeModelNode* node) {
if (GetNodeType(node) != BOOKMARK)
return NULL;
@@ -65,11 +65,11 @@ void BookmarkFolderTreeModel::BookmarkModelBeingDeleted(BookmarkModel* model) {
}
void BookmarkFolderTreeModel::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
- BookmarkNode* moved_node = new_parent->GetChild(new_index);
+ const BookmarkNode* moved_node = new_parent->GetChild(new_index);
if (!moved_node->is_folder())
return; // We're only showing folders, so we can ignore this.
@@ -84,9 +84,9 @@ void BookmarkFolderTreeModel::BookmarkNodeMoved(BookmarkModel* model,
}
void BookmarkFolderTreeModel::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
- BookmarkNode* new_node = parent->GetChild(index);
+ const BookmarkNode* new_node = parent->GetChild(index);
if (!new_node->is_folder())
return; // We're only showing folders, so we can ignore this.
@@ -96,9 +96,9 @@ void BookmarkFolderTreeModel::BookmarkNodeAdded(BookmarkModel* model,
}
void BookmarkFolderTreeModel::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (!node->is_folder())
return; // We're only showing folders.
@@ -117,7 +117,7 @@ void BookmarkFolderTreeModel::BookmarkNodeRemoved(BookmarkModel* model,
}
void BookmarkFolderTreeModel::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (!node->is_folder())
return;
@@ -132,14 +132,14 @@ void BookmarkFolderTreeModel::BookmarkNodeChanged(BookmarkModel* model,
void BookmarkFolderTreeModel::BookmarkNodeChildrenReordered(
BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
FolderNode* folder_node = GetFolderNodeForBookmarkNode(node);
DCHECK(folder_node);
if (folder_node->GetChildCount() <= 1)
return; // Order won't have changed if 1 or fewer nodes.
// Build a map between folder node and bookmark node.
- std::map<BookmarkNode*, FolderNode*> bn_to_folder;
+ std::map<const BookmarkNode*, FolderNode*> bn_to_folder;
for (int i = 0; i < folder_node->GetChildCount(); ++i)
bn_to_folder[folder_node->GetChild(i)->value] = folder_node->GetChild(i);
@@ -149,7 +149,7 @@ void BookmarkFolderTreeModel::BookmarkNodeChildrenReordered(
// And add them back in the new order.
for (int i = 0; i < node->GetChildCount(); ++i) {
- BookmarkNode* child = node->GetChild(i);
+ const BookmarkNode* child = node->GetChild(i);
if (child->is_folder()) {
DCHECK(bn_to_folder.find(child) != bn_to_folder.end());
folder_node->Add(folder_node->GetChildCount(), bn_to_folder[child]);
@@ -189,7 +189,7 @@ void BookmarkFolderTreeModel::AddRootChildren() {
FolderNode* BookmarkFolderTreeModel::GetFolderNodeForBookmarkNode(
FolderNode* folder_node,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
DCHECK(node->is_folder());
if (folder_node->value == node)
return folder_node;
@@ -202,25 +202,26 @@ FolderNode* BookmarkFolderTreeModel::GetFolderNodeForBookmarkNode(
return NULL;
}
-FolderNode* BookmarkFolderTreeModel::CreateFolderNode(BookmarkNode* node) {
+FolderNode* BookmarkFolderTreeModel::CreateFolderNode(
+ const BookmarkNode* node) {
DCHECK(node->is_folder());
FolderNode* folder_node = new FolderNode(node);
folder_node->SetTitle(node->GetTitle());
// And clone the children folders.
for (int i = 0; i < node->GetChildCount(); ++i) {
- BookmarkNode* child = node->GetChild(i);
+ const BookmarkNode* child = node->GetChild(i);
if (child->is_folder())
folder_node->Add(folder_node->GetChildCount(), CreateFolderNode(child));
}
return folder_node;
}
-int BookmarkFolderTreeModel::CalculateIndexForChild(BookmarkNode* node) {
- BookmarkNode* parent = node->GetParent();
+int BookmarkFolderTreeModel::CalculateIndexForChild(const BookmarkNode* node) {
+ const BookmarkNode* parent = node->GetParent();
DCHECK(parent);
for (int i = 0, folder_count = 0; i < parent->GetChildCount(); ++i) {
- BookmarkNode* child = parent->GetChild(i);
+ const BookmarkNode* child = parent->GetChild(i);
if (child == node)
return folder_count;
if (child->is_folder())
diff --git a/chrome/browser/bookmarks/bookmark_folder_tree_model.h b/chrome/browser/bookmarks/bookmark_folder_tree_model.h
index 4faff4e..fb88e1c 100644
--- a/chrome/browser/bookmarks/bookmark_folder_tree_model.h
+++ b/chrome/browser/bookmarks/bookmark_folder_tree_model.h
@@ -11,7 +11,7 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
// The type of nodes created by BookmarkFolderTreeModel.
-typedef TreeNodeWithValue<BookmarkNode*> FolderNode;
+typedef TreeNodeWithValue<const BookmarkNode*> FolderNode;
// TreeModel implementation that shows the folders from the BookmarkModel.
// The root node contains the following nodes:
@@ -40,11 +40,11 @@ class BookmarkFolderTreeModel : public TreeNodeModel<FolderNode>,
NodeType GetNodeType(TreeModelNode* node);
// Returns the FolderNode for the specified BookmarkNode.
- FolderNode* GetFolderNodeForBookmarkNode(BookmarkNode* node);
+ FolderNode* GetFolderNodeForBookmarkNode(const BookmarkNode* node);
// Converts the tree node into a BookmarkNode. Returns NULL if |node| is NULL
// or not of NodeType::BOOKMARK.
- BookmarkNode* TreeNodeAsBookmarkNode(TreeModelNode* node);
+ const BookmarkNode* TreeNodeAsBookmarkNode(TreeModelNode* node);
// Returns the search node.
FolderNode* search_node() const { return search_node_; }
@@ -53,24 +53,24 @@ class BookmarkFolderTreeModel : public TreeNodeModel<FolderNode>,
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// Folders don't have favicons, so we ignore this.
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
// The following are overriden to return custom icons for the recently
// bookmarked and search nodes.
@@ -85,17 +85,17 @@ private:
// represents |node|, |folder_node| is returned, otherwise this recurses
// through the children.
FolderNode* GetFolderNodeForBookmarkNode(FolderNode* folder_node,
- BookmarkNode* node);
+ const BookmarkNode* node);
// Creates a new folder node for |node| and all its children.
- FolderNode* CreateFolderNode(BookmarkNode* node);
+ FolderNode* CreateFolderNode(const BookmarkNode* node);
// Returns the number of folders that precede |node| in |node|s parent.
// The returned value is the index of the folder node representing |node|
// in its parent.
// This is used when new bookmarks are created to determine where the
// corresponding folder node should be created.
- int CalculateIndexForChild(BookmarkNode* node);
+ int CalculateIndexForChild(const BookmarkNode* node);
// The model we're getting data from. Owned by the Profile.
BookmarkModel* model_;
diff --git a/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc b/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
index ce50564..ddefae0 100644
--- a/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
@@ -38,12 +38,12 @@ class BookmarkFolderTreeModelTest : public testing::Test,
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
// Populate with some default data.
- BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
+ const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
bookmark_model()->AddURL(bb, 0, L"url1", url1_);
- BookmarkNode* f1 = bookmark_model()->AddGroup(bb, 1, L"f1");
+ const BookmarkNode* f1 = bookmark_model()->AddGroup(bb, 1, L"f1");
bookmark_model()->AddGroup(f1, 0, L"f11");
- BookmarkNode* other = bookmark_model()->other_node();
+ const BookmarkNode* other = bookmark_model()->other_node();
bookmark_model()->AddURL(other, 0, L"url2", url2_);
bookmark_model()->AddGroup(other, 1, L"f2");
bookmark_model()->AddURL(other, 2, L"url3", url3_);
@@ -176,7 +176,7 @@ TEST_F(BookmarkFolderTreeModelTest, RemoveFolder) {
// Adds a folder and makes sure we get the right notification.
TEST_F(BookmarkFolderTreeModelTest, AddFolder) {
- BookmarkNode* new_group =
+ const BookmarkNode* new_group =
bookmark_model()->AddGroup(
bookmark_model()->GetBookmarkBarNode(), 0, L"fa");
VerifyAndClearObserverCounts(0, 1, 0, 0);
@@ -198,7 +198,7 @@ TEST_F(BookmarkFolderTreeModelTest, ChangeFolder) {
// Sorts the other folder, making sure the resulting order is correct and the
// appropriate notification is sent.
TEST_F(BookmarkFolderTreeModelTest, Sort) {
- BookmarkNode* other = bookmark_model()->other_node();
+ const BookmarkNode* other = bookmark_model()->other_node();
bookmark_model()->AddGroup(other, 3, L"a1");
bookmark_model()->AddGroup(other, 4, L"g1");
ResetCounts();
diff --git a/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc b/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
index d1f5a4e..a47e204 100644
--- a/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
@@ -85,17 +85,18 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
base::Time t1(base::Time::Now());
base::Time t2(t1 + base::TimeDelta::FromHours(1));
base::Time t3(t1 + base::TimeDelta::FromHours(1));
- BookmarkNode* f1 = model.AddGroup(model.GetBookmarkBarNode(), 0, f1_title);
+ const BookmarkNode* f1 = model.AddGroup(
+ model.GetBookmarkBarNode(), 0, f1_title);
model.AddURLWithCreationTime(f1, 0, url1_title, url1, t1);
- BookmarkNode* f2 = model.AddGroup(f1, 1, f2_title);
+ const BookmarkNode* f2 = model.AddGroup(f1, 1, f2_title);
model.AddURLWithCreationTime(f2, 0, url2_title, url2, t2);
model.AddURLWithCreationTime(model.GetBookmarkBarNode(), 1, url3_title, url3,
t3);
model.AddURLWithCreationTime(model.other_node(), 0, url1_title, url1, t1);
model.AddURLWithCreationTime(model.other_node(), 1, url2_title, url2, t2);
- BookmarkNode* f3 = model.AddGroup(model.other_node(), 2, f3_title);
- BookmarkNode* f4 = model.AddGroup(f3, 0, f4_title);
+ const BookmarkNode* f3 = model.AddGroup(model.other_node(), 2, f3_title);
+ const BookmarkNode* f4 = model.AddGroup(f3, 0, f4_title);
model.AddURLWithCreationTime(f4, 0, url1_title, url1, t1);
// Write to a temp file.
diff --git a/chrome/browser/bookmarks/bookmark_index.cc b/chrome/browser/bookmarks/bookmark_index.cc
index e769d74..0bdc87f 100644
--- a/chrome/browser/bookmarks/bookmark_index.cc
+++ b/chrome/browser/bookmarks/bookmark_index.cc
@@ -21,7 +21,7 @@ BookmarkIndex::NodeSet::const_iterator BookmarkIndex::Match::nodes_end() const {
return nodes.empty() ? terms.front()->second.end() : nodes.end();
}
-void BookmarkIndex::Add(BookmarkNode* node) {
+void BookmarkIndex::Add(const BookmarkNode* node) {
if (!node->is_url())
return;
std::vector<std::wstring> terms = ExtractQueryWords(node->GetTitle());
@@ -29,7 +29,7 @@ void BookmarkIndex::Add(BookmarkNode* node) {
RegisterNode(terms[i], node);
}
-void BookmarkIndex::Remove(BookmarkNode* node) {
+void BookmarkIndex::Remove(const BookmarkNode* node) {
if (!node->is_url())
return;
@@ -179,7 +179,7 @@ std::vector<std::wstring> BookmarkIndex::ExtractQueryWords(
}
void BookmarkIndex::RegisterNode(const std::wstring& term,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (std::find(index_[term].begin(), index_[term].end(), node) !=
index_[term].end()) {
// We've already added node for term.
@@ -189,7 +189,7 @@ void BookmarkIndex::RegisterNode(const std::wstring& term,
}
void BookmarkIndex::UnregisterNode(const std::wstring& term,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
Index::iterator i = index_.find(term);
if (i == index_.end()) {
// We can get here if the node has the same term more than once. For
diff --git a/chrome/browser/bookmarks/bookmark_index.h b/chrome/browser/bookmarks/bookmark_index.h
index 98a6a57..f3da604 100644
--- a/chrome/browser/bookmarks/bookmark_index.h
+++ b/chrome/browser/bookmarks/bookmark_index.h
@@ -34,10 +34,10 @@ class BookmarkIndex {
BookmarkIndex() {}
// Invoked when a bookmark has been added to the model.
- void Add(BookmarkNode* node);
+ void Add(const BookmarkNode* node);
// Invoked when a bookmark has been removed from the model.
- void Remove(BookmarkNode* node);
+ void Remove(const BookmarkNode* node);
// Returns up to |max_count| of bookmarks containing the text |query|.
void GetBookmarksWithTitlesMatching(
@@ -46,7 +46,7 @@ class BookmarkIndex {
std::vector<bookmark_utils::TitleMatch>* results);
private:
- typedef std::set<BookmarkNode*> NodeSet;
+ typedef std::set<const BookmarkNode*> NodeSet;
typedef std::map<std::wstring, NodeSet> Index;
// Used when finding the set of bookmarks that match a query. Each match
@@ -116,10 +116,10 @@ class BookmarkIndex {
std::vector<std::wstring> ExtractQueryWords(const std::wstring& query);
// Adds |node| to |index_|.
- void RegisterNode(const std::wstring& term, BookmarkNode* node);
+ void RegisterNode(const std::wstring& term, const BookmarkNode* node);
// Removes |node| from |index_|.
- void UnregisterNode(const std::wstring& term, BookmarkNode* node);
+ void UnregisterNode(const std::wstring& term, const BookmarkNode* node);
Index index_;
diff --git a/chrome/browser/bookmarks/bookmark_index_unittest.cc b/chrome/browser/bookmarks/bookmark_index_unittest.cc
index 10f43f0..cfd7b2f 100644
--- a/chrome/browser/bookmarks/bookmark_index_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_index_unittest.cc
@@ -191,8 +191,8 @@ TEST_F(BookmarkIndexTest, HonorMax) {
// Makes sure if the lower case string of a bookmark title is more characters
// than the upper case string no match positions are returned.
TEST_F(BookmarkIndexTest, EmptyMatchOnMultiwideLowercaseString) {
- BookmarkNode* n1 = model_->AddURL(model_->other_node(), 0, L"\u0130 i",
- GURL("http://www.google.com"));
+ const BookmarkNode* n1 = model_->AddURL(model_->other_node(), 0, L"\u0130 i",
+ GURL("http://www.google.com"));
std::vector<bookmark_utils::TitleMatch> matches;
model_->GetBookmarksWithTitlesMatching(L"i", 100, &matches);
diff --git a/chrome/browser/bookmarks/bookmark_manager.h b/chrome/browser/bookmarks/bookmark_manager.h
index 28a210b..4116b76 100644
--- a/chrome/browser/bookmarks/bookmark_manager.h
+++ b/chrome/browser/bookmarks/bookmark_manager.h
@@ -15,7 +15,7 @@ class BookmarkManager {
public:
// Select |node| in the tree view of the bookmark manager, but only if the
// manager is showing and is for |profile|.
- static void SelectInTree(Profile* profile, BookmarkNode* node);
+ static void SelectInTree(Profile* profile, const BookmarkNode* node);
// Show the bookmark manager for |profile|. Only one bookmark manager shows
// at a time, so if another one is showing, this does nothing.
diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc
index 83bd08a..3a52ae6 100644
--- a/chrome/browser/bookmarks/bookmark_model.cc
+++ b/chrome/browser/bookmarks/bookmark_model.cc
@@ -19,6 +19,15 @@
using base::Time;
+namespace {
+
+// Helper to get a mutable bookmark node.
+static BookmarkNode* AsMutable(const BookmarkNode* node) {
+ return const_cast<BookmarkNode*>(node);
+}
+
+} // anonymous namespace
+
// BookmarkNode ---------------------------------------------------------------
BookmarkNode::BookmarkNode(const GURL& url)
@@ -60,14 +69,14 @@ const wchar_t kPrefPersistIDs[] = L"bookmarks.persist_ids";
// Comparator used when sorting bookmarks. Folders are sorted first, then
// bookmarks.
-class SortComparator : public std::binary_function<BookmarkNode*,
- BookmarkNode*,
+class SortComparator : public std::binary_function<const BookmarkNode*,
+ const BookmarkNode*,
bool> {
public:
explicit SortComparator(Collator* collator) : collator_(collator) { }
// Returns true if lhs preceeds rhs.
- bool operator() (BookmarkNode* n1, BookmarkNode* n2) {
+ bool operator() (const BookmarkNode* n1, const BookmarkNode* n2) {
if (n1->GetType() == n2->GetType()) {
// Types are the same, compare the names.
if (!collator_)
@@ -135,26 +144,25 @@ void BookmarkModel::Load() {
store_->LoadBookmarks(CreateLoadDetails());
}
-BookmarkNode* BookmarkModel::GetParentForNewNodes() {
- std::vector<BookmarkNode*> nodes =
+const BookmarkNode* BookmarkModel::GetParentForNewNodes() {
+ std::vector<const BookmarkNode*> nodes =
bookmark_utils::GetMostRecentlyModifiedGroups(this, 1);
return nodes.empty() ? bookmark_bar_node_ : nodes[0];
}
-void BookmarkModel::Remove(BookmarkNode* parent, int index) {
- if (!loaded_ || !IsValidIndex(parent, index, false) || parent == &root_) {
+void BookmarkModel::Remove(const BookmarkNode* parent, int index) {
+ if (!loaded_ || !IsValidIndex(parent, index, false) || is_root(parent)) {
NOTREACHED();
return;
}
- RemoveAndDeleteNode(parent->GetChild(index));
+ RemoveAndDeleteNode(AsMutable(parent->GetChild(index)));
}
-void BookmarkModel::Move(BookmarkNode* node,
- BookmarkNode* new_parent,
+void BookmarkModel::Move(const BookmarkNode* node,
+ const 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_) {
+ is_root(new_parent) || is_permanent_node(node)) {
NOTREACHED();
return;
}
@@ -167,7 +175,7 @@ void BookmarkModel::Move(BookmarkNode* node,
SetDateGroupModified(new_parent, Time::Now());
- BookmarkNode* old_parent = node->GetParent();
+ const BookmarkNode* old_parent = node->GetParent();
int old_index = old_parent->IndexOfChild(node);
if (old_parent == new_parent &&
@@ -178,7 +186,8 @@ void BookmarkModel::Move(BookmarkNode* node,
if (old_parent == new_parent && index > old_index)
index--;
- new_parent->Add(index, node);
+ BookmarkNode* mutable_new_parent = AsMutable(new_parent);
+ mutable_new_parent->Add(index, AsMutable(node));
if (store_.get())
store_->ScheduleSave();
@@ -188,16 +197,17 @@ void BookmarkModel::Move(BookmarkNode* node,
new_parent, index));
}
-const SkBitmap& BookmarkModel::GetFavIcon(BookmarkNode* node) {
+const SkBitmap& BookmarkModel::GetFavIcon(const BookmarkNode* node) {
DCHECK(node);
- if (!node->loaded_favicon_) {
- node->loaded_favicon_ = true;
- LoadFavIcon(node);
+ if (!node->is_favicon_loaded()) {
+ BookmarkNode* mutable_node = AsMutable(node);
+ mutable_node->set_favicon_loaded(true);
+ LoadFavIcon(mutable_node);
}
return node->favicon();
}
-void BookmarkModel::SetTitle(BookmarkNode* node,
+void BookmarkModel::SetTitle(const BookmarkNode* node,
const std::wstring& title) {
if (!node) {
NOTREACHED();
@@ -209,9 +219,7 @@ void BookmarkModel::SetTitle(BookmarkNode* node,
// The title index doesn't support changing the title, instead we remove then
// add it back.
index_->Remove(node);
-
- node->SetTitle(title);
-
+ AsMutable(node)->SetTitle(title);
index_->Add(node);
if (store_.get())
@@ -222,7 +230,7 @@ void BookmarkModel::SetTitle(BookmarkNode* node,
}
void BookmarkModel::GetNodesByURL(const GURL& url,
- std::vector<BookmarkNode*>* nodes) {
+ std::vector<const BookmarkNode*>* nodes) {
AutoLock url_lock(url_lock_);
BookmarkNode tmp_node(url);
NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.find(&tmp_node);
@@ -232,8 +240,9 @@ void BookmarkModel::GetNodesByURL(const GURL& url,
}
}
-BookmarkNode* BookmarkModel::GetMostRecentlyAddedNodeForURL(const GURL& url) {
- std::vector<BookmarkNode*> nodes;
+const BookmarkNode* BookmarkModel::GetMostRecentlyAddedNodeForURL(
+ const GURL& url) {
+ std::vector<const BookmarkNode*> nodes;
GetNodesByURL(url, &nodes);
if (nodes.empty())
return NULL;
@@ -247,7 +256,7 @@ void BookmarkModel::GetBookmarks(std::vector<GURL>* urls) {
const GURL* last_url = NULL;
for (NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.begin();
i != nodes_ordered_by_url_set_.end(); ++i) {
- const GURL* url = &((*i)->url_);
+ const GURL* url = &((*i)->GetURL());
// Only add unique URLs.
if (!last_url || *url != *last_url)
urls->push_back(*url);
@@ -260,15 +269,14 @@ bool BookmarkModel::IsBookmarked(const GURL& url) {
return IsBookmarkedNoLock(url);
}
-BookmarkNode* BookmarkModel::GetNodeByID(int id) {
+const BookmarkNode* BookmarkModel::GetNodeByID(int id) {
// TODO(sky): TreeNode needs a method that visits all nodes using a predicate.
return GetNodeByID(&root_, id);
}
-BookmarkNode* BookmarkModel::AddGroup(
- BookmarkNode* parent,
- int index,
- const std::wstring& title) {
+const BookmarkNode* BookmarkModel::AddGroup(const BookmarkNode* parent,
+ int index,
+ const std::wstring& title) {
if (!loaded_ || parent == &root_ || !IsValidIndex(parent, index, true)) {
// Can't add to the root.
NOTREACHED();
@@ -277,27 +285,27 @@ BookmarkNode* BookmarkModel::AddGroup(
BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(),
GURL());
- new_node->date_group_modified_ = Time::Now();
+ new_node->set_date_group_modified(Time::Now());
new_node->SetTitle(title);
- new_node->type_ = history::StarredEntry::USER_GROUP;
+ new_node->SetType(history::StarredEntry::USER_GROUP);
- return AddNode(parent, index, new_node, false);
+ return AddNode(AsMutable(parent), index, new_node, false);
}
-BookmarkNode* BookmarkModel::AddURL(BookmarkNode* parent,
- int index,
- const std::wstring& title,
- const GURL& url) {
+const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent,
+ int index,
+ const std::wstring& title,
+ const GURL& url) {
return AddURLWithCreationTime(parent, index, title, url, Time::Now());
}
-BookmarkNode* BookmarkModel::AddURLWithCreationTime(
- BookmarkNode* parent,
+const BookmarkNode* BookmarkModel::AddURLWithCreationTime(
+ const BookmarkNode* parent,
int index,
const std::wstring& title,
const GURL& url,
const Time& creation_time) {
- if (!loaded_ || !url.is_valid() || parent == &root_ ||
+ if (!loaded_ || !url.is_valid() || is_root(parent) ||
!IsValidIndex(parent, index, true)) {
NOTREACHED();
return NULL;
@@ -309,8 +317,8 @@ BookmarkNode* BookmarkModel::AddURLWithCreationTime(
BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), url);
new_node->SetTitle(title);
- new_node->date_added_ = creation_time;
- new_node->type_ = history::StarredEntry::URL;
+ new_node->set_date_added(creation_time);
+ new_node->SetType(history::StarredEntry::URL);
{
// Only hold the lock for the duration of the insert.
@@ -318,11 +326,11 @@ BookmarkNode* BookmarkModel::AddURLWithCreationTime(
nodes_ordered_by_url_set_.insert(new_node);
}
- return AddNode(parent, index, new_node, was_bookmarked);
+ return AddNode(AsMutable(parent), index, new_node, was_bookmarked);
}
-void BookmarkModel::SortChildren(BookmarkNode* parent) {
- if (!parent || !parent->is_folder() || parent == root_node() ||
+void BookmarkModel::SortChildren(const BookmarkNode* parent) {
+ if (!parent || !parent->is_folder() || is_root(parent) ||
parent->GetChildCount() <= 1) {
return;
}
@@ -334,7 +342,9 @@ void BookmarkModel::SortChildren(BookmarkNode* parent) {
error));
if (U_FAILURE(error))
collator.reset(NULL);
- std::sort(parent->children().begin(), parent->children().end(),
+ BookmarkNode* mutable_parent = AsMutable(parent);
+ std::sort(mutable_parent->children().begin(),
+ mutable_parent->children().end(),
SortComparator(collator.get()));
if (store_.get())
@@ -347,7 +357,7 @@ void BookmarkModel::SortChildren(BookmarkNode* parent) {
void BookmarkModel::SetURLStarred(const GURL& url,
const std::wstring& title,
bool is_starred) {
- std::vector<BookmarkNode*> bookmarks;
+ std::vector<const BookmarkNode*> bookmarks;
GetNodesByURL(url, &bookmarks);
bool bookmarks_exist = !bookmarks.empty();
if (is_starred == bookmarks_exist)
@@ -355,18 +365,18 @@ void BookmarkModel::SetURLStarred(const GURL& url,
if (is_starred) {
// Create a bookmark.
- BookmarkNode* parent = GetParentForNewNodes();
+ const BookmarkNode* parent = GetParentForNewNodes();
AddURL(parent, parent->GetChildCount(), title, url);
} else {
// Remove all the bookmarks.
for (size_t i = 0; i < bookmarks.size(); ++i) {
- BookmarkNode* node = bookmarks[i];
+ const BookmarkNode* node = bookmarks[i];
Remove(node->GetParent(), node->GetParent()->IndexOfChild(node));
}
}
}
-void BookmarkModel::ResetDateGroupModified(BookmarkNode* node) {
+void BookmarkModel::ResetDateGroupModified(const BookmarkNode* node) {
SetDateGroupModified(node, Time());
}
@@ -404,7 +414,7 @@ bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) {
nodes_ordered_by_url_set_.end());
}
-void BookmarkModel::FavIconLoaded(BookmarkNode* node) {
+void BookmarkModel::FavIconLoaded(const BookmarkNode* node) {
// Send out notification to the observer.
FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
BookmarkNodeFavIconLoaded(this, node));
@@ -412,8 +422,7 @@ void BookmarkModel::FavIconLoaded(BookmarkNode* node) {
void BookmarkModel::RemoveNode(BookmarkNode* node,
std::set<GURL>* removed_urls) {
- if (!loaded_ || !node || node == &root_ || node == bookmark_bar_node_ ||
- node == other_node_) {
+ if (!loaded_ || !node || is_permanent_node(node)) {
NOTREACHED();
return;
}
@@ -486,7 +495,7 @@ void BookmarkModel::DoneLoading(
void BookmarkModel::RemoveAndDeleteNode(BookmarkNode* delete_me) {
scoped_ptr<BookmarkNode> node(delete_me);
- BookmarkNode* parent = node->GetParent();
+ BookmarkNode* parent = AsMutable(node->GetParent());
DCHECK(parent);
int index = parent->IndexOfChild(node.get());
parent->Remove(index);
@@ -564,19 +573,20 @@ void BookmarkModel::BlockTillLoaded() {
loaded_signal_.Wait();
}
-BookmarkNode* BookmarkModel::GetNodeByID(BookmarkNode* node, int id) {
+const BookmarkNode* BookmarkModel::GetNodeByID(const BookmarkNode* node,
+ int id) {
if (node->id() == id)
return node;
for (int i = 0; i < node->GetChildCount(); ++i) {
- BookmarkNode* result = GetNodeByID(node->GetChild(i), id);
+ const BookmarkNode* result = GetNodeByID(node->GetChild(i), id);
if (result)
return result;
}
return NULL;
}
-bool BookmarkModel::IsValidIndex(BookmarkNode* parent,
+bool BookmarkModel::IsValidIndex(const BookmarkNode* parent,
int index,
bool allow_end) {
return (parent && parent->is_folder() &&
@@ -584,10 +594,10 @@ bool BookmarkModel::IsValidIndex(BookmarkNode* parent,
(allow_end && index == parent->GetChildCount()))));
}
-void BookmarkModel::SetDateGroupModified(BookmarkNode* parent,
+void BookmarkModel::SetDateGroupModified(const BookmarkNode* parent,
const Time time) {
DCHECK(parent);
- parent->date_group_modified_ = time;
+ AsMutable(parent)->set_date_group_modified(time);
if (store_.get())
store_->ScheduleSave();
@@ -629,10 +639,10 @@ void BookmarkModel::OnFavIconDataAvailable(
load_consumer_.GetClientData(
profile_->GetHistoryService(Profile::EXPLICIT_ACCESS), handle);
DCHECK(node);
- node->favicon_load_handle_ = 0;
+ node->set_favicon_load_handle(0);
if (know_favicon && data.get() &&
PNGDecoder::Decode(&data->data, &fav_icon)) {
- node->favicon_ = fav_icon;
+ node->set_favicon(fav_icon);
FavIconLoaded(node);
}
}
@@ -651,16 +661,16 @@ void BookmarkModel::LoadFavIcon(BookmarkNode* node) {
node->GetURL(), &load_consumer_,
NewCallback(this, &BookmarkModel::OnFavIconDataAvailable));
load_consumer_.SetClientData(history_service, handle, node);
- node->favicon_load_handle_ = handle;
+ node->set_favicon_load_handle(handle);
}
void BookmarkModel::CancelPendingFavIconLoadRequests(BookmarkNode* node) {
- if (node->favicon_load_handle_) {
+ if (node->favicon_load_handle()) {
HistoryService* history =
profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
if (history)
- history->CancelRequest(node->favicon_load_handle_);
- node->favicon_load_handle_ = 0;
+ history->CancelRequest(node->favicon_load_handle());
+ node->set_favicon_load_handle(0);
}
}
@@ -673,11 +683,11 @@ void BookmarkModel::Observe(NotificationType type,
Details<history::FavIconChangeDetails> favicon_details(details);
for (std::set<GURL>::const_iterator i = favicon_details->urls.begin();
i != favicon_details->urls.end(); ++i) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
GetNodesByURL(*i, &nodes);
for (size_t i = 0; i < nodes.size(); ++i) {
// Got an updated favicon, for a URL, do a new request.
- BookmarkNode* node = nodes[i];
+ BookmarkNode* node = AsMutable(nodes[i]);
node->InvalidateFavicon();
CancelPendingFavIconLoadRequests(node);
FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h
index d00e7c6..19b0ed0 100644
--- a/chrome/browser/bookmarks/bookmark_model.h
+++ b/chrome/browser/bookmarks/bookmark_model.h
@@ -42,18 +42,12 @@ class StarredURLDatabase;
//
class BookmarkNode : public TreeNode<BookmarkNode> {
friend class BookmarkModel;
- friend class BookmarkCodec;
- friend class history::StarredURLDatabase;
- FRIEND_TEST(BookmarkCodecTest, PersistIDsTest);
- FRIEND_TEST(BookmarkEditorViewTest, ChangeParentAndURL);
- FRIEND_TEST(BookmarkEditorViewTest, EditURLKeepsPosition);
- FRIEND_TEST(BookmarkMenuBridgeTest, TestAddNodeToMenu);
- FRIEND_TEST(BookmarkEditorGtkTest, ChangeParentAndURL);
- FRIEND_TEST(BookmarkEditorGtkTest, EditURLKeepsPosition);
- FRIEND_TEST(BookmarkModelTest, MostRecentlyAddedEntries);
- FRIEND_TEST(BookmarkModelTest, GetMostRecentlyAddedNodeForURL);
public:
+ // Creates a new node with the specified url and id of 0
+ explicit BookmarkNode(const GURL& url);
+ // Creates a new node with the specified url and id.
+ BookmarkNode(int id, const GURL& url);
virtual ~BookmarkNode() {}
// Returns the URL.
@@ -64,25 +58,25 @@ class BookmarkNode : public TreeNode<BookmarkNode> {
// NOTE: this id is only unique for the session and NOT unique across
// sessions. Don't persist it!
int id() const { return id_; }
+ // Sets the id to the given value.
+ void set_id(int id) { id_ = id; }
// Returns the type of this node.
history::StarredEntry::Type GetType() const { return type_; }
-
- // Called when the favicon becomes invalid.
- void InvalidateFavicon() {
- loaded_favicon_ = false;
- favicon_ = SkBitmap();
- }
+ void SetType(history::StarredEntry::Type type) { type_ = type; }
// Returns the time the bookmark/group was added.
- base::Time date_added() const { return date_added_; }
-
+ const base::Time& date_added() const { return date_added_; }
// Sets the time the bookmark/group was added.
void set_date_added(const base::Time& date) { date_added_ = date; }
// Returns the last time the group was modified. This is only maintained
// for folders (including the bookmark and other folder).
- base::Time date_group_modified() const { return date_group_modified_; }
+ const base::Time& date_group_modified() const { return date_group_modified_; }
+ // Sets the last time the group was modified.
+ void set_date_group_modified(const base::Time& date) {
+ date_group_modified_ = date;
+ }
// Convenience for testing if this nodes represents a group. A group is
// a node whose type is not URL.
@@ -91,27 +85,42 @@ class BookmarkNode : public TreeNode<BookmarkNode> {
// Is this a URL?
bool is_url() const { return type_ == history::StarredEntry::URL; }
- // TODO(sky): Consider adding last visit time here, it'll greatly simplify
- // HistoryContentsProvider.
+ // Returns the favicon. In nearly all cases you should use the method
+ // BookmarkModel::GetFavicon rather than this. BookmarkModel::GetFavicon
+ // takes care of loading the favicon if it isn't already loaded, where as
+ // this does not.
+ const SkBitmap& favicon() const { return favicon_; }
+ void set_favicon(const SkBitmap& icon) { favicon_ = icon; }
- private:
- // Creates a new node with the specified url and id of 0
- explicit BookmarkNode(const GURL& url);
- // Creates a new node with the specified url and id.
- BookmarkNode(int id, const GURL& url);
+ // The following methods are used by the bookmark model, and are not
+ // really useful outside of it.
- // 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.
- const SkBitmap& favicon() const { return favicon_; }
+ bool is_favicon_loaded() const { return loaded_favicon_; }
+ void set_favicon_loaded(bool value) { loaded_favicon_ = value; }
- // helper to initialize various fields during construction.
- void Initialize(int id);
+ HistoryService::Handle favicon_load_handle() const {
+ return favicon_load_handle_;
+ }
+ void set_favicon_load_handle(HistoryService::Handle handle) {
+ favicon_load_handle_ = handle;
+ }
+
+ // Called when the favicon becomes invalid.
+ void InvalidateFavicon() {
+ loaded_favicon_ = false;
+ favicon_ = SkBitmap();
+ }
// Resets the properties of the node from the supplied entry.
+ // This is used by the bookmark model and not really useful outside of it.
void Reset(const history::StarredEntry& entry);
- // Sets the id to the given value.
- void set_id(int id) { id_ = id; }
+ // TODO(sky): Consider adding last visit time here, it'll greatly simplify
+ // HistoryContentsProvider.
+
+ private:
+ // helper to initialize various fields during construction.
+ void Initialize(int id);
// Unique identifier for this node.
int id_;
@@ -157,40 +166,40 @@ class BookmarkModelObserver {
// Invoked when a node has moved.
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) = 0;
// Invoked when a node has been added.
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) = 0;
// Invoked when a node has been removed, the item may still be starred though.
// TODO(sky): merge these two into one.
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int old_index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
BookmarkNodeRemoved(model, parent, old_index);
}
// Invoked when the title or favicon of a node has changed.
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) = 0;
+ const BookmarkNode* node) = 0;
// Invoked when a favicon has finished loading.
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) = 0;
+ const BookmarkNode* node) = 0;
// Invoked when the children (just direct children, not descendants) of
// |node| have been reordered in some way, such as sorted.
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) = 0;
+ const BookmarkNode* node) = 0;
};
// BookmarkModel --------------------------------------------------------------
@@ -219,17 +228,17 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
// Returns the root node. The bookmark bar node and other node are children of
// the root node.
- BookmarkNode* root_node() { return &root_; }
+ const BookmarkNode* root_node() { return &root_; }
// Returns the bookmark bar node. This is NULL until loaded.
- BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; }
+ const BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; }
// Returns the 'other' node. This is NULL until loaded.
- BookmarkNode* other_node() { return other_node_; }
+ const 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).
- BookmarkNode* GetParentForNewNodes();
+ const BookmarkNode* GetParentForNewNodes();
void AddObserver(BookmarkModelObserver* observer) {
observers_.AddObserver(observer);
@@ -241,27 +250,29 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
// Unstars or deletes the specified entry. Removing a group entry recursively
// unstars all nodes. Observers are notified immediately.
- void Remove(BookmarkNode* parent, int index);
+ void Remove(const BookmarkNode* parent, int index);
// Moves the specified entry to a new location.
- void Move(BookmarkNode* node, BookmarkNode* new_parent, int index);
+ void Move(const BookmarkNode* node,
+ const BookmarkNode* new_parent,
+ int index);
// Returns the favicon for |node|. If the favicon has not yet been
// loaded it is loaded and the observer of the model notified when done.
- const SkBitmap& GetFavIcon(BookmarkNode* node);
+ const SkBitmap& GetFavIcon(const BookmarkNode* node);
// Sets the title of the specified node.
- void SetTitle(BookmarkNode* node, const std::wstring& title);
+ void SetTitle(const BookmarkNode* node, const std::wstring& title);
// Returns true if the model finished loading.
bool IsLoaded() { return loaded_; }
// Returns the set of nodes with the specified URL.
- void GetNodesByURL(const GURL& url, std::vector<BookmarkNode*>* nodes);
+ void GetNodesByURL(const GURL& url, std::vector<const BookmarkNode*>* nodes);
// Returns the most recently added node for the url. Returns NULL if url is
// not bookmarked.
- BookmarkNode* GetMostRecentlyAddedNodeForURL(const GURL& url);
+ const BookmarkNode* GetMostRecentlyAddedNodeForURL(const GURL& url);
// Returns all the bookmarked urls. This method is thread safe.
virtual void GetBookmarks(std::vector<GURL>* urls);
@@ -276,29 +287,29 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
// Returns the node with the specified id, or NULL if there is no node with
// the specified id.
- BookmarkNode* GetNodeByID(int id);
+ const BookmarkNode* GetNodeByID(int id);
// Adds a new group node at the specified position.
- BookmarkNode* AddGroup(BookmarkNode* parent,
- int index,
- const std::wstring& title);
+ const BookmarkNode* AddGroup(const BookmarkNode* parent,
+ int index,
+ const std::wstring& title);
// Adds a url at the specified position.
- BookmarkNode* AddURL(BookmarkNode* parent,
- int index,
- const std::wstring& title,
- const GURL& url);
+ const BookmarkNode* AddURL(const BookmarkNode* parent,
+ int index,
+ const std::wstring& title,
+ const GURL& url);
// Adds a url with a specific creation date.
- BookmarkNode* AddURLWithCreationTime(BookmarkNode* parent,
- int index,
- const std::wstring& title,
- const GURL& url,
- const base::Time& creation_time);
+ const BookmarkNode* AddURLWithCreationTime(const BookmarkNode* parent,
+ int index,
+ const std::wstring& title,
+ const GURL& url,
+ const base::Time& creation_time);
// Sorts the children of |parent|, notifying observers by way of the
// BookmarkNodeChildrenReordered method.
- void SortChildren(BookmarkNode* parent);
+ void SortChildren(const BookmarkNode* parent);
// This is the convenience that makes sure the url is starred or not starred.
// If is_starred is false, all bookmarks for URL are removed. If is_starred is
@@ -310,7 +321,7 @@ class BookmarkModel : 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(BookmarkNode* node);
+ void ResetDateGroupModified(const BookmarkNode* node);
void GetBookmarksWithTitlesMatching(
const std::wstring& text,
@@ -319,6 +330,21 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
Profile* profile() const { return profile_; }
+ bool is_root(const BookmarkNode* node) const { return node == &root_; }
+ bool is_bookmark_bar_node(const BookmarkNode* node) const {
+ return node == bookmark_bar_node_;
+ }
+ bool is_other_bookmarks_node(const BookmarkNode* node) const {
+ return node == other_node_;
+ }
+ // Returns whether the given node is one of the permanent nodes - root node,
+ // bookmark bar node or other bookmarks node.
+ bool is_permanent_node(const BookmarkNode* node) const {
+ return is_root(node) ||
+ is_bookmark_bar_node(node) ||
+ is_other_bookmarks_node(node);
+ }
+
// Sets the store to NULL, making it so the BookmarkModel does not persist
// any changes to disk. This is only useful during testing to speed up
// testing.
@@ -335,7 +361,7 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
// Used to order BookmarkNodes by URL.
class NodeURLComparator {
public:
- bool operator()(BookmarkNode* n1, BookmarkNode* n2) const {
+ bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const {
return n1->GetURL() < n2->GetURL();
}
};
@@ -345,7 +371,7 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
bool IsBookmarkedNoLock(const GURL& url);
// Overriden to notify the observer the favicon has been loaded.
- void FavIconLoaded(BookmarkNode* node);
+ void FavIconLoaded(const BookmarkNode* node);
// Removes the node from internal maps and recurses through all children. If
// the node is a url, its url is added to removed_urls.
@@ -373,13 +399,13 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
bool was_bookmarked);
// Implementation of GetNodeByID.
- BookmarkNode* GetNodeByID(BookmarkNode* node, int id);
+ const BookmarkNode* GetNodeByID(const BookmarkNode* node, int id);
// Returns true if the parent and index are valid.
- bool IsValidIndex(BookmarkNode* parent, int index, bool allow_end);
+ bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end);
// Sets the date modified time of the specified node.
- void SetDateGroupModified(BookmarkNode* parent, const base::Time time);
+ void SetDateGroupModified(const BookmarkNode* parent, const base::Time time);
// Creates the bookmark bar/other nodes. These call into
// CreateRootNodeFromStarredEntry.
diff --git a/chrome/browser/bookmarks/bookmark_model_test_utils.cc b/chrome/browser/bookmarks/bookmark_model_test_utils.cc
index 004bf51..e8e9d40 100644
--- a/chrome/browser/bookmarks/bookmark_model_test_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_model_test_utils.cc
@@ -8,8 +8,8 @@
#include "testing/gtest/include/gtest/gtest.h"
// static
-void BookmarkModelTestUtils::AssertNodesEqual(BookmarkNode* expected,
- BookmarkNode* actual,
+void BookmarkModelTestUtils::AssertNodesEqual(const BookmarkNode* expected,
+ const BookmarkNode* actual,
bool check_ids) {
ASSERT_TRUE(expected);
ASSERT_TRUE(actual);
diff --git a/chrome/browser/bookmarks/bookmark_model_test_utils.h b/chrome/browser/bookmarks/bookmark_model_test_utils.h
index fbd814f..e942bd6 100644
--- a/chrome/browser/bookmarks/bookmark_model_test_utils.h
+++ b/chrome/browser/bookmarks/bookmark_model_test_utils.h
@@ -19,8 +19,8 @@ class BookmarkModelTestUtils {
private:
// Helper to verify the two given bookmark nodes.
// The IDs of the bookmark nodes are compared only if check_ids is true.
- static void AssertNodesEqual(BookmarkNode* expected,
- BookmarkNode* actual,
+ static void AssertNodesEqual(const BookmarkNode* expected,
+ const BookmarkNode* actual,
bool check_ids);
};
diff --git a/chrome/browser/bookmarks/bookmark_model_unittest.cc b/chrome/browser/bookmarks/bookmark_model_unittest.cc
index 5fe296f..fc9fe0b 100644
--- a/chrome/browser/bookmarks/bookmark_model_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_model_unittest.cc
@@ -19,6 +19,21 @@
using base::Time;
using base::TimeDelta;
+namespace {
+
+// Helper to get a mutable bookmark node.
+static BookmarkNode* AsMutable(const BookmarkNode* node) {
+ return const_cast<BookmarkNode*>(node);
+}
+
+void SwapDateAdded(BookmarkNode* n1, BookmarkNode* n2) {
+ Time tmp = n1->date_added();
+ n1->set_date_added(n2->date_added());
+ n2->set_date_added(tmp);
+}
+
+} // anonymous namespace
+
class BookmarkModelTest : public testing::Test, public BookmarkModelObserver {
public:
struct ObserverDetails {
@@ -26,8 +41,8 @@ class BookmarkModelTest : public testing::Test, public BookmarkModelObserver {
Set(NULL, NULL, -1, -1);
}
- void Set(BookmarkNode* node1,
- BookmarkNode* node2,
+ void Set(const BookmarkNode* node1,
+ const BookmarkNode* node2,
int index1,
int index2) {
this->node1 = node1;
@@ -36,8 +51,8 @@ class BookmarkModelTest : public testing::Test, public BookmarkModelObserver {
this->index2 = index2;
}
- void AssertEquals(BookmarkNode* node1,
- BookmarkNode* node2,
+ void AssertEquals(const BookmarkNode* node1,
+ const BookmarkNode* node2,
int index1,
int index2) {
ASSERT_TRUE(this->node1 == node1);
@@ -46,8 +61,8 @@ class BookmarkModelTest : public testing::Test, public BookmarkModelObserver {
ASSERT_EQ(index2, this->index2);
}
- BookmarkNode* node1;
- BookmarkNode* node2;
+ const BookmarkNode* node1;
+ const BookmarkNode* node2;
int index1;
int index2;
};
@@ -64,41 +79,41 @@ class BookmarkModelTest : public testing::Test, public BookmarkModelObserver {
}
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
moved_count++;
observer_details.Set(old_parent, new_parent, old_index, new_index);
}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
added_count++;
observer_details.Set(parent, NULL, index, -1);
}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
removed_count++;
observer_details.Set(parent, NULL, index, -1);
}
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
changed_count++;
observer_details.Set(node, NULL, -1, -1);
}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
reordered_count_++;
}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
// We never attempt to load favicons, so that this method never
// gets invoked.
}
@@ -136,12 +151,12 @@ class BookmarkModelTest : public testing::Test, public BookmarkModelObserver {
};
TEST_F(BookmarkModelTest, InitialState) {
- BookmarkNode* bb_node = model.GetBookmarkBarNode();
+ const 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());
- BookmarkNode* other_node = model.other_node();
+ const 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());
@@ -150,11 +165,11 @@ TEST_F(BookmarkModelTest, InitialState) {
}
TEST_F(BookmarkModelTest, AddURL) {
- BookmarkNode* root = model.GetBookmarkBarNode();
+ const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring title(L"foo");
const GURL url("http://foo.com");
- BookmarkNode* new_node = model.AddURL(root, 0, title, url);
+ const BookmarkNode* new_node = model.AddURL(root, 0, title, url);
AssertObserverCount(1, 0, 0, 0, 0);
observer_details.AssertEquals(root, NULL, 0, -1);
@@ -169,10 +184,10 @@ TEST_F(BookmarkModelTest, AddURL) {
}
TEST_F(BookmarkModelTest, AddGroup) {
- BookmarkNode* root = model.GetBookmarkBarNode();
+ const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring title(L"foo");
- BookmarkNode* new_node = model.AddGroup(root, 0, title);
+ const BookmarkNode* new_node = model.AddGroup(root, 0, title);
AssertObserverCount(1, 0, 0, 0, 0);
observer_details.AssertEquals(root, NULL, 0, -1);
@@ -191,7 +206,7 @@ TEST_F(BookmarkModelTest, AddGroup) {
}
TEST_F(BookmarkModelTest, RemoveURL) {
- BookmarkNode* root = model.GetBookmarkBarNode();
+ const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring title(L"foo");
const GURL url("http://foo.com");
model.AddURL(root, 0, title, url);
@@ -207,8 +222,8 @@ TEST_F(BookmarkModelTest, RemoveURL) {
}
TEST_F(BookmarkModelTest, RemoveGroup) {
- BookmarkNode* root = model.GetBookmarkBarNode();
- BookmarkNode* group = model.AddGroup(root, 0, L"foo");
+ const BookmarkNode* root = model.GetBookmarkBarNode();
+ const BookmarkNode* group = model.AddGroup(root, 0, L"foo");
ClearCounts();
@@ -230,10 +245,10 @@ TEST_F(BookmarkModelTest, RemoveGroup) {
}
TEST_F(BookmarkModelTest, SetTitle) {
- BookmarkNode* root = model.GetBookmarkBarNode();
+ const BookmarkNode* root = model.GetBookmarkBarNode();
std::wstring title(L"foo");
const GURL url("http://foo.com");
- BookmarkNode* node = model.AddURL(root, 0, title, url);
+ const BookmarkNode* node = model.AddURL(root, 0, title, url);
ClearCounts();
@@ -245,11 +260,11 @@ TEST_F(BookmarkModelTest, SetTitle) {
}
TEST_F(BookmarkModelTest, Move) {
- BookmarkNode* root = model.GetBookmarkBarNode();
+ const BookmarkNode* root = model.GetBookmarkBarNode();
std::wstring title(L"foo");
const GURL url("http://foo.com");
- BookmarkNode* node = model.AddURL(root, 0, title, url);
- BookmarkNode* group1 = model.AddGroup(root, 0, L"foo");
+ const BookmarkNode* node = model.AddURL(root, 0, title, url);
+ const BookmarkNode* group1 = model.AddGroup(root, 0, L"foo");
ClearCounts();
model.Move(node, group1, 0);
@@ -285,12 +300,12 @@ TEST_F(BookmarkModelTest, ParentForNewNodes) {
// Make sure recently modified stays in sync when adding a URL.
TEST_F(BookmarkModelTest, MostRecentlyModifiedGroups) {
// Add a group.
- BookmarkNode* group = model.AddGroup(model.other_node(), 0, L"foo");
+ const 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<BookmarkNode*> most_recent_groups =
+ std::vector<const BookmarkNode*> most_recent_groups =
bookmark_utils::GetMostRecentlyModifiedGroups(&model, 1);
ASSERT_EQ(1U, most_recent_groups.size());
ASSERT_EQ(group, most_recent_groups[0]);
@@ -309,21 +324,29 @@ 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();
- BookmarkNode* n1 = model.AddURL(
- model.GetBookmarkBarNode(), 0, L"blah", GURL("http://foo.com/0"));
- BookmarkNode* n2 = model.AddURL(
- model.GetBookmarkBarNode(), 1, L"blah", GURL("http://foo.com/1"));
- BookmarkNode* n3 = model.AddURL(
- model.GetBookmarkBarNode(), 2, L"blah", GURL("http://foo.com/2"));
- 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);
- n3->date_added_ = base_time + TimeDelta::FromDays(2);
- n4->date_added_ = base_time + TimeDelta::FromDays(1);
+ BookmarkNode* n1 = AsMutable(model.AddURL(model.GetBookmarkBarNode(),
+ 0,
+ L"blah",
+ GURL("http://foo.com/0")));
+ BookmarkNode* n2 = AsMutable(model.AddURL(model.GetBookmarkBarNode(),
+ 1,
+ L"blah",
+ GURL("http://foo.com/1")));
+ BookmarkNode* n3 = AsMutable(model.AddURL(model.GetBookmarkBarNode(),
+ 2,
+ L"blah",
+ GURL("http://foo.com/2")));
+ BookmarkNode* n4 = AsMutable(model.AddURL(model.GetBookmarkBarNode(),
+ 3,
+ L"blah",
+ GURL("http://foo.com/3")));
+ n1->set_date_added(base_time + TimeDelta::FromDays(4));
+ n2->set_date_added(base_time + TimeDelta::FromDays(3));
+ n3->set_date_added(base_time + TimeDelta::FromDays(2));
+ n4->set_date_added(base_time + TimeDelta::FromDays(1));
// Make sure order is honored.
- std::vector<BookmarkNode*> recently_added;
+ std::vector<const BookmarkNode*> recently_added;
bookmark_utils::GetMostRecentlyAddedEntries(&model, 2, &recently_added);
ASSERT_EQ(2U, recently_added.size());
ASSERT_TRUE(n1 == recently_added[0]);
@@ -331,7 +354,7 @@ TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) {
// swap 1 and 2, then check again.
recently_added.clear();
- std::swap(n1->date_added_, n2->date_added_);
+ SwapDateAdded(n1, n2);
bookmark_utils::GetMostRecentlyAddedEntries(&model, 4, &recently_added);
ASSERT_EQ(4U, recently_added.size());
ASSERT_TRUE(n2 == recently_added[0]);
@@ -346,16 +369,18 @@ TEST_F(BookmarkModelTest, GetMostRecentlyAddedNodeForURL) {
// nodes: n1 > n2
Time base_time = Time::Now();
const GURL url("http://foo.com/0");
- BookmarkNode* n1 = model.AddURL(model.GetBookmarkBarNode(), 0, L"blah", url);
- BookmarkNode* n2 = model.AddURL(model.GetBookmarkBarNode(), 1, L"blah", url);
- n1->date_added_ = base_time + TimeDelta::FromDays(4);
- n2->date_added_ = base_time + TimeDelta::FromDays(3);
+ BookmarkNode* n1 = AsMutable(model.AddURL(
+ model.GetBookmarkBarNode(), 0, L"blah", url));
+ BookmarkNode* n2 = AsMutable(model.AddURL(
+ model.GetBookmarkBarNode(), 1, L"blah", url));
+ n1->set_date_added(base_time + TimeDelta::FromDays(4));
+ n2->set_date_added(base_time + TimeDelta::FromDays(3));
// Make sure order is honored.
ASSERT_EQ(n1, model.GetMostRecentlyAddedNodeForURL(url));
// swap 1 and 2, then check again.
- std::swap(n1->date_added_, n2->date_added_);
+ SwapDateAdded(n1, n2);
ASSERT_EQ(n2, model.GetMostRecentlyAddedNodeForURL(url));
}
@@ -408,7 +433,8 @@ class StarredListener : public NotificationObserver {
TEST_F(BookmarkModelTest, NotifyURLsStarred) {
StarredListener listener;
const GURL url("http://foo.com/0");
- BookmarkNode* n1 = model.AddURL(model.GetBookmarkBarNode(), 0, L"blah", url);
+ const BookmarkNode* n1 = model.AddURL(
+ model.GetBookmarkBarNode(), 0, L"blah", url);
// Starred notification should be sent.
EXPECT_EQ(1, listener.notification_count_);
@@ -420,7 +446,8 @@ TEST_F(BookmarkModelTest, NotifyURLsStarred) {
// Add another bookmark for the same URL. This should not send any
// notification.
- BookmarkNode* n2 = model.AddURL(model.GetBookmarkBarNode(), 1, L"blah", url);
+ const BookmarkNode* n2 = model.AddURL(
+ model.GetBookmarkBarNode(), 1, L"blah", url);
EXPECT_EQ(0, listener.notification_count_);
@@ -512,11 +539,11 @@ static void PopulateNodeFromString(const std::wstring& description,
// Populates the BookmarkNode with the children of parent.
static void PopulateBookmarkNode(TestNode* parent,
BookmarkModel* model,
- BookmarkNode* bb_node) {
+ const BookmarkNode* bb_node) {
for (int i = 0; i < parent->GetChildCount(); ++i) {
TestNode* child = parent->GetChild(i);
if (child->value == history::StarredEntry::USER_GROUP) {
- BookmarkNode* new_bb_node =
+ const BookmarkNode* new_bb_node =
model->AddGroup(bb_node, i, child->GetTitle());
PopulateBookmarkNode(child, model, new_bb_node);
} else {
@@ -545,11 +572,11 @@ class BookmarkModelTestWithProfile : public testing::Test,
protected:
// Verifies the contents of the bookmark bar node match the contents of the
// TestNode.
- void VerifyModelMatchesNode(TestNode* expected, BookmarkNode* actual) {
+ void VerifyModelMatchesNode(TestNode* expected, const BookmarkNode* actual) {
ASSERT_EQ(expected->GetChildCount(), actual->GetChildCount());
for (int i = 0; i < expected->GetChildCount(); ++i) {
TestNode* expected_child = expected->GetChild(i);
- BookmarkNode* actual_child = actual->GetChild(i);
+ const 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() ==
@@ -567,7 +594,7 @@ class BookmarkModelTestWithProfile : public testing::Test,
}
void VerifyNoDuplicateIDs(BookmarkModel* model) {
- TreeNodeIterator<BookmarkNode> it(model->root_node());
+ TreeNodeIterator<const BookmarkNode> it(model->root_node());
base::hash_set<int> ids;
while (it.has_next())
ASSERT_TRUE(ids.insert(it.Next()->id()).second);
@@ -605,22 +632,22 @@ class BookmarkModelTestWithProfile : public testing::Test,
MessageLoop::current()->Quit();
}
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {}
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
MessageLoopForUI message_loop_;
};
@@ -691,10 +718,10 @@ class BookmarkModelTestWithProfile2 : public BookmarkModelTestWithProfile {
// other
// OF1
// http://www.google.com/intl/en/about.html - About Google
- BookmarkNode* bbn = bb_model_->GetBookmarkBarNode();
+ const BookmarkNode* bbn = bb_model_->GetBookmarkBarNode();
ASSERT_EQ(2, bbn->GetChildCount());
- BookmarkNode* child = bbn->GetChild(0);
+ const 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"));
@@ -704,7 +731,7 @@ class BookmarkModelTestWithProfile2 : public BookmarkModelTestWithProfile {
ASSERT_EQ(L"F1", child->GetTitle());
ASSERT_EQ(2, child->GetChildCount());
- BookmarkNode* parent = child;
+ const BookmarkNode* parent = child;
child = parent->GetChild(0);
ASSERT_EQ(history::StarredEntry::URL, child->GetType());
ASSERT_EQ(L"Google Advertising", child->GetTitle());
@@ -808,13 +835,15 @@ TEST_F(BookmarkModelTest, Sort) {
// 'C' and 'a' are folders.
TestNode bbn;
PopulateNodeFromString(L"B [ a ] d [ a ]", &bbn);
- BookmarkNode* parent = model.GetBookmarkBarNode();
+ const BookmarkNode* parent = model.GetBookmarkBarNode();
PopulateBookmarkNode(&bbn, &model, parent);
- parent->GetChild(1)->SetTitle(L"a");
- delete parent->GetChild(1)->Remove(0);
- parent->GetChild(3)->SetTitle(L"C");
- delete parent->GetChild(3)->Remove(0);
+ BookmarkNode* child1 = AsMutable(parent->GetChild(1));
+ child1->SetTitle(L"a");
+ delete child1->Remove(0);
+ BookmarkNode* child3 = AsMutable(parent->GetChild(3));
+ child3->SetTitle(L"C");
+ delete child3->Remove(0);
ClearCounts();
diff --git a/chrome/browser/bookmarks/bookmark_table_model.cc b/chrome/browser/bookmarks/bookmark_table_model.cc
index 733c99e..f8d8615 100644
--- a/chrome/browser/bookmarks/bookmark_table_model.cc
+++ b/chrome/browser/bookmarks/bookmark_table_model.cc
@@ -35,7 +35,7 @@ class VectorBackedBookmarkTableModel : public BookmarkTableModel {
: BookmarkTableModel(model) {
}
- virtual BookmarkNode* GetNodeForRow(int row) {
+ virtual const BookmarkNode* GetNodeForRow(int row) {
return nodes_[row];
}
@@ -44,25 +44,25 @@ class VectorBackedBookmarkTableModel : public BookmarkTableModel {
}
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
NotifyObserverOfChange(new_parent->GetChild(new_index));
}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
NotifyObserverOfChange(node);
}
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
NotifyObserverOfChange(node);
}
protected:
- void NotifyObserverOfChange(BookmarkNode* node) {
+ void NotifyObserverOfChange(const BookmarkNode* node) {
if (!observer())
return;
@@ -71,7 +71,7 @@ class VectorBackedBookmarkTableModel : public BookmarkTableModel {
observer()->OnItemsChanged(index, 1);
}
- typedef std::vector<BookmarkNode*> Nodes;
+ typedef std::vector<const BookmarkNode*> Nodes;
Nodes& nodes() { return nodes_; }
private:
@@ -88,16 +88,16 @@ class VectorBackedBookmarkTableModel : public BookmarkTableModel {
// node is moved.
class FolderBookmarkTableModel : public VectorBackedBookmarkTableModel {
public:
- FolderBookmarkTableModel(BookmarkModel* model, BookmarkNode* root_node)
+ FolderBookmarkTableModel(BookmarkModel* model, const BookmarkNode* root_node)
: VectorBackedBookmarkTableModel(model),
root_node_(root_node) {
PopulateNodesFromRoot();
}
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
if (old_parent == root_node_) {
nodes().erase(nodes().begin() + old_index);
@@ -113,7 +113,7 @@ class FolderBookmarkTableModel : public VectorBackedBookmarkTableModel {
}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
if (root_node_ == parent) {
nodes().insert(nodes().begin() + index, parent->GetChild(index));
@@ -123,9 +123,9 @@ class FolderBookmarkTableModel : public VectorBackedBookmarkTableModel {
}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (root_node_->HasAncestor(node)) {
// We, or one of our ancestors was removed.
root_node_ = NULL;
@@ -142,17 +142,17 @@ class FolderBookmarkTableModel : public VectorBackedBookmarkTableModel {
}
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
NotifyChanged(node);
}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
NotifyChanged(node);
}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (node != root_node_)
return;
@@ -164,7 +164,7 @@ class FolderBookmarkTableModel : public VectorBackedBookmarkTableModel {
}
private:
- void NotifyChanged(BookmarkNode* node) {
+ void NotifyChanged(const BookmarkNode* node) {
if (node->GetParent() == root_node_ && observer())
observer()->OnItemsChanged(node->GetParent()->IndexOfChild(node), 1);
}
@@ -176,7 +176,7 @@ class FolderBookmarkTableModel : public VectorBackedBookmarkTableModel {
// The node we're showing the children of. This is set to NULL if the node
// (or one of its ancestors) is removed from the model.
- BookmarkNode* root_node_;
+ const BookmarkNode* root_node_;
DISALLOW_COPY_AND_ASSIGN(FolderBookmarkTableModel);
};
@@ -191,16 +191,16 @@ class RecentlyBookmarkedTableModel : public VectorBackedBookmarkTableModel {
}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
if (parent->GetChild(index)->is_url())
UpdateRecentlyBookmarked();
}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int old_index,
- BookmarkNode* old_node) {
+ const BookmarkNode* old_node) {
if (old_node->is_url())
UpdateRecentlyBookmarked();
}
@@ -234,9 +234,9 @@ class BookmarkSearchTableModel : public VectorBackedBookmarkTableModel {
}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
- BookmarkNode* node = parent->GetChild(index);
+ const BookmarkNode* node = parent->GetChild(index);
if (bookmark_utils::DoesBookmarkContainText(
node, search_text_, languages_)) {
nodes().push_back(node);
@@ -246,9 +246,9 @@ class BookmarkSearchTableModel : public VectorBackedBookmarkTableModel {
}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
int internal_index = IndexOfNode(node);
if (internal_index == -1)
return;
@@ -277,7 +277,7 @@ BookmarkTableModel* BookmarkTableModel::CreateRecentlyBookmarkedModel(
// static
BookmarkTableModel* BookmarkTableModel::CreateBookmarkTableModelForFolder(
- BookmarkModel* model, BookmarkNode* node) {
+ BookmarkModel* model, const BookmarkNode* node) {
return new FolderBookmarkTableModel(model, node);
}
@@ -301,7 +301,7 @@ BookmarkTableModel::~BookmarkTableModel() {
}
std::wstring BookmarkTableModel::GetText(int row, int column_id) {
- BookmarkNode* node = GetNodeForRow(row);
+ const BookmarkNode* node = GetNodeForRow(row);
switch (column_id) {
case IDS_BOOKMARK_TABLE_TITLE: {
std::wstring title = node->GetTitle();
@@ -368,7 +368,7 @@ SkBitmap BookmarkTableModel::GetIcon(int row) {
static SkBitmap* default_icon = ResourceBundle::GetSharedInstance().
GetBitmapNamed(IDR_DEFAULT_FAVICON);
- BookmarkNode* node = GetNodeForRow(row);
+ const BookmarkNode* node = GetNodeForRow(row);
if (node->is_folder())
return *folder_icon;
@@ -383,7 +383,7 @@ void BookmarkTableModel::BookmarkModelBeingDeleted(BookmarkModel* model) {
model_ = NULL;
}
-int BookmarkTableModel::IndexOfNode(BookmarkNode* node) {
+int BookmarkTableModel::IndexOfNode(const BookmarkNode* node) {
for (int i = RowCount() - 1; i >= 0; --i) {
if (GetNodeForRow(i) == node)
return i;
@@ -391,7 +391,8 @@ int BookmarkTableModel::IndexOfNode(BookmarkNode* node) {
return -1;
}
-void BookmarkTableModel::BuildPath(BookmarkNode* node, std::wstring* path) {
+void BookmarkTableModel::BuildPath(const BookmarkNode* node,
+ std::wstring* path) {
if (!node) {
NOTREACHED();
return;
diff --git a/chrome/browser/bookmarks/bookmark_table_model.h b/chrome/browser/bookmarks/bookmark_table_model.h
index 7dd7f9e..997d7f0 100644
--- a/chrome/browser/bookmarks/bookmark_table_model.h
+++ b/chrome/browser/bookmarks/bookmark_table_model.h
@@ -24,7 +24,7 @@ class BookmarkTableModel : public TableModel,
static BookmarkTableModel* CreateRecentlyBookmarkedModel(
BookmarkModel* model);
static BookmarkTableModel* CreateBookmarkTableModelForFolder(
- BookmarkModel* model, BookmarkNode* node);
+ BookmarkModel* model, const BookmarkNode* node);
static BookmarkTableModel* CreateSearchTableModel(
BookmarkModel* model,
const std::wstring& text,
@@ -44,15 +44,15 @@ class BookmarkTableModel : public TableModel,
virtual void Loaded(BookmarkModel* model) {}
virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
// Returns the index of the specified node, or -1 if the node isn't in the
// model.
- virtual int IndexOfNode(BookmarkNode* node);
+ virtual int IndexOfNode(const BookmarkNode* node);
// Returns the BookmarkNode at the specified index.
- virtual BookmarkNode* GetNodeForRow(int row) = 0;
+ virtual const BookmarkNode* GetNodeForRow(int row) = 0;
// Returns the underlying BookmarkModel.
BookmarkModel* model() const { return model_; }
@@ -62,7 +62,7 @@ class BookmarkTableModel : public TableModel,
private:
// Builds the path shown in the path column for the specified node.
- void BuildPath(BookmarkNode* node, std::wstring* path);
+ void BuildPath(const BookmarkNode* node, std::wstring* path);
BookmarkModel* model_;
TableModelObserver* observer_;
diff --git a/chrome/browser/bookmarks/bookmark_table_model_unittest.cc b/chrome/browser/bookmarks/bookmark_table_model_unittest.cc
index 9003256..39bc782 100644
--- a/chrome/browser/bookmarks/bookmark_table_model_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_table_model_unittest.cc
@@ -40,11 +40,11 @@ class BookmarkTableModelTest : public testing::Test,
profile_->CreateBookmarkModel(true);
// Populate with some default data.
Time t0 = Time::Now();
- BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
+ const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
bookmark_model()->AddURLWithCreationTime(bb, 0, L"a", url1_, t0);
bookmark_model()->AddGroup(bb, 1, L"f1");
- BookmarkNode* other = bookmark_model()->other_node();
+ const BookmarkNode* other = bookmark_model()->other_node();
bookmark_model()->AddURLWithCreationTime(other, 0, L"b",
url2_, t0 + TimeDelta::FromDays(2));
bookmark_model()->AddGroup(other, 1, L"f2");
@@ -129,10 +129,10 @@ TEST_F(BookmarkTableModelTest, FolderInitialState) {
// Verifies adding an item to folder model generates the correct event.
TEST_F(BookmarkTableModelTest, AddToFolder) {
- BookmarkNode* other = bookmark_model()->other_node();
+ const BookmarkNode* other = bookmark_model()->other_node();
SetModel(BookmarkTableModel::CreateBookmarkTableModelForFolder(
bookmark_model(), other));
- BookmarkNode* new_node = bookmark_model()->AddURL(other, 0, L"new", url1_);
+ const BookmarkNode* new_node = bookmark_model()->AddURL(other, 0, L"new", url1_);
// Should have gotten notification of the add.
VerifyAndClearOberserverCounts(0, 0, 1, 0);
ASSERT_EQ(4, model_->RowCount());
@@ -146,7 +146,7 @@ TEST_F(BookmarkTableModelTest, AddToFolder) {
// Verifies sort sends out notification and results in a sort.
TEST_F(BookmarkTableModelTest, SortFolder) {
- BookmarkNode* other = bookmark_model()->other_node();
+ const BookmarkNode* other = bookmark_model()->other_node();
SetModel(BookmarkTableModel::CreateBookmarkTableModelForFolder(
bookmark_model(), other));
ASSERT_EQ(3, model_->RowCount());
@@ -163,7 +163,7 @@ TEST_F(BookmarkTableModelTest, SortFolder) {
// Verifies removing an item from folder model generates the correct event.
TEST_F(BookmarkTableModelTest, RemoveFromFolder) {
- BookmarkNode* other = bookmark_model()->other_node();
+ const BookmarkNode* other = bookmark_model()->other_node();
SetModel(BookmarkTableModel::CreateBookmarkTableModelForFolder(
bookmark_model(), other));
bookmark_model()->Remove(other, 0);
@@ -179,7 +179,7 @@ TEST_F(BookmarkTableModelTest, RemoveFromFolder) {
// Verifies changing an item in the folder model generates the correct event.
TEST_F(BookmarkTableModelTest, ChangeFolder) {
- BookmarkNode* other = bookmark_model()->other_node();
+ const BookmarkNode* other = bookmark_model()->other_node();
SetModel(BookmarkTableModel::CreateBookmarkTableModelForFolder(
bookmark_model(), other));
bookmark_model()->SetTitle(other->GetChild(0), L"new");
@@ -199,8 +199,8 @@ TEST_F(BookmarkTableModelTest, RecentlyBookmarkedOrder) {
SetModel(BookmarkTableModel::CreateRecentlyBookmarkedModel(bookmark_model()));
EXPECT_EQ(3, model_->RowCount());
- BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
- BookmarkNode* other = bookmark_model()->other_node();
+ const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
+ const BookmarkNode* other = bookmark_model()->other_node();
EXPECT_TRUE(other->GetChild(0) == model_->GetNodeForRow(0));
EXPECT_TRUE(other->GetChild(2) == model_->GetNodeForRow(1));
EXPECT_TRUE(bb->GetChild(0) == model_->GetNodeForRow(2));
@@ -262,7 +262,7 @@ TEST_F(BookmarkTableModelTest, Search) {
TEST_F(BookmarkTableModelTest, AddToSearch) {
SetModel(BookmarkTableModel::CreateSearchTableModel(
bookmark_model(), L"c", std::wstring()));
- BookmarkNode* new_node =
+ const BookmarkNode* new_node =
bookmark_model()->AddURL(bookmark_model()->other_node(), 0, L"c", url1_);
// Should have gotten notification of the add.
VerifyAndClearOberserverCounts(0, 0, 1, 0);
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index 88456c4..f7c18cf 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -76,23 +76,24 @@ class NewBrowserPageNavigator : public PageNavigator {
void CloneDragDataImpl(BookmarkModel* model,
const BookmarkDragData::Element& element,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index_to_add_at) {
if (element.is_url) {
model->AddURL(parent, index_to_add_at, element.title, element.url);
} else {
- BookmarkNode* new_folder = model->AddGroup(parent, index_to_add_at,
- element.title);
+ const BookmarkNode* new_folder = model->AddGroup(parent,
+ index_to_add_at,
+ element.title);
for (int i = 0; i < static_cast<int>(element.children.size()); ++i)
CloneDragDataImpl(model, element.children[i], new_folder, i);
}
}
// Returns the number of descendants of node that are of type url.
-int DescendantURLCount(BookmarkNode* node) {
+int DescendantURLCount(const BookmarkNode* node) {
int result = 0;
for (int i = 0; i < node->GetChildCount(); ++i) {
- BookmarkNode* child = node->GetChild(i);
+ const BookmarkNode* child = node->GetChild(i);
if (child->is_url())
result++;
else
@@ -107,7 +108,7 @@ int DescendantURLCount(BookmarkNode* node) {
// PageNavigator of the last active tab. This is done to handle a window
// disposition of new window, in which case we want subsequent tabs to open in
// that window.
-void OpenAllImpl(BookmarkNode* node,
+void OpenAllImpl(const BookmarkNode* node,
WindowOpenDisposition initial_disposition,
PageNavigator** navigator,
bool* opened_url) {
@@ -141,7 +142,7 @@ void OpenAllImpl(BookmarkNode* node,
}
bool ShouldOpenAll(gfx::NativeView parent,
- const std::vector<BookmarkNode*>& nodes) {
+ const std::vector<const BookmarkNode*>& nodes) {
int descendant_count = 0;
for (size_t i = 0; i < nodes.size(); ++i)
descendant_count += DescendantURLCount(nodes[i]);
@@ -163,7 +164,7 @@ bool ShouldOpenAll(gfx::NativeView parent,
}
// Comparison function that compares based on date modified of the two nodes.
-bool MoreRecentlyModified(BookmarkNode* n1, BookmarkNode* n2) {
+bool MoreRecentlyModified(const BookmarkNode* n1, const BookmarkNode* n2) {
return n1->date_group_modified() > n2->date_group_modified();
}
@@ -180,7 +181,7 @@ bool DoesBookmarkTextContainWords(const std::wstring& text,
// Returns true if |node|s title or url contains the strings in |words|.
// |languages| argument is user's accept-language setting to decode IDN.
-bool DoesBookmarkContainWords(BookmarkNode* node,
+bool DoesBookmarkContainWords(const BookmarkNode* node,
const std::vector<std::wstring>& words,
const std::wstring& languages) {
return
@@ -210,7 +211,7 @@ int PreferredDropOperation(int source_operations, int operations) {
return DragDropTypes::DRAG_NONE;
}
-int BookmarkDragOperation(BookmarkNode* node) {
+int BookmarkDragOperation(const BookmarkNode* node) {
if (node->is_url()) {
return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE |
DragDropTypes::DRAG_LINK;
@@ -221,7 +222,7 @@ int BookmarkDragOperation(BookmarkNode* node) {
int BookmarkDropOperation(Profile* profile,
const views::DropTargetEvent& event,
const BookmarkDragData& data,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
if (data.IsFromProfile(profile) && data.size() > 1)
// Currently only accept one dragged node at a time.
@@ -241,9 +242,9 @@ int BookmarkDropOperation(Profile* profile,
int PerformBookmarkDrop(Profile* profile,
const BookmarkDragData& data,
- BookmarkNode* parent_node,
+ const BookmarkNode* parent_node,
int index) {
- BookmarkNode* dragged_node = data.GetFirstNode(profile);
+ const BookmarkNode* dragged_node = data.GetFirstNode(profile);
BookmarkModel* model = profile->GetBookmarkModel();
if (dragged_node) {
// Drag from same profile, do a move.
@@ -269,7 +270,7 @@ int PerformBookmarkDrop(Profile* profile,
bool IsValidDropLocation(Profile* profile,
const BookmarkDragData& data,
- BookmarkNode* drop_parent,
+ const BookmarkNode* drop_parent,
int index) {
if (!drop_parent->is_folder()) {
NOTREACHED();
@@ -280,11 +281,11 @@ bool IsValidDropLocation(Profile* profile,
return false;
if (data.IsFromProfile(profile)) {
- std::vector<BookmarkNode*> nodes = data.GetNodes(profile);
+ std::vector<const BookmarkNode*> nodes = data.GetNodes(profile);
for (size_t i = 0; i < nodes.size(); ++i) {
// Don't allow the drop if the user is attempting to drop on one of the
// nodes being dragged.
- BookmarkNode* node = nodes[i];
+ const BookmarkNode* node = nodes[i];
int node_index = (drop_parent == node->GetParent()) ?
drop_parent->IndexOfChild(nodes[i]) : -1;
if (node_index != -1 && (index == node_index || index == node_index + 1))
@@ -302,7 +303,7 @@ bool IsValidDropLocation(Profile* profile,
void CloneDragData(BookmarkModel* model,
const std::vector<BookmarkDragData::Element>& elements,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index_to_add_at) {
if (!parent->is_folder() || !model) {
NOTREACHED();
@@ -315,7 +316,7 @@ void CloneDragData(BookmarkModel* model,
void OpenAll(gfx::NativeView parent,
Profile* profile,
PageNavigator* navigator,
- const std::vector<BookmarkNode*>& nodes,
+ const std::vector<const BookmarkNode*>& nodes,
WindowOpenDisposition initial_disposition) {
if (!ShouldOpenAll(parent, nodes))
return;
@@ -343,15 +344,15 @@ void OpenAll(gfx::NativeView parent,
void OpenAll(gfx::NativeView parent,
Profile* profile,
PageNavigator* navigator,
- BookmarkNode* node,
+ const BookmarkNode* node,
WindowOpenDisposition initial_disposition) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(node);
OpenAll(parent, profile, navigator, nodes, initial_disposition);
}
void CopyToClipboard(BookmarkModel* model,
- const std::vector<BookmarkNode*>& nodes,
+ const std::vector<const BookmarkNode*>& nodes,
bool remove_nodes) {
if (nodes.empty())
return;
@@ -375,7 +376,7 @@ void CopyToClipboard(BookmarkModel* model,
}
void PasteFromClipboard(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
if (!parent)
return;
@@ -398,7 +399,7 @@ void PasteFromClipboard(BookmarkModel* model,
#endif
}
-bool CanPasteFromClipboard(BookmarkNode* node) {
+bool CanPasteFromClipboard(const BookmarkNode* node) {
if (!node)
return false;
@@ -416,18 +417,18 @@ bool CanPasteFromClipboard(BookmarkNode* node) {
#endif
}
-std::vector<BookmarkNode*> GetMostRecentlyModifiedGroups(
+std::vector<const BookmarkNode*> GetMostRecentlyModifiedGroups(
BookmarkModel* model,
size_t max_count) {
- std::vector<BookmarkNode*> nodes;
- TreeNodeIterator<BookmarkNode> iterator(model->root_node());
+ std::vector<const BookmarkNode*> nodes;
+ TreeNodeIterator<const BookmarkNode> iterator(model->root_node());
while (iterator.has_next()) {
- BookmarkNode* parent = iterator.Next();
+ const BookmarkNode* parent = iterator.Next();
if (parent->is_folder() && parent->date_group_modified() > base::Time()) {
if (max_count == 0) {
nodes.push_back(parent);
} else {
- std::vector<BookmarkNode*>::iterator i =
+ std::vector<const BookmarkNode*>::iterator i =
std::upper_bound(nodes.begin(), nodes.end(), parent,
&MoreRecentlyModified);
if (nodes.size() < max_count || i != nodes.end()) {
@@ -457,12 +458,12 @@ std::vector<BookmarkNode*> GetMostRecentlyModifiedGroups(
void GetMostRecentlyAddedEntries(BookmarkModel* model,
size_t count,
- std::vector<BookmarkNode*>* nodes) {
- TreeNodeIterator<BookmarkNode> iterator(model->root_node());
+ std::vector<const BookmarkNode*>* nodes) {
+ TreeNodeIterator<const BookmarkNode> iterator(model->root_node());
while (iterator.has_next()) {
- BookmarkNode* node = iterator.Next();
+ const BookmarkNode* node = iterator.Next();
if (node->is_url()) {
- std::vector<BookmarkNode*>::iterator insert_position =
+ std::vector<const BookmarkNode*>::iterator insert_position =
std::upper_bound(nodes->begin(), nodes->end(), node,
&MoreRecentlyAdded);
if (nodes->size() < count || insert_position != nodes->end()) {
@@ -474,7 +475,7 @@ void GetMostRecentlyAddedEntries(BookmarkModel* model,
}
}
-bool MoreRecentlyAdded(BookmarkNode* n1, BookmarkNode* n2) {
+bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2) {
return n1->date_added() > n2->date_added();
}
@@ -482,16 +483,16 @@ void GetBookmarksContainingText(BookmarkModel* model,
const std::wstring& text,
size_t max_count,
const std::wstring& languages,
- std::vector<BookmarkNode*>* nodes) {
+ std::vector<const BookmarkNode*>* nodes) {
std::vector<std::wstring> words;
QueryParser parser;
parser.ExtractQueryWords(l10n_util::ToLower(text), &words);
if (words.empty())
return;
- TreeNodeIterator<BookmarkNode> iterator(model->root_node());
+ TreeNodeIterator<const BookmarkNode> iterator(model->root_node());
while (iterator.has_next()) {
- BookmarkNode* node = iterator.Next();
+ const BookmarkNode* node = iterator.Next();
if (node->is_url() && DoesBookmarkContainWords(node, words, languages)) {
nodes->push_back(node);
if (nodes->size() == max_count)
@@ -500,7 +501,7 @@ void GetBookmarksContainingText(BookmarkModel* model,
}
}
-bool DoesBookmarkContainText(BookmarkNode* node,
+bool DoesBookmarkContainText(const BookmarkNode* node,
const std::wstring& text,
const std::wstring& languages) {
std::vector<std::wstring> words;
@@ -513,12 +514,12 @@ bool DoesBookmarkContainText(BookmarkNode* node,
}
void ApplyEditsWithNoGroupChange(BookmarkModel* model,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
const std::wstring& new_title,
const GURL& new_url,
BookmarkEditor::Handler* handler) {
- BookmarkNode* old_parent = node ? node->GetParent() : NULL;
+ const BookmarkNode* old_parent = node ? node->GetParent() : NULL;
const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
if (!node) {
@@ -546,12 +547,12 @@ void ApplyEditsWithNoGroupChange(BookmarkModel* model,
}
void ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
- BookmarkNode* new_parent,
- BookmarkNode* node,
+ const BookmarkNode* new_parent,
+ const BookmarkNode* node,
const std::wstring& new_title,
const GURL& new_url,
BookmarkEditor::Handler* handler) {
- BookmarkNode* old_parent = node ? node->GetParent() : NULL;
+ const BookmarkNode* old_parent = node ? node->GetParent() : NULL;
const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
if (node) {
@@ -560,19 +561,16 @@ void ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
// The parent is the same.
if (new_url != node->GetURL()) {
model->Remove(old_parent, old_index);
- BookmarkNode* new_node =
- model->AddURL(old_parent, old_index, new_title, new_url);
- new_node->set_date_added(date_added);
+ model->AddURLWithCreationTime(old_parent, old_index,
+ new_title, new_url, date_added);
} else {
model->SetTitle(node, new_title);
}
} else if (new_url != node->GetURL()) {
// The parent and URL changed.
model->Remove(old_parent, old_index);
- BookmarkNode* new_node =
- model->AddURL(new_parent, new_parent->GetChildCount(), new_title,
- new_url);
- new_node->set_date_added(date_added);
+ model->AddURLWithCreationTime(new_parent, new_parent->GetChildCount(),
+ new_title, new_url, date_added);
} else {
// The parent and title changed. Move the node and change the title.
model->Move(node, new_parent, new_parent->GetChildCount());
diff --git a/chrome/browser/bookmarks/bookmark_utils.h b/chrome/browser/bookmarks/bookmark_utils.h
index 2a7cbda..a1a3e7b 100644
--- a/chrome/browser/bookmarks/bookmark_utils.h
+++ b/chrome/browser/bookmarks/bookmark_utils.h
@@ -33,7 +33,7 @@ namespace bookmark_utils {
int PreferredDropOperation(int source_operations, int operations);
// Returns the drag operations for the specified node.
-int BookmarkDragOperation(BookmarkNode* node);
+int BookmarkDragOperation(const BookmarkNode* node);
// Returns the preferred drop operation on a bookmark menu/bar.
// |parent| is the parent node the drop is to occur on and |index| the index the
@@ -41,14 +41,14 @@ int BookmarkDragOperation(BookmarkNode* node);
int BookmarkDropOperation(Profile* profile,
const views::DropTargetEvent& event,
const BookmarkDragData& data,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
// Performs a drop of bookmark data onto |parent_node| at |index|. Returns the
// type of drop the resulted.
int PerformBookmarkDrop(Profile* profile,
const BookmarkDragData& data,
- BookmarkNode* parent_node,
+ const BookmarkNode* parent_node,
int index);
// Returns true if the bookmark data can be dropped on |drop_parent| at
@@ -58,14 +58,14 @@ int PerformBookmarkDrop(Profile* profile,
// a child of |drop_parent| at |index|.
bool IsValidDropLocation(Profile* profile,
const BookmarkDragData& data,
- BookmarkNode* drop_parent,
+ const BookmarkNode* drop_parent,
int index);
// Clones drag data, adding newly created nodes to |parent| starting at
// |index_to_add_at|.
void CloneDragData(BookmarkModel* model,
const std::vector<BookmarkDragData::Element>& elements,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index_to_add_at);
// Recursively opens all bookmarks. |initial_disposition| dictates how the
@@ -76,55 +76,55 @@ void CloneDragData(BookmarkModel* model,
void OpenAll(gfx::NativeView parent,
Profile* profile,
PageNavigator* navigator,
- const std::vector<BookmarkNode*>& nodes,
+ const std::vector<const BookmarkNode*>& nodes,
WindowOpenDisposition initial_disposition);
// Convenience for opening a single BookmarkNode.
void OpenAll(gfx::NativeView parent,
Profile* profile,
PageNavigator* navigator,
- BookmarkNode* node,
+ const BookmarkNode* node,
WindowOpenDisposition initial_disposition);
// Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are
// removed after copied to the clipboard. The nodes are copied in such a way
// that if pasted again copies are made.
void CopyToClipboard(BookmarkModel* model,
- const std::vector<BookmarkNode*>& nodes,
+ const std::vector<const BookmarkNode*>& nodes,
bool remove_nodes);
// Pastes from the clipboard. The new nodes are added to |parent|, unless
// |parent| is null in which case this does nothing. The nodes are inserted
// at |index|. If |index| is -1 the nodes are added to the end.
void PasteFromClipboard(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
// Returns true if the user can copy from the pasteboard.
-bool CanPasteFromClipboard(BookmarkNode* node);
+bool CanPasteFromClipboard(const BookmarkNode* node);
// Returns a vector containing up to |max_count| of the most recently modified
// groups. This never returns an empty vector.
-std::vector<BookmarkNode*> GetMostRecentlyModifiedGroups(BookmarkModel* model,
- size_t max_count);
+std::vector<const BookmarkNode*> GetMostRecentlyModifiedGroups(
+ BookmarkModel* model, size_t max_count);
// Returns the most recently added bookmarks. This does not return groups,
// only nodes of type url.
void GetMostRecentlyAddedEntries(BookmarkModel* model,
size_t count,
- std::vector<BookmarkNode*>* nodes);
+ std::vector<const BookmarkNode*>* nodes);
// Used by GetBookmarksMatchingText to return a matching node and the location
// of the match in the title.
struct TitleMatch {
- BookmarkNode* node;
+ const BookmarkNode* node;
// Location of the matching words in the title of the node.
Snippet::MatchPositions match_positions;
};
// Returns true if |n1| was added more recently than |n2|.
-bool MoreRecentlyAdded(BookmarkNode* n1, BookmarkNode* n2);
+bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2);
// Returns up to |max_count| bookmarks from |model| whose url or title contains
// the text |text|. |languages| is user's accept-language setting to decode
@@ -133,19 +133,19 @@ void GetBookmarksContainingText(BookmarkModel* model,
const std::wstring& text,
size_t max_count,
const std::wstring& languages,
- std::vector<BookmarkNode*>* nodes);
+ std::vector<const BookmarkNode*>* nodes);
// Returns true if |node|'s url or title contains the string |text|.
// |languages| is user's accept-language setting to decode IDN.
-bool DoesBookmarkContainText(BookmarkNode* node,
+bool DoesBookmarkContainText(const BookmarkNode* node,
const std::wstring& text,
const std::wstring& languages);
// Modifies a bookmark node (assuming that there's no magic that needs to be
// done regarding moving from one folder to another).
void ApplyEditsWithNoGroupChange(BookmarkModel* model,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
const std::wstring& new_title,
const GURL& new_url,
BookmarkEditor::Handler* handler);
@@ -153,8 +153,8 @@ void ApplyEditsWithNoGroupChange(BookmarkModel* model,
// Modifies a bookmark node assuming that the parent of the node may have
// changed and the node will need to be removed and reinserted.
void ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
- BookmarkNode* new_parent,
- BookmarkNode* node,
+ const BookmarkNode* new_parent,
+ const BookmarkNode* node,
const std::wstring& new_title,
const GURL& new_url,
BookmarkEditor::Handler* handler);
diff --git a/chrome/browser/bookmarks/bookmark_utils_unittest.cc b/chrome/browser/bookmarks/bookmark_utils_unittest.cc
index 2bd612f..e89ad8e 100644
--- a/chrome/browser/bookmarks/bookmark_utils_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_utils_unittest.cc
@@ -11,16 +11,16 @@ typedef testing::Test BookmarkUtilsTest;
TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) {
BookmarkModel model(NULL);
- BookmarkNode* n1 =
+ const BookmarkNode* n1 =
model.AddURL(model.other_node(), 0, L"foo bar",
GURL("http://www.google.com"));
- BookmarkNode* n2 =
+ const BookmarkNode* n2 =
model.AddURL(model.other_node(), 0, L"baz buz",
GURL("http://www.cnn.com"));
model.AddGroup(model.other_node(), 0, L"foo");
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
bookmark_utils::GetBookmarksContainingText(
&model, L"foo", 100, std::wstring(), &nodes);
ASSERT_EQ(1U, nodes.size());
@@ -48,8 +48,8 @@ TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) {
TEST_F(BookmarkUtilsTest, DoesBookmarkContainText) {
BookmarkModel model(NULL);
- BookmarkNode* node = model.AddURL(model.other_node(), 0, L"foo bar",
- GURL("http://www.google.com"));
+ const BookmarkNode* node = model.AddURL(model.other_node(), 0, L"foo bar",
+ GURL("http://www.google.com"));
// Matches to the title.
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, L"ar", std::wstring()));
diff --git a/chrome/browser/cocoa/bookmark_bar_bridge.h b/chrome/browser/cocoa/bookmark_bar_bridge.h
index 4d5c488..79805953 100644
--- a/chrome/browser/cocoa/bookmark_bar_bridge.h
+++ b/chrome/browser/cocoa/bookmark_bar_bridge.h
@@ -26,19 +26,19 @@ class BookmarkBarBridge : public BookmarkModelObserver {
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
private:
BookmarkBarController* controller_; // weak; owns me
diff --git a/chrome/browser/cocoa/bookmark_bar_bridge.mm b/chrome/browser/cocoa/bookmark_bar_bridge.mm
index 54b3f5b..2263a3c 100644
--- a/chrome/browser/cocoa/bookmark_bar_bridge.mm
+++ b/chrome/browser/cocoa/bookmark_bar_bridge.mm
@@ -29,9 +29,9 @@ void BookmarkBarBridge::BookmarkModelBeingDeleted(BookmarkModel* model) {
}
void BookmarkBarBridge::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
[controller_ nodeMoved:model
oldParent:old_parent oldIndex:old_index
@@ -39,22 +39,22 @@ void BookmarkBarBridge::BookmarkNodeMoved(BookmarkModel* model,
}
void BookmarkBarBridge::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
[controller_ nodeAdded:model parent:parent index:index];
}
void BookmarkBarBridge::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
[controller_ nodeChanged:model node:node];
}
void BookmarkBarBridge::BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
[controller_ nodeFavIconLoaded:model node:node];
}
-void BookmarkBarBridge::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+void BookmarkBarBridge::BookmarkNodeChildrenReordered(
+ BookmarkModel* model, const BookmarkNode* node) {
[controller_ nodeChildrenReordered:model node:node];
}
diff --git a/chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm b/chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm
index c5ac97b..2853cca 100644
--- a/chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm
+++ b/chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm
@@ -52,28 +52,28 @@ typedef std::pair<GURL,WindowOpenDisposition> OpenInfo;
}
- (void)nodeMoved:(BookmarkModel*)model
- oldParent:(BookmarkNode*)oldParent oldIndex:(int)oldIndex
- newParent:(BookmarkNode*)newParent newIndex:(int)newIndex {
+ oldParent:(const BookmarkNode*)oldParent oldIndex:(int)oldIndex
+ newParent:(const BookmarkNode*)newParent newIndex:(int)newIndex {
[callbacks_ addObject:[NSNumber numberWithInt:2]];
}
- (void)nodeAdded:(BookmarkModel*)model
- parent:(BookmarkNode*)oldParent index:(int)index {
+ parent:(const BookmarkNode*)oldParent index:(int)index {
[callbacks_ addObject:[NSNumber numberWithInt:3]];
}
- (void)nodeChanged:(BookmarkModel*)model
- node:(BookmarkNode*)node {
+ node:(const BookmarkNode*)node {
[callbacks_ addObject:[NSNumber numberWithInt:4]];
}
- (void)nodeFavIconLoaded:(BookmarkModel*)model
- node:(BookmarkNode*)node {
+ node:(const BookmarkNode*)node {
[callbacks_ addObject:[NSNumber numberWithInt:5]];
}
- (void)nodeChildrenReordered:(BookmarkModel*)model
- node:(BookmarkNode*)node {
+ node:(const BookmarkNode*)node {
[callbacks_ addObject:[NSNumber numberWithInt:6]];
}
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.h b/chrome/browser/cocoa/bookmark_bar_controller.h
index ca9dc0f..87ac43e 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.h
+++ b/chrome/browser/cocoa/bookmark_bar_controller.h
@@ -78,16 +78,16 @@ class Profile;
- (void)loaded:(BookmarkModel*)model;
- (void)beingDeleted:(BookmarkModel*)model;
- (void)nodeMoved:(BookmarkModel*)model
- oldParent:(BookmarkNode*)oldParent oldIndex:(int)oldIndex
- newParent:(BookmarkNode*)newParent newIndex:(int)newIndex;
+ oldParent:(const BookmarkNode*)oldParent oldIndex:(int)oldIndex
+ newParent:(const BookmarkNode*)newParent newIndex:(int)newIndex;
- (void)nodeAdded:(BookmarkModel*)model
- parent:(BookmarkNode*)oldParent index:(int)index;
+ parent:(const BookmarkNode*)oldParent index:(int)index;
- (void)nodeChanged:(BookmarkModel*)model
- node:(BookmarkNode*)node;
+ node:(const BookmarkNode*)node;
- (void)nodeFavIconLoaded:(BookmarkModel*)model
- node:(BookmarkNode*)node;
+ node:(const BookmarkNode*)node;
- (void)nodeChildrenReordered:(BookmarkModel*)model
- node:(BookmarkNode*)node;
+ node:(const BookmarkNode*)node;
@end
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm
index ad92820..e3a4bed 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_controller.mm
@@ -143,15 +143,14 @@ const CGFloat kBookmarkHorizontalPadding = 8.0;
// TODO(jrg): add an openBookmarkInBackground() for ctrl-click which
// has a different disposition.
- (void)openBookmark:(id)sender {
- BookmarkNode* node = static_cast<BookmarkNode*>([[[sender cell]
- representedObject]
- pointerValue]);
+ const BookmarkNode* node = static_cast<const BookmarkNode*>(
+ [[[sender cell]representedObject]pointerValue]);
DCHECK(node);
[delegate_ openBookmarkURL:node->GetURL() disposition:CURRENT_TAB];
}
// Return an autoreleased NSCell suitable for a bookmark button.
-- (NSCell *)cellForBookmarkNode:(BookmarkNode*)node frame:(NSRect)frame {
+- (NSCell *)cellForBookmarkNode:(const BookmarkNode*)node frame:(NSRect)frame {
NSString* title = base::SysWideToNSString(node->GetTitle());
NSButtonCell *cell = [[[BookmarkButtonCell alloc] initTextCell:nil]
autorelease];
@@ -212,9 +211,9 @@ const CGFloat kBookmarkHorizontalPadding = 8.0;
// TODO(jrg): write a "build bar" so there is a nice spot for things
// like the contextual menu which is invoked when not over a
// bookmark. On Safari that menu has a "new folder" option.
-- (void)addNodesToBar:(BookmarkNode*)node {
+- (void)addNodesToBar:(const BookmarkNode*)node {
for (int i = 0; i < node->GetChildCount(); i++) {
- BookmarkNode* child = node->GetChild(i);
+ const BookmarkNode* child = node->GetChild(i);
NSRect frame = [self frameForBookmarkAtIndex:i];
NSButton* button = [[[NSButton alloc] initWithFrame:frame]
@@ -255,7 +254,7 @@ const CGFloat kBookmarkHorizontalPadding = 8.0;
if ((barIsVisible_ == NO) || !model->IsLoaded())
return;
// Else brute force nuke and build.
- BookmarkNode* node = model->GetBookmarkBarNode();
+ const BookmarkNode* node = model->GetBookmarkBarNode();
[self clearBookmarkBar];
[self addNodesToBar:node];
}
@@ -266,32 +265,32 @@ const CGFloat kBookmarkHorizontalPadding = 8.0;
// TODO(jrg): for now this is brute force.
- (void)nodeMoved:(BookmarkModel*)model
- oldParent:(BookmarkNode*)oldParent oldIndex:(int)oldIndex
- newParent:(BookmarkNode*)newParent newIndex:(int)newIndex {
+ oldParent:(const BookmarkNode*)oldParent oldIndex:(int)oldIndex
+ newParent:(const BookmarkNode*)newParent newIndex:(int)newIndex {
[self loaded:model];
}
// TODO(jrg): for now this is brute force.
- (void)nodeAdded:(BookmarkModel*)model
- parent:(BookmarkNode*)oldParent index:(int)index {
+ parent:(const BookmarkNode*)oldParent index:(int)index {
[self loaded:model];
}
// TODO(jrg): for now this is brute force.
- (void)nodeChanged:(BookmarkModel*)model
- node:(BookmarkNode*)node {
+ node:(const BookmarkNode*)node {
[self loaded:model];
}
// TODO(jrg): linear searching is bad.
// Need a BookmarkNode-->NSCell mapping.
- (void)nodeFavIconLoaded:(BookmarkModel*)model
- node:(BookmarkNode*)node {
+ node:(const BookmarkNode*)node {
NSArray* views = [bookmarkBarView_ subviews];
for (NSButton* button in views) {
NSButtonCell* cell = [button cell];
void* pointer = [[cell representedObject] pointerValue];
- BookmarkNode* cellnode = static_cast<BookmarkNode*>(pointer);
+ const BookmarkNode* cellnode = static_cast<const BookmarkNode*>(pointer);
if (cellnode == node) {
NSImage* image = gfx::SkBitmapToNSImage(bookmarkModel_->GetFavIcon(node));
if (image) {
@@ -305,7 +304,7 @@ const CGFloat kBookmarkHorizontalPadding = 8.0;
// TODO(jrg): for now this is brute force.
- (void)nodeChildrenReordered:(BookmarkModel*)model
- node:(BookmarkNode*)node {
+ node:(const BookmarkNode*)node {
[self loaded:model];
}
diff --git a/chrome/browser/cocoa/bookmark_menu_bridge.h b/chrome/browser/cocoa/bookmark_menu_bridge.h
index b350fd5..163514e 100644
--- a/chrome/browser/cocoa/bookmark_menu_bridge.h
+++ b/chrome/browser/cocoa/bookmark_menu_bridge.h
@@ -37,19 +37,19 @@ class BookmarkMenuBridge : public BookmarkModelObserver,
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// Overridden from BrowserList::Observer
virtual void OnBrowserAdded(const Browser* browser);
@@ -67,7 +67,7 @@ class BookmarkMenuBridge : public BookmarkModelObserver,
// Helper for recursively adding items to our bookmark menu
// All children of |node| will be added to |menu|.
// TODO(jrg): add a counter to enforce maximum nodes added
- void AddNodeToMenu(BookmarkNode* node, NSMenu* menu);
+ void AddNodeToMenu(const BookmarkNode* node, NSMenu* menu);
// Return the Bookmark menu.
NSMenu* BookmarkMenu();
diff --git a/chrome/browser/cocoa/bookmark_menu_bridge.mm b/chrome/browser/cocoa/bookmark_menu_bridge.mm
index fc29548..d13a509 100644
--- a/chrome/browser/cocoa/bookmark_menu_bridge.mm
+++ b/chrome/browser/cocoa/bookmark_menu_bridge.mm
@@ -65,36 +65,36 @@ void BookmarkMenuBridge::BookmarkModelBeingDeleted(BookmarkModel* model) {
}
void BookmarkMenuBridge::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
// TODO(jrg): this is brute force; perhaps we should be nicer.
Loaded(model);
}
void BookmarkMenuBridge::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
// TODO(jrg): this is brute force; perhaps we should be nicer.
Loaded(model);
}
void BookmarkMenuBridge::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
// TODO(jrg): this is brute force; perhaps we should be nicer.
Loaded(model);
}
void BookmarkMenuBridge::BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
// Nothing to do here -- no icons in the menubar menus yet.
// TODO(jrg):
// Both Safari and FireFox have icons in their menubars for bookmarks.
}
-void BookmarkMenuBridge::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+void BookmarkMenuBridge::BookmarkNodeChildrenReordered(
+ BookmarkModel* model, const BookmarkNode* node) {
// TODO(jrg): this is brute force; perhaps we should be nicer.
Loaded(model);
}
@@ -171,9 +171,9 @@ const NSUInteger kMenuTrimSizeInChars = 30;
}
-void BookmarkMenuBridge::AddNodeToMenu(BookmarkNode* node, NSMenu* menu) {
+void BookmarkMenuBridge::AddNodeToMenu(const BookmarkNode* node, NSMenu* menu) {
for (int i = 0; i < node->GetChildCount(); i++) {
- BookmarkNode* child = node->GetChild(i);
+ const BookmarkNode* child = node->GetChild(i);
NSString* full_title = base::SysWideToNSString(child->GetTitle());
NSString* title = full_title;
if ([title length] > kMaximumMenuWidthInChars) {
diff --git a/chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm b/chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm
index 6cf2efb..813b03c 100644
--- a/chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm
+++ b/chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm
@@ -21,7 +21,7 @@ class BookmarkMenuBridgeTest : public testing::Test {
bridge->ClearBookmarkMenu(menu);
}
- void AddNodeToMenu(BookmarkMenuBridge* bridge, BookmarkNode* root,
+ void AddNodeToMenu(BookmarkMenuBridge* bridge, const BookmarkNode* root,
NSMenu* menu) {
bridge->AddNodeToMenu(root, menu);
}
@@ -75,8 +75,8 @@ TEST_F(BookmarkMenuBridgeTest, TestAddNodeToMenu) {
NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"foo"] autorelease];
BookmarkModel* model = profile->GetBookmarkModel();
- BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
- BookmarkNode* root = model->AddGroup(bookmark_bar, 0, empty);
+ const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
+ const BookmarkNode* root = model->AddGroup(bookmark_bar, 0, empty);
EXPECT_TRUE(model && root);
const char* short_url = "http://foo/";
@@ -87,7 +87,7 @@ TEST_F(BookmarkMenuBridgeTest, TestAddNodeToMenu) {
// 3 nodes; middle one has a child, last one has a HUGE URL
// Set their titles to be the same as the URLs
- BookmarkNode* node = NULL;
+ const BookmarkNode* node = NULL;
model->AddURL(root, 0, ASCIIToWide(short_url), GURL(short_url));
node = model->AddGroup(root, 1, empty);
model->AddURL(root, 2, ASCIIToWide(long_url), GURL(long_url));
diff --git a/chrome/browser/cocoa/bookmark_menu_cocoa_controller.h b/chrome/browser/cocoa/bookmark_menu_cocoa_controller.h
index 83e6098..b1e9bde 100644
--- a/chrome/browser/cocoa/bookmark_menu_cocoa_controller.h
+++ b/chrome/browser/cocoa/bookmark_menu_cocoa_controller.h
@@ -29,8 +29,8 @@ class BookmarkMenuBridge;
@interface BookmarkMenuCocoaController (ExposedForUnitTests)
-- (BookmarkNode*)nodeForIdentifier:(int)identifier;
-- (void)openURLForNode:(BookmarkNode*)node;
+- (const BookmarkNode*)nodeForIdentifier:(int)identifier;
+- (void)openURLForNode:(const BookmarkNode*)node;
@end // BookmarkMenuCocoaController (ExposedForUnitTests)
#endif // CHROME_BROWSER_COCOA_BOOKMARK_MENU_COCOA_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm b/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm
index 3aa9906..25b2b4c 100644
--- a/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm
+++ b/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm
@@ -21,12 +21,12 @@
// Return the a BookmarkNode that has the given id (called
// "identifier" here to avoid conflict with objc's concept of "id").
-- (BookmarkNode*)nodeForIdentifier:(int)identifier {
+- (const BookmarkNode*)nodeForIdentifier:(int)identifier {
return bridge_->GetBookmarkModel()->GetNodeByID(identifier);
}
// Open the URL of the given BookmarkNode in the current tab.
-- (void)openURLForNode:(BookmarkNode*)node {
+- (void)openURLForNode:(const BookmarkNode*)node {
Browser* browser = BrowserList::GetLastActive();
if (!browser) { // No windows open?
@@ -45,7 +45,7 @@
- (IBAction)openBookmarkMenuItem:(id)sender {
NSInteger tag = [sender tag];
int identifier = tag;
- BookmarkNode* node = [self nodeForIdentifier:identifier];
+ const BookmarkNode* node = [self nodeForIdentifier:identifier];
DCHECK(node);
if (!node)
return; // shouldn't be reached
diff --git a/chrome/browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm b/chrome/browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm
index 90895fc..23ecf3e 100644
--- a/chrome/browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm
+++ b/chrome/browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm
@@ -11,7 +11,7 @@
@interface FakeBookmarkMenuController : BookmarkMenuCocoaController {
@public
BrowserTestHelper* helper_;
- BookmarkNode* nodes_[2];
+ const BookmarkNode* nodes_[2];
BOOL opened_[2];
}
@end
@@ -23,7 +23,7 @@
std::wstring empty;
helper_ = new BrowserTestHelper();
BookmarkModel* model = helper_->browser()->profile()->GetBookmarkModel();
- BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
+ const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
nodes_[0] = model->AddURL(bookmark_bar, 0, empty, GURL("http://0.com"));
nodes_[1] = model->AddURL(bookmark_bar, 1, empty, GURL("http://1.com"));
}
@@ -35,13 +35,13 @@
[super dealloc];
}
-- (BookmarkNode*)nodeForIdentifier:(int)identifier {
+- (const BookmarkNode*)nodeForIdentifier:(int)identifier {
if ((identifier < 0) || (identifier >= 2))
return NULL;
return nodes_[identifier];
}
-- (void)openURLForNode:(BookmarkNode*)node {
+- (void)openURLForNode:(const BookmarkNode*)node {
std::string url = node->GetURL().possibly_invalid_spec();
if (url.find("http://0.com") != std::string::npos)
opened_[0] = YES;
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index 2c4de50..9be3e72 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -1005,24 +1005,24 @@ class RecentlyBookmarkedHandler : public DOMMessageHandler,
// BookmarkModelObserver methods. These invoke SendBookmarksToPage.
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// These won't effect what is shown, so they do nothing.
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
DOMUI* dom_ui_;
// The model we're getting bookmarks from. The model is owned by the Profile.
@@ -1057,12 +1057,12 @@ void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) {
}
void RecentlyBookmarkedHandler::SendBookmarksToPage() {
- std::vector<BookmarkNode*> recently_bookmarked;
+ std::vector<const BookmarkNode*> recently_bookmarked;
bookmark_utils::GetMostRecentlyAddedEntries(
model_, kRecentBookmarks, &recently_bookmarked);
ListValue list_value;
for (size_t i = 0; i < recently_bookmarked.size(); ++i) {
- BookmarkNode* node = recently_bookmarked[i];
+ const BookmarkNode* node = recently_bookmarked[i];
DictionaryValue* entry_value = new DictionaryValue;
SetURLTitleAndDirection(entry_value,
WideToUTF16(node->GetTitle()), node->GetURL());
@@ -1078,19 +1078,19 @@ void RecentlyBookmarkedHandler::Loaded(BookmarkModel* model) {
}
void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
SendBookmarksToPage();
}
void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
SendBookmarksToPage();
}
void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
SendBookmarksToPage();
}
diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc
index c12062a..f25bd40 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.cc
+++ b/chrome/browser/extensions/extension_bookmarks_module.cc
@@ -22,11 +22,12 @@ namespace keys = extension_bookmarks_module_constants;
class ExtensionBookmarks {
public:
// Convert |node| into a JSON value
- static DictionaryValue* GetNodeDictionary(BookmarkNode* node, bool recurse) {
+ static DictionaryValue* GetNodeDictionary(const BookmarkNode* node,
+ bool recurse) {
DictionaryValue* dict = new DictionaryValue();
dict->SetInteger(keys::kIdKey, node->id());
- BookmarkNode* parent = node->GetParent();
+ const BookmarkNode* parent = node->GetParent();
if (parent)
dict->SetInteger(keys::kParentIdKey, parent->id());
@@ -38,7 +39,7 @@ class ExtensionBookmarks {
int childCount = node->GetChildCount();
ListValue* children = new ListValue();
for (int i = 0; i < childCount; ++i) {
- BookmarkNode* child = node->GetChild(i);
+ const BookmarkNode* child = node->GetChild(i);
if (recurse) {
DictionaryValue* dict = GetNodeDictionary(child, true);
children->Append(dict);
@@ -50,14 +51,14 @@ class ExtensionBookmarks {
}
// Add a JSON representation of |node| to the JSON |list|.
- static void AddNode(BookmarkNode* node, ListValue* list, bool recurse) {
+ static void AddNode(const BookmarkNode* node, ListValue* list, bool recurse) {
DictionaryValue* dict = GetNodeDictionary(node, recurse);
list->Append(dict);
}
static bool RemoveNode(BookmarkModel* model, int id, bool recursive,
std::string* error) {
- BookmarkNode* node = model->GetNodeByID(id);
+ const BookmarkNode* node = model->GetNodeByID(id);
if (!node) {
*error = keys::kNoNodeError;
return false;
@@ -73,7 +74,7 @@ class ExtensionBookmarks {
return false;
}
- BookmarkNode* parent = node->GetParent();
+ const BookmarkNode* parent = node->GetParent();
int index = parent->IndexOfChild(node);
model->Remove(parent, index);
return true;
@@ -140,13 +141,14 @@ void ExtensionBookmarkEventRouter::Loaded(BookmarkModel* model) {
// so they know when it's safe to use the API?
}
-void ExtensionBookmarkEventRouter::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
- int old_index,
- BookmarkNode* new_parent,
- int new_index) {
+void ExtensionBookmarkEventRouter::BookmarkNodeMoved(
+ BookmarkModel* model,
+ const BookmarkNode* old_parent,
+ int old_index,
+ const BookmarkNode* new_parent,
+ int new_index) {
ListValue args;
- BookmarkNode* node = new_parent->GetChild(new_index);
+ const BookmarkNode* node = new_parent->GetChild(new_index);
args.Append(new FundamentalValue(node->id()));
DictionaryValue* object_args = new DictionaryValue();
object_args->SetInteger(keys::kParentIdKey, new_parent->id());
@@ -161,10 +163,10 @@ void ExtensionBookmarkEventRouter::BookmarkNodeMoved(BookmarkModel* model,
}
void ExtensionBookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
ListValue args;
- BookmarkNode* node = parent->GetChild(index);
+ const BookmarkNode* node = parent->GetChild(index);
args.Append(new FundamentalValue(node->id()));
DictionaryValue* object_args = new DictionaryValue();
object_args->SetString(keys::kTitleKey, node->GetTitle());
@@ -178,9 +180,10 @@ void ExtensionBookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model,
DispatchEvent(model->profile(), keys::kOnBookmarkAdded, json_args);
}
-void ExtensionBookmarkEventRouter::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
- int index) {
+void ExtensionBookmarkEventRouter::BookmarkNodeRemoved(
+ BookmarkModel* model,
+ const BookmarkNode* parent,
+ int index) {
ListValue args;
DictionaryValue* object_args = new DictionaryValue();
object_args->SetInteger(keys::kParentIdKey, parent->id());
@@ -192,8 +195,8 @@ void ExtensionBookmarkEventRouter::BookmarkNodeRemoved(BookmarkModel* model,
DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args);
}
-void ExtensionBookmarkEventRouter::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+void ExtensionBookmarkEventRouter::BookmarkNodeChanged(
+ BookmarkModel* model, const BookmarkNode* node) {
ListValue args;
args.Append(new FundamentalValue(node->id()));
@@ -212,18 +215,18 @@ void ExtensionBookmarkEventRouter::BookmarkNodeChanged(BookmarkModel* model,
}
void ExtensionBookmarkEventRouter::BookmarkNodeFavIconLoaded(
- BookmarkModel* model, BookmarkNode* node) {
+ BookmarkModel* model, const BookmarkNode* node) {
// TODO(erikkay) anything we should do here?
}
void ExtensionBookmarkEventRouter::BookmarkNodeChildrenReordered(
- BookmarkModel* model, BookmarkNode* node) {
+ BookmarkModel* model, const BookmarkNode* node) {
ListValue args;
args.Append(new FundamentalValue(node->id()));
int childCount = node->GetChildCount();
ListValue* children = new ListValue();
for (int i = 0; i < childCount; ++i) {
- BookmarkNode* child = node->GetChild(i);
+ const BookmarkNode* child = node->GetChild(i);
Value* child_id = new FundamentalValue(child->id());
children->Append(child_id);
}
@@ -246,7 +249,7 @@ bool GetBookmarksFunction::RunImpl() {
for (size_t i = 0; i < count; ++i) {
int id = 0;
EXTENSION_FUNCTION_VALIDATE(ids->GetInteger(i, &id));
- BookmarkNode* node = model->GetNodeByID(id);
+ const BookmarkNode* node = model->GetNodeByID(id);
if (!node) {
error_ = keys::kNoNodeError;
return false;
@@ -257,7 +260,7 @@ bool GetBookmarksFunction::RunImpl() {
} else {
int id;
EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&id));
- BookmarkNode* node = model->GetNodeByID(id);
+ const BookmarkNode* node = model->GetNodeByID(id);
if (!node) {
error_ = keys::kNoNodeError;
return false;
@@ -274,14 +277,14 @@ bool GetBookmarkChildrenFunction::RunImpl() {
int id;
EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&id));
scoped_ptr<ListValue> json(new ListValue());
- BookmarkNode* node = model->GetNodeByID(id);
+ const BookmarkNode* node = model->GetNodeByID(id);
if (!node) {
error_ = keys::kNoNodeError;
return false;
}
int child_count = node->GetChildCount();
for (int i = 0; i < child_count; ++i) {
- BookmarkNode* child = node->GetChild(i);
+ const BookmarkNode* child = node->GetChild(i);
ExtensionBookmarks::AddNode(child, json.get(), false);
}
@@ -292,7 +295,7 @@ bool GetBookmarkChildrenFunction::RunImpl() {
bool GetBookmarkTreeFunction::RunImpl() {
BookmarkModel* model = profile()->GetBookmarkModel();
scoped_ptr<ListValue> json(new ListValue());
- BookmarkNode* node = model->root_node();
+ const BookmarkNode* node = model->root_node();
ExtensionBookmarks::AddNode(node, json.get(), true);
result_.reset(json.release());
return true;
@@ -307,11 +310,11 @@ bool SearchBookmarksFunction::RunImpl() {
BookmarkModel* model = profile()->GetBookmarkModel();
ListValue* json = new ListValue();
std::wstring lang = profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
bookmark_utils::GetBookmarksContainingText(model, query, 50, lang, &nodes);
- std::vector<BookmarkNode*>::iterator i = nodes.begin();
+ std::vector<const BookmarkNode*>::iterator i = nodes.begin();
for (; i != nodes.end(); ++i) {
- BookmarkNode* node = *i;
+ const BookmarkNode* node = *i;
ExtensionBookmarks::AddNode(node, json, false);
}
@@ -356,7 +359,7 @@ bool CreateBookmarkFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(json->GetInteger(keys::kParentIdKey,
&parentId));
}
- BookmarkNode* parent = model->GetNodeByID(parentId);
+ const BookmarkNode* parent = model->GetNodeByID(parentId);
if (!parent) {
error_ = keys::kNoParentError;
return false;
@@ -387,7 +390,7 @@ bool CreateBookmarkFunction::RunImpl() {
return false;
}
- BookmarkNode* node;
+ const BookmarkNode* node;
if (url_string.length())
node = model->AddURL(parent, index, title, url);
else
@@ -413,7 +416,7 @@ bool MoveBookmarkFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &destination));
BookmarkModel* model = profile()->GetBookmarkModel();
- BookmarkNode* node = model->GetNodeByID(id);
+ const BookmarkNode* node = model->GetNodeByID(id);
if (!node) {
error_ = keys::kNoNodeError;
return false;
@@ -425,7 +428,7 @@ bool MoveBookmarkFunction::RunImpl() {
return false;
}
- BookmarkNode* parent;
+ const BookmarkNode* parent;
if (!destination->HasKey(keys::kParentIdKey)) {
// optional, defaults to current parent
parent = node->GetParent();
@@ -471,7 +474,7 @@ bool SetBookmarkTitleFunction::RunImpl() {
BookmarkModel* model = profile()->GetBookmarkModel();
int id = 0;
EXTENSION_FUNCTION_VALIDATE(json->GetInteger(keys::kIdKey, &id));
- BookmarkNode* node = model->GetNodeByID(id);
+ const BookmarkNode* node = model->GetNodeByID(id);
if (!node) {
error_ = keys::kNoNodeError;
return false;
diff --git a/chrome/browser/extensions/extension_bookmarks_module.h b/chrome/browser/extensions/extension_bookmarks_module.h
index 8dc795e..426e145 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.h
+++ b/chrome/browser/extensions/extension_bookmarks_module.h
@@ -27,28 +27,28 @@ class ExtensionBookmarkEventRouter : public BookmarkModelObserver {
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkModelBeingDeleted(BookmarkModel* model) { }
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int old_index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
BookmarkNodeRemoved(model, parent, old_index);
}
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
private:
ExtensionBookmarkEventRouter();
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc
index cfadd13..dc86bab 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bar_gtk.cc
@@ -279,7 +279,7 @@ void BookmarkBarGtk::Loaded(BookmarkModel* model) {
return;
RemoveAllBookmarkButtons();
- BookmarkNode* node = model_->GetBookmarkBarNode();
+ const BookmarkNode* node = model_->GetBookmarkBarNode();
DCHECK(node && model_->other_node());
CreateAllBookmarkButtons(node);
@@ -297,16 +297,16 @@ void BookmarkBarGtk::BookmarkModelBeingDeleted(BookmarkModel* model) {
}
void BookmarkBarGtk::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
BookmarkNodeRemoved(model, old_parent, old_index);
BookmarkNodeAdded(model, new_parent, new_index);
}
void BookmarkBarGtk::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
if (parent != model_->GetBookmarkBarNode()) {
// We only care about nodes on the bookmark bar.
@@ -322,7 +322,7 @@ void BookmarkBarGtk::BookmarkNodeAdded(BookmarkModel* model,
}
void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
if (parent != model_->GetBookmarkBarNode()) {
// We only care about nodes on the bookmark bar.
@@ -339,7 +339,7 @@ void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model,
}
void BookmarkBarGtk::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (node->GetParent() != model_->GetBookmarkBarNode()) {
// We only care about nodes on the bookmark bar.
return;
@@ -354,12 +354,12 @@ void BookmarkBarGtk::BookmarkNodeChanged(BookmarkModel* model,
}
void BookmarkBarGtk::BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
BookmarkNodeChanged(model, node);
}
void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (node != model_->GetBookmarkBarNode())
return; // We only care about reordering of the bookmark bar node.
@@ -368,7 +368,7 @@ void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
CreateAllBookmarkButtons(node);
}
-void BookmarkBarGtk::CreateAllBookmarkButtons(BookmarkNode* node) {
+void BookmarkBarGtk::CreateAllBookmarkButtons(const BookmarkNode* node) {
// Create a button for each of the children on the bookmark bar.
for (int i = 0; i < node->GetChildCount(); ++i) {
GtkToolItem* item = CreateBookmarkToolItem(node->GetChild(i));
@@ -378,7 +378,8 @@ void BookmarkBarGtk::CreateAllBookmarkButtons(BookmarkNode* node) {
SetInstructionState(node);
}
-void BookmarkBarGtk::SetInstructionState(BookmarkNode* boomarks_bar_node) {
+void BookmarkBarGtk::SetInstructionState(
+ const BookmarkNode* boomarks_bar_node) {
show_instructions_ = (boomarks_bar_node->GetChildCount() == 0);
if (show_instructions_) {
gtk_widget_show_all(instructions_);
@@ -418,7 +419,7 @@ void BookmarkBarGtk::AnimationEnded(const Animation* animation) {
gtk_widget_hide(bookmark_hbox_.get());
}
-void BookmarkBarGtk::ConfigureButtonForNode(BookmarkNode* node,
+void BookmarkBarGtk::ConfigureButtonForNode(const BookmarkNode* node,
GtkWidget* button) {
std::string tooltip = BuildTooltip(node);
if (!tooltip.empty())
@@ -439,10 +440,10 @@ void BookmarkBarGtk::ConfigureButtonForNode(BookmarkNode* node,
SetButtonTextColors(button);
g_object_set_data(G_OBJECT(button), kBookmarkNode,
- reinterpret_cast<void*>(node));
+ reinterpret_cast<void*>(const_cast<BookmarkNode*>(node)));
}
-GtkWidget* BookmarkBarGtk::CreateBookmarkButton(BookmarkNode* node) {
+GtkWidget* BookmarkBarGtk::CreateBookmarkButton(const BookmarkNode* node) {
GtkWidget* button = gtk_chrome_button_new();
ConfigureButtonForNode(node, button);
@@ -477,7 +478,7 @@ GtkWidget* BookmarkBarGtk::CreateBookmarkButton(BookmarkNode* node) {
return button;
}
-GtkToolItem* BookmarkBarGtk::CreateBookmarkToolItem(BookmarkNode* node) {
+GtkToolItem* BookmarkBarGtk::CreateBookmarkToolItem(const BookmarkNode* node) {
GtkWidget* button = CreateBookmarkButton(node);
g_object_set_data(G_OBJECT(button), "left-align-popup",
reinterpret_cast<void*>(true));
@@ -499,13 +500,13 @@ void BookmarkBarGtk::ConnectFolderButtonEvents(GtkWidget* widget) {
G_CALLBACK(OnFolderButtonReleased), this);
}
-std::string BookmarkBarGtk::BuildTooltip(BookmarkNode* node) {
+std::string BookmarkBarGtk::BuildTooltip(const BookmarkNode* node) {
// TODO(erg): Actually build the tooltip. For now, we punt and just return
// the URL.
return node->GetURL().possibly_invalid_spec();
}
-BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) {
+const BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) {
// First check to see if |button| is special cased.
if (widget == other_bookmarks_button_)
return model_->other_node();
@@ -542,15 +543,16 @@ void BookmarkBarGtk::InitBackground() {
0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0));
}
-void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, BookmarkNode* node,
+void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender,
+ const BookmarkNode* node,
GdkEventButton* event) {
if (!model_->IsLoaded()) {
// Don't do anything if the model isn't loaded.
return;
}
- BookmarkNode* parent = NULL;
- std::vector<BookmarkNode*> nodes;
+ const BookmarkNode* parent = NULL;
+ std::vector<const BookmarkNode*> nodes;
if (sender == other_bookmarks_button_) {
parent = model_->GetBookmarkBarNode();
nodes.push_back(parent);
@@ -578,7 +580,7 @@ gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender,
bar->ignore_button_release_ = false;
if (event->button == 3) {
- BookmarkNode* node = bar->GetNodeForToolButton(sender);
+ const BookmarkNode* node = bar->GetNodeForToolButton(sender);
DCHECK(node);
DCHECK(bar->page_navigator_);
bar->PopupMenuForNode(sender, node, event);
@@ -597,7 +599,7 @@ gboolean BookmarkBarGtk::OnButtonReleased(GtkWidget* sender,
return FALSE;
}
- BookmarkNode* node = bar->GetNodeForToolButton(sender);
+ const BookmarkNode* node = bar->GetNodeForToolButton(sender);
DCHECK(node);
DCHECK(bar->page_navigator_);
@@ -630,7 +632,7 @@ void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button,
// pressing.
bar->ignore_button_release_ = true;
- BookmarkNode* node = bar->GetNodeForToolButton(button);
+ const BookmarkNode* node = bar->GetNodeForToolButton(button);
DCHECK(!bar->dragged_node_);
bar->dragged_node_ = node;
DCHECK(bar->dragged_node_);
@@ -680,8 +682,8 @@ void BookmarkBarGtk::OnButtonDragGet(GtkWidget* widget, GdkDragContext* context,
GtkSelectionData* selection_data,
guint target_type, guint time,
BookmarkBarGtk* bar) {
- BookmarkNode* node =
- reinterpret_cast<BookmarkNode*>(
+ const BookmarkNode* node =
+ reinterpret_cast<const BookmarkNode*>(
g_object_get_data(G_OBJECT(widget), kBookmarkNode));
bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type,
bar->profile_);
@@ -697,7 +699,7 @@ gboolean BookmarkBarGtk::OnFolderButtonReleased(GtkWidget* sender,
return FALSE;
}
- BookmarkNode* node = bar->GetNodeForToolButton(sender);
+ const BookmarkNode* node = bar->GetNodeForToolButton(sender);
DCHECK(node);
DCHECK(bar->page_navigator_);
@@ -807,7 +809,7 @@ void BookmarkBarGtk::OnToolbarDragReceived(GtkWidget* widget,
gboolean dnd_success = FALSE;
gboolean delete_selection_data = FALSE;
- std::vector<BookmarkNode*> nodes =
+ std::vector<const BookmarkNode*> nodes =
bookmark_utils::GetNodesFromSelection(context, selection_data,
target_type,
bar->profile_,
@@ -816,7 +818,7 @@ void BookmarkBarGtk::OnToolbarDragReceived(GtkWidget* widget,
DCHECK(!nodes.empty());
gint index = gtk_toolbar_get_drop_index(
GTK_TOOLBAR(bar->bookmark_toolbar_.get()), x, y);
- for (std::vector<BookmarkNode*>::iterator it = nodes.begin();
+ for (std::vector<const BookmarkNode*>::iterator it = nodes.begin();
it != nodes.end(); ++it) {
bar->model_->Move(*it, bar->model_->GetBookmarkBarNode(), index);
index = bar->model_->GetBookmarkBarNode()->IndexOfChild(*it) + 1;
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h
index 154dc36..be07088 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.h
+++ b/chrome/browser/gtk/bookmark_bar_gtk.h
@@ -74,15 +74,15 @@ class BookmarkBarGtk : public AnimationDelegate,
private:
// Helper function that sets visual properties of GtkButton |button| to the
// contents of |node|.
- void ConfigureButtonForNode(BookmarkNode* node,
+ void ConfigureButtonForNode(const BookmarkNode* node,
GtkWidget* button);
// Helper function which generates GtkToolItems for |bookmark_toolbar_|.
- void CreateAllBookmarkButtons(BookmarkNode* node);
+ void CreateAllBookmarkButtons(const BookmarkNode* node);
// Sets the visibility of the instructional text based on whether there are
// any bookmarks in |node|. |node| is assumed to be the bookmarks bar node.
- void SetInstructionState(BookmarkNode* boomarks_bar_node);
+ void SetInstructionState(const BookmarkNode* boomarks_bar_node);
// Helper function which destroys all the bookmark buttons in the GtkToolbar.
void RemoveAllBookmarkButtons();
@@ -103,40 +103,40 @@ class BookmarkBarGtk : public AnimationDelegate,
// Invoked when a node has moved.
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// Invoked when a favicon has finished loading.
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
private:
- GtkWidget* CreateBookmarkButton(BookmarkNode* node);
- GtkToolItem* CreateBookmarkToolItem(BookmarkNode* node);
+ GtkWidget* CreateBookmarkButton(const BookmarkNode* node);
+ GtkToolItem* CreateBookmarkToolItem(const BookmarkNode* node);
void ConnectFolderButtonEvents(GtkWidget* widget);
- std::string BuildTooltip(BookmarkNode* node);
+ std::string BuildTooltip(const BookmarkNode* node);
// Finds the BookmarkNode from the model associated with |button|.
- BookmarkNode* GetNodeForToolButton(GtkWidget* button);
+ const BookmarkNode* GetNodeForToolButton(GtkWidget* button);
// Loads the background image into memory, or does nothing if already loaded.
void InitBackground();
// Creates and displays a popup menu for BookmarkNode |node|.
- void PopupMenuForNode(GtkWidget* sender, BookmarkNode* node,
+ void PopupMenuForNode(GtkWidget* sender, const BookmarkNode* node,
GdkEventButton* event);
// GtkButton callbacks
@@ -221,7 +221,7 @@ class BookmarkBarGtk : public AnimationDelegate,
// The BookmarkNode from the model being dragged. NULL when we aren't
// dragging.
- BookmarkNode* dragged_node_;
+ const BookmarkNode* dragged_node_;
// We create a GtkToolbarItem from |dragged_node_| for display.
GtkToolItem* toolbar_drop_item_;
diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc
index ae07e3d..30e93d6 100644
--- a/chrome/browser/gtk/bookmark_bubble_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc
@@ -31,19 +31,19 @@ BookmarkBubbleGtk* g_bubble = NULL;
// Max number of most recently used folders.
const size_t kMaxMRUFolders = 5;
-std::vector<BookmarkNode*> PopulateFolderCombo(BookmarkModel* model,
- const GURL& url,
- GtkWidget* folder_combo) {
- BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url);
- BookmarkNode* parent = node->GetParent();
- BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
- BookmarkNode* other = model->other_node();
+std::vector<const BookmarkNode*> PopulateFolderCombo(BookmarkModel* model,
+ const GURL& url,
+ GtkWidget* folder_combo) {
+ const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url);
+ const BookmarkNode* parent = node->GetParent();
+ const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
+ const BookmarkNode* other = model->other_node();
// Use + 2 to account for bookmark bar and other node.
- std::vector<BookmarkNode*> recent_nodes =
+ std::vector<const BookmarkNode*> recent_nodes =
bookmark_utils::GetMostRecentlyModifiedGroups(model, kMaxMRUFolders + 2);
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
// Make the parent the first item, unless it's the bookmark bar or other node.
if (parent != bookmark_bar && parent != other)
nodes.push_back(parent);
@@ -217,7 +217,7 @@ BookmarkBubbleGtk::~BookmarkBubbleGtk() {
ApplyEdits();
} else if (remove_bookmark_) {
BookmarkModel* model = profile_->GetBookmarkModel();
- BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
+ const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
if (node)
model->Remove(node->GetParent(), node->GetParent()->IndexOfChild(node));
}
@@ -269,7 +269,7 @@ void BookmarkBubbleGtk::ApplyEdits() {
apply_edits_ = false;
BookmarkModel* model = profile_->GetBookmarkModel();
- BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
+ const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
if (node) {
// NOTE: Would be nice to save a strlen and use gtk_entry_get_text_length,
// but it is fairly new and not always in our GTK version.
@@ -286,7 +286,7 @@ void BookmarkBubbleGtk::ApplyEdits() {
// Last index ('Choose another folder...') is not in folder_nodes_.
if (cur_folder < folder_nodes_.size()) {
- BookmarkNode* new_parent = folder_nodes_[cur_folder];
+ const BookmarkNode* new_parent = folder_nodes_[cur_folder];
if (new_parent != node->GetParent()) {
UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_);
model->Move(node, new_parent, new_parent->GetChildCount());
@@ -297,7 +297,8 @@ void BookmarkBubbleGtk::ApplyEdits() {
std::string BookmarkBubbleGtk::GetTitle() {
BookmarkModel* bookmark_model= profile_->GetBookmarkModel();
- BookmarkNode* node = bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
+ const BookmarkNode* node =
+ bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
if (!node) {
NOTREACHED();
return std::string();
@@ -307,7 +308,7 @@ std::string BookmarkBubbleGtk::GetTitle() {
}
void BookmarkBubbleGtk::ShowEditor() {
- BookmarkNode* node =
+ const BookmarkNode* node =
profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_);
// Commit any edits now.
diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.h b/chrome/browser/gtk/bookmark_bubble_gtk.h
index 8e67f6c..48890b6 100644
--- a/chrome/browser/gtk/bookmark_bubble_gtk.h
+++ b/chrome/browser/gtk/bookmark_bubble_gtk.h
@@ -121,7 +121,7 @@ class BookmarkBubbleGtk : public InfoBubbleGtkDelegate {
GtkWidget* folder_combo_;
// The bookmark nodes in |folder_combo_|.
- std::vector<BookmarkNode*> folder_nodes_;
+ std::vector<const BookmarkNode*> folder_nodes_;
InfoBubbleGtk* bubble_;
diff --git a/chrome/browser/gtk/bookmark_context_menu.cc b/chrome/browser/gtk/bookmark_context_menu.cc
index ff92135..8af8058 100644
--- a/chrome/browser/gtk/bookmark_context_menu.cc
+++ b/chrome/browser/gtk/bookmark_context_menu.cc
@@ -30,7 +30,7 @@ namespace {
// Returns true if the specified node is of type URL, or has a descendant
// of type URL.
-bool NodeHasURLs(BookmarkNode* node) {
+bool NodeHasURLs(const BookmarkNode* node) {
if (node->is_url())
return true;
@@ -57,7 +57,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
static void Show(Profile* profile,
gfx::NativeView wnd,
- BookmarkNode* node,
+ const BookmarkNode* node,
bool is_new,
bool show_in_manager) {
// EditFolderController deletes itself when done.
@@ -69,7 +69,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
private:
EditFolderController(Profile* profile,
gfx::NativeView wnd,
- BookmarkNode* node,
+ const BookmarkNode* node,
bool is_new,
bool show_in_manager)
: profile_(profile),
@@ -103,7 +103,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
virtual void InputAccepted(const std::wstring& text) {
if (is_new_) {
- ALLOW_UNUSED BookmarkNode* node =
+ ALLOW_UNUSED const BookmarkNode* node =
model_->AddGroup(node_, node_->GetChildCount(), text);
if (show_in_manager_) {
#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS))
@@ -130,35 +130,36 @@ class EditFolderController : public InputWindowDialog::Delegate,
}
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
ModelChanged();
}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
ModelChanged();
}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
ModelChanged();
}
- virtual void BookmarkNodeChanged(BookmarkModel* model, BookmarkNode* node) {
+ virtual void BookmarkNodeChanged(BookmarkModel* model,
+ const BookmarkNode* node) {
ModelChanged();
}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
ModelChanged();
}
@@ -170,7 +171,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
BookmarkModel* model_;
// 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.
- BookmarkNode* node_;
+ const BookmarkNode* node_;
bool is_new_;
@@ -192,7 +193,7 @@ class SelectOnCreationHandler : public BookmarkEditor::Handler {
explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) {
}
- virtual void NodeCreated(BookmarkNode* new_node) {
+ virtual void NodeCreated(const BookmarkNode* new_node) {
BookmarkManager::SelectInTree(profile_, new_node);
}
@@ -212,8 +213,8 @@ BookmarkContextMenu::BookmarkContextMenu(
Profile* profile,
Browser* browser,
PageNavigator* navigator,
- BookmarkNode* parent,
- const std::vector<BookmarkNode*>& selection,
+ const BookmarkNode* parent,
+ const std::vector<const BookmarkNode*>& selection,
ConfigurationType configuration)
: wnd_(wnd),
profile_(profile),
@@ -502,33 +503,33 @@ void BookmarkContextMenu::BookmarkModelBeingDeleted(BookmarkModel* model) {
}
void BookmarkContextMenu::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
ModelChanged();
}
void BookmarkContextMenu::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
ModelChanged();
}
void BookmarkContextMenu::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
ModelChanged();
}
void BookmarkContextMenu::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
ModelChanged();
}
-void BookmarkContextMenu::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+void BookmarkContextMenu::BookmarkNodeChildrenReordered(
+ BookmarkModel* model, const BookmarkNode* node) {
ModelChanged();
}
@@ -551,7 +552,7 @@ bool BookmarkContextMenu::HasURLs() const {
return false;
}
-BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const {
+const BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const {
return (selection_.size() == 1 && selection_[0]->is_folder()) ?
selection_[0] : parent_;
}
diff --git a/chrome/browser/gtk/bookmark_context_menu.h b/chrome/browser/gtk/bookmark_context_menu.h
index 38dc37a..db601c9 100644
--- a/chrome/browser/gtk/bookmark_context_menu.h
+++ b/chrome/browser/gtk/bookmark_context_menu.h
@@ -59,8 +59,8 @@ class BookmarkContextMenu : public BookmarkModelObserver,
Profile* profile,
Browser* browser,
PageNavigator* navigator,
- BookmarkNode* parent,
- const std::vector<BookmarkNode*>& selection,
+ const BookmarkNode* parent,
+ const std::vector<const BookmarkNode*>& selection,
ConfigurationType configuration);
virtual ~BookmarkContextMenu();
@@ -89,23 +89,23 @@ class BookmarkContextMenu : public BookmarkModelObserver,
virtual void Loaded(BookmarkModel* model) {}
virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// Invoked from the various bookmark model observer methods. Closes the menu.
void ModelChanged();
@@ -131,14 +131,14 @@ class BookmarkContextMenu : public BookmarkModelObserver,
// Returns the parent for newly created folders/bookmarks. If selection_
// has one element and it is a folder, selection_[0] is returned, otherwise
// parent_ is returned.
- BookmarkNode* GetParentForNewNodes() const;
+ const BookmarkNode* GetParentForNewNodes() const;
gfx::NativeView wnd_;
Profile* profile_;
Browser* browser_;
PageNavigator* navigator_;
- BookmarkNode* parent_;
- std::vector<BookmarkNode*> selection_;
+ const BookmarkNode* parent_;
+ std::vector<const BookmarkNode*> selection_;
BookmarkModel* model_;
ConfigurationType configuration_;
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc
index 05d1ec2..1a6171c 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk.cc
+++ b/chrome/browser/gtk/bookmark_editor_gtk.cc
@@ -37,8 +37,8 @@ static const int kTreeHeight = 150;
// static
void BookmarkEditor::Show(gfx::NativeView parent_hwnd,
Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
Configuration configuration,
Handler* handler) {
DCHECK(profile);
@@ -51,8 +51,8 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd,
BookmarkEditorGtk::BookmarkEditorGtk(
GtkWindow* window,
Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler)
: profile_(profile),
@@ -228,23 +228,23 @@ void BookmarkEditorGtk::Close() {
}
void BookmarkEditorGtk::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
Reset();
}
void BookmarkEditorGtk::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
Reset();
}
void BookmarkEditorGtk::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if ((node_ && node_->HasAncestor(node)) ||
(parent_ && parent_->HasAncestor(node))) {
// The node, or its parent was removed. Close the dialog.
@@ -254,8 +254,8 @@ void BookmarkEditorGtk::BookmarkNodeRemoved(BookmarkModel* model,
}
}
-void BookmarkEditorGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+void BookmarkEditorGtk::BookmarkNodeChildrenReordered(
+ BookmarkModel* model, const BookmarkNode* node) {
Reset();
}
@@ -306,7 +306,8 @@ void BookmarkEditorGtk::ApplyEdits(GtkTreeIter* selected_parent) {
}
// Create the new groups and update the titles.
- BookmarkNode* new_parent = bookmark_utils::CommitTreeStoreDifferencesBetween(
+ const BookmarkNode* new_parent =
+ bookmark_utils::CommitTreeStoreDifferencesBetween(
bb_model_, tree_store_, selected_parent);
if (!new_parent) {
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.h b/chrome/browser/gtk/bookmark_editor_gtk.h
index 4149a05..70ed8c4 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk.h
+++ b/chrome/browser/gtk/bookmark_editor_gtk.h
@@ -26,8 +26,8 @@ class BookmarkEditorGtk : public BookmarkEditor,
public:
BookmarkEditorGtk(GtkWindow* window,
Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler);
@@ -43,23 +43,23 @@ class BookmarkEditorGtk : public BookmarkEditor,
// resetting the tree model.
virtual void Loaded(BookmarkModel* model) { }
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
// Resets the model of the tree and updates the various buttons appropriately.
void Reset();
@@ -117,10 +117,10 @@ class BookmarkEditorGtk : public BookmarkEditor,
// that into a GObject that implements the interface GtkTreeModel.
// Initial parent to select. Is only used if node_ is NULL.
- BookmarkNode* parent_;
+ const BookmarkNode* parent_;
// Node being edited. Is NULL if creating a new node.
- BookmarkNode* node_;
+ const BookmarkNode* node_;
// Mode used to create nodes from.
BookmarkModel* bb_model_;
diff --git a/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc b/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
index ccbd033..7cb3a44 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
+++ b/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
@@ -48,7 +48,7 @@ class BookmarkEditorGtkTest : public testing::Test {
std::string base_path() const { return "file:///c:/tmp/"; }
- BookmarkNode* GetNode(const std::string& name) {
+ const BookmarkNode* GetNode(const std::string& name) {
return model_->GetMostRecentlyAddedNodeForURL(GURL(base_path() + name));
}
@@ -70,16 +70,18 @@ class BookmarkEditorGtkTest : public testing::Test {
model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a",
GURL(test_base + "a"));
- BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1");
+ const BookmarkNode* f1 =
+ model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1");
model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a"));
- BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11");
+ const 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"));
- BookmarkNode* of1 = model_->AddGroup(model_->other_node(), 1, L"OF1");
+ const BookmarkNode* of1 =
+ model_->AddGroup(model_->other_node(), 1, L"OF1");
model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a"));
}
};
@@ -134,7 +136,8 @@ TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) {
ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node));
editor.ApplyEdits(&bookmark_bar_node);
- BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
+ const 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());
@@ -142,8 +145,7 @@ TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) {
// Changes the url and makes sure parent/visual order doesn't change.
TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) {
- Time node_time = Time::Now() + TimeDelta::FromDays(2);
- GetNode("a")->date_added_ = node_time;
+ Time node_time = GetNode("a")->date_added();
BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"),
BookmarkEditor::SHOW_TREE, NULL);
gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
@@ -154,7 +156,8 @@ TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) {
ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node));
editor.ApplyEdits(&bookmark_bar_node);
- BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
+ const 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());
@@ -172,7 +175,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeParent) {
ASSERT_TRUE(gtk_tree_model_iter_next(store, &gtk_other_node));
editor.ApplyEdits(&gtk_other_node);
- BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
+ const 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());
}
@@ -180,8 +183,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeParent) {
// Moves 'a' to be a child of the other node.
// Moves 'a' to be a child of the other node and changes its url to new_a.
TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) {
- Time node_time = Time::Now() + TimeDelta::FromDays(2);
- GetNode("a")->date_added_ = node_time;
+ Time node_time = GetNode("a")->date_added();
BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"),
BookmarkEditor::SHOW_TREE, NULL);
@@ -194,7 +196,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) {
ASSERT_TRUE(gtk_tree_model_iter_next(store, &gtk_other_node));
editor.ApplyEdits(&gtk_other_node);
- BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
+ const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle());
ASSERT_TRUE(GURL(base_path() + "new_a") == other_node->GetChild(2)->GetURL());
ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added());
@@ -230,8 +232,9 @@ TEST_F(BookmarkEditorGtkTest, MoveToNewParent) {
editor.ApplyEdits(&f2_iter);
- BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
- BookmarkNode* mf2 = bb_node->GetChild(1);
+ const BookmarkNode* bb_node =
+ profile_->GetBookmarkModel()->GetBookmarkBarNode();
+ const 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());
@@ -241,7 +244,7 @@ TEST_F(BookmarkEditorGtkTest, MoveToNewParent) {
ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle());
// F21 should have one child, F211.
- BookmarkNode* mf21 = mf2->GetChild(0);
+ const BookmarkNode* mf21 = mf2->GetChild(0);
ASSERT_EQ(1, mf21->GetChildCount());
ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle());
}
@@ -260,10 +263,11 @@ TEST_F(BookmarkEditorGtkTest, NewURL) {
ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node));
editor.ApplyEdits(&bookmark_bar_node);
- BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
+ const BookmarkNode* bb_node =
+ profile_->GetBookmarkModel()->GetBookmarkBarNode();
ASSERT_EQ(4, bb_node->GetChildCount());
- BookmarkNode* new_node = bb_node->GetChild(3);
+ const BookmarkNode* new_node = bb_node->GetChild(3);
EXPECT_EQ(L"new_a", new_node->GetTitle());
EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL());
}
@@ -280,10 +284,10 @@ TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) {
editor.ApplyEdits(NULL);
- BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
+ const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
ASSERT_EQ(2, other_node->GetChildCount());
- BookmarkNode* new_node = other_node->GetChild(0);
+ const BookmarkNode* new_node = other_node->GetChild(0);
EXPECT_EQ(L"new_a", new_node->GetTitle());
EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL());
@@ -298,9 +302,9 @@ TEST_F(BookmarkEditorGtkTest, ChangeTitleNoTree) {
editor.ApplyEdits();
- BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
+ const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
ASSERT_EQ(2, other_node->GetChildCount());
- BookmarkNode* new_node = other_node->GetChild(0);
+ const BookmarkNode* new_node = other_node->GetChild(0);
EXPECT_EQ(L"new_a", new_node->GetTitle());
}
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc
index fca5f1f..b1db3ad 100644
--- a/chrome/browser/gtk/bookmark_manager_gtk.cc
+++ b/chrome/browser/gtk/bookmark_manager_gtk.cc
@@ -72,7 +72,7 @@ class ImportObserverImpl : public ImportObserver {
BookmarkModel* model = profile_->GetBookmarkModel();
int other_count = model->other_node()->GetChildCount();
if (other_count == initial_other_count_ + 1) {
- BookmarkNode* imported_node =
+ const BookmarkNode* imported_node =
model->other_node()->GetChild(initial_other_count_);
manager->SelectInTree(imported_node, true);
}
@@ -112,7 +112,7 @@ void SetMenuBarStyle() {
// BookmarkManager -------------------------------------------------------------
-void BookmarkManager::SelectInTree(Profile* profile, BookmarkNode* node) {
+void BookmarkManager::SelectInTree(Profile* profile, const BookmarkNode* node) {
if (manager && manager->profile() == profile)
manager->SelectInTree(node, false);
}
@@ -123,7 +123,7 @@ void BookmarkManager::Show(Profile* profile) {
// BookmarkManagerGtk, public --------------------------------------------------
-void BookmarkManagerGtk::SelectInTree(BookmarkNode* node, bool expand) {
+void BookmarkManagerGtk::SelectInTree(const BookmarkNode* node, bool expand) {
GtkTreeIter iter = { 0, };
if (RecursiveFind(GTK_TREE_MODEL(left_store_), &iter, node->id())) {
GtkTreePath* path = gtk_tree_model_get_path(GTK_TREE_MODEL(left_store_),
@@ -160,9 +160,9 @@ void BookmarkManagerGtk::BookmarkModelBeingDeleted(BookmarkModel* model) {
}
void BookmarkManagerGtk::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
BookmarkNodeRemoved(model, old_parent, old_index,
new_parent->GetChild(new_index));
@@ -170,9 +170,9 @@ void BookmarkManagerGtk::BookmarkNodeMoved(BookmarkModel* model,
}
void BookmarkManagerGtk::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
- BookmarkNode* node = parent->GetChild(index);
+ const BookmarkNode* node = parent->GetChild(index);
if (node->is_folder()) {
GtkTreeIter iter = { 0, };
if (RecursiveFind(GTK_TREE_MODEL(left_store_), &iter, parent->id()))
@@ -181,15 +181,15 @@ void BookmarkManagerGtk::BookmarkNodeAdded(BookmarkModel* model,
}
void BookmarkManagerGtk::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
NOTREACHED();
}
void BookmarkManagerGtk::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int old_index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (node->is_folder()) {
GtkTreeIter iter = { 0, };
if (RecursiveFind(GTK_TREE_MODEL(left_store_), &iter, node->id())) {
@@ -207,17 +207,17 @@ void BookmarkManagerGtk::BookmarkNodeRemoved(BookmarkModel* model,
}
void BookmarkManagerGtk::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
// TODO(estade): rename in the left tree view.
}
-void BookmarkManagerGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+void BookmarkManagerGtk::BookmarkNodeChildrenReordered(
+ BookmarkModel* model, const BookmarkNode* node) {
// TODO(estade): reorder in the left tree view.
}
void BookmarkManagerGtk::BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
// I don't think we have anything to do, as we should never get this for a
// folder node and we handle it via OnItemsChanged for any URL node.
}
@@ -473,8 +473,8 @@ GtkWidget* BookmarkManagerGtk::MakeRightPane() {
void BookmarkManagerGtk::ResetOrganizeMenu(bool left) {
organize_is_for_left_ = left;
- BookmarkNode* parent = GetFolder();
- std::vector<BookmarkNode*> nodes;
+ const BookmarkNode* parent = GetFolder();
+ std::vector<const BookmarkNode*> nodes;
if (!left)
nodes = GetRightSelection();
else if (parent)
@@ -520,7 +520,7 @@ void BookmarkManagerGtk::BuildLeftStore() {
}
void BookmarkManagerGtk::BuildRightStore() {
- BookmarkNode* node = GetFolder();
+ const BookmarkNode* node = GetFolder();
gtk_list_store_clear(right_store_);
@@ -574,8 +574,8 @@ int BookmarkManagerGtk::GetRowIDAt(GtkTreeModel* model, GtkTreeIter* iter) {
return id;
}
-BookmarkNode* BookmarkManagerGtk::GetNodeAt(GtkTreeModel* model,
- GtkTreeIter* iter) {
+const BookmarkNode* BookmarkManagerGtk::GetNodeAt(GtkTreeModel* model,
+ GtkTreeIter* iter) {
int id = GetRowIDAt(model, iter);
if (id > 0)
return model_->GetNodeByID(id);
@@ -583,7 +583,7 @@ BookmarkNode* BookmarkManagerGtk::GetNodeAt(GtkTreeModel* model,
return NULL;
}
-BookmarkNode* BookmarkManagerGtk::GetFolder() {
+const BookmarkNode* BookmarkManagerGtk::GetFolder() {
GtkTreeModel* model;
GtkTreeIter iter;
if (!gtk_tree_selection_get_selected(left_selection(), &model, &iter))
@@ -598,11 +598,11 @@ int BookmarkManagerGtk::GetSelectedRowID() {
return GetRowIDAt(model, &iter);
}
-std::vector<BookmarkNode*> BookmarkManagerGtk::GetRightSelection() {
+std::vector<const BookmarkNode*> BookmarkManagerGtk::GetRightSelection() {
GtkTreeModel* model;
GList* paths = gtk_tree_selection_get_selected_rows(right_selection(),
&model);
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
for (GList* item = paths; item; item = item->next) {
GtkTreeIter iter;
gtk_tree_model_get_iter(model, &iter,
@@ -617,7 +617,7 @@ std::vector<BookmarkNode*> BookmarkManagerGtk::GetRightSelection() {
void BookmarkManagerGtk::SetRightSideColumnValues(int row, GtkTreeIter* iter) {
// TODO(estade): building the path could be optimized out when we aren't
// showing the path column.
- BookmarkNode* node = right_tree_model_->GetNodeForRow(row);
+ const BookmarkNode* node = right_tree_model_->GetNodeForRow(row);
GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model_);
std::wstring title =
right_tree_model_->GetText(row, IDS_BOOKMARK_TABLE_TITLE);
@@ -742,7 +742,7 @@ void BookmarkManagerGtk::OnLeftTreeViewDragReceived(
gboolean dnd_success = FALSE;
gboolean delete_selection_data = FALSE;
- std::vector<BookmarkNode*> nodes =
+ std::vector<const BookmarkNode*> nodes =
bookmark_utils::GetNodesFromSelection(context, selection_data,
target_type,
bm->profile_,
@@ -765,8 +765,9 @@ void BookmarkManagerGtk::OnLeftTreeViewDragReceived(
GtkTreeIter iter;
gtk_tree_model_get_iter(GTK_TREE_MODEL(bm->left_store_), &iter, path);
- BookmarkNode* folder = bm->GetNodeAt(GTK_TREE_MODEL(bm->left_store_), &iter);
- for (std::vector<BookmarkNode*>::iterator it = nodes.begin();
+ const BookmarkNode* folder = bm->GetNodeAt(
+ GTK_TREE_MODEL(bm->left_store_), &iter);
+ for (std::vector<const BookmarkNode*>::iterator it = nodes.begin();
it != nodes.end(); ++it) {
// Don't try to drop a node into one of its descendants.
if (!folder->HasAncestor(*it))
@@ -836,7 +837,7 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived(
gboolean dnd_success = FALSE;
gboolean delete_selection_data = FALSE;
- std::vector<BookmarkNode*> nodes =
+ std::vector<const BookmarkNode*> nodes =
bookmark_utils::GetNodesFromSelection(context, selection_data,
target_type,
bm->profile_,
@@ -857,7 +858,7 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived(
bool drop_after = pos == GTK_TREE_VIEW_DROP_AFTER;
// The parent folder and index therein to drop the nodes.
- BookmarkNode* parent = NULL;
+ const BookmarkNode* parent = NULL;
int idx = -1;
// |path| will be null when we are looking at an empty folder.
@@ -865,7 +866,7 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived(
GtkTreeIter iter;
GtkTreeModel* model = GTK_TREE_MODEL(bm->right_store_);
gtk_tree_model_get_iter(model, &iter, path);
- BookmarkNode* node = bm->GetNodeAt(model, &iter);
+ const BookmarkNode* node = bm->GetNodeAt(model, &iter);
if (node->is_folder()) {
parent = node;
idx = parent->GetChildCount();
@@ -883,7 +884,7 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived(
idx = !path ? parent->GetChildCount() : gtk_tree_path_get_indices(path)[0];
}
- for (std::vector<BookmarkNode*>::iterator it = nodes.begin();
+ for (std::vector<const BookmarkNode*>::iterator it = nodes.begin();
it != nodes.end(); ++it) {
// Don't try to drop a node into one of its descendants.
if (!parent->HasAncestor(*it)) {
@@ -913,7 +914,7 @@ gboolean BookmarkManagerGtk::OnRightTreeViewDragMotion(
gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y,
&path, &pos);
- BookmarkNode* parent = bm->GetFolder();
+ const BookmarkNode* parent = bm->GetFolder();
if (path) {
int idx =
gtk_tree_path_get_indices(path)[gtk_tree_path_get_depth(path) - 1];
@@ -937,7 +938,7 @@ gboolean BookmarkManagerGtk::OnRightTreeViewDragMotion(
// static
void BookmarkManagerGtk::OnRightTreeViewRowActivated(GtkTreeView* tree_view,
GtkTreePath* path, GtkTreeViewColumn* column, BookmarkManagerGtk* bm) {
- std::vector<BookmarkNode*> nodes = bm->GetRightSelection();
+ std::vector<const BookmarkNode*> nodes = bm->GetRightSelection();
if (nodes.empty())
return;
if (nodes.size() == 1 && nodes[0]->is_folder()) {
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h
index 1ef9041..64586b1 100644
--- a/chrome/browser/gtk/bookmark_manager_gtk.h
+++ b/chrome/browser/gtk/bookmark_manager_gtk.h
@@ -28,7 +28,7 @@ class BookmarkManagerGtk : public BookmarkModelObserver,
Profile* profile() { return profile_; }
// Show the node in the tree.
- void SelectInTree(BookmarkNode* node, bool expand);
+ void SelectInTree(const BookmarkNode* node, bool expand);
// Shows the bookmark manager. Only one bookmark manager exists.
static void Show(Profile* profile);
@@ -39,26 +39,26 @@ class BookmarkManagerGtk : public BookmarkModelObserver,
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int old_index,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// TableModelObserver implementation.
virtual void OnModelChanged();
@@ -93,16 +93,16 @@ class BookmarkManagerGtk : public BookmarkModelObserver,
// Get the node from |model| at |iter|. If the item is not a node, return
// NULL.
- BookmarkNode* GetNodeAt(GtkTreeModel* model, GtkTreeIter* iter);
+ const BookmarkNode* GetNodeAt(GtkTreeModel* model, GtkTreeIter* iter);
// Get the node that is selected in the left tree view.
- BookmarkNode* GetFolder();
+ const BookmarkNode* GetFolder();
// Get the ID of the selected row.
int GetSelectedRowID();
// Get the nodes that are selected in the right tree view.
- std::vector<BookmarkNode*> GetRightSelection();
+ std::vector<const BookmarkNode*> GetRightSelection();
// Set the fields for a row.
void SetRightSideColumnValues(int row, GtkTreeIter* iter);
diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc
index 68b4ffdf..a0d905b 100644
--- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc
+++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc
@@ -29,18 +29,22 @@ void SetImageMenuItem(GtkWidget* menu_item, const SkBitmap& bitmap) {
g_object_unref(pixbuf);
}
-BookmarkNode* GetNodeFromMenuItem(GtkWidget* menu_item) {
- return static_cast<BookmarkNode*>(
+const BookmarkNode* GetNodeFromMenuItem(GtkWidget* menu_item) {
+ return static_cast<const BookmarkNode*>(
g_object_get_data(G_OBJECT(menu_item), "bookmark-node"));
}
+void* AsVoid(const BookmarkNode* node) {
+ return const_cast<BookmarkNode*>(node);
+}
+
} // namespace
BookmarkMenuController::BookmarkMenuController(Browser* browser,
Profile* profile,
PageNavigator* navigator,
GtkWindow* window,
- BookmarkNode* node,
+ const BookmarkNode* node,
int start_child_index,
bool show_other_folder)
: browser_(browser),
@@ -71,9 +75,9 @@ void BookmarkMenuController::BookmarkModelChanged() {
gtk_menu_popdown(GTK_MENU(menu_.get()));
}
-void BookmarkMenuController::BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
- std::map<BookmarkNode*, GtkWidget*>::iterator it =
+void BookmarkMenuController::BookmarkNodeFavIconLoaded(
+ BookmarkModel* model, const BookmarkNode* node) {
+ std::map<const BookmarkNode*, GtkWidget*>::iterator it =
node_to_menu_widget_map_.find(node);
if (it != node_to_menu_widget_map_.end())
SetImageMenuItem(it->second, model->GetFavIcon(node));
@@ -82,20 +86,20 @@ void BookmarkMenuController::BookmarkNodeFavIconLoaded(BookmarkModel* model,
void BookmarkMenuController::NavigateToMenuItem(
GtkWidget* menu_item,
WindowOpenDisposition disposition) {
- BookmarkNode* node = GetNodeFromMenuItem(menu_item);
+ const BookmarkNode* node = GetNodeFromMenuItem(menu_item);
DCHECK(node);
DCHECK(page_navigator_);
page_navigator_->OpenURL(
node->GetURL(), GURL(), disposition, PageTransition::AUTO_BOOKMARK);
}
-void BookmarkMenuController::BuildMenu(BookmarkNode* parent,
+void BookmarkMenuController::BuildMenu(const BookmarkNode* parent,
int start_child_index,
GtkWidget* menu) {
DCHECK(!parent->GetChildCount() ||
start_child_index < parent->GetChildCount());
for (int i = start_child_index; i < parent->GetChildCount(); ++i) {
- BookmarkNode* node = parent->GetChild(i);
+ const BookmarkNode* node = parent->GetChild(i);
GtkWidget* menu_item = gtk_image_menu_item_new_with_label(
WideToUTF8(node->GetTitle()).c_str());
@@ -107,7 +111,7 @@ void BookmarkMenuController::BuildMenu(BookmarkNode* parent,
GetBitmapNamed(IDR_DEFAULT_FAVICON);
}
SetImageMenuItem(menu_item, icon);
- g_object_set_data(G_OBJECT(menu_item), "bookmark-node", node);
+ g_object_set_data(G_OBJECT(menu_item), "bookmark-node", AsVoid(node));
g_signal_connect(G_OBJECT(menu_item), "activate",
G_CALLBACK(OnMenuItemActivated), this);
g_signal_connect(G_OBJECT(menu_item), "button-press-event",
@@ -144,9 +148,9 @@ gboolean BookmarkMenuController::OnButtonPressed(
BookmarkMenuController* controller) {
if (event->button == 3) {
// Show the right click menu and stop processing this button event.
- BookmarkNode* node = GetNodeFromMenuItem(sender);
- BookmarkNode* parent = node->GetParent();
- std::vector<BookmarkNode*> nodes;
+ const BookmarkNode* node = GetNodeFromMenuItem(sender);
+ const BookmarkNode* parent = node->GetParent();
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(node);
controller->context_menu_.reset(
new BookmarkContextMenu(
diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.h b/chrome/browser/gtk/bookmark_menu_controller_gtk.h
index 4d8e7b5..07993c4 100644
--- a/chrome/browser/gtk/bookmark_menu_controller_gtk.h
+++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.h
@@ -29,7 +29,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver {
Profile* profile,
PageNavigator* page_navigator,
GtkWindow* window,
- BookmarkNode* node,
+ const BookmarkNode* node,
int start_child_index,
bool show_other_folder);
virtual ~BookmarkMenuController();
@@ -40,12 +40,12 @@ class BookmarkMenuController : public BaseBookmarkModelObserver {
// Overridden from BaseBookmarkModelObserver:
virtual void BookmarkModelChanged();
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
private:
// Recursively change the bookmark hierarchy rooted in |parent| into a set of
// gtk menus rooted in |menu|.
- void BuildMenu(BookmarkNode* parent,
+ void BuildMenu(const BookmarkNode* parent,
int start_child_index,
GtkWidget* menu);
@@ -80,7 +80,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver {
BookmarkModel* model_;
// The node we're showing the contents of.
- BookmarkNode* node_;
+ const BookmarkNode* node_;
// Our bookmark menus. We don't use the MenuGtk class because we have to do
// all sorts of weird non-standard things with this menu, like:
@@ -90,7 +90,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver {
// Mapping from node to GtkMenuItem menu id. This only contains entries for
// nodes of type URL.
- std::map<BookmarkNode*, GtkWidget*> node_to_menu_widget_map_;
+ std::map<const BookmarkNode*, GtkWidget*> node_to_menu_widget_map_;
// Owns our right click context menu.
scoped_ptr<BookmarkContextMenu> context_menu_;
diff --git a/chrome/browser/gtk/bookmark_tree_model.cc b/chrome/browser/gtk/bookmark_tree_model.cc
index 14f7471..ab3b24e 100644
--- a/chrome/browser/gtk/bookmark_tree_model.cc
+++ b/chrome/browser/gtk/bookmark_tree_model.cc
@@ -13,7 +13,7 @@
namespace {
-void AddSingleNodeToTreeStore(GtkTreeStore* store, BookmarkNode* node,
+void AddSingleNodeToTreeStore(GtkTreeStore* store, const BookmarkNode* node,
GtkTreeIter *iter, GtkTreeIter* parent) {
gtk_tree_store_append(store, iter, parent);
// TODO(estade): we should show the folder open icon when it's expanded.
@@ -29,10 +29,10 @@ void AddSingleNodeToTreeStore(GtkTreeStore* store, BookmarkNode* node,
// Helper function for CommitTreeStoreDifferencesBetween() which recursively
// merges changes back from a GtkTreeStore into a tree of BookmarkNodes. This
// function only works on non-root nodes; our caller handles that special case.
-void RecursiveResolve(BookmarkModel* bb_model, BookmarkNode* bb_node,
+void RecursiveResolve(BookmarkModel* bb_model, const BookmarkNode* bb_node,
GtkTreeModel* tree_model, GtkTreeIter* parent_iter,
GtkTreePath* selected_path,
- BookmarkNode** selected_node) {
+ const BookmarkNode** selected_node) {
GtkTreePath* current_path = gtk_tree_model_get_path(tree_model, parent_iter);
if (gtk_tree_path_compare(current_path, selected_path) == 0)
*selected_node = bb_node;
@@ -44,7 +44,7 @@ void RecursiveResolve(BookmarkModel* bb_model, BookmarkNode* bb_node,
int id = bookmark_utils::GetIdFromTreeIter(tree_model, &child_iter);
std::wstring title =
bookmark_utils::GetTitleFromTreeIter(tree_model, &child_iter);
- BookmarkNode* child_bb_node = NULL;
+ const BookmarkNode* child_bb_node = NULL;
if (id == 0) {
child_bb_node = bb_model->AddGroup(bb_node, bb_node->GetChildCount(),
title);
@@ -52,7 +52,7 @@ void RecursiveResolve(BookmarkModel* bb_model, BookmarkNode* bb_node,
// Existing node, reset the title (BBModel ignores changes if the title
// is the same).
for (int j = 0; j < bb_node->GetChildCount(); ++j) {
- BookmarkNode* node = bb_node->GetChild(j);
+ const BookmarkNode* node = bb_node->GetChild(j);
if (node->is_folder() && node->id() == id) {
child_bb_node = node;
break;
@@ -79,14 +79,14 @@ GtkTreeStore* MakeFolderTreeStore() {
void AddToTreeStore(BookmarkModel* model, int selected_id,
GtkTreeStore* store, GtkTreeIter* selected_iter) {
- BookmarkNode* root_node = model->root_node();
+ const BookmarkNode* root_node = model->root_node();
for (int i = 0; i < root_node->GetChildCount(); ++i) {
AddToTreeStoreAt(root_node->GetChild(i), selected_id, store,
selected_iter, NULL);
}
}
-void AddToTreeStoreAt(BookmarkNode* node, int selected_id,
+void AddToTreeStoreAt(const BookmarkNode* node, int selected_id,
GtkTreeStore* store, GtkTreeIter* selected_iter,
GtkTreeIter* parent) {
if (!node->is_folder())
@@ -107,9 +107,9 @@ void AddToTreeStoreAt(BookmarkNode* node, int selected_id,
}
}
-BookmarkNode* CommitTreeStoreDifferencesBetween(
+const BookmarkNode* CommitTreeStoreDifferencesBetween(
BookmarkModel* bb_model, GtkTreeStore* tree_store, GtkTreeIter* selected) {
- BookmarkNode* node_to_return = NULL;
+ const BookmarkNode* node_to_return = NULL;
GtkTreeModel* tree_model = GTK_TREE_MODEL(tree_store);
GtkTreePath* selected_path = gtk_tree_model_get_path(tree_model, selected);
@@ -123,15 +123,15 @@ BookmarkNode* CommitTreeStoreDifferencesBetween(
// set of top level nodes that are the root BookmarksNode's children. These
// items in the top level are not editable and therefore don't need the extra
// complexity of trying to modify their title.
- BookmarkNode* root_node = bb_model->root_node();
+ const BookmarkNode* root_node = bb_model->root_node();
do {
DCHECK(GetIdFromTreeIter(tree_model, &tree_root) != 0)
<< "It should be impossible to add another toplevel node";
int id = GetIdFromTreeIter(tree_model, &tree_root);
- BookmarkNode* child_node = NULL;
+ const BookmarkNode* child_node = NULL;
for (int j = 0; j < root_node->GetChildCount(); ++j) {
- BookmarkNode* node = root_node->GetChild(j);
+ const BookmarkNode* node = root_node->GetChild(j);
if (node->is_folder() && node->id() == id) {
child_node = node;
break;
diff --git a/chrome/browser/gtk/bookmark_tree_model.h b/chrome/browser/gtk/bookmark_tree_model.h
index 4ca0c5b..c691212 100644
--- a/chrome/browser/gtk/bookmark_tree_model.h
+++ b/chrome/browser/gtk/bookmark_tree_model.h
@@ -41,14 +41,14 @@ void AddToTreeStore(BookmarkModel* model, int selected_id,
// As above, but inserts just the tree rooted at |node| as a child of |parent|.
// If |parent| is NULL, add it at the top level.
-void AddToTreeStoreAt(BookmarkNode* node, int selected_id,
+void AddToTreeStoreAt(const BookmarkNode* node, int selected_id,
GtkTreeStore* store, GtkTreeIter* selected_iter,
GtkTreeIter* parent);
// Commits changes to a GtkTreeStore built from BuildTreeStoreFrom() back
// into the BookmarkModel it was generated from. Returns the BookmarkNode that
// represented by |selected|.
-BookmarkNode* CommitTreeStoreDifferencesBetween(
+const BookmarkNode* CommitTreeStoreDifferencesBetween(
BookmarkModel* model, GtkTreeStore* tree_store,
GtkTreeIter* selected);
diff --git a/chrome/browser/gtk/bookmark_utils_gtk.cc b/chrome/browser/gtk/bookmark_utils_gtk.cc
index 313dca4..4551794 100644
--- a/chrome/browser/gtk/bookmark_utils_gtk.cc
+++ b/chrome/browser/gtk/bookmark_utils_gtk.cc
@@ -48,7 +48,7 @@ GdkPixbuf* GetDefaultFavicon() {
return default_bookmark_icon;
}
-GdkPixbuf* GetPixbufForNode(BookmarkNode* node, BookmarkModel* model) {
+GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model) {
GdkPixbuf* pixbuf;
if (node->is_url()) {
@@ -68,17 +68,17 @@ GdkPixbuf* GetPixbufForNode(BookmarkNode* node, BookmarkModel* model) {
// DnD-related -----------------------------------------------------------------
-void WriteBookmarkToSelection(BookmarkNode* node,
+void WriteBookmarkToSelection(const BookmarkNode* node,
GtkSelectionData* selection_data,
guint target_type,
Profile* profile) {
DCHECK(node);
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(node);
WriteBookmarksToSelection(nodes, selection_data, target_type, profile);
}
-void WriteBookmarksToSelection(const std::vector<BookmarkNode*>& nodes,
+void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes,
GtkSelectionData* selection_data,
guint target_type,
Profile* profile) {
@@ -100,7 +100,7 @@ void WriteBookmarksToSelection(const std::vector<BookmarkNode*>& nodes,
}
}
-std::vector<BookmarkNode*> GetNodesFromSelection(
+std::vector<const BookmarkNode*> GetNodesFromSelection(
GdkDragContext* context,
GtkSelectionData* selection_data,
guint target_type,
@@ -130,7 +130,7 @@ std::vector<BookmarkNode*> GetNodesFromSelection(
}
}
- return std::vector<BookmarkNode*>();
+ return std::vector<const BookmarkNode*>();
}
} // namespace bookmark_utils
diff --git a/chrome/browser/gtk/bookmark_utils_gtk.h b/chrome/browser/gtk/bookmark_utils_gtk.h
index 819748c..32fe615 100644
--- a/chrome/browser/gtk/bookmark_utils_gtk.h
+++ b/chrome/browser/gtk/bookmark_utils_gtk.h
@@ -25,25 +25,25 @@ GdkPixbuf* GetDefaultFavicon();
// Get the image that is used to represent the node. This function adds a ref
// to the returned pixbuf, so it requires a matching call to g_object_unref().
-GdkPixbuf* GetPixbufForNode(BookmarkNode* node, BookmarkModel* model);
+GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model);
// Drag and drop. --------------------------------------------------------------
// Pickle a node into a GtkSelection.
-void WriteBookmarkToSelection(BookmarkNode* node,
+void WriteBookmarkToSelection(const BookmarkNode* node,
GtkSelectionData* selection_data,
guint target_type,
Profile* profile);
// Pickle a vector of nodes into a GtkSelection.
-void WriteBookmarksToSelection(const std::vector<BookmarkNode*>& nodes,
+void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes,
GtkSelectionData* selection_data,
guint target_type,
Profile* profile);
// Un-pickle node(s) from a GtkSelection.
// The last two arguments are out parameters.
-std::vector<BookmarkNode*> GetNodesFromSelection(
+std::vector<const BookmarkNode*> GetNodesFromSelection(
GdkDragContext* context,
GtkSelectionData* selection_data,
guint target_type,
diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc
index 74d2694..5af5572 100644
--- a/chrome/browser/importer/importer.cc
+++ b/chrome/browser/importer/importer.cc
@@ -95,7 +95,7 @@ void ProfileWriter::AddBookmarkEntry(
GenerateUniqueFolderName(model, first_folder_name);
bool show_bookmark_toolbar = false;
- std::set<BookmarkNode*> groups_added_to;
+ std::set<const BookmarkNode*> groups_added_to;
for (std::vector<BookmarkEntry>::const_iterator it = bookmark.begin();
it != bookmark.end(); ++it) {
// Don't insert this url if it isn't valid.
@@ -113,16 +113,16 @@ void ProfileWriter::AddBookmarkEntry(
// the subgroup of path[i-1]. Finally they construct a path in the
// model:
// path[0] \ path[1] \ ... \ path[size() - 1]
- BookmarkNode* parent =
+ const 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) {
- BookmarkNode* child = NULL;
- const std::wstring& folder_name = (!import_to_bookmark_bar &&
+ const BookmarkNode* child = NULL;
+ const std::wstring& folder_name = (!import_to_bookmark_bar &&
!it->in_toolbar && (i == it->path.begin())) ? real_first_folder : *i;
for (int index = 0; index < parent->GetChildCount(); ++index) {
- BookmarkNode* node = parent->GetChild(index);
+ const BookmarkNode* node = parent->GetChild(index);
if ((node->GetType() == history::StarredEntry::BOOKMARK_BAR ||
node->GetType() == history::StarredEntry::USER_GROUP) &&
node->GetTitle() == folder_name) {
@@ -147,7 +147,8 @@ 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<BookmarkNode*>::const_iterator i = groups_added_to.begin();
+ for (std::set<const BookmarkNode*>::const_iterator i =
+ groups_added_to.begin();
i != groups_added_to.end(); ++i) {
model->ResetDateGroupModified(*i);
}
@@ -299,9 +300,9 @@ std::wstring ProfileWriter::GenerateUniqueFolderName(
const std::wstring& folder_name) {
// Build a set containing the folder names of the other folder.
std::set<std::wstring> other_folder_names;
- BookmarkNode* other = model->other_node();
+ const BookmarkNode* other = model->other_node();
for (int i = 0; i < other->GetChildCount(); ++i) {
- BookmarkNode* node = other->GetChild(i);
+ const BookmarkNode* node = other->GetChild(i);
if (node->is_folder())
other_folder_names.insert(node->GetTitle());
}
@@ -324,19 +325,19 @@ bool ProfileWriter::DoesBookmarkExist(
const BookmarkEntry& entry,
const std::wstring& first_folder_name,
bool import_to_bookmark_bar) {
- std::vector<BookmarkNode*> nodes_with_same_url;
+ std::vector<const BookmarkNode*> nodes_with_same_url;
model->GetNodesByURL(entry.url, &nodes_with_same_url);
if (nodes_with_same_url.empty())
return false;
for (size_t i = 0; i < nodes_with_same_url.size(); ++i) {
- BookmarkNode* node = nodes_with_same_url[i];
+ const BookmarkNode* node = nodes_with_same_url[i];
if (entry.title != node->GetTitle())
continue;
// Does the path match?
bool found_match = true;
- BookmarkNode* parent = node->GetParent();
+ const BookmarkNode* parent = node->GetParent();
for (std::vector<std::wstring>::const_reverse_iterator path_it =
entry.path.rbegin();
(path_it != entry.path.rend()) && found_match; ++path_it) {
diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h
index 93ed19b..41ef11b 100644
--- a/chrome/browser/importer/importer.h
+++ b/chrome/browser/importer/importer.h
@@ -172,22 +172,22 @@ class ImporterHost : public base::RefCounted<ImporterHost>,
// BookmarkModelObserver methods.
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {}
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
// NotificationObserver method. Called when TemplateURLModel has been loaded.
void Observe(NotificationType type,
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 57a326b..30e1628 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -1699,7 +1699,9 @@ void MetricsService::LogChildProcessChange(
}
// Recursively counts the number of bookmarks and folders in node.
-static void CountBookmarks(BookmarkNode* node, int* bookmarks, int* folders) {
+static void CountBookmarks(const BookmarkNode* node,
+ int* bookmarks,
+ int* folders) {
if (node->GetType() == history::StarredEntry::URL)
(*bookmarks)++;
else
@@ -1708,7 +1710,7 @@ static void CountBookmarks(BookmarkNode* node, int* bookmarks, int* folders) {
CountBookmarks(node->GetChild(i), bookmarks, folders);
}
-void MetricsService::LogBookmarks(BookmarkNode* node,
+void MetricsService::LogBookmarks(const BookmarkNode* node,
const wchar_t* num_bookmarks_key,
const wchar_t* num_folders_key) {
DCHECK(node);
diff --git a/chrome/browser/metrics/metrics_service.h b/chrome/browser/metrics/metrics_service.h
index e78a66a..a955da1 100644
--- a/chrome/browser/metrics/metrics_service.h
+++ b/chrome/browser/metrics/metrics_service.h
@@ -316,7 +316,7 @@ 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(BookmarkNode* node,
+ void LogBookmarks(const BookmarkNode* node,
const wchar_t* num_bookmarks_key,
const wchar_t* num_folders_key);
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 0483ca6..459e4c2 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -740,7 +740,7 @@ int BookmarkBarView::OnDragUpdated(const DropTargetEvent& event) {
}
if (drop_on || is_over_overflow || is_over_other) {
- BookmarkNode* node;
+ const BookmarkNode* node;
if (is_over_other)
node = model_->other_node();
else if (is_over_overflow)
@@ -777,8 +777,9 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) {
if (!drop_info_.get() || !drop_info_->drag_operation)
return DragDropTypes::DRAG_NONE;
- BookmarkNode* root = drop_info_->is_over_other ? model_->other_node() :
- model_->GetBookmarkBarNode();
+ const 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;
@@ -791,7 +792,7 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) {
}
drop_info_.reset();
- BookmarkNode* parent_node;
+ const BookmarkNode* parent_node;
if (is_over_other) {
parent_node = root;
index = parent_node->GetChildCount();
@@ -928,7 +929,7 @@ int BookmarkBarView::GetBookmarkButtonCount() {
}
void BookmarkBarView::Loaded(BookmarkModel* model) {
- BookmarkNode* node = model_->GetBookmarkBarNode();
+ const 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)
@@ -960,9 +961,9 @@ void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) {
}
void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
StopThrobbing(true);
BookmarkNodeRemovedImpl(model, old_parent, old_index);
@@ -971,7 +972,7 @@ void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model,
}
void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
StopThrobbing(true);
BookmarkNodeAddedImpl(model, parent, index);
@@ -979,7 +980,7 @@ void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model,
}
void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
NotifyModelChanged();
if (parent != model_->GetBookmarkBarNode()) {
@@ -993,7 +994,7 @@ void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
}
void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
StopThrobbing(true);
BookmarkNodeRemovedImpl(model, parent, index);
@@ -1001,7 +1002,7 @@ void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model,
}
void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
StopThrobbing(true);
// No need to start throbbing again as the bookmark bubble can't be up at
@@ -1021,13 +1022,13 @@ void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
}
void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
NotifyModelChanged();
BookmarkNodeChangedImpl(model, node);
}
void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if (node->GetParent() != model_->GetBookmarkBarNode()) {
// We only care about nodes on the bookmark bar.
return;
@@ -1047,7 +1048,7 @@ void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model,
}
void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
NotifyModelChanged();
if (node != model_->GetBookmarkBarNode())
return; // We only care about reordering of the bookmark bar node.
@@ -1068,7 +1069,7 @@ void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model,
}
void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
BookmarkNodeChangedImpl(model, node);
}
@@ -1093,7 +1094,7 @@ void BookmarkBarView::WriteDragData(View* sender,
NOTREACHED();
}
-void BookmarkBarView::WriteDragData(BookmarkNode* node,
+void BookmarkBarView::WriteDragData(const BookmarkNode* node,
OSExchangeData* data) {
DCHECK(node && data);
BookmarkDragData drag_data(node);
@@ -1123,7 +1124,7 @@ int BookmarkBarView::GetDragOperations(View* sender, int x, int y) {
void BookmarkBarView::RunMenu(views::View* view,
const gfx::Point& pt,
gfx::NativeView hwnd) {
- BookmarkNode* node;
+ const BookmarkNode* node;
MenuItemView::AnchorPosition anchor_point = MenuItemView::TOPLEFT;
// When we set the menu's position, we must take into account the mirrored
@@ -1176,7 +1177,7 @@ void BookmarkBarView::RunMenu(views::View* view,
}
void BookmarkBarView::ButtonPressed(views::Button* sender) {
- BookmarkNode* node;
+ const BookmarkNode* node;
if (sender->tag() == kOtherFolderButtonTag) {
node = model_->other_node();
} else {
@@ -1214,8 +1215,8 @@ void BookmarkBarView::ShowContextMenu(View* source,
return;
}
- BookmarkNode* parent = NULL;
- std::vector<BookmarkNode*> nodes;
+ const BookmarkNode* parent = NULL;
+ std::vector<const BookmarkNode*> nodes;
if (source == other_bookmarked_button_) {
parent = model_->other_node();
// Do this so the user can open all bookmarks. BookmarkContextMenu makes
@@ -1227,7 +1228,7 @@ void BookmarkBarView::ShowContextMenu(View* source,
int bookmark_button_index = GetChildIndex(source);
DCHECK(bookmark_button_index != -1 &&
bookmark_button_index < GetBookmarkButtonCount());
- BookmarkNode* node =
+ const BookmarkNode* node =
model_->GetBookmarkBarNode()->GetChild(bookmark_button_index);
nodes.push_back(node);
parent = node->GetParent();
@@ -1242,7 +1243,7 @@ void BookmarkBarView::ShowContextMenu(View* source,
controller.RunMenuAt(x, y);
}
-views::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) {
+views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) {
if (node->is_url()) {
BookmarkButton* button = new BookmarkButton(this,
node->GetURL(),
@@ -1259,7 +1260,7 @@ views::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) {
}
}
-void BookmarkBarView::ConfigureButton(BookmarkNode* node,
+void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
views::TextButton* button) {
button->SetText(node->GetTitle());
@@ -1325,7 +1326,7 @@ void BookmarkBarView::NotifyModelChanged() {
model_changed_listener_->ModelChanged();
}
-void BookmarkBarView::ShowDropFolderForNode(BookmarkNode* node) {
+void BookmarkBarView::ShowDropFolderForNode(const BookmarkNode* node) {
if (bookmark_drop_menu_) {
if (bookmark_drop_menu_->node() == node) {
// Already showing for the specified node.
@@ -1388,7 +1389,7 @@ void BookmarkBarView::StopShowFolderDropMenuTimer() {
show_folder_drop_menu_task_->Cancel();
}
-void BookmarkBarView::StartShowFolderDropMenuTimer(BookmarkNode* node) {
+void BookmarkBarView::StartShowFolderDropMenuTimer(const BookmarkNode* node) {
if (testing_) {
// So that tests can run as fast as possible disable the delay during
// testing.
@@ -1462,7 +1463,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event,
int button_w = button->width();
if (button_x < button_w) {
found = true;
- BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(i);
+ const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(i);
if (node->is_folder()) {
if (button_x <= views::kDropBetweenPixels) {
*index = i;
@@ -1507,7 +1508,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event,
}
if (*drop_on) {
- BookmarkNode* parent =
+ const BookmarkNode* parent =
*is_over_other ? model_->other_node() :
model_->GetBookmarkBarNode()->GetChild(*index);
int operation =
@@ -1544,15 +1545,16 @@ void BookmarkBarView::StartThrobbing() {
if (!GetWidget())
return; // We're not showing, don't do anything.
- BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(bubble_url_);
+ const BookmarkNode* node =
+ model_->GetMostRecentlyAddedNodeForURL(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())) {
- BookmarkNode* bbn = model_->GetBookmarkBarNode();
- BookmarkNode* parent_on_bb = node;
+ const BookmarkNode* bbn = model_->GetBookmarkBarNode();
+ const 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 c747610..e53a2db 100644
--- a/chrome/browser/views/bookmark_bar_view.h
+++ b/chrome/browser/views/bookmark_bar_view.h
@@ -184,7 +184,7 @@ class BookmarkBarView : public views::View,
// deletes itself once run.
class ShowFolderDropMenuTask : public Task {
public:
- ShowFolderDropMenuTask(BookmarkBarView* view, BookmarkNode* node)
+ ShowFolderDropMenuTask(BookmarkBarView* view, const BookmarkNode* node)
: view_(view),
node_(node) {
}
@@ -204,7 +204,7 @@ class BookmarkBarView : public views::View,
private:
BookmarkBarView* view_;
- BookmarkNode* node_;
+ const BookmarkNode* node_;
DISALLOW_COPY_AND_ASSIGN(ShowFolderDropMenuTask);
};
@@ -233,51 +233,51 @@ class BookmarkBarView : public views::View,
// Invokes added followed by removed.
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const 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(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
// Implementation for BookmarkNodeAddedImpl.
void BookmarkNodeAddedImpl(BookmarkModel* model,
- BookmarkNode* parent,
+ const 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(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
// Implementation for BookmarkNodeRemoved.
void BookmarkNodeRemovedImpl(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
// Notifies ModelChangedListener and invokes BookmarkNodeChangedImpl.
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// If the node is a child of the root node, the button is updated
// appropriately.
- void BookmarkNodeChangedImpl(BookmarkModel* model, BookmarkNode* node);
+ void BookmarkNodeChangedImpl(BookmarkModel* model, const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const 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(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// DragController method. Determines the node representing sender and invokes
// WriteDragData to write the actual data.
@@ -287,7 +287,7 @@ class BookmarkBarView : public views::View,
OSExchangeData* data);
// Writes a BookmarkDragData for node to data.
- void WriteDragData(BookmarkNode* node, OSExchangeData* data);
+ void WriteDragData(const BookmarkNode* node, OSExchangeData* data);
// Returns the drag operations for the specified button.
virtual int GetDragOperations(views::View* sender, int x, int y);
@@ -313,11 +313,11 @@ class BookmarkBarView : public views::View,
bool is_mouse_gesture);
// Creates the button for rendering the specified bookmark node.
- views::View* CreateBookmarkButton(BookmarkNode* node);
+ views::View* CreateBookmarkButton(const BookmarkNode* node);
// COnfigures the button from the specified node. This sets the text,
// and icon.
- void ConfigureButton(BookmarkNode* node, views::TextButton* button);
+ void ConfigureButton(const BookmarkNode* node, views::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
@@ -337,13 +337,13 @@ class BookmarkBarView : public views::View,
void NotifyModelChanged();
// Shows the menu used during drag and drop for the specified node.
- void ShowDropFolderForNode(BookmarkNode* node);
+ void ShowDropFolderForNode(const 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(BookmarkNode* node);
+ void StartShowFolderDropMenuTimer(const 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.
diff --git a/chrome/browser/views/bookmark_bar_view_test.cc b/chrome/browser/views/bookmark_bar_view_test.cc
index 73eb686..8313920 100644
--- a/chrome/browser/views/bookmark_bar_view_test.cc
+++ b/chrome/browser/views/bookmark_bar_view_test.cc
@@ -137,9 +137,10 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase {
void AddTestData(bool big_menu) {
std::string test_base = "file:///c:/tmp/";
- BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 0, L"F1");
+ const BookmarkNode* f1 = model_->AddGroup(
+ model_->GetBookmarkBarNode(), 0, L"F1");
model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a"));
- BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11");
+ const 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) {
@@ -156,10 +157,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"));
- BookmarkNode* of = model_->AddGroup(model_->other_node(), 1, L"OF");
+ const 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"));
- BookmarkNode* of2 = model_->AddGroup(model_->other_node(), 2, L"OF2");
+ const 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 9a2a8f6..69af750 100644
--- a/chrome/browser/views/bookmark_bubble_view.cc
+++ b/chrome/browser/views/bookmark_bubble_view.cc
@@ -74,7 +74,7 @@ bool IsBookmarkBubbleViewShowing() {
// RecentlyUsedFoldersModel ---------------------------------------------------
BookmarkBubbleView::RecentlyUsedFoldersModel::RecentlyUsedFoldersModel(
- BookmarkModel* bb_model, BookmarkNode* node)
+ BookmarkModel* bb_model, const BookmarkNode* node)
// Use + 2 to account for bookmark bar and other node.
: nodes_(bookmark_utils::GetMostRecentlyModifiedGroups(
bb_model, kMaxMRUFolders + 2)),
@@ -117,14 +117,14 @@ std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt(
return nodes_[index]->GetTitle();
}
-BookmarkNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt(
+const BookmarkNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt(
int index) {
return nodes_[index];
}
void BookmarkBubbleView::RecentlyUsedFoldersModel::RemoveNode(
- BookmarkNode* node) {
- std::vector<BookmarkNode*>::iterator i =
+ const BookmarkNode* node) {
+ std::vector<const BookmarkNode*>::iterator i =
find(nodes_.begin(), nodes_.end(), node);
if (i != nodes_.end())
nodes_.erase(i);
@@ -169,7 +169,7 @@ BookmarkBubbleView::~BookmarkBubbleView() {
ApplyEdits();
} else if (remove_bookmark_) {
BookmarkModel* model = profile_->GetBookmarkModel();
- BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
+ const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
if (node)
model->Remove(node->GetParent(), node->GetParent()->IndexOfChild(node));
}
@@ -304,7 +304,8 @@ void BookmarkBubbleView::Init() {
std::wstring BookmarkBubbleView::GetTitle() {
BookmarkModel* bookmark_model= profile_->GetBookmarkModel();
- BookmarkNode* node = bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
+ const BookmarkNode* node =
+ bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
if (node)
return node->GetTitle();
else
@@ -374,7 +375,7 @@ void BookmarkBubbleView::Close() {
}
void BookmarkBubbleView::ShowEditor() {
- BookmarkNode* node =
+ const BookmarkNode* node =
profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_);
// Commit any edits now.
@@ -408,7 +409,7 @@ void BookmarkBubbleView::ApplyEdits() {
apply_edits_ = false;
BookmarkModel* model = profile_->GetBookmarkModel();
- BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
+ const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
if (node) {
const std::wstring new_title = title_tf_->text();
if (new_title != node->GetTitle()) {
@@ -419,7 +420,7 @@ void BookmarkBubbleView::ApplyEdits() {
// Last index means 'Choose another folder...'
if (parent_combobox_->selected_item() <
parent_model_.GetItemCount(parent_combobox_) - 1) {
- BookmarkNode* new_parent =
+ const BookmarkNode* new_parent =
parent_model_.GetNodeAt(parent_combobox_->selected_item());
if (new_parent != node->GetParent()) {
UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_);
diff --git a/chrome/browser/views/bookmark_bubble_view.h b/chrome/browser/views/bookmark_bubble_view.h
index 5083a52..517aea9 100644
--- a/chrome/browser/views/bookmark_bubble_view.h
+++ b/chrome/browser/views/bookmark_bubble_view.h
@@ -62,23 +62,23 @@ class BookmarkBubbleView : public views::View,
// also contains an extra item that shows the text 'Choose another folder...'.
class RecentlyUsedFoldersModel : public views::Combobox::Model {
public:
- RecentlyUsedFoldersModel(BookmarkModel* bb_model, BookmarkNode* node);
+ RecentlyUsedFoldersModel(BookmarkModel* bb_model, const BookmarkNode* node);
// Combobox::Model methods. Call through to nodes_.
virtual int GetItemCount(views::Combobox* source);
virtual std::wstring GetItemAt(views::Combobox* source, int index);
// Returns the node at the specified index.
- BookmarkNode* GetNodeAt(int index);
+ const 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(BookmarkNode* node);
+ void RemoveNode(const BookmarkNode* node);
- std::vector<BookmarkNode*> nodes_;
+ std::vector<const BookmarkNode*> nodes_;
int node_parent_index_;
DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersModel);
diff --git a/chrome/browser/views/bookmark_context_menu.cc b/chrome/browser/views/bookmark_context_menu.cc
index a29336b..9d9ca29 100644
--- a/chrome/browser/views/bookmark_context_menu.cc
+++ b/chrome/browser/views/bookmark_context_menu.cc
@@ -30,7 +30,7 @@ namespace {
// Returns true if the specified node is of type URL, or has a descendant
// of type URL.
-bool NodeHasURLs(BookmarkNode* node) {
+bool NodeHasURLs(const BookmarkNode* node) {
if (node->is_url())
return true;
@@ -57,7 +57,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
static void Show(Profile* profile,
gfx::NativeView wnd,
- BookmarkNode* node,
+ const BookmarkNode* node,
bool is_new,
bool show_in_manager) {
// EditFolderController deletes itself when done.
@@ -69,7 +69,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
private:
EditFolderController(Profile* profile,
gfx::NativeView wnd,
- BookmarkNode* node,
+ const BookmarkNode* node,
bool is_new,
bool show_in_manager)
: profile_(profile),
@@ -103,7 +103,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
virtual void InputAccepted(const std::wstring& text) {
if (is_new_) {
- ALLOW_UNUSED BookmarkNode* node =
+ ALLOW_UNUSED const BookmarkNode* node =
model_->AddGroup(node_, node_->GetChildCount(), text);
if (show_in_manager_) {
#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS))
@@ -130,35 +130,36 @@ class EditFolderController : public InputWindowDialog::Delegate,
}
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
ModelChanged();
}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
ModelChanged();
}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
ModelChanged();
}
- virtual void BookmarkNodeChanged(BookmarkModel* model, BookmarkNode* node) {
+ virtual void BookmarkNodeChanged(BookmarkModel* model,
+ const BookmarkNode* node) {
ModelChanged();
}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
ModelChanged();
}
@@ -170,7 +171,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
BookmarkModel* model_;
// 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.
- BookmarkNode* node_;
+ const BookmarkNode* node_;
bool is_new_;
@@ -192,7 +193,7 @@ class SelectOnCreationHandler : public BookmarkEditor::Handler {
explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) {
}
- virtual void NodeCreated(BookmarkNode* new_node) {
+ virtual void NodeCreated(const BookmarkNode* new_node) {
BookmarkManager::SelectInTree(profile_, new_node);
}
@@ -212,8 +213,8 @@ BookmarkContextMenu::BookmarkContextMenu(
Profile* profile,
Browser* browser,
PageNavigator* navigator,
- BookmarkNode* parent,
- const std::vector<BookmarkNode*>& selection,
+ const BookmarkNode* parent,
+ const std::vector<const BookmarkNode*>& selection,
ConfigurationType configuration)
: wnd_(wnd),
profile_(profile),
@@ -502,33 +503,33 @@ void BookmarkContextMenu::BookmarkModelBeingDeleted(BookmarkModel* model) {
}
void BookmarkContextMenu::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
ModelChanged();
}
void BookmarkContextMenu::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
ModelChanged();
}
void BookmarkContextMenu::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
ModelChanged();
}
void BookmarkContextMenu::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
ModelChanged();
}
-void BookmarkContextMenu::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+void BookmarkContextMenu::BookmarkNodeChildrenReordered(
+ BookmarkModel* model, const BookmarkNode* node) {
ModelChanged();
}
@@ -551,7 +552,7 @@ bool BookmarkContextMenu::HasURLs() const {
return false;
}
-BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const {
+const BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const {
return (selection_.size() == 1 && selection_[0]->is_folder()) ?
selection_[0] : parent_;
}
diff --git a/chrome/browser/views/bookmark_context_menu.h b/chrome/browser/views/bookmark_context_menu.h
index 9903f44..f9e6584 100644
--- a/chrome/browser/views/bookmark_context_menu.h
+++ b/chrome/browser/views/bookmark_context_menu.h
@@ -59,8 +59,8 @@ class BookmarkContextMenu : public BookmarkModelObserver,
Profile* profile,
Browser* browser,
PageNavigator* navigator,
- BookmarkNode* parent,
- const std::vector<BookmarkNode*>& selection,
+ const BookmarkNode* parent,
+ const std::vector<const BookmarkNode*>& selection,
ConfigurationType configuration);
virtual ~BookmarkContextMenu();
@@ -89,23 +89,23 @@ class BookmarkContextMenu : public BookmarkModelObserver,
virtual void Loaded(BookmarkModel* model) {}
virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
// Invoked from the various bookmark model observer methods. Closes the menu.
void ModelChanged();
@@ -131,14 +131,14 @@ class BookmarkContextMenu : public BookmarkModelObserver,
// Returns the parent for newly created folders/bookmarks. If selection_
// has one element and it is a folder, selection_[0] is returned, otherwise
// parent_ is returned.
- BookmarkNode* GetParentForNewNodes() const;
+ const BookmarkNode* GetParentForNewNodes() const;
gfx::NativeView wnd_;
Profile* profile_;
Browser* browser_;
PageNavigator* navigator_;
- BookmarkNode* parent_;
- std::vector<BookmarkNode*> selection_;
+ const BookmarkNode* parent_;
+ std::vector<const BookmarkNode*> selection_;
BookmarkModel* model_;
ConfigurationType configuration_;
diff --git a/chrome/browser/views/bookmark_context_menu_test.cc b/chrome/browser/views/bookmark_context_menu_test.cc
index 44b9609..217764c 100644
--- a/chrome/browser/views/bookmark_context_menu_test.cc
+++ b/chrome/browser/views/bookmark_context_menu_test.cc
@@ -86,14 +86,14 @@ class BookmarkContextMenuTest : public testing::Test {
model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a",
GURL(test_base + "a"));
- BookmarkNode* f1 =
+ const BookmarkNode* f1 =
model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1");
model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a"));
- BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11");
+ const 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");
model_->AddGroup(model_->GetBookmarkBarNode(), 3, L"F3");
- BookmarkNode* f4 =
+ const BookmarkNode* f4 =
model_->AddGroup(model_->GetBookmarkBarNode(), 4, L"F4");
model_->AddURL(f4, 0, L"f4a", GURL(test_base + "f4a"));
}
@@ -101,7 +101,7 @@ class BookmarkContextMenuTest : public testing::Test {
// Tests Deleting from the menu.
TEST_F(BookmarkContextMenuTest, DeleteURL) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0));
BookmarkContextMenu controller(
NULL, profile_.get(), NULL, NULL, nodes[0]->GetParent(), nodes,
@@ -116,7 +116,7 @@ TEST_F(BookmarkContextMenuTest, DeleteURL) {
// Tests open all on a folder with a couple of bookmarks.
TEST_F(BookmarkContextMenuTest, OpenAll) {
- BookmarkNode* folder = model_->GetBookmarkBarNode()->GetChild(1);
+ const BookmarkNode* folder = model_->GetBookmarkBarNode()->GetChild(1);
bookmark_utils::OpenAll(
NULL, profile_.get(), &navigator_, folder, NEW_FOREGROUND_TAB);
@@ -131,7 +131,7 @@ TEST_F(BookmarkContextMenuTest, OpenAll) {
TEST_F(BookmarkContextMenuTest, EmptyNodes) {
BookmarkContextMenu controller(
NULL, profile_.get(), NULL, NULL, model_->other_node(),
- std::vector<BookmarkNode*>(), BookmarkContextMenu::BOOKMARK_BAR);
+ std::vector<const BookmarkNode*>(), BookmarkContextMenu::BOOKMARK_BAR);
EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL));
EXPECT_FALSE(
controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW));
@@ -148,7 +148,7 @@ TEST_F(BookmarkContextMenuTest, EmptyNodes) {
// Tests the enabled state of the menus when supplied a vector with a single
// url.
TEST_F(BookmarkContextMenuTest, SingleURL) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0));
BookmarkContextMenu controller(
NULL, profile_.get(), NULL, NULL, nodes[0]->GetParent(),
@@ -169,7 +169,7 @@ TEST_F(BookmarkContextMenuTest, SingleURL) {
// Tests the enabled state of the menus when supplied a vector with multiple
// urls.
TEST_F(BookmarkContextMenuTest, MultipleURLs) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0));
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(1)->GetChild(0));
BookmarkContextMenu controller(
@@ -191,7 +191,7 @@ TEST_F(BookmarkContextMenuTest, MultipleURLs) {
// Tests the enabled state of the menus when supplied an vector with a single
// folder.
TEST_F(BookmarkContextMenuTest, SingleFolder) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2));
BookmarkContextMenu controller(
NULL, profile_.get(), NULL, NULL, nodes[0]->GetParent(),
@@ -212,7 +212,7 @@ TEST_F(BookmarkContextMenuTest, SingleFolder) {
// Tests the enabled state of the menus when supplied a vector with multiple
// folders, all of which are empty.
TEST_F(BookmarkContextMenuTest, MultipleEmptyFolders) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2));
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3));
BookmarkContextMenu controller(
@@ -234,7 +234,7 @@ TEST_F(BookmarkContextMenuTest, MultipleEmptyFolders) {
// Tests the enabled state of the menus when supplied a vector with multiple
// folders, some of which contain URLs.
TEST_F(BookmarkContextMenuTest, MultipleFoldersWithURLs) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3));
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(4));
BookmarkContextMenu controller(
@@ -255,7 +255,7 @@ TEST_F(BookmarkContextMenuTest, MultipleFoldersWithURLs) {
// Tests the enabled state of open incognito.
TEST_F(BookmarkContextMenuTest, DisableIncognito) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0));
BookmarkContextMenu controller(
NULL, profile_.get(), NULL, NULL, nodes[0]->GetParent(),
@@ -267,7 +267,7 @@ TEST_F(BookmarkContextMenuTest, DisableIncognito) {
// Tests that you can't remove/edit when showing the other node.
TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(model_->other_node());
BookmarkContextMenu controller(
NULL, profile_.get(), NULL, NULL, nodes[0], nodes,
@@ -280,7 +280,8 @@ TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) {
// parent.
TEST_F(BookmarkContextMenuTest, EmptyNodesNullParent) {
BookmarkContextMenu controller(
- NULL, profile_.get(), NULL, NULL, NULL, std::vector<BookmarkNode*>(),
+ NULL, profile_.get(), NULL, NULL, NULL,
+ std::vector<const BookmarkNode*>(),
BookmarkContextMenu::BOOKMARK_MANAGER_ORGANIZE_MENU);
EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL));
EXPECT_FALSE(
diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc
index 3208099..ed51083 100644
--- a/chrome/browser/views/bookmark_editor_view.cc
+++ b/chrome/browser/views/bookmark_editor_view.cc
@@ -47,8 +47,8 @@ static const int kNewGroupButtonID = 1002;
// static
void BookmarkEditor::Show(HWND parent_hwnd,
Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
Configuration configuration,
Handler* handler) {
DCHECK(profile);
@@ -59,8 +59,8 @@ void BookmarkEditor::Show(HWND parent_hwnd,
BookmarkEditorView::BookmarkEditorView(
Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler)
: profile_(profile),
@@ -339,23 +339,23 @@ void BookmarkEditorView::Init() {
}
void BookmarkEditorView::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {
Reset();
}
void BookmarkEditorView::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {
Reset();
}
void BookmarkEditorView::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node) {
+ const BookmarkNode* node) {
if ((node_ && node_->HasAncestor(node)) ||
(parent_ && parent_->HasAncestor(node))) {
// The node, or its parent was removed. Close the dialog.
@@ -365,8 +365,8 @@ void BookmarkEditorView::BookmarkNodeRemoved(BookmarkModel* model,
}
}
-void BookmarkEditorView::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
+void BookmarkEditorView::BookmarkNodeChildrenReordered(
+ BookmarkModel* model, const BookmarkNode* node) {
Reset();
}
@@ -440,7 +440,7 @@ BookmarkEditorView::EditorNode* BookmarkEditorView::AddNewGroup(
void BookmarkEditorView::ExpandAndSelect() {
tree_view_->ExpandAll();
- BookmarkNode* to_select = node_ ? node_->GetParent() : parent_;
+ const BookmarkNode* to_select = node_ ? node_->GetParent() : parent_;
int group_id_to_select = to_select->id();
DCHECK(group_id_to_select); // GetMostRecentParent should never return NULL.
EditorNode* b_node =
@@ -453,7 +453,7 @@ void BookmarkEditorView::ExpandAndSelect() {
BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() {
EditorNode* root_node = new EditorNode(std::wstring(), 0);
- BookmarkNode* bb_root_node = bb_model_->root_node();
+ const 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() ==
@@ -462,10 +462,10 @@ BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() {
return root_node;
}
-void BookmarkEditorView::CreateNodes(BookmarkNode* bb_node,
+void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node,
BookmarkEditorView::EditorNode* b_node) {
for (int i = 0; i < bb_node->GetChildCount(); ++i) {
- BookmarkNode* child_bb_node = bb_node->GetChild(i);
+ const BookmarkNode* child_bb_node = bb_node->GetChild(i);
if (child_bb_node->is_folder()) {
EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(),
child_bb_node->id());
@@ -518,7 +518,7 @@ void BookmarkEditorView::ApplyEdits(EditorNode* parent) {
}
// Create the new groups and update the titles.
- BookmarkNode* new_parent = NULL;
+ const BookmarkNode* new_parent = NULL;
ApplyNameChangesAndCreateNewGroups(
bb_model_->root_node(), tree_model_->GetRoot(), parent, &new_parent);
@@ -527,15 +527,15 @@ void BookmarkEditorView::ApplyEdits(EditorNode* parent) {
}
void BookmarkEditorView::ApplyNameChangesAndCreateNewGroups(
- BookmarkNode* bb_node,
+ const BookmarkNode* bb_node,
BookmarkEditorView::EditorNode* b_node,
BookmarkEditorView::EditorNode* parent_b_node,
- BookmarkNode** parent_bb_node) {
+ const BookmarkNode** parent_bb_node) {
if (parent_b_node == b_node)
*parent_bb_node = bb_node;
for (int i = 0; i < b_node->GetChildCount(); ++i) {
EditorNode* child_b_node = b_node->GetChild(i);
- BookmarkNode* child_bb_node = NULL;
+ const BookmarkNode* child_bb_node = NULL;
if (child_b_node->value == 0) {
// New group.
child_bb_node = bb_model_->AddGroup(bb_node,
@@ -544,7 +544,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) {
- BookmarkNode* node = bb_node->GetChild(j);
+ const 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 51ef925..a03d3e9 100644
--- a/chrome/browser/views/bookmark_editor_view.h
+++ b/chrome/browser/views/bookmark_editor_view.h
@@ -54,8 +54,8 @@ class BookmarkEditorView : public BookmarkEditor,
FRIEND_TEST(BookmarkEditorViewTest, ChangeTitleNoTree);
public:
BookmarkEditorView(Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
+ const BookmarkNode* parent,
+ const BookmarkNode* node,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler);
@@ -140,23 +140,23 @@ class BookmarkEditorView : public BookmarkEditor,
// resetting the tree model.
virtual void Loaded(BookmarkModel* model) { }
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
// Resets the model of the tree and updates the various buttons appropriately.
void Reset();
@@ -172,7 +172,7 @@ class BookmarkEditorView : public BookmarkEditor,
// Adds and creates a child node in b_node for all children of bb_node that
// are groups.
- void CreateNodes(BookmarkNode* bb_node, EditorNode* b_node);
+ void CreateNodes(const BookmarkNode* bb_node, EditorNode* b_node);
// Returns the node with the specified id, or NULL if one can't be found.
EditorNode* FindNodeWithID(BookmarkEditorView::EditorNode* node, int id);
@@ -194,10 +194,10 @@ class BookmarkEditorView : public BookmarkEditor,
// used to determine the new BookmarkNode parent based on the EditorNode
// parent.
void ApplyNameChangesAndCreateNewGroups(
- BookmarkNode* bb_node,
+ const BookmarkNode* bb_node,
BookmarkEditorView::EditorNode* b_node,
BookmarkEditorView::EditorNode* parent_b_node,
- BookmarkNode** parent_bb_node);
+ const BookmarkNode** parent_bb_node);
// Returns the current url the user has input.
GURL GetInputURL() const;
@@ -238,10 +238,10 @@ class BookmarkEditorView : public BookmarkEditor,
views::Textfield title_tf_;
// Initial parent to select. Is only used if node_ is NULL.
- BookmarkNode* parent_;
+ const BookmarkNode* parent_;
// Node being edited. Is NULL if creating a new node.
- BookmarkNode* node_;
+ const BookmarkNode* node_;
// The context menu.
scoped_ptr<views::SimpleMenuModel> context_menu_contents_;
diff --git a/chrome/browser/views/bookmark_editor_view_unittest.cc b/chrome/browser/views/bookmark_editor_view_unittest.cc
index 4024c34..22570bb 100644
--- a/chrome/browser/views/bookmark_editor_view_unittest.cc
+++ b/chrome/browser/views/bookmark_editor_view_unittest.cc
@@ -41,10 +41,14 @@ class BookmarkEditorViewTest : public testing::Test {
std::string base_path() const { return "file:///c:/tmp/"; }
- BookmarkNode* GetNode(const std::string& name) {
+ const BookmarkNode* GetNode(const std::string& name) {
return model_->GetMostRecentlyAddedNodeForURL(GURL(base_path() + name));
}
+ BookmarkNode* GetMutableNode(const std::string& name) {
+ return const_cast<BookmarkNode*>(GetNode(name));
+ }
+
private:
// Creates the following structure:
// bookmark bar node
@@ -63,16 +67,18 @@ class BookmarkEditorViewTest : public testing::Test {
model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a",
GURL(test_base + "a"));
- BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1");
+ const BookmarkNode* f1 =
+ model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1");
model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a"));
- BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11");
+ const 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"));
- BookmarkNode* of1 = model_->AddGroup(model_->other_node(), 1, L"OF1");
+ const BookmarkNode* of1 =
+ model_->AddGroup(model_->other_node(), 1, L"OF1");
model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a"));
}
};
@@ -110,7 +116,8 @@ TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) {
editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0));
- BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
+ const 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());
@@ -119,7 +126,7 @@ TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) {
// Changes the url and makes sure parent/visual order doesn't change.
TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) {
Time node_time = Time::Now() + TimeDelta::FromDays(2);
- GetNode("a")->date_added_ = node_time;
+ GetMutableNode("a")->set_date_added(node_time);
BookmarkEditorView editor(profile_.get(), NULL, GetNode("a"),
BookmarkEditorView::SHOW_TREE, NULL);
@@ -127,7 +134,8 @@ TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) {
editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0));
- BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
+ const 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());
@@ -141,7 +149,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParent) {
editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(1));
- BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
+ const 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());
}
@@ -149,7 +157,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParent) {
// Moves 'a' to be a child of the other node and changes its url to new_a.
TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) {
Time node_time = Time::Now() + TimeDelta::FromDays(2);
- GetNode("a")->date_added_ = node_time;
+ GetMutableNode("a")->set_date_added(node_time);
BookmarkEditorView editor(profile_.get(), NULL, GetNode("a"),
BookmarkEditorView::SHOW_TREE, NULL);
@@ -157,7 +165,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) {
editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(1));
- BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
+ const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle());
ASSERT_TRUE(GURL(base_path() + "new_a") == other_node->GetChild(2)->GetURL());
ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added());
@@ -179,8 +187,9 @@ TEST_F(BookmarkEditorViewTest, MoveToNewParent) {
// Parent the node to "F21".
editor.ApplyEdits(f2);
- BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
- BookmarkNode* mf2 = bb_node->GetChild(1);
+ const BookmarkNode* bb_node =
+ profile_->GetBookmarkModel()->GetBookmarkBarNode();
+ const 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());
@@ -190,7 +199,7 @@ TEST_F(BookmarkEditorViewTest, MoveToNewParent) {
ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle());
// F21 should have one child, F211.
- BookmarkNode* mf21 = mf2->GetChild(0);
+ const BookmarkNode* mf21 = mf2->GetChild(0);
ASSERT_EQ(1, mf21->GetChildCount());
ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle());
}
@@ -205,10 +214,11 @@ TEST_F(BookmarkEditorViewTest, NewURL) {
editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0));
- BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
+ const BookmarkNode* bb_node =
+ profile_->GetBookmarkModel()->GetBookmarkBarNode();
ASSERT_EQ(4, bb_node->GetChildCount());
- BookmarkNode* new_node = bb_node->GetChild(3);
+ const BookmarkNode* new_node = bb_node->GetChild(3);
EXPECT_EQ(L"new_a", new_node->GetTitle());
EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL());
@@ -225,10 +235,10 @@ TEST_F(BookmarkEditorViewTest, ChangeURLNoTree) {
editor.ApplyEdits(NULL);
- BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
+ const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
ASSERT_EQ(2, other_node->GetChildCount());
- BookmarkNode* new_node = other_node->GetChild(0);
+ const BookmarkNode* new_node = other_node->GetChild(0);
EXPECT_EQ(L"new_a", new_node->GetTitle());
EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL());
@@ -244,10 +254,10 @@ TEST_F(BookmarkEditorViewTest, ChangeTitleNoTree) {
editor.ApplyEdits(NULL);
- BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
+ const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
ASSERT_EQ(2, other_node->GetChildCount());
- BookmarkNode* new_node = other_node->GetChild(0);
+ const BookmarkNode* new_node = other_node->GetChild(0);
EXPECT_EQ(L"new_a", new_node->GetTitle());
}
diff --git a/chrome/browser/views/bookmark_folder_tree_view.cc b/chrome/browser/views/bookmark_folder_tree_view.cc
index eda92f5..bd464c8 100644
--- a/chrome/browser/views/bookmark_folder_tree_view.cc
+++ b/chrome/browser/views/bookmark_folder_tree_view.cc
@@ -78,7 +78,7 @@ int BookmarkFolderTreeView::OnPerformDrop(const views::DropTargetEvent& event) {
return drop_operation;
}
-BookmarkNode* BookmarkFolderTreeView::GetSelectedBookmarkNode() {
+const BookmarkNode* BookmarkFolderTreeView::GetSelectedBookmarkNode() {
TreeModelNode* selected_node = GetSelectedNode();
if (!selected_node)
return NULL;
@@ -113,7 +113,7 @@ int BookmarkFolderTreeView::UpdateDropInfo() {
return drop_info_->drop_operation();
}
-void BookmarkFolderTreeView::BeginDrag(BookmarkNode* node) {
+void BookmarkFolderTreeView::BeginDrag(const BookmarkNode* node) {
BookmarkModel* model = profile_->GetBookmarkModel();
// Only allow the drag if the user has selected a node of type bookmark and it
// isn't the bookmark bar or other bookmarks folders.
@@ -122,7 +122,7 @@ void BookmarkFolderTreeView::BeginDrag(BookmarkNode* node) {
return;
}
- std::vector<BookmarkNode*> nodes_to_drag;
+ std::vector<const BookmarkNode*> nodes_to_drag;
nodes_to_drag.push_back(node);
scoped_refptr<OSExchangeData> data = new OSExchangeData;
@@ -212,7 +212,7 @@ int BookmarkFolderTreeView::CalculateDropOperation(
}
void BookmarkFolderTreeView::OnPerformDropImpl() {
- BookmarkNode* parent_node =
+ const BookmarkNode* parent_node =
TreeNodeAsBookmarkNode(drop_info_->position().parent);
int drop_index = FolderIndexToBookmarkIndex(drop_info_->position());
BookmarkModel* model = profile_->GetBookmarkModel();
@@ -226,7 +226,8 @@ void BookmarkFolderTreeView::OnPerformDropImpl() {
}
// else, move.
- std::vector<BookmarkNode*> nodes = drop_info_->data().GetNodes(profile_);
+ std::vector<const BookmarkNode*> nodes =
+ drop_info_->data().GetNodes(profile_);
if (nodes.empty())
return;
@@ -286,13 +287,14 @@ BookmarkFolderTreeModel* BookmarkFolderTreeView::folder_model() const {
return static_cast<BookmarkFolderTreeModel*>(model());
}
-BookmarkNode* BookmarkFolderTreeView::TreeNodeAsBookmarkNode(FolderNode* node) {
+const BookmarkNode* BookmarkFolderTreeView::TreeNodeAsBookmarkNode(
+ FolderNode* node) {
return folder_model()->TreeNodeAsBookmarkNode(node);
}
int BookmarkFolderTreeView::FolderIndexToBookmarkIndex(
const DropPosition& position) {
- BookmarkNode* parent_node = TreeNodeAsBookmarkNode(position.parent);
+ const BookmarkNode* parent_node = TreeNodeAsBookmarkNode(position.parent);
if (position.on || position.index == position.parent->GetChildCount())
return parent_node->GetChildCount();
diff --git a/chrome/browser/views/bookmark_folder_tree_view.h b/chrome/browser/views/bookmark_folder_tree_view.h
index 2a47b1b..93f5205 100644
--- a/chrome/browser/views/bookmark_folder_tree_view.h
+++ b/chrome/browser/views/bookmark_folder_tree_view.h
@@ -32,7 +32,7 @@ class BookmarkFolderTreeView : public views::TreeView {
// Returns the selected node as a BookmarkNode. This returns NULL if the
// selected node is not of type BookmarkFolderTreeModel::BOOKMARK or
// nothing is selected.
- BookmarkNode* GetSelectedBookmarkNode();
+ const BookmarkNode* GetSelectedBookmarkNode();
protected:
// Overriden to start a drag.
@@ -96,7 +96,7 @@ class BookmarkFolderTreeView : public views::TreeView {
int UpdateDropInfo();
// Starts a drag operation for the specified node.
- void BeginDrag(BookmarkNode* node);
+ void BeginDrag(const BookmarkNode* node);
// Calculates the drop position.
DropPosition CalculateDropPosition(int y, bool only_folders);
@@ -115,7 +115,7 @@ class BookmarkFolderTreeView : public views::TreeView {
BookmarkFolderTreeModel* folder_model() const;
// Converts FolderNode into a BookmarkNode.
- BookmarkNode* TreeNodeAsBookmarkNode(FolderNode* node);
+ const BookmarkNode* TreeNodeAsBookmarkNode(FolderNode* node);
// Converts the position in terms of the BookmarkFolderTreeModel to an index
// in terms of the BookmarkModel. The returned index is the index the drop
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index 3582b86..b873249 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -80,7 +80,7 @@ class ImportObserverImpl : public ImportObserver {
BookmarkModel* model = profile_->GetBookmarkModel();
int other_count = model->other_node()->GetChildCount();
if (other_count == initial_other_count_ + 1) {
- BookmarkNode* imported_node =
+ const BookmarkNode* imported_node =
model->other_node()->GetChild(initial_other_count_);
manager->SelectInTree(imported_node);
manager->ExpandAll(imported_node);
@@ -145,7 +145,7 @@ void ShowBookmarkManagerView(Profile* profile) {
// BookmarkManager -------------------------------------------------------------
-void BookmarkManager::SelectInTree(Profile* profile, BookmarkNode* node) {
+void BookmarkManager::SelectInTree(Profile* profile, const BookmarkNode* node) {
if (manager && manager->profile() == profile)
manager->SelectInTree(node);
}
@@ -276,11 +276,11 @@ BookmarkManagerView* BookmarkManagerView::current() {
return manager;
}
-void BookmarkManagerView::SelectInTree(BookmarkNode* node) {
+void BookmarkManagerView::SelectInTree(const BookmarkNode* node) {
if (!node)
return;
- BookmarkNode* parent = node->is_url() ? node->GetParent() : node;
+ const BookmarkNode* parent = node->is_url() ? node->GetParent() : node;
FolderNode* folder_node = tree_model_->GetFolderNodeForBookmarkNode(parent);
if (!folder_node) {
NOTREACHED();
@@ -298,8 +298,8 @@ void BookmarkManagerView::SelectInTree(BookmarkNode* node) {
}
}
-void BookmarkManagerView::ExpandAll(BookmarkNode* node) {
- BookmarkNode* parent = node->is_url() ? node->GetParent() : node;
+void BookmarkManagerView::ExpandAll(const BookmarkNode* node) {
+ const BookmarkNode* parent = node->is_url() ? node->GetParent() : node;
FolderNode* folder_node = tree_model_->GetFolderNodeForBookmarkNode(parent);
if (!folder_node) {
NOTREACHED();
@@ -308,12 +308,12 @@ void BookmarkManagerView::ExpandAll(BookmarkNode* node) {
tree_view_->ExpandAll(folder_node);
}
-BookmarkNode* BookmarkManagerView::GetSelectedFolder() {
+const BookmarkNode* BookmarkManagerView::GetSelectedFolder() {
return tree_view_->GetSelectedBookmarkNode();
}
-std::vector<BookmarkNode*> BookmarkManagerView::GetSelectedTableNodes() {
- std::vector<BookmarkNode*> nodes;
+std::vector<const BookmarkNode*> BookmarkManagerView::GetSelectedTableNodes() {
+ std::vector<const BookmarkNode*> nodes;
for (views::TableView::iterator i = table_view_->SelectionBegin();
i != table_view_->SelectionEnd(); ++i) {
nodes.push_back(table_model_->GetNodeForRow(*i));
@@ -362,7 +362,7 @@ bool BookmarkManagerView::AcceleratorPressed(
}
void BookmarkManagerView::OnDoubleClick() {
- std::vector<BookmarkNode*> nodes = GetSelectedTableNodes();
+ std::vector<const BookmarkNode*> nodes = GetSelectedTableNodes();
if (nodes.empty())
return;
if (nodes.size() == 1 && nodes[0]->is_folder()) {
@@ -378,7 +378,7 @@ void BookmarkManagerView::OnDoubleClick() {
}
void BookmarkManagerView::OnMiddleClick() {
- std::vector<BookmarkNode*> nodes = GetSelectedTableNodes();
+ std::vector<const BookmarkNode*> nodes = GetSelectedTableNodes();
if (nodes.empty())
return;
if (nodes.size() == 1 && nodes[0]->is_folder()) {
@@ -391,7 +391,7 @@ void BookmarkManagerView::OnMiddleClick() {
}
void BookmarkManagerView::OnTableViewDelete(views::TableView* table) {
- std::vector<BookmarkNode*> nodes = GetSelectedTableNodes();
+ std::vector<const BookmarkNode*> nodes = GetSelectedTableNodes();
if (nodes.empty())
return;
for (size_t i = 0; i < nodes.size(); ++i) {
@@ -403,7 +403,7 @@ void BookmarkManagerView::OnTableViewDelete(views::TableView* table) {
void BookmarkManagerView::OnKeyDown(unsigned short virtual_keycode) {
switch (virtual_keycode) {
case VK_RETURN: {
- std::vector<BookmarkNode*> selected_nodes = GetSelectedTableNodes();
+ std::vector<const BookmarkNode*> selected_nodes = GetSelectedTableNodes();
if (selected_nodes.size() == 1 && selected_nodes[0]->is_folder()) {
SelectInTree(selected_nodes[0]);
} else {
@@ -415,7 +415,7 @@ void BookmarkManagerView::OnKeyDown(unsigned short virtual_keycode) {
}
case VK_BACK: {
- BookmarkNode* selected_folder = GetSelectedFolder();
+ const BookmarkNode* selected_folder = GetSelectedFolder();
if (selected_folder != NULL &&
selected_folder->GetParent() != GetBookmarkModel()->root_node()) {
SelectInTree(selected_folder->GetParent());
@@ -434,7 +434,7 @@ void BookmarkManagerView::OnTreeViewSelectionChanged(
TreeModelNode* node = tree_view_->GetSelectedNode();
BookmarkTableModel* new_table_model = NULL;
- BookmarkNode* table_parent_node = NULL;
+ const BookmarkNode* table_parent_node = NULL;
bool is_search = false;
if (node) {
@@ -470,11 +470,11 @@ void BookmarkManagerView::OnTreeViewSelectionChanged(
void BookmarkManagerView::OnTreeViewKeyDown(unsigned short virtual_keycode) {
switch (virtual_keycode) {
case VK_DELETE: {
- BookmarkNode* node = GetSelectedFolder();
+ const BookmarkNode* node = GetSelectedFolder();
if (!node || node->GetParent() == GetBookmarkModel()->root_node())
return;
- BookmarkNode* parent = node->GetParent();
+ const BookmarkNode* parent = node->GetParent();
GetBookmarkModel()->Remove(parent, parent->IndexOfChild(node));
break;
}
@@ -599,7 +599,7 @@ BookmarkTableModel* BookmarkManagerView::CreateSearchTableModel() {
}
void BookmarkManagerView::SetTableModel(BookmarkTableModel* new_table_model,
- BookmarkNode* parent_node,
+ const BookmarkNode* parent_node,
bool is_search) {
// Be sure and reset the model on the view before updating table_model_.
// Otherwise the view will attempt to use the deleted model when we set the
@@ -656,7 +656,7 @@ void BookmarkManagerView::PrepareForShow() {
void BookmarkManagerView::LoadedImpl() {
BookmarkModel* bookmark_model = GetBookmarkModel();
- BookmarkNode* bookmark_bar_node = bookmark_model->GetBookmarkBarNode();
+ const BookmarkNode* bookmark_bar_node = bookmark_model->GetBookmarkBarNode();
table_model_.reset(
BookmarkTableModel::CreateBookmarkTableModelForFolder(bookmark_model,
bookmark_bar_node));
@@ -693,8 +693,8 @@ void BookmarkManagerView::ShowMenu(
if (config == BookmarkContextMenu::BOOKMARK_MANAGER_TABLE ||
(config == BookmarkContextMenu::BOOKMARK_MANAGER_ORGANIZE_MENU &&
table_view_->HasFocus())) {
- std::vector<BookmarkNode*> nodes = GetSelectedTableNodes();
- BookmarkNode* parent = GetSelectedFolder();
+ std::vector<const BookmarkNode*> nodes = GetSelectedTableNodes();
+ const BookmarkNode* parent = GetSelectedFolder();
if (!parent) {
if (config == BookmarkContextMenu::BOOKMARK_MANAGER_TABLE)
config = BookmarkContextMenu::BOOKMARK_MANAGER_TABLE_OTHER;
@@ -705,8 +705,8 @@ void BookmarkManagerView::ShowMenu(
config);
menu.RunMenuAt(x, y);
} else {
- BookmarkNode* node = GetSelectedFolder();
- std::vector<BookmarkNode*> nodes;
+ const BookmarkNode* node = GetSelectedFolder();
+ std::vector<const BookmarkNode*> nodes;
if (node)
nodes.push_back(node);
BookmarkContextMenu menu(GetWidget()->GetNativeView(), profile_, NULL, NULL,
@@ -718,11 +718,11 @@ void BookmarkManagerView::ShowMenu(
void BookmarkManagerView::OnCutCopyPaste(CutCopyPasteType type,
bool from_table) {
if (type == CUT || type == COPY) {
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
if (from_table) {
nodes = GetSelectedTableNodes();
} else {
- BookmarkNode* node = GetSelectedFolder();
+ const BookmarkNode* node = GetSelectedFolder();
if (!node || node->GetParent() == GetBookmarkModel()->root_node())
return;
nodes.push_back(node);
diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h
index 2139a0b..a8f3ca6 100644
--- a/chrome/browser/views/bookmark_manager_view.h
+++ b/chrome/browser/views/bookmark_manager_view.h
@@ -62,16 +62,16 @@ class BookmarkManagerView : public views::View,
// Selects the specified node in the tree. If node is a URL it's parent is
// selected and node is selected in the table.
- void SelectInTree(BookmarkNode* node);
+ void SelectInTree(const BookmarkNode* node);
// Expands all the children of the selected folder.
- void ExpandAll(BookmarkNode* node);
+ void ExpandAll(const BookmarkNode* node);
// Returns the selected folder in the tree, which may be null.
- BookmarkNode* GetSelectedFolder();
+ const BookmarkNode* GetSelectedFolder();
// Returns the selection of the table.
- std::vector<BookmarkNode*> GetSelectedTableNodes();
+ std::vector<const BookmarkNode*> GetSelectedTableNodes();
virtual void PaintBackground(gfx::Canvas* canvas);
@@ -112,26 +112,26 @@ class BookmarkManagerView : public views::View,
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkModelBeingDeleted(BookmarkModel* model) {}
virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
+ const BookmarkNode* old_parent,
int old_index,
- BookmarkNode* new_parent,
+ const BookmarkNode* new_parent,
int new_index) {}
virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int index) {}
virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
+ const BookmarkNode* parent,
int old_index,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
+ const BookmarkNode* node) {}
// Textfield::Controller methods.
// Starts a timer to search for the search text.
@@ -165,7 +165,7 @@ class BookmarkManagerView : public views::View,
// Sets the model of the table and its parent node. If |is_search| is true,
// it means the table is showing search results.
void SetTableModel(BookmarkTableModel* new_table_model,
- BookmarkNode* parent_node,
+ const BookmarkNode* parent_node,
bool is_search);
// Sets the table's model to the results of CreateSearchTableModel and selects
diff --git a/chrome/browser/views/bookmark_menu_button.cc b/chrome/browser/views/bookmark_menu_button.cc
index 2b299cb..4a4889b 100644
--- a/chrome/browser/views/bookmark_menu_button.cc
+++ b/chrome/browser/views/bookmark_menu_button.cc
@@ -89,7 +89,7 @@ int BookmarkMenuButton::OnPerformDrop(const views::DropTargetEvent& event) {
if (!model)
return DragDropTypes::DRAG_NONE;
- BookmarkNode* parent = model->GetBookmarkBarNode();
+ const BookmarkNode* parent = model->GetBookmarkBarNode();
return bookmark_utils::PerformBookmarkDrop(
browser_->profile(), data, parent, parent->GetChildCount());
}
diff --git a/chrome/browser/views/bookmark_menu_controller_views.cc b/chrome/browser/views/bookmark_menu_controller_views.cc
index cd550ca..5fc5c97 100644
--- a/chrome/browser/views/bookmark_menu_controller_views.cc
+++ b/chrome/browser/views/bookmark_menu_controller_views.cc
@@ -22,7 +22,7 @@ BookmarkMenuController::BookmarkMenuController(Browser* browser,
Profile* profile,
PageNavigator* navigator,
gfx::NativeView parent,
- BookmarkNode* node,
+ const BookmarkNode* node,
int start_child_index,
bool show_other_folder)
: browser_(browser),
@@ -84,7 +84,7 @@ bool BookmarkMenuController::CanDrop(views::MenuItemView* menu,
if (drop_data_.has_single_url())
return true;
- BookmarkNode* drag_node = drop_data_.GetFirstNode(profile_);
+ const BookmarkNode* drag_node = drop_data_.GetFirstNode(profile_);
if (!drag_node) {
// Dragging a group from another profile, always accept.
return true;
@@ -92,7 +92,7 @@ bool BookmarkMenuController::CanDrop(views::MenuItemView* menu,
// 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.
- BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()];
+ const BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()];
DCHECK(drop_node);
while (drop_node && drop_node != drag_node)
drop_node = drop_node->GetParent();
@@ -106,8 +106,8 @@ int BookmarkMenuController::GetDropOperation(
// Should only get here if we have drop data.
DCHECK(drop_data_.is_valid());
- BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()];
- BookmarkNode* drop_parent = node->GetParent();
+ const BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()];
+ const BookmarkNode* drop_parent = node->GetParent();
int index_to_drop_at = drop_parent->IndexOfChild(node);
if (*position == DROP_AFTER) {
if (node == profile_->GetBookmarkModel()->other_node()) {
@@ -128,11 +128,11 @@ int BookmarkMenuController::GetDropOperation(
int BookmarkMenuController::OnPerformDrop(views::MenuItemView* menu,
DropPosition position,
const views::DropTargetEvent& event) {
- BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()];
+ const BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()];
DCHECK(drop_node);
BookmarkModel* model = profile_->GetBookmarkModel();
DCHECK(model);
- BookmarkNode* drop_parent = drop_node->GetParent();
+ const BookmarkNode* drop_parent = drop_node->GetParent();
DCHECK(drop_parent);
int index_to_drop_at = drop_parent->IndexOfChild(drop_node);
if (position == DROP_AFTER) {
@@ -156,7 +156,7 @@ bool BookmarkMenuController::ShowContextMenu(views::MenuItemView* source,
int y,
bool is_mouse_gesture) {
DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end());
- std::vector<BookmarkNode*> nodes;
+ std::vector<const BookmarkNode*> nodes;
nodes.push_back(menu_id_to_node_map_[id]);
context_menu_.reset(
new BookmarkContextMenu(parent_,
@@ -176,7 +176,7 @@ void BookmarkMenuController::DropMenuClosed(views::MenuItemView* menu) {
}
bool BookmarkMenuController::CanDrag(views::MenuItemView* menu) {
- BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()];
+ const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()];
// Don't let users drag the other folder.
return node->GetParent() != profile_->GetBookmarkModel()->root_node();
}
@@ -200,14 +200,14 @@ void BookmarkMenuController::BookmarkModelChanged() {
menu_->Cancel();
}
-void BookmarkMenuController::BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {
+void BookmarkMenuController::BookmarkNodeFavIconLoaded(
+ BookmarkModel* model, const BookmarkNode* node) {
if (node_to_menu_id_map_.find(node) != node_to_menu_id_map_.end())
menu_->SetIcon(model->GetFavIcon(node), node_to_menu_id_map_[node]);
}
void BookmarkMenuController::BuildOtherFolderMenu(int* next_menu_id) {
- BookmarkNode* other_folder = profile_->GetBookmarkModel()->other_node();
+ const BookmarkNode* other_folder = profile_->GetBookmarkModel()->other_node();
int id = *next_menu_id;
(*next_menu_id)++;
SkBitmap* folder_icon = ResourceBundle::GetSharedInstance().
@@ -218,14 +218,14 @@ void BookmarkMenuController::BuildOtherFolderMenu(int* next_menu_id) {
menu_id_to_node_map_[id] = other_folder;
}
-void BookmarkMenuController::BuildMenu(BookmarkNode* parent,
+void BookmarkMenuController::BuildMenu(const BookmarkNode* parent,
int start_child_index,
views::MenuItemView* menu,
int* next_menu_id) {
DCHECK(!parent->GetChildCount() ||
start_child_index < parent->GetChildCount());
for (int i = start_child_index; i < parent->GetChildCount(); ++i) {
- BookmarkNode* node = parent->GetChild(i);
+ const BookmarkNode* node = parent->GetChild(i);
int id = *next_menu_id;
(*next_menu_id)++;
diff --git a/chrome/browser/views/bookmark_menu_controller_views.h b/chrome/browser/views/bookmark_menu_controller_views.h
index a87ecfe..e9bd5d3 100644
--- a/chrome/browser/views/bookmark_menu_controller_views.h
+++ b/chrome/browser/views/bookmark_menu_controller_views.h
@@ -39,7 +39,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver,
Profile* profile,
PageNavigator* page_navigator,
gfx::NativeView parent,
- BookmarkNode* node,
+ const BookmarkNode* node,
int start_child_index,
bool show_other_folder);
@@ -52,7 +52,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver,
void Cancel();
// Returns the node the menu is showing for.
- BookmarkNode* node() const { return node_; }
+ const BookmarkNode* node() const { return node_; }
// Returns the menu.
views::MenuItemView* menu() const { return menu_.get(); }
@@ -86,7 +86,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver,
virtual void BookmarkModelChanged();
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node);
+ const BookmarkNode* node);
private:
// BookmarkMenuController deletes itself as necessary.
@@ -98,7 +98,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver,
// Creates an entry in menu for each child node of |parent| starting at
// |start_child_index|.
- void BuildMenu(BookmarkNode* parent,
+ void BuildMenu(const BookmarkNode* parent,
int start_child_index,
views::MenuItemView* menu,
int* next_menu_id);
@@ -113,14 +113,14 @@ class BookmarkMenuController : public BaseBookmarkModelObserver,
gfx::NativeView parent_;
// The node we're showing the contents of.
- BookmarkNode* node_;
+ const BookmarkNode* node_;
// Maps from menu id to BookmarkNode.
- std::map<int, BookmarkNode*> menu_id_to_node_map_;
+ std::map<int, const BookmarkNode*> menu_id_to_node_map_;
// Mapping from node to menu id. This only contains entries for nodes of type
// URL.
- std::map<BookmarkNode*, int> node_to_menu_id_map_;
+ std::map<const BookmarkNode*, int> node_to_menu_id_map_;
// The menu.
scoped_ptr<views::MenuItemView> menu_;
diff --git a/chrome/browser/views/bookmark_table_view.cc b/chrome/browser/views/bookmark_table_view.cc
index 7705d1b..3eaa2f3 100644
--- a/chrome/browser/views/bookmark_table_view.cc
+++ b/chrome/browser/views/bookmark_table_view.cc
@@ -64,7 +64,7 @@ bool BookmarkTableView::CanDrop(const OSExchangeData& data) {
// Don't allow the user to drop an ancestor of the parent node onto the
// parent node. This would create a cycle, which is definitely a no-no.
- std::vector<BookmarkNode*> nodes = drag_data.GetNodes(profile_);
+ std::vector<const BookmarkNode*> nodes = drag_data.GetNodes(profile_);
for (size_t i = 0; i < nodes.size(); ++i) {
if (parent_node_->HasAncestor(nodes[i]))
return false;
@@ -187,7 +187,7 @@ int BookmarkTableView::UpdateDropInfo() {
}
void BookmarkTableView::BeginDrag() {
- std::vector<BookmarkNode*> nodes_to_drag;
+ std::vector<const BookmarkNode*> nodes_to_drag;
for (TableView::iterator i = SelectionBegin(); i != SelectionEnd(); ++i)
nodes_to_drag.push_back(bookmark_table_model()->GetNodeForRow(*i));
if (nodes_to_drag.empty())
@@ -213,7 +213,7 @@ int BookmarkTableView::CalculateDropOperation(const DropPosition& position) {
return DragDropTypes::DRAG_COPY;
int real_drop_index;
- BookmarkNode* drop_parent = GetDropParentAndIndex(position,
+ const BookmarkNode* drop_parent = GetDropParentAndIndex(position,
&real_drop_index);
if (!bookmark_utils::IsValidDropLocation(
profile_, drop_info_->data(), drop_parent, real_drop_index)) {
@@ -230,7 +230,7 @@ int BookmarkTableView::CalculateDropOperation(const DropPosition& position) {
void BookmarkTableView::OnPerformDropImpl() {
int drop_index;
- BookmarkNode* drop_parent = GetDropParentAndIndex(
+ const BookmarkNode* drop_parent = GetDropParentAndIndex(
drop_info_->position(), &drop_index);
BookmarkModel* model = profile_->GetBookmarkModel();
int min_selection;
@@ -246,7 +246,8 @@ void BookmarkTableView::OnPerformDropImpl() {
static_cast<int>(drop_info_->data().elements.size());
} else {
// else, move.
- std::vector<BookmarkNode*> nodes = drop_info_->data().GetNodes(profile_);
+ std::vector<const BookmarkNode*> nodes =
+ drop_info_->data().GetNodes(profile_);
if (nodes.empty())
return;
@@ -330,11 +331,11 @@ BookmarkTableView::DropPosition
return DropPosition(row_count, false);
}
-BookmarkNode* BookmarkTableView::GetDropParentAndIndex(
+const BookmarkNode* BookmarkTableView::GetDropParentAndIndex(
const DropPosition& position,
int* index) {
if (position.on) {
- BookmarkNode* parent = parent_node_->GetChild(position.index);
+ const BookmarkNode* parent = parent_node_->GetChild(position.index);
*index = parent->GetChildCount();
return parent;
}
diff --git a/chrome/browser/views/bookmark_table_view.h b/chrome/browser/views/bookmark_table_view.h
index b80d1fa..2cd6891 100644
--- a/chrome/browser/views/bookmark_table_view.h
+++ b/chrome/browser/views/bookmark_table_view.h
@@ -35,7 +35,7 @@ class BookmarkTableView : public views::TableView {
// Sets the parent of the nodes being displayed. For search and recently
// found results |parent| is NULL.
- void set_parent_node(BookmarkNode* parent) { parent_node_ = parent; }
+ void set_parent_node(const BookmarkNode* parent) { parent_node_ = parent; }
// Sets whether the path column should be shown. The path column is shown
// for search results and recently bookmarked.
@@ -127,8 +127,8 @@ class BookmarkTableView : public views::TableView {
DropPosition CalculateDropPosition(int y);
// Returns the BookmarkNode the drop should occur on.
- BookmarkNode* GetDropParentAndIndex(const DropPosition& position,
- int* index);
+ const BookmarkNode* GetDropParentAndIndex(const DropPosition& position,
+ int* index);
// Returns the bounds of drop indicator shown when the drop is to occur
// between rows (drop_on is false).
@@ -149,7 +149,7 @@ class BookmarkTableView : public views::TableView {
Profile* profile_;
- BookmarkNode* parent_node_;
+ const BookmarkNode* parent_node_;
scoped_ptr<DropInfo> drop_info_;
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index 83c9107..430da1c 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -757,7 +757,7 @@ void ToolbarView::WriteDragData(views::View* sender,
TabContents* tab = browser_->GetSelectedTabContents();
if (tab) {
if (profile_ && profile_->GetBookmarkModel()) {
- BookmarkNode* node = profile_->GetBookmarkModel()->
+ const BookmarkNode* node = profile_->GetBookmarkModel()->
GetMostRecentlyAddedNodeForURL(tab->GetURL());
if (node) {
BookmarkDragData bookmark_data(node);