diff options
author | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 22:29:20 +0000 |
---|---|---|
committer | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 22:29:20 +0000 |
commit | b3c33d463366d2725ec4d669b98dc468a751c541 (patch) | |
tree | d8496a8ae8fc73ed71b93d67c055e9f1bba4fcc7 /chrome/browser/cocoa | |
parent | 7b91dfd0bce7b4f864d9654e8bd0a9f93683cec0 (diff) | |
download | chromium_src-b3c33d463366d2725ec4d669b98dc468a751c541.zip chromium_src-b3c33d463366d2725ec4d669b98dc468a751c541.tar.gz chromium_src-b3c33d463366d2725ec4d669b98dc468a751c541.tar.bz2 |
Make bookmark model public interface use const BookmarkNode* instead of
BookmarkNode*. This helps in making the BookmarkNode class setters public
also without worrying about someone inadvertently changing BookmarkNode
properties directly for bookmark model bookmarks.
Change all the call sites to reflect this.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/146116
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_bridge.h | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_bridge.mm | 14 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.h | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 27 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_menu_bridge.h | 14 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_menu_bridge.mm | 18 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_menu_cocoa_controller.h | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm | 8 |
11 files changed, 67 insertions, 68 deletions
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; |