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

Side by Side Diff: chrome/browser/ui/cocoa/download/download_shelf_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: Add HasWeakBrowserPointer protocol. Allow -dealloc without preceding -browserWillBeDestroyed. 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/download/download_shelf_controller.h" 5 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/download/download_stats.h" 9 #include "chrome/browser/download/download_stats.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 name:kWillEnterFullscreenNotification 135 name:kWillEnterFullscreenNotification
136 object:nil]; 136 object:nil];
137 [defaultCenter addObserver:self 137 [defaultCenter addObserver:self
138 selector:@selector(willLeaveFullscreen) 138 selector:@selector(willLeaveFullscreen)
139 name:kWillLeaveFullscreenNotification 139 name:kWillLeaveFullscreenNotification
140 object:nil]; 140 object:nil];
141 [self installTrackingArea]; 141 [self installTrackingArea];
142 } 142 }
143 143
144 - (void)dealloc { 144 - (void)dealloc {
145 [[NSNotificationCenter defaultCenter] removeObserver:self]; 145 [self browserWillBeDestroyed];
146 [self cancelAutoClose];
147 [self removeTrackingArea];
148
149 // The controllers will unregister themselves as observers when they are
150 // deallocated. No need to do that here.
151 [super dealloc]; 146 [super dealloc];
152 } 147 }
153 148
149 - (void)browserWillBeDestroyed {
150 [[NSNotificationCenter defaultCenter] removeObserver:self];
151
152 // We need to explicitly release our download controllers here since they need
153 // to remove themselves as observers before the remaining shutdown happens.
154 [[self animatableView] stopAnimation];
erikchen 2015/07/08 18:02:17 this logic looks copy-pasted from -exiting. Please
Robert Sesek 2015/07/08 22:15:18 -editing was removed.
155 [self removeTrackingArea];
156 [self cancelAutoClose];
157 while ([downloadItemControllers_ count] > 0) {
158 [self removeDownload:[downloadItemControllers_ lastObject]
159 isShelfClosing:YES];
160 }
161 downloadItemControllers_.reset();
162
163 bridge_.reset();
164 navigator_ = nullptr;
165 }
166
154 // Called after the frame's rect has changed; usually when the height is 167 // Called after the frame's rect has changed; usually when the height is
155 // animated. 168 // animated.
156 - (void)viewFrameDidChange:(NSNotification*)notification { 169 - (void)viewFrameDidChange:(NSNotification*)notification {
157 // Anchor subviews at the top of |view|, so that it looks like the shelf 170 // Anchor subviews at the top of |view|, so that it looks like the shelf
158 // is sliding out. 171 // is sliding out.
159 CGFloat newShelfHeight = NSHeight([[self view] frame]); 172 CGFloat newShelfHeight = NSHeight([[self view] frame]);
160 if (newShelfHeight == currentShelfHeight_) 173 if (newShelfHeight == currentShelfHeight_)
161 return; 174 return;
162 175
163 for (NSView* view in [[self view] subviews]) { 176 for (NSView* view in [[self view] subviews]) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 [self maybeAutoCloseAfterDelay]; 219 [self maybeAutoCloseAfterDelay];
207 } 220 }
208 } 221 }
209 222
210 - (void)downloadWasOpened:(DownloadItemController*)item_controller { 223 - (void)downloadWasOpened:(DownloadItemController*)item_controller {
211 // This should only be called on the main thead. 224 // This should only be called on the main thead.
212 DCHECK([NSThread isMainThread]); 225 DCHECK([NSThread isMainThread]);
213 [self maybeAutoCloseAfterDelay]; 226 [self maybeAutoCloseAfterDelay];
214 } 227 }
215 228
216 // We need to explicitly release our download controllers here since they need
217 // to remove themselves as observers before the remaining shutdown happens.
218 - (void)exiting {
219 [[self animatableView] stopAnimation];
220 [self removeTrackingArea];
221 [self cancelAutoClose];
222 while ([downloadItemControllers_ count] > 0) {
223 [self removeDownload:[downloadItemControllers_ lastObject]
224 isShelfClosing:YES];
225 }
226 downloadItemControllers_.reset();
227 }
228
229 - (void)showDownloadShelf:(BOOL)show 229 - (void)showDownloadShelf:(BOOL)show
230 isUserAction:(BOOL)isUserAction { 230 isUserAction:(BOOL)isUserAction {
231 [self cancelAutoClose]; 231 [self cancelAutoClose];
232 shouldCloseOnMouseExit_ = NO; 232 shouldCloseOnMouseExit_ = NO;
233 233
234 if ([self isVisible] == show) 234 if ([self isVisible] == show)
235 return; 235 return;
236 236
237 if (!show) { 237 if (!show) {
238 int numInProgress = 0; 238 int numInProgress = 0;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 504 }
505 505
506 // Set the tracking off to create a new tracking area for the control. 506 // Set the tracking off to create a new tracking area for the control.
507 // When changing the bounds/frame on a HoverButton, the tracking isn't updated 507 // When changing the bounds/frame on a HoverButton, the tracking isn't updated
508 // correctly, it needs to be turned off and back on. 508 // correctly, it needs to be turned off and back on.
509 [hoverCloseButton_ setTrackingEnabled:NO]; 509 [hoverCloseButton_ setTrackingEnabled:NO];
510 [hoverCloseButton_ setFrame:bounds]; 510 [hoverCloseButton_ setFrame:bounds];
511 [hoverCloseButton_ setTrackingEnabled:YES]; 511 [hoverCloseButton_ setTrackingEnabled:YES];
512 } 512 }
513 @end 513 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698