1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/web/net/cookie_notification_bridge.h"
7 #import <Foundation/Foundation.h>
10 #include "base/location.h"
11 #include "ios/net/cookies/cookie_store_ios.h"
12 #include "ios/web/public/web_thread.h"
16 CookieNotificationBridge::CookieNotificationBridge() {
17 observer_.reset([[NSNotificationCenter defaultCenter]
18 addObserverForName:NSHTTPCookieManagerCookiesChangedNotification
19 object:[NSHTTPCookieStorage sharedHTTPCookieStorage]
21 usingBlock:^(NSNotification* notification) {
22 OnNotificationReceived(notification);
26 CookieNotificationBridge::~CookieNotificationBridge() {
27 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
30 void CookieNotificationBridge::OnNotificationReceived(
31 NSNotification* notification) {
32 DCHECK(thread_checker_.CalledOnValidThread());
33 DCHECK([[notification name]
34 isEqualToString:NSHTTPCookieManagerCookiesChangedNotification]);
35 web::WebThread::PostTask(
36 web::WebThread::IO, FROM_HERE,
37 base::Bind(&net::CookieStoreIOS::NotifySystemCookiesChanged));