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

Side by Side Diff: net/base/cookie_monster.h

Issue 115204: Add a separate cookie store that's used for extensions.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Brought to you by the letter D and the number 2. 5 // Brought to you by the letter D and the number 2.
6 6
7 #ifndef NET_BASE_COOKIE_MONSTER_H_ 7 #ifndef NET_BASE_COOKIE_MONSTER_H_
8 #define NET_BASE_COOKIE_MONSTER_H_ 8 #define NET_BASE_COOKIE_MONSTER_H_
9 9
10 #include <map> 10 #include <map>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // class, but it must remain valid for the duration of the cookie monster's 69 // class, but it must remain valid for the duration of the cookie monster's
70 // existence. 70 // existence.
71 CookieMonster(PersistentCookieStore* store); 71 CookieMonster(PersistentCookieStore* store);
72 72
73 #ifdef UNIT_TEST 73 #ifdef UNIT_TEST
74 CookieMonster(int last_access_threshold_seconds) 74 CookieMonster(int last_access_threshold_seconds)
75 : initialized_(false), 75 : initialized_(false),
76 store_(NULL), 76 store_(NULL),
77 last_access_threshold_( 77 last_access_threshold_(
78 base::TimeDelta::FromSeconds(last_access_threshold_seconds)) { 78 base::TimeDelta::FromSeconds(last_access_threshold_seconds)) {
79 SetDefaultCookieableSchemes();
79 } 80 }
80 #endif 81 #endif
81 82
82 ~CookieMonster(); 83 ~CookieMonster();
83 84
84 // Parse the string with the cookie time (very forgivingly). 85 // Parse the string with the cookie time (very forgivingly).
85 static base::Time ParseCookieTime(const std::string& time_string); 86 static base::Time ParseCookieTime(const std::string& time_string);
86 87
87 // Set a single cookie. Expects a cookie line, like "a=1; domain=b.com". 88 // Set a single cookie. Expects a cookie line, like "a=1; domain=b.com".
88 bool SetCookie(const GURL& url, const std::string& cookie_line); 89 bool SetCookie(const GURL& url, const std::string& cookie_line);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 bool sync_to_store); 127 bool sync_to_store);
127 // Delete all of the cookies that have a creation_date more recent than the 128 // Delete all of the cookies that have a creation_date more recent than the
128 // one passed into the function via |delete_after|. 129 // one passed into the function via |delete_after|.
129 int DeleteAllCreatedAfter(const base::Time& delete_begin, bool sync_to_store); 130 int DeleteAllCreatedAfter(const base::Time& delete_begin, bool sync_to_store);
130 131
131 // Delete one specific cookie. 132 // Delete one specific cookie.
132 bool DeleteCookie(const std::string& domain, 133 bool DeleteCookie(const std::string& domain,
133 const CanonicalCookie& cookie, 134 const CanonicalCookie& cookie,
134 bool sync_to_store); 135 bool sync_to_store);
135 136
137 // Override the default list of schemes that are allowed to be set in
138 // this cookie store. Calling his overrides the value of
139 // "enable_file_scheme_".
140 void SetCookieableSchemes(const char* schemes[], size_t num_schemes);
141
136 // There are some unknowns about how to correctly handle file:// cookies, 142 // There are some unknowns about how to correctly handle file:// cookies,
137 // and our implementation for this is not robust enough. This allows you 143 // and our implementation for this is not robust enough. This allows you
138 // to enable support, but it should only be used for testing. Bug 1157243. 144 // to enable support, but it should only be used for testing. Bug 1157243.
145 // Must be called before creating a CookieMonster instance.
139 static void EnableFileScheme(); 146 static void EnableFileScheme();
140 static bool enable_file_scheme_; 147 static bool enable_file_scheme_;
141 148
142 private: 149 private:
143 // Called by all non-static functions to ensure that the cookies store has 150 // Called by all non-static functions to ensure that the cookies store has
144 // been initialized. This is not done during creating so it doesn't block 151 // been initialized. This is not done during creating so it doesn't block
145 // the window showing. 152 // the window showing.
146 // Note: this method should always be called with lock_ held. 153 // Note: this method should always be called with lock_ held.
147 void InitIfNecessary() { 154 void InitIfNecessary() {
148 if (!initialized_) { 155 if (!initialized_) {
149 if (store_) 156 if (store_)
150 InitStore(); 157 InitStore();
151 initialized_ = true; 158 initialized_ = true;
152 } 159 }
153 } 160 }
154 161
155 // Initializes the backing store and reads existing cookies from it. 162 // Initializes the backing store and reads existing cookies from it.
156 // Should only be called by InitIfNecessary(). 163 // Should only be called by InitIfNecessary().
157 void InitStore(); 164 void InitStore();
158 165
166 void SetDefaultCookieableSchemes();
167
159 void FindCookiesForHostAndDomain(const GURL& url, 168 void FindCookiesForHostAndDomain(const GURL& url,
160 const CookieOptions& options, 169 const CookieOptions& options,
161 std::vector<CanonicalCookie*>* cookies); 170 std::vector<CanonicalCookie*>* cookies);
162 171
163 void FindCookiesForKey(const std::string& key, 172 void FindCookiesForKey(const std::string& key,
164 const GURL& url, 173 const GURL& url,
165 const CookieOptions& options, 174 const CookieOptions& options,
166 const base::Time& current, 175 const base::Time& current,
167 std::vector<CanonicalCookie*>* cookies); 176 std::vector<CanonicalCookie*>* cookies);
168 177
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 212
204 // Helper for GarbageCollectRange(); can be called directly as well. Deletes 213 // Helper for GarbageCollectRange(); can be called directly as well. Deletes
205 // all expired cookies in |itpair|. If |cookie_its| is non-NULL, it is 214 // all expired cookies in |itpair|. If |cookie_its| is non-NULL, it is
206 // populated with all the non-expired cookies from |itpair|. 215 // populated with all the non-expired cookies from |itpair|.
207 // 216 //
208 // Returns the number of cookies deleted. 217 // Returns the number of cookies deleted.
209 int GarbageCollectExpired(const base::Time& current, 218 int GarbageCollectExpired(const base::Time& current,
210 const CookieMapItPair& itpair, 219 const CookieMapItPair& itpair,
211 std::vector<CookieMap::iterator>* cookie_its); 220 std::vector<CookieMap::iterator>* cookie_its);
212 221
222 bool HasCookieableScheme(const GURL& url);
223
213 CookieMap cookies_; 224 CookieMap cookies_;
214 225
215 // Indicates whether the cookie store has been initialized. This happens 226 // Indicates whether the cookie store has been initialized. This happens
216 // lazily in InitStoreIfNecessary(). 227 // lazily in InitStoreIfNecessary().
217 bool initialized_; 228 bool initialized_;
218 229
219 PersistentCookieStore* store_; 230 PersistentCookieStore* store_;
220 231
221 // The resolution of our time isn't enough, so we do something 232 // The resolution of our time isn't enough, so we do something
222 // ugly and increment when we've seen the same time twice. 233 // ugly and increment when we've seen the same time twice.
223 base::Time CurrentTime(); 234 base::Time CurrentTime();
224 base::Time last_time_seen_; 235 base::Time last_time_seen_;
225 236
226 // Minimum delay after updating a cookie's LastAccessDate before we will 237 // Minimum delay after updating a cookie's LastAccessDate before we will
227 // update it again. 238 // update it again.
228 const base::TimeDelta last_access_threshold_; 239 const base::TimeDelta last_access_threshold_;
229 240
241 std::vector<std::string> cookieable_schemes_;
242
230 // Lock for thread-safety 243 // Lock for thread-safety
231 Lock lock_; 244 Lock lock_;
232 245
233 DISALLOW_COPY_AND_ASSIGN(CookieMonster); 246 DISALLOW_COPY_AND_ASSIGN(CookieMonster);
234 }; 247 };
235 248
236 class CookieMonster::ParsedCookie { 249 class CookieMonster::ParsedCookie {
237 public: 250 public:
238 typedef std::pair<std::string, std::string> TokenValuePair; 251 typedef std::pair<std::string, std::string> TokenValuePair;
239 typedef std::vector<TokenValuePair> PairList; 252 typedef std::vector<TokenValuePair> PairList;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 protected: 396 protected:
384 PersistentCookieStore() { } 397 PersistentCookieStore() { }
385 398
386 private: 399 private:
387 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); 400 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
388 }; 401 };
389 402
390 } // namespace net 403 } // namespace net
391 404
392 #endif // NET_BASE_COOKIE_MONSTER_H_ 405 #endif // NET_BASE_COOKIE_MONSTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698