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..ac629d3ee292d50b342a9c53d109bd5c7c9ffcfe 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()]; |
} |
} |
@@ -161,8 +164,8 @@ void OnManagerShuttingDown( |
} |
UpgradeInfoBarDelegate* infobar_delegate_; |
- UpgradeCenter* dismiss_delegate_; |
- base::scoped_nsobject<NSString> tab_id_; |
+ __weak UpgradeCenter* dismiss_delegate_; |
+ NSString* tab_id_; |
sdefresne
2017/06/15 16:34:30
nit: __strong NSString* tab_id_;
liaoyuke
2017/06/15 19:08:48
Done.
|
ScopedObserver<infobars::InfoBarManager, infobars::InfoBarManager::Observer> |
scoped_observer_; |
@@ -210,12 +213,12 @@ @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<NSString*, DelegateHolder*>* upgradeInfoBarDelegates_; |
sdefresne
2017/06/15 16:34:30
nit: __strong NSMutableDictionary<NSString*, Deleg
liaoyuke
2017/06/15 19:08:47
Done.
|
// Stores the clients of the upgrade center. These objectiveC objects are not |
// retained. |
- std::set<id<UpgradeCenterClientProtocol>> clients_; |
+ NSHashTable<id<UpgradeCenterClientProtocol>>* clients_; |
sdefresne
2017/06/15 16:34:30
nit: __strong NSHashTable<id<UpgradeCenterClientPr
liaoyuke
2017/06/15 19:08:47
Done.
|
#ifndef NDEBUG |
- bool inCallback_; |
+ BOOL inCallback_; |
#endif |
} |
@@ -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. |
@@ -242,6 +245,7 @@ - (instancetype)init { |
object:nil]; |
upgradeInfoBarIsVisible_ = [self shouldShowInfoBar]; |
+ clients_ = [NSHashTable weakObjectsHashTable]; |
} |
return self; |
} |
@@ -284,7 +288,7 @@ - (void)applicationWillEnterForeground:(NSNotification*)note { |
} |
- (void)registerClient:(id<UpgradeCenterClientProtocol>)client { |
- clients_.insert(client); |
+ [clients_ addObject:client]; |
if (upgradeInfoBarIsVisible_) |
[client showUpgrade:self]; |
} |
@@ -293,7 +297,7 @@ - (void)unregisterClient:(id<UpgradeCenterClientProtocol>)client { |
#ifndef NDEBUG |
DCHECK(!inCallback_); |
#endif |
- clients_.erase(client); |
+ [clients_ removeObject:client]; |
} |
- (void)addInfoBarToManager:(infobars::InfoBarManager*)infoBarManager |
@@ -310,11 +314,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 +334,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 +357,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]; |
@@ -374,9 +378,9 @@ - (void)showUpgradeInfoBars { |
inCallback_ = YES; |
#endif |
upgradeInfoBarIsVisible_ = YES; |
- std::set<id<UpgradeCenterClientProtocol>>::iterator it; |
- for (it = clients_.begin(); it != clients_.end(); ++it) |
- [*it showUpgrade:self]; |
+ NSEnumerator* enumerator = [clients_ objectEnumerator]; |
sdefresne
2017/06/15 16:34:30
NSHashTable supports NSFastEnumeration, so you can
liaoyuke
2017/06/15 19:08:48
Done.
|
+ while (id value = [enumerator nextObject]) |
+ [value showUpgrade:self]; |
#ifndef NDEBUG |
inCallback_ = NO; |
#endif |
@@ -392,9 +396,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); |
@@ -446,7 +450,7 @@ - (void)resetForTests { |
[defaults removeObjectForKey:kNextVersionKey]; |
[defaults removeObjectForKey:kUpgradeURLKey]; |
[defaults removeObjectForKey:kLastInfobarDisplayTimeKey]; |
- clients_.clear(); |
+ [clients_ removeAllObjects]; |
} |
- (void)setLastDisplayToPast { |