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 @@
#include "base/macros.h"
@protocol NSObject;
@class NSNotification;
namespace web {
......@@ -21,7 +22,10 @@ class CookieNotificationBridge {
private:
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);
};
......
......@@ -20,18 +20,18 @@
namespace web {
CookieNotificationBridge::CookieNotificationBridge() {
id<NSObject> observer = [[NSNotificationCenter defaultCenter]
id<NSObject> registration = [[NSNotificationCenter defaultCenter]
addObserverForName:NSHTTPCookieManagerCookiesChangedNotification
object:[NSHTTPCookieStorage sharedHTTPCookieStorage]
queue:nil
usingBlock:^(NSNotification* notification) {
OnNotificationReceived(notification);
}];
observer_ = observer;
registration_ = registration;
}
CookieNotificationBridge::~CookieNotificationBridge() {
[[NSNotificationCenter defaultCenter] removeObserver:observer_];
[[NSNotificationCenter defaultCenter] removeObserver:registration_];
}
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