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/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" |
17 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "ios/net/cookies/cookie_cache.h" | 20 #include "ios/net/cookies/cookie_cache.h" |
20 #include "net/cookies/cookie_monster.h" | 21 #include "net/cookies/cookie_monster.h" |
21 #include "net/cookies/cookie_store.h" | 22 #include "net/cookies/cookie_store.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
23 | 24 |
24 @class NSHTTPCookie; | 25 @class NSHTTPCookie; |
25 @class NSHTTPCookieStorage; | 26 @class NSHTTPCookieStorage; |
26 @class NSArray; | 27 @class NSArray; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 public: | 66 public: |
66 // Creates a CookieStoreIOS with a default value of | 67 // Creates a CookieStoreIOS with a default value of |
67 // |NSHTTPCookieStorage sharedCookieStorage| as the system's cookie store. | 68 // |NSHTTPCookieStorage sharedCookieStorage| as the system's cookie store. |
68 explicit CookieStoreIOS( | 69 explicit CookieStoreIOS( |
69 net::CookieMonster::PersistentCookieStore* persistent_store); | 70 net::CookieMonster::PersistentCookieStore* persistent_store); |
70 | 71 |
71 explicit CookieStoreIOS( | 72 explicit CookieStoreIOS( |
72 net::CookieMonster::PersistentCookieStore* persistent_store, | 73 net::CookieMonster::PersistentCookieStore* persistent_store, |
73 NSHTTPCookieStorage* system_store); | 74 NSHTTPCookieStorage* system_store); |
74 | 75 |
| 76 ~CookieStoreIOS() override; |
| 77 |
75 enum CookiePolicy { ALLOW, BLOCK }; | 78 enum CookiePolicy { ALLOW, BLOCK }; |
76 | 79 |
77 // Must be called on the thread where CookieStoreIOS instances live. | 80 // Must be called on the thread where CookieStoreIOS instances live. |
78 // Affects only those CookieStoreIOS instances that are backed by | 81 // Affects only those CookieStoreIOS instances that are backed by |
79 // |NSHTTPCookieStorage sharedHTTPCookieStorage|. | 82 // |NSHTTPCookieStorage sharedHTTPCookieStorage|. |
80 static void SetCookiePolicy(CookiePolicy setting); | 83 static void SetCookiePolicy(CookiePolicy setting); |
81 | 84 |
82 // Create an instance of CookieStoreIOS that is generated from the cookies | 85 // Create an instance of CookieStoreIOS that is generated from the cookies |
83 // stored in |cookie_storage|. The CookieStoreIOS uses the |cookie_storage| | 86 // stored in |cookie_storage|. The CookieStoreIOS uses the |cookie_storage| |
84 // as its default backend and is initially synchronized with it. | 87 // as its default backend and is initially synchronized with it. |
85 // Apple does not persist the cookies' creation dates in NSHTTPCookieStorage, | 88 // Apple does not persist the cookies' creation dates in NSHTTPCookieStorage, |
86 // so callers should not expect these values to be populated. | 89 // so callers should not expect these values to be populated. |
87 static CookieStoreIOS* CreateCookieStore(NSHTTPCookieStorage* cookie_storage); | 90 static scoped_ptr<CookieStoreIOS> CreateCookieStore( |
| 91 NSHTTPCookieStorage* cookie_storage); |
88 | 92 |
89 // As there is only one system store, only one CookieStoreIOS at a time may | 93 // As there is only one system store, only one CookieStoreIOS at a time may |
90 // be synchronized with it. | 94 // be synchronized with it. |
91 static void SwitchSynchronizedStore(CookieStoreIOS* old_store, | 95 static void SwitchSynchronizedStore(CookieStoreIOS* old_store, |
92 CookieStoreIOS* new_store); | 96 CookieStoreIOS* new_store); |
93 | 97 |
94 // Must be called when the state of | 98 // Must be called when the state of |
95 // |NSHTTPCookieStorage sharedHTTPCookieStorage| changes. | 99 // |NSHTTPCookieStorage sharedHTTPCookieStorage| changes. |
96 // Affects only those CookieStoreIOS instances that are backed by | 100 // Affects only those CookieStoreIOS instances that are backed by |
97 // |NSHTTPCookieStorage sharedHTTPCookieStorage|. | 101 // |NSHTTPCookieStorage sharedHTTPCookieStorage|. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 const GURL& url, | 154 const GURL& url, |
151 const DeleteCallback& callback) override; | 155 const DeleteCallback& callback) override; |
152 void DeleteSessionCookiesAsync(const DeleteCallback& callback) override; | 156 void DeleteSessionCookiesAsync(const DeleteCallback& callback) override; |
153 void FlushStore(const base::Closure& callback) override; | 157 void FlushStore(const base::Closure& callback) override; |
154 | 158 |
155 scoped_ptr<CookieChangedSubscription> AddCallbackForCookie( | 159 scoped_ptr<CookieChangedSubscription> AddCallbackForCookie( |
156 const GURL& url, | 160 const GURL& url, |
157 const std::string& name, | 161 const std::string& name, |
158 const CookieChangedCallback& callback) override; | 162 const CookieChangedCallback& callback) override; |
159 | 163 |
160 protected: | |
161 ~CookieStoreIOS() override; | |
162 | |
163 private: | 164 private: |
164 // For tests. | 165 // For tests. |
165 friend struct CookieStoreIOSTestTraits; | 166 friend struct CookieStoreIOSTestTraits; |
166 | 167 |
167 enum SynchronizationState { | 168 enum SynchronizationState { |
168 NOT_SYNCHRONIZED, // Uses CookieMonster as backend. | 169 NOT_SYNCHRONIZED, // Uses CookieMonster as backend. |
169 SYNCHRONIZING, // Moves from NSHTTPCookieStorage to CookieMonster. | 170 SYNCHRONIZING, // Moves from NSHTTPCookieStorage to CookieMonster. |
170 SYNCHRONIZED // Uses NSHTTPCookieStorage as backend. | 171 SYNCHRONIZED // Uses NSHTTPCookieStorage as backend. |
171 }; | 172 }; |
172 | 173 |
(...skipping 20 matching lines...) Expand all Loading... |
193 // Runs all the pending tasks. | 194 // Runs all the pending tasks. |
194 void RunAllPendingTasks(); | 195 void RunAllPendingTasks(); |
195 | 196 |
196 // Inherited CookieNotificationObserver methods. | 197 // Inherited CookieNotificationObserver methods. |
197 void OnSystemCookiesChanged() override; | 198 void OnSystemCookiesChanged() override; |
198 void OnSystemCookiePolicyChanged() override; | 199 void OnSystemCookiePolicyChanged() override; |
199 | 200 |
200 void DeleteCookiesWithFilter(const CookieFilterFunction& filter, | 201 void DeleteCookiesWithFilter(const CookieFilterFunction& filter, |
201 const DeleteCallback& callback); | 202 const DeleteCallback& callback); |
202 | 203 |
203 scoped_refptr<net::CookieMonster> cookie_monster_; | 204 scoped_ptr<net::CookieMonster> cookie_monster_; |
204 NSHTTPCookieStorage* system_store_; | 205 NSHTTPCookieStorage* system_store_; |
205 scoped_ptr<CookieCreationTimeManager> creation_time_manager_; | 206 scoped_ptr<CookieCreationTimeManager> creation_time_manager_; |
206 bool metrics_enabled_; | 207 bool metrics_enabled_; |
207 base::TimeDelta flush_delay_; | 208 base::TimeDelta flush_delay_; |
208 base::CancelableClosure flush_closure_; | 209 base::CancelableClosure flush_closure_; |
209 | 210 |
210 SynchronizationState synchronization_state_; | 211 SynchronizationState synchronization_state_; |
211 // Tasks received when SYNCHRONIZING are queued and run when SYNCHRONIZED. | 212 // Tasks received when SYNCHRONIZING are queued and run when SYNCHRONIZED. |
212 std::vector<base::Closure> tasks_pending_synchronization_; | 213 std::vector<base::Closure> tasks_pending_synchronization_; |
213 | 214 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 318 |
318 // Cached values of system cookies. Only cookies which have an observer added | 319 // Cached values of system cookies. Only cookies which have an observer added |
319 // with AddCallbackForCookie are kept in this cache. | 320 // with AddCallbackForCookie are kept in this cache. |
320 scoped_ptr<CookieCache> cookie_cache_; | 321 scoped_ptr<CookieCache> cookie_cache_; |
321 | 322 |
322 // Callbacks for cookie changes installed by AddCallbackForCookie. | 323 // Callbacks for cookie changes installed by AddCallbackForCookie. |
323 typedef std::map<std::pair<GURL, std::string>, CookieChangedCallbackList*> | 324 typedef std::map<std::pair<GURL, std::string>, CookieChangedCallbackList*> |
324 CookieChangedHookMap; | 325 CookieChangedHookMap; |
325 CookieChangedHookMap hook_map_; | 326 CookieChangedHookMap hook_map_; |
326 | 327 |
| 328 base::WeakPtrFactory<CookieStoreIOS> weak_factory_; |
| 329 |
327 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS); | 330 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS); |
328 }; | 331 }; |
329 | 332 |
330 } // namespace net | 333 } // namespace net |
331 | 334 |
332 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ | 335 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ |
OLD | NEW |