| 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 <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "ios/net/cookies/cookie_cache.h" | 18 #include "ios/net/cookies/cookie_cache.h" |
| 19 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
| 20 #include "net/cookies/cookie_store.h" | 20 #include "net/cookies/cookie_store.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 #if defined(__OBJC__) | 23 #if defined(__OBJC__) |
| 24 @class NSHTTPCookie; | 24 @class NSHTTPCookie; |
| 25 @class NSHTTPCookieStorage; |
| 25 @class NSArray; | 26 @class NSArray; |
| 26 #else | 27 #else |
| 27 class NSHTTPCookie; | 28 class NSHTTPCookie; |
| 29 class NSHTTPCookieStorage; |
| 28 class NSArray; | 30 class NSArray; |
| 29 #endif | 31 #endif |
| 30 | 32 |
| 31 namespace net { | 33 namespace net { |
| 32 | 34 |
| 33 class CookieCreationTimeManager; | 35 class CookieCreationTimeManager; |
| 34 | 36 |
| 35 // Observer for system cookie notifications. | 37 // Observer for system cookie notifications. |
| 36 class CookieNotificationObserver { | 38 class CookieNotificationObserver { |
| 37 public: | 39 public: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 // directly to the system cookie store, then propagated to the backing store by | 59 // directly to the system cookie store, then propagated to the backing store by |
| 58 // OnSystemCookiesChanged, which is called by the system store once the change | 60 // OnSystemCookiesChanged, which is called by the system store once the change |
| 59 // to the system store is written back. | 61 // to the system store is written back. |
| 60 // | 62 // |
| 61 // To unsynchronize, CookieStoreIOS copies the system cookie store into its | 63 // To unsynchronize, CookieStoreIOS copies the system cookie store into its |
| 62 // backing CookieStore. To synchronize, CookieStoreIOS clears the system cookie | 64 // backing CookieStore. To synchronize, CookieStoreIOS clears the system cookie |
| 63 // store, copies its backing CookieStore into the system cookie store. | 65 // store, copies its backing CookieStore into the system cookie store. |
| 64 class CookieStoreIOS : public net::CookieStore, | 66 class CookieStoreIOS : public net::CookieStore, |
| 65 public CookieNotificationObserver { | 67 public CookieNotificationObserver { |
| 66 public: | 68 public: |
| 69 // Creates a CookieStoreIOS with a default value of |
| 70 // |NSHTTPCookieStorage sharedCookieStorage| as the system's cookie store. |
| 67 explicit CookieStoreIOS( | 71 explicit CookieStoreIOS( |
| 68 net::CookieMonster::PersistentCookieStore* persistent_store); | 72 net::CookieMonster::PersistentCookieStore* persistent_store); |
| 69 | 73 |
| 74 explicit CookieStoreIOS( |
| 75 net::CookieMonster::PersistentCookieStore* persistent_store, |
| 76 NSHTTPCookieStorage* system_store); |
| 77 |
| 70 enum CookiePolicy { ALLOW, BLOCK }; | 78 enum CookiePolicy { ALLOW, BLOCK }; |
| 71 | 79 |
| 72 // Must be called on the thread where CookieStoreIOS instances live. | 80 // Must be called on the thread where CookieStoreIOS instances live. |
| 73 static void SetCookiePolicy(CookiePolicy setting); | 81 static void SetCookiePolicy(CookiePolicy setting); |
| 74 | 82 |
| 75 // Create an instance of CookieStoreIOS that is generated from the cookies | 83 // Create an instance of CookieStoreIOS that is generated from the cookies |
| 76 // stored in the system NSHTTPCookieStorage. The caller is responsible for | 84 // stored in |cookie_storage|. The CookieStoreIOS uses the |cookie_storage| |
| 77 // deleting the cookie store. | 85 // as its default backend. |
| 78 // Apple does not persist the cookies' creation dates in the system store, | 86 // Apple does not persist the cookies' creation dates in NSHTTPCookieStorage, |
| 79 // so callers should not expect these values to be populated. | 87 // so callers should not expect these values to be populated. |
| 80 static CookieStoreIOS* CreateCookieStoreFromNSHTTPCookieStorage(); | 88 static CookieStoreIOS* CreateCookieStore(NSHTTPCookieStorage* cookie_storage); |
| 81 | 89 |
| 82 // As there is only one system store, only one CookieStoreIOS at a time may | 90 // As there is only one system store, only one CookieStoreIOS at a time may |
| 83 // be synchronized with it. | 91 // be synchronized with it. |
| 84 static void SwitchSynchronizedStore(CookieStoreIOS* old_store, | 92 static void SwitchSynchronizedStore(CookieStoreIOS* old_store, |
| 85 CookieStoreIOS* new_store); | 93 CookieStoreIOS* new_store); |
| 86 | 94 |
| 87 // Must be called when the state of the system cookie store changes. | 95 // Must be called when the state of the system cookie store changes. |
| 88 static void NotifySystemCookiesChanged(); | 96 static void NotifySystemCookiesChanged(); |
| 89 | 97 |
| 90 // Saves the cookies to the cookie monster. | 98 // Saves the cookies to the cookie monster. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 void RunAllPendingTasks(); | 176 void RunAllPendingTasks(); |
| 169 | 177 |
| 170 // Inherited CookieNotificationObserver methods. | 178 // Inherited CookieNotificationObserver methods. |
| 171 void OnSystemCookiesChanged() override; | 179 void OnSystemCookiesChanged() override; |
| 172 void OnSystemCookiePolicyChanged() override; | 180 void OnSystemCookiePolicyChanged() override; |
| 173 | 181 |
| 174 void DeleteCookiesWithFilter(const CookieFilterFunction& filter, | 182 void DeleteCookiesWithFilter(const CookieFilterFunction& filter, |
| 175 const DeleteCallback& callback); | 183 const DeleteCallback& callback); |
| 176 | 184 |
| 177 scoped_refptr<net::CookieMonster> cookie_monster_; | 185 scoped_refptr<net::CookieMonster> cookie_monster_; |
| 186 NSHTTPCookieStorage* system_store_; |
| 178 scoped_ptr<CookieCreationTimeManager> creation_time_manager_; | 187 scoped_ptr<CookieCreationTimeManager> creation_time_manager_; |
| 179 bool metrics_enabled_; | 188 bool metrics_enabled_; |
| 180 base::TimeDelta flush_delay_; | 189 base::TimeDelta flush_delay_; |
| 181 base::CancelableClosure flush_closure_; | 190 base::CancelableClosure flush_closure_; |
| 182 | 191 |
| 183 SynchronizationState synchronization_state_; | 192 SynchronizationState synchronization_state_; |
| 184 // Tasks received when SYNCHRONIZING are queued and run when SYNCHRONIZED. | 193 // Tasks received when SYNCHRONIZING are queued and run when SYNCHRONIZED. |
| 185 std::vector<base::Closure> tasks_pending_synchronization_; | 194 std::vector<base::Closure> tasks_pending_synchronization_; |
| 186 | 195 |
| 187 base::ThreadChecker thread_checker_; | 196 base::ThreadChecker thread_checker_; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 typedef std::map<std::pair<GURL, std::string>, CookieChangedCallbackList*> | 300 typedef std::map<std::pair<GURL, std::string>, CookieChangedCallbackList*> |
| 292 CookieChangedHookMap; | 301 CookieChangedHookMap; |
| 293 CookieChangedHookMap hook_map_; | 302 CookieChangedHookMap hook_map_; |
| 294 | 303 |
| 295 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS); | 304 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS); |
| 296 }; | 305 }; |
| 297 | 306 |
| 298 } // namespace net | 307 } // namespace net |
| 299 | 308 |
| 300 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ | 309 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ |
| OLD | NEW |