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

Unified Diff: ios/chrome/browser/web_state_list/web_state_list_fast_enumeration_helper.mm

Issue 2809543003: [ios] Change WebStateListObserverBridge to use weak reference. (Closed)
Patch Set: Fix DCHECK in WebStateList's ObserverList destructor. Created 3 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: ios/chrome/browser/web_state_list/web_state_list_fast_enumeration_helper.mm
diff --git a/ios/chrome/browser/web_state_list/web_state_list_fast_enumeration_helper.mm b/ios/chrome/browser/web_state_list/web_state_list_fast_enumeration_helper.mm
index 990c6e9333e7b65663690fc87d691dc6fb976391..7d8915313544a2bd698fae801d80937fcbefc151 100644
--- a/ios/chrome/browser/web_state_list/web_state_list_fast_enumeration_helper.mm
+++ b/ios/chrome/browser/web_state_list/web_state_list_fast_enumeration_helper.mm
@@ -17,68 +17,9 @@
#error "This file requires ARC support."
#endif
-#pragma mark - WebStateListFastEnumerationHelperObserver
-
-// Observer for WebStateListFastEnumerationHelper that will increment the
-// mutation counter provided in the constructor every time the WebStateList
-// it is tracking is modified.
-@interface WebStateListFastEnumerationHelperObserver
- : NSObject<WebStateListObserving>
-
-// Initializes the observer with a pointer to the mutation counter to increment
-// when the WebStateList is mutated.
-- (instancetype)initWithMutationCounter:(unsigned long*)mutationCounter
- NS_DESIGNATED_INITIALIZER;
-
-- (instancetype)init NS_UNAVAILABLE;
-
-@end
-
-@implementation WebStateListFastEnumerationHelperObserver {
- // Pointer to the mutation counter to increment when the WebStateList is
- // mutated.
- unsigned long* _mutationCounter;
-}
-
-- (instancetype)initWithMutationCounter:(unsigned long*)mutationCounter {
- DCHECK(mutationCounter);
- if ((self = [super init]))
- _mutationCounter = mutationCounter;
- return self;
-}
-
-#pragma mark WebStateListObserving
-
-- (void)webStateList:(WebStateList*)webStateList
- didInsertWebState:(web::WebState*)webState
- atIndex:(int)index {
- ++*_mutationCounter;
-}
-
-- (void)webStateList:(WebStateList*)webStateList
- didMoveWebState:(web::WebState*)webState
- fromIndex:(int)fromIndex
- toIndex:(int)toIndex {
- ++*_mutationCounter;
-}
-
-- (void)webStateList:(WebStateList*)webStateList
- didReplaceWebState:(web::WebState*)oldWebState
- byWebState:(web::WebState*)newWebState
- atIndex:(int)index {
- ++*_mutationCounter;
-}
-
-- (void)webStateList:(WebStateList*)webStateList
- didDetachWebState:(web::WebState*)webState
- atIndex:(int)index {
- ++*_mutationCounter;
-}
-
+@interface WebStateListFastEnumerationHelper ()<WebStateListObserving>
@end
-#pragma mark - WebStateListFastEnumerationHelper
-
@implementation WebStateListFastEnumerationHelper {
// The wrapped WebStateList.
WebStateList* _webStateList;
@@ -100,9 +41,7 @@
if ((self = [super init])) {
_webStateList = webStateList;
_proxyFactory = proxyFactory;
- _observerBridge = base::MakeUnique<WebStateListObserverBridge>(
- [[WebStateListFastEnumerationHelperObserver alloc]
- initWithMutationCounter:&_mutationCounter]);
+ _observerBridge = base::MakeUnique<WebStateListObserverBridge>(self);
_webStateList->AddObserver(_observerBridge.get());
}
return self;
@@ -144,4 +83,32 @@
return static_cast<NSUInteger>(count);
}
+#pragma mark WebStateListObserving
+
+- (void)webStateList:(WebStateList*)webStateList
+ didInsertWebState:(web::WebState*)webState
+ atIndex:(int)index {
+ ++_mutationCounter;
+}
+
+- (void)webStateList:(WebStateList*)webStateList
+ didMoveWebState:(web::WebState*)webState
+ fromIndex:(int)fromIndex
+ toIndex:(int)toIndex {
+ ++_mutationCounter;
+}
+
+- (void)webStateList:(WebStateList*)webStateList
+ didReplaceWebState:(web::WebState*)oldWebState
+ byWebState:(web::WebState*)newWebState
+ atIndex:(int)index {
+ ++_mutationCounter;
+}
+
+- (void)webStateList:(WebStateList*)webStateList
+ didDetachWebState:(web::WebState*)webState
+ atIndex:(int)index {
+ ++_mutationCounter;
+}
+
@end
« no previous file with comments | « ios/chrome/browser/tabs/tab_model.mm ('k') | ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698