QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / ios / web / net / cookie_notification_bridge.mm
blob8ebb9a7bcf78e69c4def4ff78ccb1673292bbcc6
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>
9 #include "base/bind.h"
10 #include "base/location.h"
11 #include "ios/net/cookies/cookie_store_ios.h"
12 #include "ios/web/public/web_thread.h"
14 namespace web {
16 CookieNotificationBridge::CookieNotificationBridge() {
17   observer_.reset([[NSNotificationCenter defaultCenter]
18       addObserverForName:NSHTTPCookieManagerCookiesChangedNotification
19                   object:[NSHTTPCookieStorage sharedHTTPCookieStorage]
20                    queue:nil
21               usingBlock:^(NSNotification* notification) {
22                   OnNotificationReceived(notification);
23               }]);
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));
40 }  // namespace web