Commit db9fc12b authored by jif's avatar jif Committed by Commit Bot

[iOS] Break retain cycle in InfoBars.

This CLs breaks retain cycles such as:
InfoBarView -> LabelLinkController ->
BeforeTranslateInfoBarController -> InfoBarView

BUG=732384

Review-Url: https://codereview.chromium.org/2933833002
Cr-Commit-Position: refs/heads/master@{#478618}
parent 804e16e2
...@@ -118,9 +118,10 @@ ConfirmInfoBarDelegate::InfoBarButton UITagToButton(NSUInteger tag) { ...@@ -118,9 +118,10 @@ ConfirmInfoBarDelegate::InfoBarButton UITagToButton(NSUInteger tag) {
base::ReplaceFirstSubstringAfterOffset( base::ReplaceFirstSubstringAfterOffset(
&messageText, 0, _confirmInfobarDelegate->GetLinkText(), msgLink); &messageText, 0, _confirmInfobarDelegate->GetLinkText(), msgLink);
__weak ConfirmInfoBarController* weakSelf = self;
[view addLabel:base::SysUTF16ToNSString(messageText) [view addLabel:base::SysUTF16ToNSString(messageText)
action:^(NSUInteger tag) { action:^(NSUInteger tag) {
[self infobarLinkDidPress:tag]; [weakSelf infobarLinkDidPress:tag];
}]; }];
} else { } else {
NSString* label = NSString* label =
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/passwords/update_password_infobar_controller.h" #import "ios/chrome/browser/passwords/update_password_infobar_controller.h"
#include "base/ios/weak_nsobject.h"
#import "base/mac/objc_property_releaser.h" #import "base/mac/objc_property_releaser.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -61,9 +62,10 @@ NSUInteger kAccountTag = 10; ...@@ -61,9 +62,10 @@ NSUInteger kAccountTag = 10;
&messageText, 0, _delegate->selected_account(), usernameLink); &messageText, 0, _delegate->selected_account(), usernameLink);
} }
base::WeakNSObject<UpdatePasswordInfoBarController> weakSelf(self);
[view addLabel:base::SysUTF16ToNSString(messageText) [view addLabel:base::SysUTF16ToNSString(messageText)
action:^(NSUInteger tag) { action:^(NSUInteger tag) {
[self infobarLinkDidPress:tag]; [weakSelf infobarLinkDidPress:tag];
}]; }];
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include "base/ios/weak_nsobject.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -172,9 +173,11 @@ NSTimeInterval kPickerAnimationDurationInSeconds = 0.2; ...@@ -172,9 +173,11 @@ NSTimeInterval kPickerAnimationDurationInSeconds = 0.2;
NSString* label = NSString* label =
l10n_util::GetNSStringF(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE_IOS, l10n_util::GetNSStringF(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE_IOS,
originalLanguageWithLink, targetLanguageWithLink); originalLanguageWithLink, targetLanguageWithLink);
base::WeakNSObject<BeforeTranslateInfoBarController> weakSelf(self);
[view addLabel:label [view addLabel:label
action:^(NSUInteger tag) { action:^(NSUInteger tag) {
[self infobarLinkDidPress:tag]; [weakSelf infobarLinkDidPress:tag];
}]; }];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment