Chromium Code Reviews| Index: ios/chrome/browser/upgrade/upgrade_center.mm |
| diff --git a/ios/chrome/browser/upgrade/upgrade_center.mm b/ios/chrome/browser/upgrade/upgrade_center.mm |
| index 3566c5316daa239357be0693194e098b7d1cd494..9f6c0a61ab1ac28d17ae4e3472da9e974481db9a 100644 |
| --- a/ios/chrome/browser/upgrade/upgrade_center.mm |
| +++ b/ios/chrome/browser/upgrade/upgrade_center.mm |
| @@ -9,7 +9,6 @@ |
| #include <utility> |
| #include "base/mac/bundle_locations.h" |
| -#include "base/mac/scoped_nsobject.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/scoped_observer.h" |
| #include "base/strings/sys_string_conversions.h" |
| @@ -29,6 +28,10 @@ |
| #include "ui/gfx/image/image.h" |
| #include "url/gurl.h" |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| @interface UpgradeCenter () |
| // Creates infobars on all tabs. |
| - (void)showUpgradeInfoBars; |
| @@ -141,7 +144,7 @@ void RegisterObserver(infobars::InfoBarManager* infobar_manager, |
| scoped_observer_.Add(infobar_manager); |
| infobar_delegate_ = infobar_delegate; |
| dismiss_delegate_ = dismiss_delegate; |
| - tab_id_.reset([tab_id copy]); |
| + tab_id_ = [tab_id copy]; |
| } |
| UpgradeInfoBarDelegate* infobar_delegate() { return infobar_delegate_; } |
| @@ -150,7 +153,7 @@ void RegisterObserver(infobars::InfoBarManager* infobar_manager, |
| // infobars::InfoBarManager::Observer implementation. |
| void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override { |
| if (infobar->delegate() == infobar_delegate_) { |
| - [dismiss_delegate_ dismissedInfoBar:tab_id_.get() |
| + [dismiss_delegate_ dismissedInfoBar:tab_id_ |
| performUpgrade:infobar_delegate_->AcceptPressed()]; |
| } |
| } |
| @@ -162,7 +165,7 @@ void OnManagerShuttingDown( |
| UpgradeInfoBarDelegate* infobar_delegate_; |
| UpgradeCenter* dismiss_delegate_; |
|
sdefresne
2017/05/31 08:16:13
This is an Objective-C pointer. Since the original
liaoyuke
2017/06/13 18:17:31
Done.
|
| - base::scoped_nsobject<NSString> tab_id_; |
| + NSString* tab_id_; |
| ScopedObserver<infobars::InfoBarManager, infobars::InfoBarManager::Observer> |
| scoped_observer_; |
| @@ -210,7 +213,7 @@ @implementation UpgradeCenter { |
| // YES if the infobars are currently visible. |
| BOOL upgradeInfoBarIsVisible_; |
| // Used to store the visible upgrade infobars, indexed by tabId. |
| - base::scoped_nsobject<NSMutableDictionary> upgradeInfoBarDelegates_; |
| + NSMutableDictionary* upgradeInfoBarDelegates_; |
|
sdefresne
2017/05/31 08:16:13
NSMutableDictionary<NSString*, DelegateHolder*>* u
liaoyuke
2017/06/13 18:17:31
Done.
|
| // Stores the clients of the upgrade center. These objectiveC objects are not |
| // retained. |
| std::set<id<UpgradeCenterClientProtocol>> clients_; |
|
sdefresne
2017/05/31 08:16:13
The comments says that the Objective-C objects are
liaoyuke
2017/06/13 18:17:31
Thank you for explaining!
Done.
|
| @@ -231,7 +234,7 @@ + (UpgradeCenter*)sharedInstance { |
| - (instancetype)init { |
| self = [super init]; |
| if (self) { |
| - upgradeInfoBarDelegates_.reset([[NSMutableDictionary alloc] init]); |
| + upgradeInfoBarDelegates_ = [[NSMutableDictionary alloc] init]; |
| // There is no dealloc and no unregister as this class is a never |
| // deallocated singleton. |
| @@ -310,11 +313,11 @@ - (void)addInfoBarToManager:(infobars::InfoBarManager*)infoBarManager |
| return; |
| auto infobarDelegate = base::MakeUnique<UpgradeInfoBarDelegate>(); |
| - base::scoped_nsobject<DelegateHolder> delegateHolder([[DelegateHolder alloc] |
| - initWithInfoBarManager:infoBarManager |
| - infoBarDelegate:infobarDelegate.get() |
| - upgradeCenter:self |
| - tabId:tabId]); |
| + DelegateHolder* delegateHolder = |
| + [[DelegateHolder alloc] initWithInfoBarManager:infoBarManager |
| + infoBarDelegate:infobarDelegate.get() |
| + upgradeCenter:self |
| + tabId:tabId]; |
| [upgradeInfoBarDelegates_ setObject:delegateHolder forKey:tabId]; |
| infoBarManager->AddInfoBar( |
| @@ -330,9 +333,9 @@ - (void)dismissedInfoBar:(NSString*)tabId performUpgrade:(BOOL)shouldUpgrade { |
| // notification. In all likelyhood it was trigerred by calling |
| // -hideUpgradeInfoBars. Or because a tab was closed without dismissing the |
| // infobar. |
| - base::scoped_nsobject<DelegateHolder> delegateHolder( |
| - [[upgradeInfoBarDelegates_ objectForKey:tabId] retain]); |
| - if (!delegateHolder.get()) |
| + DelegateHolder* delegateHolder = |
| + [upgradeInfoBarDelegates_ objectForKey:tabId]; |
| + if (!delegateHolder) |
| return; |
| // Forget about this dismissed infobar. |
| @@ -353,8 +356,8 @@ - (void)dismissedInfoBar:(NSString*)tabId performUpgrade:(BOOL)shouldUpgrade { |
| if (web::UrlHasWebScheme(url)) { |
| // This URL can be opened in the application, just open in a new tab. |
| - base::scoped_nsobject<OpenUrlCommand> command( |
| - [[OpenUrlCommand alloc] initWithURLFromChrome:url]); |
| + OpenUrlCommand* command = |
| + [[OpenUrlCommand alloc] initWithURLFromChrome:url]; |
| UIWindow* main_window = [[UIApplication sharedApplication] keyWindow]; |
| DCHECK(main_window); |
| [main_window chromeExecuteCommand:command]; |
| @@ -392,9 +395,9 @@ - (void)hideUpgradeInfoBars { |
| for (NSString* tabId in [upgradeInfoBarDelegates_ allKeys]) { |
| // It is important to retain the delegateHolder as otherwise it is |
| // deallocated as soon as it is removed from the dictionary. |
| - base::scoped_nsobject<DelegateHolder> delegateHolder( |
| - [[upgradeInfoBarDelegates_ objectForKey:tabId] retain]); |
| - if (delegateHolder.get()) { |
| + DelegateHolder* delegateHolder = |
| + [upgradeInfoBarDelegates_ objectForKey:tabId]; |
| + if (delegateHolder) { |
| [upgradeInfoBarDelegates_ removeObjectForKey:tabId]; |
| UpgradeInfoBarDelegate* delegate = [delegateHolder infoBarDelegate]; |
| DCHECK(delegate); |