| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ | 5 #ifndef IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ |
| 6 #define IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ | 6 #define IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 namespace net { | 30 namespace net { |
| 31 | 31 |
| 32 class CookieCreationTimeManager; | 32 class CookieCreationTimeManager; |
| 33 | 33 |
| 34 // Observer for changes on |NSHTTPCookieStorge sharedHTTPCookieStorage|. | 34 // Observer for changes on |NSHTTPCookieStorge sharedHTTPCookieStorage|. |
| 35 class CookieNotificationObserver { | 35 class CookieNotificationObserver { |
| 36 public: | 36 public: |
| 37 // Called when any cookie is added, deleted or changed in | 37 // Called when any cookie is added, deleted or changed in |
| 38 // |NSHTTPCookieStorge sharedHTTPCookieStorage|. | 38 // |NSHTTPCookieStorge sharedHTTPCookieStorage|. |
| 39 virtual void OnSystemCookiesChanged() = 0; | 39 virtual void OnSystemCookiesChanged() = 0; |
| 40 // Called when the cookie policy changes on | |
| 41 // |NSHTTPCookieStorge sharedHTTPCookieStorage|. | |
| 42 virtual void OnSystemCookiePolicyChanged() = 0; | |
| 43 }; | 40 }; |
| 44 | 41 |
| 45 // The CookieStoreIOS is an implementation of CookieStore relying on | 42 // The CookieStoreIOS is an implementation of CookieStore relying on |
| 46 // NSHTTPCookieStorage, ensuring that the cookies are consistent between the | 43 // NSHTTPCookieStorage, ensuring that the cookies are consistent between the |
| 47 // network stack and the UIWebViews. | 44 // network stack and the UIWebViews. |
| 48 // On iOS, the Chrome CookieMonster is not used in conjunction with UIWebView, | 45 // On iOS, the Chrome CookieMonster is not used in conjunction with UIWebView, |
| 49 // because UIWebView expects the cookies to be in the shared | 46 // because UIWebView expects the cookies to be in the shared |
| 50 // NSHTTPCookieStorage. In particular, javascript may read and write cookies | 47 // NSHTTPCookieStorage. In particular, javascript may read and write cookies |
| 51 // there. | 48 // there. |
| 52 // CookieStoreIOS is not thread safe. | 49 // CookieStoreIOS is not thread safe. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 71 net::CookieMonster::PersistentCookieStore* persistent_store); | 68 net::CookieMonster::PersistentCookieStore* persistent_store); |
| 72 | 69 |
| 73 explicit CookieStoreIOS( | 70 explicit CookieStoreIOS( |
| 74 net::CookieMonster::PersistentCookieStore* persistent_store, | 71 net::CookieMonster::PersistentCookieStore* persistent_store, |
| 75 NSHTTPCookieStorage* system_store); | 72 NSHTTPCookieStorage* system_store); |
| 76 | 73 |
| 77 ~CookieStoreIOS() override; | 74 ~CookieStoreIOS() override; |
| 78 | 75 |
| 79 enum CookiePolicy { ALLOW, BLOCK }; | 76 enum CookiePolicy { ALLOW, BLOCK }; |
| 80 | 77 |
| 81 // Must be called on the thread where CookieStoreIOS instances live. | |
| 82 // Affects only those CookieStoreIOS instances that are backed by | |
| 83 // |NSHTTPCookieStorage sharedHTTPCookieStorage|. | |
| 84 static void SetCookiePolicy(CookiePolicy setting); | |
| 85 | |
| 86 // Create an instance of CookieStoreIOS that is generated from the cookies | 78 // Create an instance of CookieStoreIOS that is generated from the cookies |
| 87 // stored in |cookie_storage|. The CookieStoreIOS uses the |cookie_storage| | 79 // stored in |cookie_storage|. The CookieStoreIOS uses the |cookie_storage| |
| 88 // as its default backend and is initially synchronized with it. | 80 // as its default backend and is initially synchronized with it. |
| 89 // Apple does not persist the cookies' creation dates in NSHTTPCookieStorage, | 81 // Apple does not persist the cookies' creation dates in NSHTTPCookieStorage, |
| 90 // so callers should not expect these values to be populated. | 82 // so callers should not expect these values to be populated. |
| 91 static std::unique_ptr<CookieStoreIOS> CreateCookieStore( | 83 static std::unique_ptr<CookieStoreIOS> CreateCookieStore( |
| 92 NSHTTPCookieStorage* cookie_storage); | 84 NSHTTPCookieStorage* cookie_storage); |
| 93 | 85 |
| 94 // As there is only one system store, only one CookieStoreIOS at a time may | 86 // As there is only one system store, only one CookieStoreIOS at a time may |
| 95 // be synchronized with it. | 87 // be synchronized with it. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // Converts |cookies| to NSHTTPCookie and add them to the system store. | 184 // Converts |cookies| to NSHTTPCookie and add them to the system store. |
| 193 void AddCookiesToSystemStore(const net::CookieList& cookies); | 185 void AddCookiesToSystemStore(const net::CookieList& cookies); |
| 194 // Copies the cookies to the backing CookieMonster. If the cookie store is not | 186 // Copies the cookies to the backing CookieMonster. If the cookie store is not |
| 195 // synchronized with the system store, this is a no-op. | 187 // synchronized with the system store, this is a no-op. |
| 196 void WriteToCookieMonster(NSArray* system_cookies); | 188 void WriteToCookieMonster(NSArray* system_cookies); |
| 197 // Runs all the pending tasks. | 189 // Runs all the pending tasks. |
| 198 void RunAllPendingTasks(); | 190 void RunAllPendingTasks(); |
| 199 | 191 |
| 200 // Inherited CookieNotificationObserver methods. | 192 // Inherited CookieNotificationObserver methods. |
| 201 void OnSystemCookiesChanged() override; | 193 void OnSystemCookiesChanged() override; |
| 202 void OnSystemCookiePolicyChanged() override; | |
| 203 | 194 |
| 204 void DeleteCookiesWithFilter(const CookieFilterFunction& filter, | 195 void DeleteCookiesWithFilter(const CookieFilterFunction& filter, |
| 205 const DeleteCallback& callback); | 196 const DeleteCallback& callback); |
| 206 | 197 |
| 207 std::unique_ptr<net::CookieMonster> cookie_monster_; | 198 std::unique_ptr<net::CookieMonster> cookie_monster_; |
| 208 base::scoped_nsobject<NSHTTPCookieStorage> system_store_; | 199 base::scoped_nsobject<NSHTTPCookieStorage> system_store_; |
| 209 std::unique_ptr<CookieCreationTimeManager> creation_time_manager_; | 200 std::unique_ptr<CookieCreationTimeManager> creation_time_manager_; |
| 210 bool metrics_enabled_; | 201 bool metrics_enabled_; |
| 211 base::TimeDelta flush_delay_; | 202 base::TimeDelta flush_delay_; |
| 212 base::CancelableClosure flush_closure_; | 203 base::CancelableClosure flush_closure_; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 hook_map_; | 320 hook_map_; |
| 330 | 321 |
| 331 base::WeakPtrFactory<CookieStoreIOS> weak_factory_; | 322 base::WeakPtrFactory<CookieStoreIOS> weak_factory_; |
| 332 | 323 |
| 333 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS); | 324 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS); |
| 334 }; | 325 }; |
| 335 | 326 |
| 336 } // namespace net | 327 } // namespace net |
| 337 | 328 |
| 338 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ | 329 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ |
| OLD | NEW |