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

Unified Diff: webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m

Issue 3013023002: Fix retain cycles in RTCUIApplicationStatusObserver. (Closed)
Patch Set: Created 3 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m
diff --git a/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m b/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m
index 168832d9ed08a2653f2595f4f425203bde3d5f7a..64b1c73e10ac75ca81a5871bda6be905181d2a8e 100644
--- a/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m
+++ b/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m
@@ -16,12 +16,23 @@
#include "webrtc/rtc_base/checks.h"
+@interface RTCUIApplicationStatusObserver ()
+
+@property(nonatomic, assign) UIApplicationState state;
+
+@end
+
@implementation RTCUIApplicationStatusObserver {
BOOL _initialized;
dispatch_block_t _initializeBlock;
UIApplicationState _state;
+
+ id<NSObject> _activeObserver;
+ id<NSObject> _backgroundObserver;
}
+@synthesize state;
+
+ (instancetype)sharedInstance {
static id sharedInstance;
static dispatch_once_t onceToken;
@@ -35,19 +46,22 @@
- (id)init {
if (self = [super init]) {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
- [center addObserverForName:UIApplicationDidBecomeActiveNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification *note) {
- _state = [UIApplication sharedApplication].applicationState;
- }];
-
- [center addObserverForName:UIApplicationDidEnterBackgroundNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification *note) {
- _state = [UIApplication sharedApplication].applicationState;
- }];
+ __weak RTCUIApplicationStatusObserver *weakSelf = self;
+ _activeObserver = [center addObserverForName:UIApplicationDidBecomeActiveNotification
+ object:nil
+ queue:[NSOperationQueue mainQueue]
+ usingBlock:^(NSNotification *note) {
+ weakSelf.state =
+ [UIApplication sharedApplication].applicationState;
+ }];
+
+ _backgroundObserver = [center addObserverForName:UIApplicationDidEnterBackgroundNotification
+ object:nil
+ queue:[NSOperationQueue mainQueue]
+ usingBlock:^(NSNotification *note) {
+ weakSelf.state =
+ [UIApplication sharedApplication].applicationState;
+ }];
_initialized = NO;
_initializeBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
@@ -61,6 +75,12 @@
return self;
}
+- (void)dealloc {
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ [center removeObserver:_activeObserver];
+ [center removeObserver:_backgroundObserver];
+}
+
- (BOOL)isApplicationActive {
if (!_initialized) {
long ret = dispatch_block_wait(_initializeBlock,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698