OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ios/web/net/cookie_notification_bridge.h" | 5 #include "ios/web/net/cookie_notification_bridge.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "ios/net/cookies/cookie_store_ios.h" | 11 #include "ios/net/cookies/cookie_store_ios.h" |
12 #include "ios/web/public/web_thread.h" | 12 #include "ios/web/public/web_thread.h" |
13 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
14 namespace web { | 18 namespace web { |
15 | 19 |
16 CookieNotificationBridge::CookieNotificationBridge() { | 20 CookieNotificationBridge::CookieNotificationBridge() { |
17 id<NSObject> observer = [[NSNotificationCenter defaultCenter] | 21 id<NSObject> observer = [[NSNotificationCenter defaultCenter] |
18 addObserverForName:NSHTTPCookieManagerCookiesChangedNotification | 22 addObserverForName:NSHTTPCookieManagerCookiesChangedNotification |
19 object:[NSHTTPCookieStorage sharedHTTPCookieStorage] | 23 object:[NSHTTPCookieStorage sharedHTTPCookieStorage] |
20 queue:nil | 24 queue:nil |
21 usingBlock:^(NSNotification* notification) { | 25 usingBlock:^(NSNotification* notification) { |
22 OnNotificationReceived(notification); | 26 OnNotificationReceived(notification); |
23 }]; | 27 }]; |
24 observer_.reset([observer retain]); | 28 observer_.reset(observer); |
25 } | 29 } |
26 | 30 |
27 CookieNotificationBridge::~CookieNotificationBridge() { | 31 CookieNotificationBridge::~CookieNotificationBridge() { |
28 [[NSNotificationCenter defaultCenter] removeObserver:observer_]; | 32 [[NSNotificationCenter defaultCenter] removeObserver:observer_]; |
29 } | 33 } |
30 | 34 |
31 void CookieNotificationBridge::OnNotificationReceived( | 35 void CookieNotificationBridge::OnNotificationReceived( |
32 NSNotification* notification) { | 36 NSNotification* notification) { |
33 DCHECK(thread_checker_.CalledOnValidThread()); | 37 DCHECK(thread_checker_.CalledOnValidThread()); |
34 DCHECK([[notification name] | 38 DCHECK([[notification name] |
35 isEqualToString:NSHTTPCookieManagerCookiesChangedNotification]); | 39 isEqualToString:NSHTTPCookieManagerCookiesChangedNotification]); |
36 web::WebThread::PostTask( | 40 web::WebThread::PostTask( |
37 web::WebThread::IO, FROM_HERE, | 41 web::WebThread::IO, FROM_HERE, |
38 base::Bind(&net::CookieStoreIOS::NotifySystemCookiesChanged)); | 42 base::Bind(&net::CookieStoreIOS::NotifySystemCookiesChanged)); |
39 } | 43 } |
40 | 44 |
41 } // namespace web | 45 } // namespace web |
OLD | NEW |