Skip to content

Commit

Permalink
bookmarks: Use empty() accessor in some places instead of relying in …
Browse files Browse the repository at this point in the history
…child_count().

BUG=None
TEST=None

R=sky@chromium.org

Review URL: http://codereview.chromium.org/7342012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92266 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tfarina@chromium.org committed Jul 12, 2011
1 parent 8c10c81 commit 785ff71
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/cookies_tree_model_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CookiesTreeModelTest : public testing::Test {
std::string GetNodesOfChildren(
const CookieTreeNode* node,
CookieTreeNode::DetailedInfo::NodeType node_type) {
if (node->child_count()) {
if (!node->empty()) {
std::string retval;
for (int i = 0; i < node->child_count(); ++i) {
retval += GetNodesOfChildren(node->GetChild(i), node_type);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/sync/glue/bookmark_change_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel(
if (!dst) // Can't do anything if we can't find the chrome node.
continue;
const BookmarkNode* parent = dst->parent();
if (dst->child_count()) {
if (!dst->empty()) {
if (!foster_parent) {
foster_parent = model->AddFolder(model->other_node(),
model->other_node()->child_count(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,8 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId());
EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId());
}
if (bnode->child_count()) {
if (!bnode->empty())
EXPECT_TRUE(gnode.GetFirstChildId());
}
}

void ExpectSyncerNodeMatching(const BookmarkNode* bnode) {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem {
if (menu == [[self view] menu]) {
thingsToDo = [buttons_ count] ? YES : NO;
} else {
if (node && node->is_folder() && node->child_count()) {
if (node && node->is_folder() && !node->empty()) {
thingsToDo = YES;
}
}
Expand Down Expand Up @@ -1142,7 +1142,7 @@ - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu {
if (child->is_folder()) {
NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease];
[menu setSubmenu:submenu forItem:item];
if (child->child_count()) {
if (!child->empty()) {
[self addFolderNode:child toMenu:submenu]; // potentially recursive
} else {
[self tagEmptyMenu:submenu];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,12 @@ void InstallAndToggleBar(BookmarkBarController* bar) {
BookmarkBarFolderController* bbfc = [bar_ folderController];
EXPECT_TRUE(bbfc);
[bbfc setIgnoreAnimations:YES];
while (parent->child_count()) {
while (!parent->empty()) {
// We've completed the job so we're done.
if ([bar_ offTheSideButtonIsHidden])
break;
// Delete the last button.
model->Remove(parent, parent->child_count()-1);
model->Remove(parent, parent->child_count() - 1);
// If last one make sure the menu is closed and the button is hidden.
// Else make sure menu stays open.
if ([bar_ offTheSideButtonIsHidden]) {
Expand Down Expand Up @@ -627,7 +627,7 @@ void InstallAndToggleBar(BookmarkBarController* bar) {
// Start deleting items; try and delete randomish ones in case it
// makes a difference.
int indices[] = { 2, 4, 5, 1, 7, 9, 2, 0, 10, 9 };
while (parent->child_count()) {
while (!parent->empty()) {
for (unsigned int i = 0; i < arraysize(indices); i++) {
if (indices[i] < parent->child_count()) {
// First we mouse-enter the button to make things harder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,14 @@ - (void)configureWindow {
// TODO(jrg): combine with addNodesToButtonList: code from
// bookmark_bar_controller.mm (but use y offset)
// http://crbug.com/35966
if (!node->child_count()) {
if (node->empty()) {
// If no children we are the empty button.
BookmarkButton* button = [self makeButtonForNode:nil
frame:buttonsOuterFrame];
[buttons_ addObject:button];
[folderView_ addSubview:button];
} else {
for (int i = startingIndex;
i < node->child_count();
i++) {
for (int i = startingIndex; i < node->child_count(); ++i) {
const BookmarkNode* child = node->GetChild(i);
BookmarkButton* button = [self makeButtonForNode:child
frame:buttonsOuterFrame];
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
// Add bookmark bar items, if any.
const BookmarkNode* barNode = model->GetBookmarkBarNode();
CHECK(barNode);
if (barNode->child_count()) {
if (!barNode->empty()) {
[bookmark_menu addItem:[NSMenuItem separatorItem]];
AddNodeToMenu(barNode, bookmark_menu, !is_submenu);
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/gtk/global_bookmark_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ void GlobalBookmarkMenu::RebuildMenu() {
ClearBookmarkMenu();

const BookmarkNode* bar_node = model->GetBookmarkBarNode();
if (bar_node->child_count()) {
if (!bar_node->empty()) {
AddBookmarkMenuItem(bookmark_menu_.get(), gtk_separator_menu_item_new());
AddNodeToMenu(bar_node, bookmark_menu_.get());
}

// Only display the other bookmarks folder in the menu if it has items in it.
const BookmarkNode* other_node = model->other_node();
if (other_node->child_count()) {
if (!other_node->empty()) {
GtkWidget* submenu = gtk_menu_new();
AddNodeToMenu(other_node, submenu);

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/webui/cookies_tree_model_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void GetCookieTreeNodeDictionary(const CookieTreeNode& node,
// Use node's address as an id for WebUI to look it up.
dict->SetString(kKeyId, PointerToHexString(&node));
dict->SetString(kKeyTitle, node.GetTitle());
dict->SetBoolean(kKeyHasChildren, !!node.child_count());
dict->SetBoolean(kKeyHasChildren, !node.empty());

switch (node.GetDetailedInfo().node_type) {
case CookieTreeNode::DetailedInfo::TYPE_ORIGIN: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ void PerformanceLiveBookmarksSyncTest::UpdateURLs(int profile) {
}

void PerformanceLiveBookmarksSyncTest::RemoveURLs(int profile) {
while (GetBookmarkBarNode(profile)->child_count()) {
while (!GetBookmarkBarNode(profile)->empty())
Remove(profile, GetBookmarkBarNode(profile), 0);
}
}

void PerformanceLiveBookmarksSyncTest::Cleanup() {
Expand Down

0 comments on commit 785ff71

Please sign in to comment.