Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: ios/net/cookies/cookie_store_ios.h

Issue 1428673003: Injecting an NSHTTPCookieStorage dependency into CookieStoreIOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: y Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 changes on |NSHTTPCookieStorge sharedHTTPCookieStorage|.
36 class CookieNotificationObserver { 38 class CookieNotificationObserver {
37 public: 39 public:
38 // Called when any cookie is added, deleted or changed in the system store. 40 // Called when any cookie is added, deleted or changed in
41 // |NSHTTPCookieStorge sharedHTTPCookieStorage|.
39 virtual void OnSystemCookiesChanged() = 0; 42 virtual void OnSystemCookiesChanged() = 0;
40 // Called when the cookie policy changes. 43 // Called when the cookie policy changes on
44 // |NSHTTPCookieStorge sharedHTTPCookieStorage|.
41 virtual void OnSystemCookiePolicyChanged() = 0; 45 virtual void OnSystemCookiePolicyChanged() = 0;
42 }; 46 };
43 47
44 // The CookieStoreIOS is an implementation of CookieStore relying on 48 // The CookieStoreIOS is an implementation of CookieStore relying on
45 // NSHTTPCookieStorage, ensuring that the cookies are consistent between the 49 // NSHTTPCookieStorage, ensuring that the cookies are consistent between the
46 // network stack and the UIWebViews. 50 // network stack and the UIWebViews.
47 // On iOS, the Chrome CookieMonster is not used in conjunction with UIWebView, 51 // On iOS, the Chrome CookieMonster is not used in conjunction with UIWebView,
48 // because UIWebView expects the cookies to be in the shared 52 // because UIWebView expects the cookies to be in the shared
49 // NSHTTPCookieStorage. In particular, javascript may read and write cookies 53 // NSHTTPCookieStorage. In particular, javascript may read and write cookies
50 // there. 54 // there.
51 // CookieStoreIOS is not thread safe. 55 // CookieStoreIOS is not thread safe.
52 // 56 //
53 // At any given time, a CookieStoreIOS can either be synchronized with the 57 // At any given time, a CookieStoreIOS can either be synchronized with the
54 // system cookie store or not. If a CookieStoreIOS is not synchronized with the 58 // system cookie store or not. If a CookieStoreIOS is not synchronized with the
55 // system store, changes are written back to the backing CookieStore. If a 59 // system store, changes are written back to the backing CookieStore. If a
56 // CookieStoreIOS is synchronized with the system store, changes are written 60 // CookieStoreIOS is synchronized with the system store, changes are written
57 // directly to the system cookie store, then propagated to the backing store by 61 // 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 62 // OnSystemCookiesChanged, which is called by the system store once the change
59 // to the system store is written back. 63 // to the system store is written back.
60 // 64 //
61 // To unsynchronize, CookieStoreIOS copies the system cookie store into its 65 // To unsynchronize, CookieStoreIOS copies the system cookie store into its
62 // backing CookieStore. To synchronize, CookieStoreIOS clears the system cookie 66 // backing CookieStore. To synchronize, CookieStoreIOS clears the system cookie
63 // store, copies its backing CookieStore into the system cookie store. 67 // store, copies its backing CookieStore into the system cookie store.
64 class CookieStoreIOS : public net::CookieStore, 68 class CookieStoreIOS : public net::CookieStore,
65 public CookieNotificationObserver { 69 public CookieNotificationObserver {
66 public: 70 public:
71 // Creates a CookieStoreIOS with a default value of
72 // |NSHTTPCookieStorage sharedCookieStorage| as the system's cookie store.
67 explicit CookieStoreIOS( 73 explicit CookieStoreIOS(
68 net::CookieMonster::PersistentCookieStore* persistent_store); 74 net::CookieMonster::PersistentCookieStore* persistent_store);
69 75
76 explicit CookieStoreIOS(
77 net::CookieMonster::PersistentCookieStore* persistent_store,
78 NSHTTPCookieStorage* system_store);
79
70 enum CookiePolicy { ALLOW, BLOCK }; 80 enum CookiePolicy { ALLOW, BLOCK };
71 81
72 // Must be called on the thread where CookieStoreIOS instances live. 82 // Must be called on the thread where CookieStoreIOS instances live.
83 // Affects only those CookieStoreIOS instances that are backed by
84 // |NSHTTPCookieStorage sharedHTTPCookieStorage|.
73 static void SetCookiePolicy(CookiePolicy setting); 85 static void SetCookiePolicy(CookiePolicy setting);
74 86
75 // Create an instance of CookieStoreIOS that is generated from the cookies 87 // Create an instance of CookieStoreIOS that is generated from the cookies
76 // stored in the system NSHTTPCookieStorage. The caller is responsible for 88 // stored in |cookie_storage|. The CookieStoreIOS uses the |cookie_storage|
77 // deleting the cookie store. 89 // as its default backend.
droger 2015/11/03 10:24:07 Nit: While you are touching this, can you add some
shreyasv1 2015/11/03 18:15:46 Done.
78 // Apple does not persist the cookies' creation dates in the system store, 90 // Apple does not persist the cookies' creation dates in NSHTTPCookieStorage,
79 // so callers should not expect these values to be populated. 91 // so callers should not expect these values to be populated.
80 static CookieStoreIOS* CreateCookieStoreFromNSHTTPCookieStorage(); 92 static CookieStoreIOS* CreateCookieStore(NSHTTPCookieStorage* cookie_storage);
81 93
82 // As there is only one system store, only one CookieStoreIOS at a time may 94 // As there is only one system store, only one CookieStoreIOS at a time may
83 // be synchronized with it. 95 // be synchronized with it.
84 static void SwitchSynchronizedStore(CookieStoreIOS* old_store, 96 static void SwitchSynchronizedStore(CookieStoreIOS* old_store,
85 CookieStoreIOS* new_store); 97 CookieStoreIOS* new_store);
86 98
87 // Must be called when the state of the system cookie store changes. 99 // Must be called when the state of
100 // |NSHTTPCookieStorage sharedHTTPCookieStorage| changes.
101 // Affects only those CookieStoreIOS instances that are backed by
102 // |NSHTTPCookieStorage sharedHTTPCookieStorage|.
88 static void NotifySystemCookiesChanged(); 103 static void NotifySystemCookiesChanged();
89 104
90 // Saves the cookies to the cookie monster. 105 // Saves the cookies to the cookie monster.
91 // Note: ignores the write cookie operation if |write_on_flush_| is false. 106 // Note: ignores the write cookie operation if |write_on_flush_| is false.
92 void Flush(const base::Closure& callback); 107 void Flush(const base::Closure& callback);
93 108
94 // Unsynchronizes the cookie store if it is currently synchronized. 109 // Unsynchronizes the cookie store if it is currently synchronized.
95 void UnSynchronize(); 110 void UnSynchronize();
96 111
97 // Only one cookie store may enable metrics. 112 // Only one cookie store may enable metrics.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 void RunAllPendingTasks(); 183 void RunAllPendingTasks();
169 184
170 // Inherited CookieNotificationObserver methods. 185 // Inherited CookieNotificationObserver methods.
171 void OnSystemCookiesChanged() override; 186 void OnSystemCookiesChanged() override;
172 void OnSystemCookiePolicyChanged() override; 187 void OnSystemCookiePolicyChanged() override;
173 188
174 void DeleteCookiesWithFilter(const CookieFilterFunction& filter, 189 void DeleteCookiesWithFilter(const CookieFilterFunction& filter,
175 const DeleteCallback& callback); 190 const DeleteCallback& callback);
176 191
177 scoped_refptr<net::CookieMonster> cookie_monster_; 192 scoped_refptr<net::CookieMonster> cookie_monster_;
193 NSHTTPCookieStorage* system_store_;
178 scoped_ptr<CookieCreationTimeManager> creation_time_manager_; 194 scoped_ptr<CookieCreationTimeManager> creation_time_manager_;
179 bool metrics_enabled_; 195 bool metrics_enabled_;
180 base::TimeDelta flush_delay_; 196 base::TimeDelta flush_delay_;
181 base::CancelableClosure flush_closure_; 197 base::CancelableClosure flush_closure_;
182 198
183 SynchronizationState synchronization_state_; 199 SynchronizationState synchronization_state_;
184 // Tasks received when SYNCHRONIZING are queued and run when SYNCHRONIZED. 200 // Tasks received when SYNCHRONIZING are queued and run when SYNCHRONIZED.
185 std::vector<base::Closure> tasks_pending_synchronization_; 201 std::vector<base::Closure> tasks_pending_synchronization_;
186 202
187 base::ThreadChecker thread_checker_; 203 base::ThreadChecker thread_checker_;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 typedef std::map<std::pair<GURL, std::string>, CookieChangedCallbackList*> 307 typedef std::map<std::pair<GURL, std::string>, CookieChangedCallbackList*>
292 CookieChangedHookMap; 308 CookieChangedHookMap;
293 CookieChangedHookMap hook_map_; 309 CookieChangedHookMap hook_map_;
294 310
295 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS); 311 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS);
296 }; 312 };
297 313
298 } // namespace net 314 } // namespace net
299 315
300 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ 316 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698