Commit df7445d3 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Improve documentation of CookieNotificationBridge

The ownership of the "observer_" member field of CookieNotificationBridge
was unclear and after a casual look at the code, it was unclear whether
the code caused a retain cycle or not.

Rename the member field, mark it as __strong and add documentation to
make it clear that the ownership model is correct, and that there is no
retain cycle caused by this object.

Bug: 1005153
Change-Id: I8f49e39e8355a0a2c758848ef34c45b4d5335b66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1809376
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697649}
parent 9d398391
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/macros.h" #include "base/macros.h"
@protocol NSObject;
@class NSNotification; @class NSNotification;
namespace web { namespace web {
...@@ -21,7 +22,10 @@ class CookieNotificationBridge { ...@@ -21,7 +22,10 @@ class CookieNotificationBridge {
private: private:
static void OnNotificationReceived(NSNotification* notification); static void OnNotificationReceived(NSNotification* notification);
id observer_;
// Token returned by NSNotificationCenter upon registration. Owned by the
// bridge and used to unregister from NSNotificationCenter in destructor.
__strong id<NSObject> registration_;
DISALLOW_COPY_AND_ASSIGN(CookieNotificationBridge); DISALLOW_COPY_AND_ASSIGN(CookieNotificationBridge);
}; };
......
...@@ -20,18 +20,18 @@ ...@@ -20,18 +20,18 @@
namespace web { namespace web {
CookieNotificationBridge::CookieNotificationBridge() { CookieNotificationBridge::CookieNotificationBridge() {
id<NSObject> observer = [[NSNotificationCenter defaultCenter] id<NSObject> registration = [[NSNotificationCenter defaultCenter]
addObserverForName:NSHTTPCookieManagerCookiesChangedNotification addObserverForName:NSHTTPCookieManagerCookiesChangedNotification
object:[NSHTTPCookieStorage sharedHTTPCookieStorage] object:[NSHTTPCookieStorage sharedHTTPCookieStorage]
queue:nil queue:nil
usingBlock:^(NSNotification* notification) { usingBlock:^(NSNotification* notification) {
OnNotificationReceived(notification); OnNotificationReceived(notification);
}]; }];
observer_ = observer; registration_ = registration;
} }
CookieNotificationBridge::~CookieNotificationBridge() { CookieNotificationBridge::~CookieNotificationBridge() {
[[NSNotificationCenter defaultCenter] removeObserver:observer_]; [[NSNotificationCenter defaultCenter] removeObserver:registration_];
} }
void CookieNotificationBridge::OnNotificationReceived( void CookieNotificationBridge::OnNotificationReceived(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment