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

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm

Issue 1221173003: [Mac] Inform reference counted objects that hold a weak Browser* when the Browser is being destroye… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove dealloc override. Created 5 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 profile:(Profile*)profile 207 profile:(Profile*)profile
208 browser:(Browser*)browser 208 browser:(Browser*)browser
209 resizeDelegate:(id<ViewResizer>)resizeDelegate 209 resizeDelegate:(id<ViewResizer>)resizeDelegate
210 nibFileNamed:(NSString*)nibName { 210 nibFileNamed:(NSString*)nibName {
211 DCHECK(commands && profile && [nibName length]); 211 DCHECK(commands && profile && [nibName length]);
212 if ((self = [super initWithNibName:nibName 212 if ((self = [super initWithNibName:nibName
213 bundle:base::mac::FrameworkBundle()])) { 213 bundle:base::mac::FrameworkBundle()])) {
214 commands_ = commands; 214 commands_ = commands;
215 profile_ = profile; 215 profile_ = profile;
216 browser_ = browser; 216 browser_ = browser;
217 resizeDelegate_ = resizeDelegate;
218 hasToolbar_ = YES; 217 hasToolbar_ = YES;
219 hasLocationBar_ = YES; 218 hasLocationBar_ = YES;
220 219
221 // Register for notifications about state changes for the toolbar buttons 220 // Register for notifications about state changes for the toolbar buttons
222 commandObserver_.reset( 221 commandObserver_.reset(
223 new ToolbarControllerInternal::CommandObserverBridge(self)); 222 new ToolbarControllerInternal::CommandObserverBridge(self));
224 223
225 commands->AddCommandObserver(IDC_BACK, commandObserver_.get()); 224 commands->AddCommandObserver(IDC_BACK, commandObserver_.get());
226 commands->AddCommandObserver(IDC_FORWARD, commandObserver_.get()); 225 commands->AddCommandObserver(IDC_FORWARD, commandObserver_.get());
227 commands->AddCommandObserver(IDC_RELOAD, commandObserver_.get()); 226 commands->AddCommandObserver(IDC_RELOAD, commandObserver_.get());
228 commands->AddCommandObserver(IDC_HOME, commandObserver_.get()); 227 commands->AddCommandObserver(IDC_HOME, commandObserver_.get());
229 commands->AddCommandObserver(IDC_BOOKMARK_PAGE, commandObserver_.get()); 228 commands->AddCommandObserver(IDC_BOOKMARK_PAGE, commandObserver_.get());
230 // NOTE: Don't remove the command observers. ToolbarController is 229 // NOTE: Don't remove the command observers. ToolbarController is
231 // autoreleased at about the same time as the CommandUpdater (owned by the 230 // autoreleased at about the same time as the CommandUpdater (owned by the
232 // Browser), so |commands_| may not be valid any more. 231 // Browser), so |commands_| may not be valid any more.
233 } 232 }
234 return self; 233 return self;
235 } 234 }
236 235
236 - (void)browserWillBeDestroyed {
237 // This method indicates imminent destruction. Destroy owned objects that hold
238 // a weak Browser*, or pass this call onto reference counted objects.
239 locationBarView_.reset();
tapted 2015/07/06 07:26:18 e.g. [locationBarView_ setController:nil] might be
jackhou1 2015/07/07 03:27:27 locationBarView_ is a C++ object.
240 [backMenuController_ browserWillBeDestroyed];
241 [forwardMenuController_ browserWillBeDestroyed];
242 [browserActionsController_ browserWillBeDestroyed];
243 [wrenchMenuController_ browserWillBeDestroyed];
244
245 browser_ = nullptr;
246 }
247
237 - (id)initWithCommands:(CommandUpdater*)commands 248 - (id)initWithCommands:(CommandUpdater*)commands
238 profile:(Profile*)profile 249 profile:(Profile*)profile
239 browser:(Browser*)browser 250 browser:(Browser*)browser
240 resizeDelegate:(id<ViewResizer>)resizeDelegate { 251 resizeDelegate:(id<ViewResizer>)resizeDelegate {
241 if ((self = [self initWithCommands:commands 252 if ((self = [self initWithCommands:commands
242 profile:profile 253 profile:profile
243 browser:browser 254 browser:browser
244 resizeDelegate:resizeDelegate 255 resizeDelegate:resizeDelegate
245 nibFileNamed:@"Toolbar"])) { 256 nibFileNamed:@"Toolbar"])) {
246 } 257 }
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 - (void)hideDropURLsIndicatorInView:(NSView*)view { 923 - (void)hideDropURLsIndicatorInView:(NSView*)view {
913 // Do nothing. 924 // Do nothing.
914 } 925 }
915 926
916 // (URLDropTargetController protocol) 927 // (URLDropTargetController protocol)
917 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { 928 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info {
918 return drag_util::IsUnsupportedDropData(profile_, info); 929 return drag_util::IsUnsupportedDropData(profile_, info);
919 } 930 }
920 931
921 @end 932 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698