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

Unified Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm

Issue 14130008: Fix race condition if a pulsing bookmark button is deleted while the bookmark bubble controller is … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: less crash Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm
index c39a01442c620c33474200075e337d8e5b8dbc40..eab6f96f31d40185ff1c49c74787fb59cabf1e8b 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm
@@ -51,7 +51,9 @@ using content::UserMetricsAction;
- (id)initWithParentWindow:(NSWindow*)parentWindow
model:(BookmarkModel*)model
node:(const BookmarkNode*)node
- alreadyBookmarked:(BOOL)alreadyBookmarked {
+ alreadyBookmarked:(BOOL)alreadyBookmarked {
+ DCHECK(model);
+ DCHECK(node);
if ((self = [super initWithWindowNibPath:@"BookmarkBubble"
parentWindow:parentWindow
anchoredAt:NSZeroPoint])) {
@@ -76,6 +78,7 @@ using content::UserMetricsAction;
if ((node->parent() == model_->bookmark_bar_node()) ||
(node == model_->other_node())) {
pulsingBookmarkNode_ = node;
+ bookmarkObserver_->StartObservingNode(pulsingBookmarkNode_);
NSValue *value = [NSValue valueWithPointer:node];
NSDictionary *dict = [NSDictionary
dictionaryWithObjectsAndKeys:value,
@@ -97,6 +100,8 @@ using content::UserMetricsAction;
if (!pulsingBookmarkNode_)
return;
NSValue *value = [NSValue valueWithPointer:pulsingBookmarkNode_];
+ if (bookmarkObserver_)
+ bookmarkObserver_->StopObservingNode(pulsingBookmarkNode_);
pulsingBookmarkNode_ = NULL;
NSDictionary *dict = [NSDictionary
dictionaryWithObjectsAndKeys:value,
@@ -121,7 +126,7 @@ using content::UserMetricsAction;
- (void)windowWillClose:(NSNotification*)notification {
// We caught a close so we don't need to watch for the parent closing.
- bookmark_observer_.reset(NULL);
+ bookmarkObserver_.reset();
[self stopPulsingBookmarkButton];
[super windowWillClose:notification];
}
@@ -163,10 +168,16 @@ using content::UserMetricsAction;
// dialog, the bookmark bubble's cancel: means "don't add this as a
// bookmark", not "cancel editing". We must take extra care to not
// touch the bookmark in this selector.
- bookmark_observer_.reset(new BookmarkModelObserverForCocoa(
- node_, model_,
- self,
- @selector(dismissWithoutEditing:)));
+ bookmarkObserver_.reset(new BookmarkModelObserverForCocoa(
+ model_,
+ ^(BOOL nodeWasDeleted) {
+ // If a watched node was deleted, the pointer to the pulsing button
+ // is likely stale.
+ if (nodeWasDeleted)
+ pulsingBookmarkNode_ = NULL;
+ [self dismissWithoutEditing:nil];
+ }));
+ bookmarkObserver_->StartObservingNode(node_);
// Pulse something interesting on the bookmark bar.
[self startPulsingBookmarkButton:node_];

Powered by Google App Engine
This is Rietveld 408576698