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

Side by Side Diff: ios/chrome/browser/passwords/update_password_infobar_controller.mm

Issue 2933833002: [iOS] Break retain cycle in InfoBars. (Closed)
Patch Set: Addressed comments. Created 3 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ios/chrome/browser/passwords/update_password_infobar_controller.h" 5 #import "ios/chrome/browser/passwords/update_password_infobar_controller.h"
6 6
7 #include "base/ios/weak_nsobject.h"
7 #import "base/mac/objc_property_releaser.h" 8 #import "base/mac/objc_property_releaser.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
10 #include "ios/chrome/browser/infobars/confirm_infobar_controller+protected.h" 11 #include "ios/chrome/browser/infobars/confirm_infobar_controller+protected.h"
11 #include "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delega te.h" 12 #include "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delega te.h"
12 #import "ios/chrome/browser/ui/elements/selector_coordinator.h" 13 #import "ios/chrome/browser/ui/elements/selector_coordinator.h"
13 #import "ios/chrome/browser/ui/infobars/infobar_view.h" 14 #import "ios/chrome/browser/ui/infobars/infobar_view.h"
14 15
15 namespace { 16 namespace {
16 // Tag for the account link in the info bar message. Set to 10 to avoid conflict 17 // Tag for the account link in the info bar message. Set to 10 to avoid conflict
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // If there are multiple possible credentials, turn the account string into a 55 // If there are multiple possible credentials, turn the account string into a
55 // link. 56 // link.
56 if (_delegate->ShowMultipleAccounts()) { 57 if (_delegate->ShowMultipleAccounts()) {
57 base::string16 usernameLink = base::SysNSStringToUTF16([[view class] 58 base::string16 usernameLink = base::SysNSStringToUTF16([[view class]
58 stringAsLink:base::SysUTF16ToNSString(_delegate->selected_account()) 59 stringAsLink:base::SysUTF16ToNSString(_delegate->selected_account())
59 tag:kAccountTag]); 60 tag:kAccountTag]);
60 base::ReplaceFirstSubstringAfterOffset( 61 base::ReplaceFirstSubstringAfterOffset(
61 &messageText, 0, _delegate->selected_account(), usernameLink); 62 &messageText, 0, _delegate->selected_account(), usernameLink);
62 } 63 }
63 64
65 base::WeakNSObject<UpdatePasswordInfoBarController> weakSelf(self);
64 [view addLabel:base::SysUTF16ToNSString(messageText) 66 [view addLabel:base::SysUTF16ToNSString(messageText)
65 action:^(NSUInteger tag) { 67 action:^(NSUInteger tag) {
66 [self infobarLinkDidPress:tag]; 68 [weakSelf infobarLinkDidPress:tag];
67 }]; 69 }];
68 } 70 }
69 71
70 - (void)infobarLinkDidPress:(NSUInteger)tag { 72 - (void)infobarLinkDidPress:(NSUInteger)tag {
71 [super infobarLinkDidPress:tag]; 73 [super infobarLinkDidPress:tag];
72 if (tag != kAccountTag) 74 if (tag != kAccountTag)
73 return; 75 return;
74 76
75 UIViewController* baseViewController = 77 UIViewController* baseViewController =
76 [[UIApplication sharedApplication] keyWindow].rootViewController; 78 [[UIApplication sharedApplication] keyWindow].rootViewController;
77 self.selectorCoordinator = [[[SelectorCoordinator alloc] 79 self.selectorCoordinator = [[[SelectorCoordinator alloc]
78 initWithBaseViewController:baseViewController] autorelease]; 80 initWithBaseViewController:baseViewController] autorelease];
79 self.selectorCoordinator.delegate = self; 81 self.selectorCoordinator.delegate = self;
80 self.selectorCoordinator.options = 82 self.selectorCoordinator.options =
81 [NSOrderedSet orderedSetWithArray:_delegate->GetAccounts()]; 83 [NSOrderedSet orderedSetWithArray:_delegate->GetAccounts()];
82 self.selectorCoordinator.defaultOption = 84 self.selectorCoordinator.defaultOption =
83 base::SysUTF16ToNSString(_delegate->selected_account()); 85 base::SysUTF16ToNSString(_delegate->selected_account());
84 [self.selectorCoordinator start]; 86 [self.selectorCoordinator start];
85 } 87 }
86 88
87 #pragma mark SelectorCoordinatorDelegate 89 #pragma mark SelectorCoordinatorDelegate
88 90
89 - (void)selectorCoordinator:(SelectorCoordinator*)coordinator 91 - (void)selectorCoordinator:(SelectorCoordinator*)coordinator
90 didCompleteWithSelection:(NSString*)selection { 92 didCompleteWithSelection:(NSString*)selection {
91 _delegate->set_selected_account(base::SysNSStringToUTF16(selection)); 93 _delegate->set_selected_account(base::SysNSStringToUTF16(selection));
92 [self updateInfobarLabel:self.view]; 94 [self updateInfobarLabel:self.view];
93 } 95 }
94 96
95 @end 97 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698