Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/browser/cocoa/bookmark_menu_bridge.mm

Issue 53116: Fix leaks found by valgrind (which now works on the Mac!)... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/cocoa/bookmark_menu_bridge.h" 5 #include "chrome/browser/cocoa/bookmark_menu_bridge.h"
6 #import <AppKit/AppKit.h> 6 #import <AppKit/AppKit.h>
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/app/chrome_dll_resource.h" // IDC_BOOKMARK_MENU 8 #include "chrome/app/chrome_dll_resource.h" // IDC_BOOKMARK_MENU
9 #import "chrome/browser/app_controller_mac.h" 9 #import "chrome/browser/app_controller_mac.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_list.h" 11 #include "chrome/browser/browser_list.h"
12 #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h" 12 #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h"
13 #include "chrome/browser/profile.h" 13 #include "chrome/browser/profile.h"
14 #include "chrome/browser/profile_manager.h" 14 #include "chrome/browser/profile_manager.h"
15 15
16 BookmarkMenuBridge::BookmarkMenuBridge() 16 BookmarkMenuBridge::BookmarkMenuBridge()
17 : controller_([[BookmarkMenuCocoaController alloc] initWithBridge:this]) { 17 : controller_([[BookmarkMenuCocoaController alloc] initWithBridge:this]),
18 observing_(true) {
18 BrowserList::AddObserver(this); 19 BrowserList::AddObserver(this);
19 } 20 }
20 21
21 BookmarkMenuBridge::~BookmarkMenuBridge() { 22 BookmarkMenuBridge::~BookmarkMenuBridge() {
22 GetBookmarkModel()->RemoveObserver(this); 23 if (observing_)
24 BrowserList::RemoveObserver(this);
25 BookmarkModel *model = GetBookmarkModel();
26 if (model)
27 model->RemoveObserver(this);
23 [controller_ release]; 28 [controller_ release];
24 } 29 }
25 30
26 NSMenu* BookmarkMenuBridge::BookmarkMenu() { 31 NSMenu* BookmarkMenuBridge::BookmarkMenu() {
27 NSMenu* bookmark_menu = [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARK_MENU] 32 NSMenu* bookmark_menu = [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARK_MENU]
28 submenu]; 33 submenu];
29 return bookmark_menu; 34 return bookmark_menu;
30 } 35 }
31 36
32 void BookmarkMenuBridge::Loaded(BookmarkModel* model) { 37 void BookmarkMenuBridge::Loaded(BookmarkModel* model) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void BookmarkMenuBridge::OnBrowserRemoving(const Browser* browser) { 96 void BookmarkMenuBridge::OnBrowserRemoving(const Browser* browser) {
92 // Intentionally empty -- we don't care, but pure virtual so we must 97 // Intentionally empty -- we don't care, but pure virtual so we must
93 // implement. 98 // implement.
94 } 99 }
95 100
96 // The current browser has changed; update the bookmark menus. For 101 // The current browser has changed; update the bookmark menus. For
97 // our use, we only care about the first one to know when a profile is 102 // our use, we only care about the first one to know when a profile is
98 // complete. 103 // complete.
99 void BookmarkMenuBridge::OnBrowserSetLastActive(const Browser* browser) { 104 void BookmarkMenuBridge::OnBrowserSetLastActive(const Browser* browser) {
100 BrowserList::RemoveObserver(this); 105 BrowserList::RemoveObserver(this);
106 observing_ = false;
101 BookmarkModel* model = GetBookmarkModel(); 107 BookmarkModel* model = GetBookmarkModel();
102 model->AddObserver(this); 108 model->AddObserver(this);
103 if (model->IsLoaded()) 109 if (model->IsLoaded())
104 Loaded(model); 110 Loaded(model);
105 } 111 }
106 112
107 BookmarkModel* BookmarkMenuBridge::GetBookmarkModel() { 113 BookmarkModel* BookmarkMenuBridge::GetBookmarkModel() {
108 // In incognito mode we use the main profile's bookmarks. 114 // In incognito mode we use the main profile's bookmarks.
109 // Thus, we don't return browser_->profile()->GetBookmarkModel(). 115 // Thus, we don't return browser_->profile()->GetBookmarkModel().
110 Profile* profile = GetDefaultProfile(); 116 Profile* profile = GetDefaultProfile();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 [item setAction:@selector(openBookmarkMenuItem:)]; 159 [item setAction:@selector(openBookmarkMenuItem:)];
154 [item setTag:child->id()]; 160 [item setTag:child->id()];
155 [menu addItem:item]; 161 [menu addItem:item];
156 if (child->is_folder()) { 162 if (child->is_folder()) {
157 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; 163 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease];
158 [menu setSubmenu:submenu forItem:item]; 164 [menu setSubmenu:submenu forItem:item];
159 AddNodeToMenu(child, submenu); // recursive call 165 AddNodeToMenu(child, submenu); // recursive call
160 } 166 }
161 } 167 }
162 } 168 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_menu_bridge.h ('k') | chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698