OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
9 * | 9 * |
10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // in CookieMonster::tasks_pending_for_key_ and executed upon receiving | 90 // in CookieMonster::tasks_pending_for_key_ and executed upon receiving |
91 // notification of key load completion triggered by the first request for the | 91 // notification of key load completion triggered by the first request for the |
92 // same eTLD+1. | 92 // same eTLD+1. |
93 | 93 |
94 static const int kMinutesInTenYears = 10 * 365 * 24 * 60; | 94 static const int kMinutesInTenYears = 10 * 365 * 24 * 60; |
95 | 95 |
96 namespace net { | 96 namespace net { |
97 | 97 |
98 // See comments at declaration of these variables in cookie_monster.h | 98 // See comments at declaration of these variables in cookie_monster.h |
99 // for details. | 99 // for details. |
100 const size_t CookieMonster::kDomainMaxCookies = 180; | 100 const size_t CookieMonster::kDomainMaxCookies = 180; |
101 const size_t CookieMonster::kDomainPurgeCookies = 30; | 101 const size_t CookieMonster::kDomainPurgeCookies = 30; |
102 const size_t CookieMonster::kMaxCookies = 3300; | 102 const size_t CookieMonster::kMaxCookies = 3300; |
103 const size_t CookieMonster::kPurgeCookies = 300; | 103 const size_t CookieMonster::kPurgeCookies = 300; |
104 | 104 |
105 const size_t CookieMonster::kDomainCookiesQuotaLow = 30; | 105 const size_t CookieMonster::kDomainCookiesQuotaLow = 30; |
106 const size_t CookieMonster::kDomainCookiesQuotaMedium = 50; | 106 const size_t CookieMonster::kDomainCookiesQuotaMedium = 50; |
107 const size_t CookieMonster::kDomainCookiesQuotaHigh = | 107 const size_t CookieMonster::kDomainCookiesQuotaHigh = |
108 kDomainMaxCookies - kDomainPurgeCookies | 108 kDomainMaxCookies - kDomainPurgeCookies - kDomainCookiesQuotaLow - |
109 - kDomainCookiesQuotaLow - kDomainCookiesQuotaMedium; | 109 kDomainCookiesQuotaMedium; |
110 | 110 |
111 const int CookieMonster::kSafeFromGlobalPurgeDays = 30; | 111 const int CookieMonster::kSafeFromGlobalPurgeDays = 30; |
112 | 112 |
113 namespace { | 113 namespace { |
114 | 114 |
115 bool ContainsControlCharacter(const std::string& s) { | 115 bool ContainsControlCharacter(const std::string& s) { |
116 for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) { | 116 for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) { |
117 if ((*i >= 0) && (*i <= 31)) | 117 if ((*i >= 0) && (*i <= 31)) |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 return false; | 121 return false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // (2) For each list with more than 1 entry, keep the cookie having the | 170 // (2) For each list with more than 1 entry, keep the cookie having the |
171 // most recent creation time, and delete the others. | 171 // most recent creation time, and delete the others. |
172 // | 172 // |
173 // Two cookies are considered equivalent if they have the same domain, | 173 // Two cookies are considered equivalent if they have the same domain, |
174 // name, and path. | 174 // name, and path. |
175 struct CookieSignature { | 175 struct CookieSignature { |
176 public: | 176 public: |
177 CookieSignature(const std::string& name, | 177 CookieSignature(const std::string& name, |
178 const std::string& domain, | 178 const std::string& domain, |
179 const std::string& path) | 179 const std::string& path) |
180 : name(name), domain(domain), path(path) { | 180 : name(name), domain(domain), path(path) {} |
181 } | |
182 | 181 |
183 // To be a key for a map this class needs to be assignable, copyable, | 182 // To be a key for a map this class needs to be assignable, copyable, |
184 // and have an operator<. The default assignment operator | 183 // and have an operator<. The default assignment operator |
185 // and copy constructor are exactly what we want. | 184 // and copy constructor are exactly what we want. |
186 | 185 |
187 bool operator<(const CookieSignature& cs) const { | 186 bool operator<(const CookieSignature& cs) const { |
188 // Name compare dominates, then domain, then path. | 187 // Name compare dominates, then domain, then path. |
189 int diff = name.compare(cs.name); | 188 int diff = name.compare(cs.name); |
190 if (diff != 0) | 189 if (diff != 0) |
191 return diff < 0; | 190 return diff < 0; |
192 | 191 |
193 diff = domain.compare(cs.domain); | 192 diff = domain.compare(cs.domain); |
194 if (diff != 0) | 193 if (diff != 0) |
195 return diff < 0; | 194 return diff < 0; |
196 | 195 |
197 return path.compare(cs.path) < 0; | 196 return path.compare(cs.path) < 0; |
198 } | 197 } |
199 | 198 |
200 std::string name; | 199 std::string name; |
201 std::string domain; | 200 std::string domain; |
202 std::string path; | 201 std::string path; |
203 }; | 202 }; |
204 | 203 |
205 // For a CookieItVector iterator range [|it_begin|, |it_end|), | 204 // For a CookieItVector iterator range [|it_begin|, |it_end|), |
206 // sorts the first |num_sort| + 1 elements by LastAccessDate(). | 205 // sorts the first |num_sort| + 1 elements by LastAccessDate(). |
207 // The + 1 element exists so for any interval of length <= |num_sort| starting | 206 // The + 1 element exists so for any interval of length <= |num_sort| starting |
208 // from |cookies_its_begin|, a LastAccessDate() bound can be found. | 207 // from |cookies_its_begin|, a LastAccessDate() bound can be found. |
209 void SortLeastRecentlyAccessed( | 208 void SortLeastRecentlyAccessed(CookieMonster::CookieItVector::iterator it_begin, |
210 CookieMonster::CookieItVector::iterator it_begin, | 209 CookieMonster::CookieItVector::iterator it_end, |
211 CookieMonster::CookieItVector::iterator it_end, | 210 size_t num_sort) { |
212 size_t num_sort) { | |
213 DCHECK_LT(static_cast<int>(num_sort), it_end - it_begin); | 211 DCHECK_LT(static_cast<int>(num_sort), it_end - it_begin); |
214 std::partial_sort(it_begin, it_begin + num_sort + 1, it_end, LRACookieSorter); | 212 std::partial_sort(it_begin, it_begin + num_sort + 1, it_end, LRACookieSorter); |
215 } | 213 } |
216 | 214 |
217 // Predicate to support PartitionCookieByPriority(). | 215 // Predicate to support PartitionCookieByPriority(). |
218 struct CookiePriorityEqualsTo | 216 struct CookiePriorityEqualsTo |
219 : std::unary_function<const CookieMonster::CookieMap::iterator, bool> { | 217 : std::unary_function<const CookieMonster::CookieMap::iterator, bool> { |
220 explicit CookiePriorityEqualsTo(CookiePriority priority) | 218 explicit CookiePriorityEqualsTo(CookiePriority priority) |
221 : priority_(priority) {} | 219 : priority_(priority) {} |
222 | 220 |
223 bool operator()(const CookieMonster::CookieMap::iterator it) const { | 221 bool operator()(const CookieMonster::CookieMap::iterator it) const { |
224 return it->second->Priority() == priority_; | 222 return it->second->Priority() == priority_; |
225 } | 223 } |
226 | 224 |
227 const CookiePriority priority_; | 225 const CookiePriority priority_; |
228 }; | 226 }; |
229 | 227 |
230 // For a CookieItVector iterator range [|it_begin|, |it_end|), | 228 // For a CookieItVector iterator range [|it_begin|, |it_end|), |
231 // moves all cookies with a given |priority| to the beginning of the list. | 229 // moves all cookies with a given |priority| to the beginning of the list. |
232 // Returns: An iterator in [it_begin, it_end) to the first element with | 230 // Returns: An iterator in [it_begin, it_end) to the first element with |
233 // priority != |priority|, or |it_end| if all have priority == |priority|. | 231 // priority != |priority|, or |it_end| if all have priority == |priority|. |
234 CookieMonster::CookieItVector::iterator PartitionCookieByPriority( | 232 CookieMonster::CookieItVector::iterator PartitionCookieByPriority( |
235 CookieMonster::CookieItVector::iterator it_begin, | 233 CookieMonster::CookieItVector::iterator it_begin, |
236 CookieMonster::CookieItVector::iterator it_end, | 234 CookieMonster::CookieItVector::iterator it_end, |
237 CookiePriority priority) { | 235 CookiePriority priority) { |
238 return std::partition(it_begin, it_end, CookiePriorityEqualsTo(priority)); | 236 return std::partition(it_begin, it_end, CookiePriorityEqualsTo(priority)); |
239 } | 237 } |
240 | 238 |
241 bool LowerBoundAccessDateComparator( | 239 bool LowerBoundAccessDateComparator(const CookieMonster::CookieMap::iterator it, |
242 const CookieMonster::CookieMap::iterator it, const Time& access_date) { | 240 const Time& access_date) { |
243 return it->second->LastAccessDate() < access_date; | 241 return it->second->LastAccessDate() < access_date; |
244 } | 242 } |
245 | 243 |
246 // For a CookieItVector iterator range [|it_begin|, |it_end|) | 244 // For a CookieItVector iterator range [|it_begin|, |it_end|) |
247 // from a CookieItVector sorted by LastAccessDate(), returns the | 245 // from a CookieItVector sorted by LastAccessDate(), returns the |
248 // first iterator with access date >= |access_date|, or cookie_its_end if this | 246 // first iterator with access date >= |access_date|, or cookie_its_end if this |
249 // holds for all. | 247 // holds for all. |
250 CookieMonster::CookieItVector::iterator LowerBoundAccessDate( | 248 CookieMonster::CookieItVector::iterator LowerBoundAccessDate( |
251 const CookieMonster::CookieItVector::iterator its_begin, | 249 const CookieMonster::CookieItVector::iterator its_begin, |
252 const CookieMonster::CookieItVector::iterator its_end, | 250 const CookieMonster::CookieItVector::iterator its_end, |
253 const Time& access_date) { | 251 const Time& access_date) { |
254 return std::lower_bound(its_begin, its_end, access_date, | 252 return std::lower_bound(its_begin, its_end, access_date, |
255 LowerBoundAccessDateComparator); | 253 LowerBoundAccessDateComparator); |
256 } | 254 } |
257 | 255 |
258 // Mapping between DeletionCause and CookieMonsterDelegate::ChangeCause; the | 256 // Mapping between DeletionCause and CookieMonsterDelegate::ChangeCause; the |
259 // mapping also provides a boolean that specifies whether or not an | 257 // mapping also provides a boolean that specifies whether or not an |
260 // OnCookieChanged notification ought to be generated. | 258 // OnCookieChanged notification ought to be generated. |
261 typedef struct ChangeCausePair_struct { | 259 typedef struct ChangeCausePair_struct { |
262 CookieMonsterDelegate::ChangeCause cause; | 260 CookieMonsterDelegate::ChangeCause cause; |
263 bool notify; | 261 bool notify; |
264 } ChangeCausePair; | 262 } ChangeCausePair; |
265 ChangeCausePair ChangeCauseMapping[] = { | 263 ChangeCausePair ChangeCauseMapping[] = { |
266 // DELETE_COOKIE_EXPLICIT | 264 // DELETE_COOKIE_EXPLICIT |
267 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true }, | 265 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true}, |
268 // DELETE_COOKIE_OVERWRITE | 266 // DELETE_COOKIE_OVERWRITE |
269 { CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true }, | 267 {CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true}, |
270 // DELETE_COOKIE_EXPIRED | 268 // DELETE_COOKIE_EXPIRED |
271 { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true }, | 269 {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true}, |
272 // DELETE_COOKIE_EVICTED | 270 // DELETE_COOKIE_EVICTED |
273 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, | 271 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
274 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE | 272 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE |
275 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, | 273 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, |
276 // DELETE_COOKIE_DONT_RECORD | 274 // DELETE_COOKIE_DONT_RECORD |
277 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, | 275 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, |
278 // DELETE_COOKIE_EVICTED_DOMAIN | 276 // DELETE_COOKIE_EVICTED_DOMAIN |
279 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, | 277 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
280 // DELETE_COOKIE_EVICTED_GLOBAL | 278 // DELETE_COOKIE_EVICTED_GLOBAL |
281 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, | 279 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
282 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE | 280 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE |
283 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, | 281 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
284 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE | 282 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE |
285 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, | 283 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
286 // DELETE_COOKIE_EXPIRED_OVERWRITE | 284 // DELETE_COOKIE_EXPIRED_OVERWRITE |
287 { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, | 285 {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true}, |
288 // DELETE_COOKIE_CONTROL_CHAR | 286 // DELETE_COOKIE_CONTROL_CHAR |
289 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 287 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
290 // DELETE_COOKIE_LAST_ENTRY | 288 // DELETE_COOKIE_LAST_ENTRY |
291 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false } | 289 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}}; |
292 }; | |
293 | 290 |
294 std::string BuildCookieLine(const CanonicalCookieVector& cookies) { | 291 std::string BuildCookieLine(const CanonicalCookieVector& cookies) { |
295 std::string cookie_line; | 292 std::string cookie_line; |
296 for (CanonicalCookieVector::const_iterator it = cookies.begin(); | 293 for (CanonicalCookieVector::const_iterator it = cookies.begin(); |
297 it != cookies.end(); ++it) { | 294 it != cookies.end(); ++it) { |
298 if (it != cookies.begin()) | 295 if (it != cookies.begin()) |
299 cookie_line += "; "; | 296 cookie_line += "; "; |
300 // In Mozilla if you set a cookie like AAAA, it will have an empty token | 297 // In Mozilla if you set a cookie like AAAA, it will have an empty token |
301 // and a value of AAAA. When it sends the cookie back, it will send AAAA, | 298 // and a value of AAAA. When it sends the cookie back, it will send AAAA, |
302 // so we need to avoid sending =AAAA for a blank token value. | 299 // so we need to avoid sending =AAAA for a blank token value. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 last_access_threshold_(base::TimeDelta::FromMilliseconds( | 337 last_access_threshold_(base::TimeDelta::FromMilliseconds( |
341 last_access_threshold_milliseconds)), | 338 last_access_threshold_milliseconds)), |
342 delegate_(delegate), | 339 delegate_(delegate), |
343 last_statistic_record_time_(base::Time::Now()), | 340 last_statistic_record_time_(base::Time::Now()), |
344 keep_expired_cookies_(false), | 341 keep_expired_cookies_(false), |
345 persist_session_cookies_(false) { | 342 persist_session_cookies_(false) { |
346 InitializeHistograms(); | 343 InitializeHistograms(); |
347 SetDefaultCookieableSchemes(); | 344 SetDefaultCookieableSchemes(); |
348 } | 345 } |
349 | 346 |
350 | |
351 // Task classes for queueing the coming request. | 347 // Task classes for queueing the coming request. |
352 | 348 |
353 class CookieMonster::CookieMonsterTask | 349 class CookieMonster::CookieMonsterTask |
354 : public base::RefCountedThreadSafe<CookieMonsterTask> { | 350 : public base::RefCountedThreadSafe<CookieMonsterTask> { |
355 public: | 351 public: |
356 // Runs the task and invokes the client callback on the thread that | 352 // Runs the task and invokes the client callback on the thread that |
357 // originally constructed the task. | 353 // originally constructed the task. |
358 virtual void Run() = 0; | 354 virtual void Run() = 0; |
359 | 355 |
360 protected: | 356 protected: |
361 explicit CookieMonsterTask(CookieMonster* cookie_monster); | 357 explicit CookieMonsterTask(CookieMonster* cookie_monster); |
362 virtual ~CookieMonsterTask(); | 358 virtual ~CookieMonsterTask(); |
363 | 359 |
364 // Invokes the callback immediately, if the current thread is the one | 360 // Invokes the callback immediately, if the current thread is the one |
365 // that originated the task, or queues the callback for execution on the | 361 // that originated the task, or queues the callback for execution on the |
366 // appropriate thread. Maintains a reference to this CookieMonsterTask | 362 // appropriate thread. Maintains a reference to this CookieMonsterTask |
367 // instance until the callback completes. | 363 // instance until the callback completes. |
368 void InvokeCallback(base::Closure callback); | 364 void InvokeCallback(base::Closure callback); |
369 | 365 |
370 CookieMonster* cookie_monster() { | 366 CookieMonster* cookie_monster() { return cookie_monster_; } |
371 return cookie_monster_; | |
372 } | |
373 | 367 |
374 private: | 368 private: |
375 friend class base::RefCountedThreadSafe<CookieMonsterTask>; | 369 friend class base::RefCountedThreadSafe<CookieMonsterTask>; |
376 | 370 |
377 CookieMonster* cookie_monster_; | 371 CookieMonster* cookie_monster_; |
378 scoped_refptr<base::MessageLoopProxy> thread_; | 372 scoped_refptr<base::MessageLoopProxy> thread_; |
379 | 373 |
380 DISALLOW_COPY_AND_ASSIGN(CookieMonsterTask); | 374 DISALLOW_COPY_AND_ASSIGN(CookieMonsterTask); |
381 }; | 375 }; |
382 | 376 |
383 CookieMonster::CookieMonsterTask::CookieMonsterTask( | 377 CookieMonster::CookieMonsterTask::CookieMonsterTask( |
384 CookieMonster* cookie_monster) | 378 CookieMonster* cookie_monster) |
385 : cookie_monster_(cookie_monster), | 379 : cookie_monster_(cookie_monster), |
386 thread_(base::MessageLoopProxy::current()) { | 380 thread_(base::MessageLoopProxy::current()) { |
387 } | 381 } |
388 | 382 |
389 CookieMonster::CookieMonsterTask::~CookieMonsterTask() {} | 383 CookieMonster::CookieMonsterTask::~CookieMonsterTask() { |
| 384 } |
390 | 385 |
391 // Unfortunately, one cannot re-bind a Callback with parameters into a closure. | 386 // Unfortunately, one cannot re-bind a Callback with parameters into a closure. |
392 // Therefore, the closure passed to InvokeCallback is a clumsy binding of | 387 // Therefore, the closure passed to InvokeCallback is a clumsy binding of |
393 // Callback::Run on a wrapped Callback instance. Since Callback is not | 388 // Callback::Run on a wrapped Callback instance. Since Callback is not |
394 // reference counted, we bind to an instance that is a member of the | 389 // reference counted, we bind to an instance that is a member of the |
395 // CookieMonsterTask subclass. Then, we cannot simply post the callback to a | 390 // CookieMonsterTask subclass. Then, we cannot simply post the callback to a |
396 // message loop because the underlying instance may be destroyed (along with the | 391 // message loop because the underlying instance may be destroyed (along with the |
397 // CookieMonsterTask instance) in the interim. Therefore, we post a callback | 392 // CookieMonsterTask instance) in the interim. Therefore, we post a callback |
398 // bound to the CookieMonsterTask, which *is* reference counted (thus preventing | 393 // bound to the CookieMonsterTask, which *is* reference counted (thus preventing |
399 // destruction of the original callback), and which invokes the closure (which | 394 // destruction of the original callback), and which invokes the closure (which |
400 // invokes the original callback with the returned data). | 395 // invokes the original callback with the returned data). |
401 void CookieMonster::CookieMonsterTask::InvokeCallback(base::Closure callback) { | 396 void CookieMonster::CookieMonsterTask::InvokeCallback(base::Closure callback) { |
402 if (thread_->BelongsToCurrentThread()) { | 397 if (thread_->BelongsToCurrentThread()) { |
403 callback.Run(); | 398 callback.Run(); |
404 } else { | 399 } else { |
405 thread_->PostTask(FROM_HERE, base::Bind( | 400 thread_->PostTask(FROM_HERE, base::Bind(&CookieMonsterTask::InvokeCallback, |
406 &CookieMonsterTask::InvokeCallback, this, callback)); | 401 this, callback)); |
407 } | 402 } |
408 } | 403 } |
409 | 404 |
410 // Task class for SetCookieWithDetails call. | 405 // Task class for SetCookieWithDetails call. |
411 class CookieMonster::SetCookieWithDetailsTask : public CookieMonsterTask { | 406 class CookieMonster::SetCookieWithDetailsTask : public CookieMonsterTask { |
412 public: | 407 public: |
413 SetCookieWithDetailsTask(CookieMonster* cookie_monster, | 408 SetCookieWithDetailsTask(CookieMonster* cookie_monster, |
414 const GURL& url, | 409 const GURL& url, |
415 const std::string& name, | 410 const std::string& name, |
416 const std::string& value, | 411 const std::string& value, |
417 const std::string& domain, | 412 const std::string& domain, |
418 const std::string& path, | 413 const std::string& path, |
419 const base::Time& expiration_time, | 414 const base::Time& expiration_time, |
420 bool secure, | 415 bool secure, |
421 bool http_only, | 416 bool http_only, |
422 CookiePriority priority, | 417 CookiePriority priority, |
423 const SetCookiesCallback& callback) | 418 const SetCookiesCallback& callback) |
424 : CookieMonsterTask(cookie_monster), | 419 : CookieMonsterTask(cookie_monster), |
425 url_(url), | 420 url_(url), |
426 name_(name), | 421 name_(name), |
427 value_(value), | 422 value_(value), |
428 domain_(domain), | 423 domain_(domain), |
429 path_(path), | 424 path_(path), |
430 expiration_time_(expiration_time), | 425 expiration_time_(expiration_time), |
431 secure_(secure), | 426 secure_(secure), |
432 http_only_(http_only), | 427 http_only_(http_only), |
433 priority_(priority), | 428 priority_(priority), |
434 callback_(callback) { | 429 callback_(callback) {} |
435 } | |
436 | 430 |
437 // CookieMonsterTask: | 431 // CookieMonsterTask: |
438 void Run() override; | 432 void Run() override; |
439 | 433 |
440 protected: | 434 protected: |
441 ~SetCookieWithDetailsTask() override {} | 435 ~SetCookieWithDetailsTask() override {} |
442 | 436 |
443 private: | 437 private: |
444 GURL url_; | 438 GURL url_; |
445 std::string name_; | 439 std::string name_; |
446 std::string value_; | 440 std::string value_; |
447 std::string domain_; | 441 std::string domain_; |
448 std::string path_; | 442 std::string path_; |
449 base::Time expiration_time_; | 443 base::Time expiration_time_; |
450 bool secure_; | 444 bool secure_; |
451 bool http_only_; | 445 bool http_only_; |
452 CookiePriority priority_; | 446 CookiePriority priority_; |
453 SetCookiesCallback callback_; | 447 SetCookiesCallback callback_; |
454 | 448 |
455 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); | 449 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); |
456 }; | 450 }; |
457 | 451 |
458 void CookieMonster::SetCookieWithDetailsTask::Run() { | 452 void CookieMonster::SetCookieWithDetailsTask::Run() { |
459 bool success = this->cookie_monster()-> | 453 bool success = this->cookie_monster()->SetCookieWithDetails( |
460 SetCookieWithDetails(url_, name_, value_, domain_, path_, | 454 url_, name_, value_, domain_, path_, expiration_time_, secure_, |
461 expiration_time_, secure_, http_only_, priority_); | 455 http_only_, priority_); |
462 if (!callback_.is_null()) { | 456 if (!callback_.is_null()) { |
463 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, | 457 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, |
464 base::Unretained(&callback_), success)); | 458 base::Unretained(&callback_), success)); |
465 } | 459 } |
466 } | 460 } |
467 | 461 |
468 // Task class for GetAllCookies call. | 462 // Task class for GetAllCookies call. |
469 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { | 463 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { |
470 public: | 464 public: |
471 GetAllCookiesTask(CookieMonster* cookie_monster, | 465 GetAllCookiesTask(CookieMonster* cookie_monster, |
472 const GetCookieListCallback& callback) | 466 const GetCookieListCallback& callback) |
473 : CookieMonsterTask(cookie_monster), | 467 : CookieMonsterTask(cookie_monster), callback_(callback) {} |
474 callback_(callback) { | |
475 } | |
476 | 468 |
477 // CookieMonsterTask | 469 // CookieMonsterTask |
478 void Run() override; | 470 void Run() override; |
479 | 471 |
480 protected: | 472 protected: |
481 ~GetAllCookiesTask() override {} | 473 ~GetAllCookiesTask() override {} |
482 | 474 |
483 private: | 475 private: |
484 GetCookieListCallback callback_; | 476 GetCookieListCallback callback_; |
485 | 477 |
486 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask); | 478 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask); |
487 }; | 479 }; |
488 | 480 |
489 void CookieMonster::GetAllCookiesTask::Run() { | 481 void CookieMonster::GetAllCookiesTask::Run() { |
490 if (!callback_.is_null()) { | 482 if (!callback_.is_null()) { |
491 CookieList cookies = this->cookie_monster()->GetAllCookies(); | 483 CookieList cookies = this->cookie_monster()->GetAllCookies(); |
492 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, | 484 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, |
493 base::Unretained(&callback_), cookies)); | 485 base::Unretained(&callback_), cookies)); |
494 } | 486 } |
495 } | 487 } |
496 | 488 |
497 // Task class for GetAllCookiesForURLWithOptions call. | 489 // Task class for GetAllCookiesForURLWithOptions call. |
498 class CookieMonster::GetAllCookiesForURLWithOptionsTask | 490 class CookieMonster::GetAllCookiesForURLWithOptionsTask |
499 : public CookieMonsterTask { | 491 : public CookieMonsterTask { |
500 public: | 492 public: |
501 GetAllCookiesForURLWithOptionsTask( | 493 GetAllCookiesForURLWithOptionsTask(CookieMonster* cookie_monster, |
502 CookieMonster* cookie_monster, | 494 const GURL& url, |
503 const GURL& url, | 495 const CookieOptions& options, |
504 const CookieOptions& options, | 496 const GetCookieListCallback& callback) |
505 const GetCookieListCallback& callback) | |
506 : CookieMonsterTask(cookie_monster), | 497 : CookieMonsterTask(cookie_monster), |
507 url_(url), | 498 url_(url), |
508 options_(options), | 499 options_(options), |
509 callback_(callback) { | 500 callback_(callback) {} |
510 } | |
511 | 501 |
512 // CookieMonsterTask: | 502 // CookieMonsterTask: |
513 void Run() override; | 503 void Run() override; |
514 | 504 |
515 protected: | 505 protected: |
516 ~GetAllCookiesForURLWithOptionsTask() override {} | 506 ~GetAllCookiesForURLWithOptionsTask() override {} |
517 | 507 |
518 private: | 508 private: |
519 GURL url_; | 509 GURL url_; |
520 CookieOptions options_; | 510 CookieOptions options_; |
521 GetCookieListCallback callback_; | 511 GetCookieListCallback callback_; |
522 | 512 |
523 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesForURLWithOptionsTask); | 513 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesForURLWithOptionsTask); |
524 }; | 514 }; |
525 | 515 |
526 void CookieMonster::GetAllCookiesForURLWithOptionsTask::Run() { | 516 void CookieMonster::GetAllCookiesForURLWithOptionsTask::Run() { |
527 if (!callback_.is_null()) { | 517 if (!callback_.is_null()) { |
528 CookieList cookies = this->cookie_monster()-> | 518 CookieList cookies = |
529 GetAllCookiesForURLWithOptions(url_, options_); | 519 this->cookie_monster()->GetAllCookiesForURLWithOptions(url_, options_); |
530 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, | 520 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, |
531 base::Unretained(&callback_), cookies)); | 521 base::Unretained(&callback_), cookies)); |
532 } | 522 } |
533 } | 523 } |
534 | 524 |
535 template <typename Result> struct CallbackType { | 525 template <typename Result> |
| 526 struct CallbackType { |
536 typedef base::Callback<void(Result)> Type; | 527 typedef base::Callback<void(Result)> Type; |
537 }; | 528 }; |
538 | 529 |
539 template <> struct CallbackType<void> { | 530 template <> |
| 531 struct CallbackType<void> { |
540 typedef base::Closure Type; | 532 typedef base::Closure Type; |
541 }; | 533 }; |
542 | 534 |
543 // Base task class for Delete*Task. | 535 // Base task class for Delete*Task. |
544 template <typename Result> | 536 template <typename Result> |
545 class CookieMonster::DeleteTask : public CookieMonsterTask { | 537 class CookieMonster::DeleteTask : public CookieMonsterTask { |
546 public: | 538 public: |
547 DeleteTask(CookieMonster* cookie_monster, | 539 DeleteTask(CookieMonster* cookie_monster, |
548 const typename CallbackType<Result>::Type& callback) | 540 const typename CallbackType<Result>::Type& callback) |
549 : CookieMonsterTask(cookie_monster), | 541 : CookieMonsterTask(cookie_monster), callback_(callback) {} |
550 callback_(callback) { | |
551 } | |
552 | 542 |
553 // CookieMonsterTask: | 543 // CookieMonsterTask: |
554 virtual void Run() override; | 544 virtual void Run() override; |
555 | 545 |
556 protected: | 546 protected: |
557 ~DeleteTask() override; | 547 ~DeleteTask() override; |
558 | 548 |
559 private: | 549 private: |
560 // Runs the delete task and returns a result. | 550 // Runs the delete task and returns a result. |
561 virtual Result RunDeleteTask() = 0; | 551 virtual Result RunDeleteTask() = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
581 } | 571 } |
582 | 572 |
583 template <> | 573 template <> |
584 base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() { | 574 base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() { |
585 RunDeleteTask(); | 575 RunDeleteTask(); |
586 return callback_; | 576 return callback_; |
587 } | 577 } |
588 | 578 |
589 template <typename Result> | 579 template <typename Result> |
590 void CookieMonster::DeleteTask<Result>::Run() { | 580 void CookieMonster::DeleteTask<Result>::Run() { |
591 this->cookie_monster()->FlushStore( | 581 this->cookie_monster()->FlushStore(base::Bind( |
592 base::Bind(&DeleteTask<Result>::FlushDone, this, | 582 &DeleteTask<Result>::FlushDone, this, RunDeleteTaskAndBindCallback())); |
593 RunDeleteTaskAndBindCallback())); | |
594 } | 583 } |
595 | 584 |
596 template <typename Result> | 585 template <typename Result> |
597 void CookieMonster::DeleteTask<Result>::FlushDone( | 586 void CookieMonster::DeleteTask<Result>::FlushDone( |
598 const base::Closure& callback) { | 587 const base::Closure& callback) { |
599 if (!callback.is_null()) { | 588 if (!callback.is_null()) { |
600 this->InvokeCallback(callback); | 589 this->InvokeCallback(callback); |
601 } | 590 } |
602 } | 591 } |
603 | 592 |
604 // Task class for DeleteAll call. | 593 // Task class for DeleteAll call. |
605 class CookieMonster::DeleteAllTask : public DeleteTask<int> { | 594 class CookieMonster::DeleteAllTask : public DeleteTask<int> { |
606 public: | 595 public: |
607 DeleteAllTask(CookieMonster* cookie_monster, | 596 DeleteAllTask(CookieMonster* cookie_monster, const DeleteCallback& callback) |
608 const DeleteCallback& callback) | 597 : DeleteTask<int>(cookie_monster, callback) {} |
609 : DeleteTask<int>(cookie_monster, callback) { | |
610 } | |
611 | 598 |
612 // DeleteTask: | 599 // DeleteTask: |
613 int RunDeleteTask() override; | 600 int RunDeleteTask() override; |
614 | 601 |
615 protected: | 602 protected: |
616 ~DeleteAllTask() override {} | 603 ~DeleteAllTask() override {} |
617 | 604 |
618 private: | 605 private: |
619 DISALLOW_COPY_AND_ASSIGN(DeleteAllTask); | 606 DISALLOW_COPY_AND_ASSIGN(DeleteAllTask); |
620 }; | 607 }; |
621 | 608 |
622 int CookieMonster::DeleteAllTask::RunDeleteTask() { | 609 int CookieMonster::DeleteAllTask::RunDeleteTask() { |
623 return this->cookie_monster()->DeleteAll(true); | 610 return this->cookie_monster()->DeleteAll(true); |
624 } | 611 } |
625 | 612 |
626 // Task class for DeleteAllCreatedBetween call. | 613 // Task class for DeleteAllCreatedBetween call. |
627 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { | 614 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { |
628 public: | 615 public: |
629 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, | 616 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, |
630 const Time& delete_begin, | 617 const Time& delete_begin, |
631 const Time& delete_end, | 618 const Time& delete_end, |
632 const DeleteCallback& callback) | 619 const DeleteCallback& callback) |
633 : DeleteTask<int>(cookie_monster, callback), | 620 : DeleteTask<int>(cookie_monster, callback), |
634 delete_begin_(delete_begin), | 621 delete_begin_(delete_begin), |
635 delete_end_(delete_end) { | 622 delete_end_(delete_end) {} |
636 } | |
637 | 623 |
638 // DeleteTask: | 624 // DeleteTask: |
639 int RunDeleteTask() override; | 625 int RunDeleteTask() override; |
640 | 626 |
641 protected: | 627 protected: |
642 ~DeleteAllCreatedBetweenTask() override {} | 628 ~DeleteAllCreatedBetweenTask() override {} |
643 | 629 |
644 private: | 630 private: |
645 Time delete_begin_; | 631 Time delete_begin_; |
646 Time delete_end_; | 632 Time delete_end_; |
647 | 633 |
648 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); | 634 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); |
649 }; | 635 }; |
650 | 636 |
651 int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { | 637 int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { |
652 return this->cookie_monster()-> | 638 return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_, |
653 DeleteAllCreatedBetween(delete_begin_, delete_end_); | 639 delete_end_); |
654 } | 640 } |
655 | 641 |
656 // Task class for DeleteAllForHost call. | 642 // Task class for DeleteAllForHost call. |
657 class CookieMonster::DeleteAllForHostTask : public DeleteTask<int> { | 643 class CookieMonster::DeleteAllForHostTask : public DeleteTask<int> { |
658 public: | 644 public: |
659 DeleteAllForHostTask(CookieMonster* cookie_monster, | 645 DeleteAllForHostTask(CookieMonster* cookie_monster, |
660 const GURL& url, | 646 const GURL& url, |
661 const DeleteCallback& callback) | 647 const DeleteCallback& callback) |
662 : DeleteTask<int>(cookie_monster, callback), | 648 : DeleteTask<int>(cookie_monster, callback), url_(url) {} |
663 url_(url) { | |
664 } | |
665 | 649 |
666 // DeleteTask: | 650 // DeleteTask: |
667 int RunDeleteTask() override; | 651 int RunDeleteTask() override; |
668 | 652 |
669 protected: | 653 protected: |
670 ~DeleteAllForHostTask() override {} | 654 ~DeleteAllForHostTask() override {} |
671 | 655 |
672 private: | 656 private: |
673 GURL url_; | 657 GURL url_; |
674 | 658 |
675 DISALLOW_COPY_AND_ASSIGN(DeleteAllForHostTask); | 659 DISALLOW_COPY_AND_ASSIGN(DeleteAllForHostTask); |
676 }; | 660 }; |
677 | 661 |
678 int CookieMonster::DeleteAllForHostTask::RunDeleteTask() { | 662 int CookieMonster::DeleteAllForHostTask::RunDeleteTask() { |
679 return this->cookie_monster()->DeleteAllForHost(url_); | 663 return this->cookie_monster()->DeleteAllForHost(url_); |
680 } | 664 } |
681 | 665 |
682 // Task class for DeleteAllCreatedBetweenForHost call. | 666 // Task class for DeleteAllCreatedBetweenForHost call. |
683 class CookieMonster::DeleteAllCreatedBetweenForHostTask | 667 class CookieMonster::DeleteAllCreatedBetweenForHostTask |
684 : public DeleteTask<int> { | 668 : public DeleteTask<int> { |
685 public: | 669 public: |
686 DeleteAllCreatedBetweenForHostTask( | 670 DeleteAllCreatedBetweenForHostTask(CookieMonster* cookie_monster, |
687 CookieMonster* cookie_monster, | 671 Time delete_begin, |
688 Time delete_begin, | 672 Time delete_end, |
689 Time delete_end, | 673 const GURL& url, |
690 const GURL& url, | 674 const DeleteCallback& callback) |
691 const DeleteCallback& callback) | |
692 : DeleteTask<int>(cookie_monster, callback), | 675 : DeleteTask<int>(cookie_monster, callback), |
693 delete_begin_(delete_begin), | 676 delete_begin_(delete_begin), |
694 delete_end_(delete_end), | 677 delete_end_(delete_end), |
695 url_(url) { | 678 url_(url) {} |
696 } | |
697 | 679 |
698 // DeleteTask: | 680 // DeleteTask: |
699 int RunDeleteTask() override; | 681 int RunDeleteTask() override; |
700 | 682 |
701 protected: | 683 protected: |
702 ~DeleteAllCreatedBetweenForHostTask() override {} | 684 ~DeleteAllCreatedBetweenForHostTask() override {} |
703 | 685 |
704 private: | 686 private: |
705 Time delete_begin_; | 687 Time delete_begin_; |
706 Time delete_end_; | 688 Time delete_end_; |
707 GURL url_; | 689 GURL url_; |
708 | 690 |
709 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); | 691 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); |
710 }; | 692 }; |
711 | 693 |
712 int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() { | 694 int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() { |
713 return this->cookie_monster()->DeleteAllCreatedBetweenForHost( | 695 return this->cookie_monster()->DeleteAllCreatedBetweenForHost( |
714 delete_begin_, delete_end_, url_); | 696 delete_begin_, delete_end_, url_); |
715 } | 697 } |
716 | 698 |
717 // Task class for DeleteCanonicalCookie call. | 699 // Task class for DeleteCanonicalCookie call. |
718 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<bool> { | 700 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<bool> { |
719 public: | 701 public: |
720 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, | 702 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, |
721 const CanonicalCookie& cookie, | 703 const CanonicalCookie& cookie, |
722 const DeleteCookieCallback& callback) | 704 const DeleteCookieCallback& callback) |
723 : DeleteTask<bool>(cookie_monster, callback), | 705 : DeleteTask<bool>(cookie_monster, callback), cookie_(cookie) {} |
724 cookie_(cookie) { | |
725 } | |
726 | 706 |
727 // DeleteTask: | 707 // DeleteTask: |
728 bool RunDeleteTask() override; | 708 bool RunDeleteTask() override; |
729 | 709 |
730 protected: | 710 protected: |
731 ~DeleteCanonicalCookieTask() override {} | 711 ~DeleteCanonicalCookieTask() override {} |
732 | 712 |
733 private: | 713 private: |
734 CanonicalCookie cookie_; | 714 CanonicalCookie cookie_; |
735 | 715 |
736 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); | 716 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); |
737 }; | 717 }; |
738 | 718 |
739 bool CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { | 719 bool CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { |
740 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); | 720 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); |
741 } | 721 } |
742 | 722 |
743 // Task class for SetCookieWithOptions call. | 723 // Task class for SetCookieWithOptions call. |
744 class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { | 724 class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { |
745 public: | 725 public: |
746 SetCookieWithOptionsTask(CookieMonster* cookie_monster, | 726 SetCookieWithOptionsTask(CookieMonster* cookie_monster, |
747 const GURL& url, | 727 const GURL& url, |
748 const std::string& cookie_line, | 728 const std::string& cookie_line, |
749 const CookieOptions& options, | 729 const CookieOptions& options, |
750 const SetCookiesCallback& callback) | 730 const SetCookiesCallback& callback) |
751 : CookieMonsterTask(cookie_monster), | 731 : CookieMonsterTask(cookie_monster), |
752 url_(url), | 732 url_(url), |
753 cookie_line_(cookie_line), | 733 cookie_line_(cookie_line), |
754 options_(options), | 734 options_(options), |
755 callback_(callback) { | 735 callback_(callback) {} |
756 } | |
757 | 736 |
758 // CookieMonsterTask: | 737 // CookieMonsterTask: |
759 void Run() override; | 738 void Run() override; |
760 | 739 |
761 protected: | 740 protected: |
762 ~SetCookieWithOptionsTask() override {} | 741 ~SetCookieWithOptionsTask() override {} |
763 | 742 |
764 private: | 743 private: |
765 GURL url_; | 744 GURL url_; |
766 std::string cookie_line_; | 745 std::string cookie_line_; |
767 CookieOptions options_; | 746 CookieOptions options_; |
768 SetCookiesCallback callback_; | 747 SetCookiesCallback callback_; |
769 | 748 |
770 DISALLOW_COPY_AND_ASSIGN(SetCookieWithOptionsTask); | 749 DISALLOW_COPY_AND_ASSIGN(SetCookieWithOptionsTask); |
771 }; | 750 }; |
772 | 751 |
773 void CookieMonster::SetCookieWithOptionsTask::Run() { | 752 void CookieMonster::SetCookieWithOptionsTask::Run() { |
774 bool result = this->cookie_monster()-> | 753 bool result = this->cookie_monster()->SetCookieWithOptions(url_, cookie_line_, |
775 SetCookieWithOptions(url_, cookie_line_, options_); | 754 options_); |
776 if (!callback_.is_null()) { | 755 if (!callback_.is_null()) { |
777 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, | 756 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, |
778 base::Unretained(&callback_), result)); | 757 base::Unretained(&callback_), result)); |
779 } | 758 } |
780 } | 759 } |
781 | 760 |
782 // Task class for GetCookiesWithOptions call. | 761 // Task class for GetCookiesWithOptions call. |
783 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { | 762 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { |
784 public: | 763 public: |
785 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, | 764 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, |
786 const GURL& url, | 765 const GURL& url, |
787 const CookieOptions& options, | 766 const CookieOptions& options, |
788 const GetCookiesCallback& callback) | 767 const GetCookiesCallback& callback) |
789 : CookieMonsterTask(cookie_monster), | 768 : CookieMonsterTask(cookie_monster), |
790 url_(url), | 769 url_(url), |
791 options_(options), | 770 options_(options), |
792 callback_(callback) { | 771 callback_(callback) {} |
793 } | |
794 | 772 |
795 // CookieMonsterTask: | 773 // CookieMonsterTask: |
796 void Run() override; | 774 void Run() override; |
797 | 775 |
798 protected: | 776 protected: |
799 ~GetCookiesWithOptionsTask() override {} | 777 ~GetCookiesWithOptionsTask() override {} |
800 | 778 |
801 private: | 779 private: |
802 GURL url_; | 780 GURL url_; |
803 CookieOptions options_; | 781 CookieOptions options_; |
804 GetCookiesCallback callback_; | 782 GetCookiesCallback callback_; |
805 | 783 |
806 DISALLOW_COPY_AND_ASSIGN(GetCookiesWithOptionsTask); | 784 DISALLOW_COPY_AND_ASSIGN(GetCookiesWithOptionsTask); |
807 }; | 785 }; |
808 | 786 |
809 void CookieMonster::GetCookiesWithOptionsTask::Run() { | 787 void CookieMonster::GetCookiesWithOptionsTask::Run() { |
810 std::string cookie = this->cookie_monster()-> | 788 std::string cookie = |
811 GetCookiesWithOptions(url_, options_); | 789 this->cookie_monster()->GetCookiesWithOptions(url_, options_); |
812 if (!callback_.is_null()) { | 790 if (!callback_.is_null()) { |
813 this->InvokeCallback(base::Bind(&GetCookiesCallback::Run, | 791 this->InvokeCallback(base::Bind(&GetCookiesCallback::Run, |
814 base::Unretained(&callback_), cookie)); | 792 base::Unretained(&callback_), cookie)); |
815 } | 793 } |
816 } | 794 } |
817 | 795 |
818 // Task class for DeleteCookie call. | 796 // Task class for DeleteCookie call. |
819 class CookieMonster::DeleteCookieTask : public DeleteTask<void> { | 797 class CookieMonster::DeleteCookieTask : public DeleteTask<void> { |
820 public: | 798 public: |
821 DeleteCookieTask(CookieMonster* cookie_monster, | 799 DeleteCookieTask(CookieMonster* cookie_monster, |
822 const GURL& url, | 800 const GURL& url, |
823 const std::string& cookie_name, | 801 const std::string& cookie_name, |
824 const base::Closure& callback) | 802 const base::Closure& callback) |
825 : DeleteTask<void>(cookie_monster, callback), | 803 : DeleteTask<void>(cookie_monster, callback), |
826 url_(url), | 804 url_(url), |
827 cookie_name_(cookie_name) { | 805 cookie_name_(cookie_name) {} |
828 } | |
829 | 806 |
830 // DeleteTask: | 807 // DeleteTask: |
831 void RunDeleteTask() override; | 808 void RunDeleteTask() override; |
832 | 809 |
833 protected: | 810 protected: |
834 ~DeleteCookieTask() override {} | 811 ~DeleteCookieTask() override {} |
835 | 812 |
836 private: | 813 private: |
837 GURL url_; | 814 GURL url_; |
838 std::string cookie_name_; | 815 std::string cookie_name_; |
839 | 816 |
840 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); | 817 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); |
841 }; | 818 }; |
842 | 819 |
843 void CookieMonster::DeleteCookieTask::RunDeleteTask() { | 820 void CookieMonster::DeleteCookieTask::RunDeleteTask() { |
844 this->cookie_monster()->DeleteCookie(url_, cookie_name_); | 821 this->cookie_monster()->DeleteCookie(url_, cookie_name_); |
845 } | 822 } |
846 | 823 |
847 // Task class for DeleteSessionCookies call. | 824 // Task class for DeleteSessionCookies call. |
848 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { | 825 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { |
849 public: | 826 public: |
850 DeleteSessionCookiesTask(CookieMonster* cookie_monster, | 827 DeleteSessionCookiesTask(CookieMonster* cookie_monster, |
851 const DeleteCallback& callback) | 828 const DeleteCallback& callback) |
852 : DeleteTask<int>(cookie_monster, callback) { | 829 : DeleteTask<int>(cookie_monster, callback) {} |
853 } | |
854 | 830 |
855 // DeleteTask: | 831 // DeleteTask: |
856 int RunDeleteTask() override; | 832 int RunDeleteTask() override; |
857 | 833 |
858 protected: | 834 protected: |
859 ~DeleteSessionCookiesTask() override {} | 835 ~DeleteSessionCookiesTask() override {} |
860 | 836 |
861 private: | 837 private: |
862 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); | 838 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); |
863 }; | 839 }; |
864 | 840 |
865 int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { | 841 int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { |
866 return this->cookie_monster()->DeleteSessionCookies(); | 842 return this->cookie_monster()->DeleteSessionCookies(); |
867 } | 843 } |
868 | 844 |
869 // Task class for HasCookiesForETLDP1Task call. | 845 // Task class for HasCookiesForETLDP1Task call. |
870 class CookieMonster::HasCookiesForETLDP1Task : public CookieMonsterTask { | 846 class CookieMonster::HasCookiesForETLDP1Task : public CookieMonsterTask { |
871 public: | 847 public: |
872 HasCookiesForETLDP1Task( | 848 HasCookiesForETLDP1Task(CookieMonster* cookie_monster, |
873 CookieMonster* cookie_monster, | 849 const std::string& etldp1, |
874 const std::string& etldp1, | 850 const HasCookiesForETLDP1Callback& callback) |
875 const HasCookiesForETLDP1Callback& callback) | |
876 : CookieMonsterTask(cookie_monster), | 851 : CookieMonsterTask(cookie_monster), |
877 etldp1_(etldp1), | 852 etldp1_(etldp1), |
878 callback_(callback) { | 853 callback_(callback) {} |
879 } | |
880 | 854 |
881 // CookieMonsterTask: | 855 // CookieMonsterTask: |
882 void Run() override; | 856 void Run() override; |
883 | 857 |
884 protected: | 858 protected: |
885 ~HasCookiesForETLDP1Task() override {} | 859 ~HasCookiesForETLDP1Task() override {} |
886 | 860 |
887 private: | 861 private: |
888 std::string etldp1_; | 862 std::string etldp1_; |
889 HasCookiesForETLDP1Callback callback_; | 863 HasCookiesForETLDP1Callback callback_; |
890 | 864 |
891 DISALLOW_COPY_AND_ASSIGN(HasCookiesForETLDP1Task); | 865 DISALLOW_COPY_AND_ASSIGN(HasCookiesForETLDP1Task); |
892 }; | 866 }; |
893 | 867 |
894 void CookieMonster::HasCookiesForETLDP1Task::Run() { | 868 void CookieMonster::HasCookiesForETLDP1Task::Run() { |
895 bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_); | 869 bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_); |
896 if (!callback_.is_null()) { | 870 if (!callback_.is_null()) { |
897 this->InvokeCallback( | 871 this->InvokeCallback(base::Bind(&HasCookiesForETLDP1Callback::Run, |
898 base::Bind(&HasCookiesForETLDP1Callback::Run, | 872 base::Unretained(&callback_), result)); |
899 base::Unretained(&callback_), result)); | |
900 } | 873 } |
901 } | 874 } |
902 | 875 |
903 // Asynchronous CookieMonster API | 876 // Asynchronous CookieMonster API |
904 | 877 |
905 void CookieMonster::SetCookieWithDetailsAsync( | 878 void CookieMonster::SetCookieWithDetailsAsync( |
906 const GURL& url, | 879 const GURL& url, |
907 const std::string& name, | 880 const std::string& name, |
908 const std::string& value, | 881 const std::string& value, |
909 const std::string& domain, | 882 const std::string& domain, |
910 const std::string& path, | 883 const std::string& path, |
911 const Time& expiration_time, | 884 const Time& expiration_time, |
912 bool secure, | 885 bool secure, |
913 bool http_only, | 886 bool http_only, |
914 CookiePriority priority, | 887 CookiePriority priority, |
915 const SetCookiesCallback& callback) { | 888 const SetCookiesCallback& callback) { |
916 scoped_refptr<SetCookieWithDetailsTask> task = | 889 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( |
917 new SetCookieWithDetailsTask(this, url, name, value, domain, path, | 890 this, url, name, value, domain, path, expiration_time, secure, http_only, |
918 expiration_time, secure, http_only, priority, | 891 priority, callback); |
919 callback); | |
920 DoCookieTaskForURL(task, url); | 892 DoCookieTaskForURL(task, url); |
921 } | 893 } |
922 | 894 |
923 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { | 895 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { |
924 scoped_refptr<GetAllCookiesTask> task = | 896 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); |
925 new GetAllCookiesTask(this, callback); | |
926 | 897 |
927 DoCookieTask(task); | 898 DoCookieTask(task); |
928 } | 899 } |
929 | 900 |
930 | |
931 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( | 901 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( |
932 const GURL& url, | 902 const GURL& url, |
933 const CookieOptions& options, | 903 const CookieOptions& options, |
934 const GetCookieListCallback& callback) { | 904 const GetCookieListCallback& callback) { |
935 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = | 905 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = |
936 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 906 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
937 | 907 |
938 DoCookieTaskForURL(task, url); | 908 DoCookieTaskForURL(task, url); |
939 } | 909 } |
940 | 910 |
941 void CookieMonster::GetAllCookiesForURLAsync( | 911 void CookieMonster::GetAllCookiesForURLAsync( |
942 const GURL& url, const GetCookieListCallback& callback) { | 912 const GURL& url, |
| 913 const GetCookieListCallback& callback) { |
943 CookieOptions options; | 914 CookieOptions options; |
944 options.set_include_httponly(); | 915 options.set_include_httponly(); |
945 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = | 916 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = |
946 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 917 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
947 | 918 |
948 DoCookieTaskForURL(task, url); | 919 DoCookieTaskForURL(task, url); |
949 } | 920 } |
950 | 921 |
951 void CookieMonster::HasCookiesForETLDP1Async( | 922 void CookieMonster::HasCookiesForETLDP1Async( |
952 const std::string& etldp1, | 923 const std::string& etldp1, |
953 const HasCookiesForETLDP1Callback& callback) { | 924 const HasCookiesForETLDP1Callback& callback) { |
954 scoped_refptr<HasCookiesForETLDP1Task> task = | 925 scoped_refptr<HasCookiesForETLDP1Task> task = |
955 new HasCookiesForETLDP1Task(this, etldp1, callback); | 926 new HasCookiesForETLDP1Task(this, etldp1, callback); |
956 | 927 |
957 DoCookieTaskForURL(task, GURL("http://" + etldp1)); | 928 DoCookieTaskForURL(task, GURL("http://" + etldp1)); |
958 } | 929 } |
959 | 930 |
960 void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { | 931 void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { |
961 scoped_refptr<DeleteAllTask> task = | 932 scoped_refptr<DeleteAllTask> task = new DeleteAllTask(this, callback); |
962 new DeleteAllTask(this, callback); | |
963 | 933 |
964 DoCookieTask(task); | 934 DoCookieTask(task); |
965 } | 935 } |
966 | 936 |
967 void CookieMonster::DeleteAllCreatedBetweenAsync( | 937 void CookieMonster::DeleteAllCreatedBetweenAsync( |
968 const Time& delete_begin, const Time& delete_end, | 938 const Time& delete_begin, |
| 939 const Time& delete_end, |
969 const DeleteCallback& callback) { | 940 const DeleteCallback& callback) { |
970 scoped_refptr<DeleteAllCreatedBetweenTask> task = | 941 scoped_refptr<DeleteAllCreatedBetweenTask> task = |
971 new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, | 942 new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback); |
972 callback); | |
973 | 943 |
974 DoCookieTask(task); | 944 DoCookieTask(task); |
975 } | 945 } |
976 | 946 |
977 void CookieMonster::DeleteAllCreatedBetweenForHostAsync( | 947 void CookieMonster::DeleteAllCreatedBetweenForHostAsync( |
978 const Time delete_begin, | 948 const Time delete_begin, |
979 const Time delete_end, | 949 const Time delete_end, |
980 const GURL& url, | 950 const GURL& url, |
981 const DeleteCallback& callback) { | 951 const DeleteCallback& callback) { |
982 scoped_refptr<DeleteAllCreatedBetweenForHostTask> task = | 952 scoped_refptr<DeleteAllCreatedBetweenForHostTask> task = |
983 new DeleteAllCreatedBetweenForHostTask( | 953 new DeleteAllCreatedBetweenForHostTask(this, delete_begin, delete_end, |
984 this, delete_begin, delete_end, url, callback); | 954 url, callback); |
985 | 955 |
986 DoCookieTaskForURL(task, url); | 956 DoCookieTaskForURL(task, url); |
987 } | 957 } |
988 | 958 |
989 void CookieMonster::DeleteAllForHostAsync( | 959 void CookieMonster::DeleteAllForHostAsync(const GURL& url, |
990 const GURL& url, const DeleteCallback& callback) { | 960 const DeleteCallback& callback) { |
991 scoped_refptr<DeleteAllForHostTask> task = | 961 scoped_refptr<DeleteAllForHostTask> task = |
992 new DeleteAllForHostTask(this, url, callback); | 962 new DeleteAllForHostTask(this, url, callback); |
993 | 963 |
994 DoCookieTaskForURL(task, url); | 964 DoCookieTaskForURL(task, url); |
995 } | 965 } |
996 | 966 |
997 void CookieMonster::DeleteCanonicalCookieAsync( | 967 void CookieMonster::DeleteCanonicalCookieAsync( |
998 const CanonicalCookie& cookie, | 968 const CanonicalCookie& cookie, |
999 const DeleteCookieCallback& callback) { | 969 const DeleteCookieCallback& callback) { |
1000 scoped_refptr<DeleteCanonicalCookieTask> task = | 970 scoped_refptr<DeleteCanonicalCookieTask> task = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 void CookieMonster::DoCookieTaskForURL( | 1028 void CookieMonster::DoCookieTaskForURL( |
1059 const scoped_refptr<CookieMonsterTask>& task_item, | 1029 const scoped_refptr<CookieMonsterTask>& task_item, |
1060 const GURL& url) { | 1030 const GURL& url) { |
1061 { | 1031 { |
1062 base::AutoLock autolock(lock_); | 1032 base::AutoLock autolock(lock_); |
1063 InitIfNecessary(); | 1033 InitIfNecessary(); |
1064 // If cookies for the requested domain key (eTLD+1) have been loaded from DB | 1034 // If cookies for the requested domain key (eTLD+1) have been loaded from DB |
1065 // then run the task, otherwise load from DB. | 1035 // then run the task, otherwise load from DB. |
1066 if (!loaded_) { | 1036 if (!loaded_) { |
1067 // Checks if the domain key has been loaded. | 1037 // Checks if the domain key has been loaded. |
1068 std::string key(cookie_util::GetEffectiveDomain(url.scheme(), | 1038 std::string key( |
1069 url.host())); | 1039 cookie_util::GetEffectiveDomain(url.scheme(), url.host())); |
1070 if (keys_loaded_.find(key) == keys_loaded_.end()) { | 1040 if (keys_loaded_.find(key) == keys_loaded_.end()) { |
1071 std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > > | 1041 std::map<std::string, |
1072 ::iterator it = tasks_pending_for_key_.find(key); | 1042 std::deque<scoped_refptr<CookieMonsterTask>>>::iterator it = |
| 1043 tasks_pending_for_key_.find(key); |
1073 if (it == tasks_pending_for_key_.end()) { | 1044 if (it == tasks_pending_for_key_.end()) { |
1074 store_->LoadCookiesForKey(key, | 1045 store_->LoadCookiesForKey( |
1075 base::Bind(&CookieMonster::OnKeyLoaded, this, key)); | 1046 key, base::Bind(&CookieMonster::OnKeyLoaded, this, key)); |
1076 it = tasks_pending_for_key_.insert(std::make_pair(key, | 1047 it = tasks_pending_for_key_ |
1077 std::deque<scoped_refptr<CookieMonsterTask> >())).first; | 1048 .insert(std::make_pair( |
| 1049 key, std::deque<scoped_refptr<CookieMonsterTask>>())) |
| 1050 .first; |
1078 } | 1051 } |
1079 it->second.push_back(task_item); | 1052 it->second.push_back(task_item); |
1080 return; | 1053 return; |
1081 } | 1054 } |
1082 } | 1055 } |
1083 } | 1056 } |
1084 task_item->Run(); | 1057 task_item->Run(); |
1085 } | 1058 } |
1086 | 1059 |
1087 bool CookieMonster::SetCookieWithDetails(const GURL& url, | 1060 bool CookieMonster::SetCookieWithDetails(const GURL& url, |
1088 const std::string& name, | 1061 const std::string& name, |
1089 const std::string& value, | 1062 const std::string& value, |
1090 const std::string& domain, | 1063 const std::string& domain, |
1091 const std::string& path, | 1064 const std::string& path, |
1092 const base::Time& expiration_time, | 1065 const base::Time& expiration_time, |
1093 bool secure, | 1066 bool secure, |
1094 bool http_only, | 1067 bool http_only, |
1095 CookiePriority priority) { | 1068 CookiePriority priority) { |
1096 base::AutoLock autolock(lock_); | 1069 base::AutoLock autolock(lock_); |
1097 | 1070 |
1098 if (!HasCookieableScheme(url)) | 1071 if (!HasCookieableScheme(url)) |
1099 return false; | 1072 return false; |
1100 | 1073 |
1101 Time creation_time = CurrentTime(); | 1074 Time creation_time = CurrentTime(); |
1102 last_time_seen_ = creation_time; | 1075 last_time_seen_ = creation_time; |
1103 | 1076 |
1104 scoped_ptr<CanonicalCookie> cc; | 1077 scoped_ptr<CanonicalCookie> cc; |
1105 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, | 1078 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, |
1106 creation_time, expiration_time, | 1079 creation_time, expiration_time, secure, |
1107 secure, http_only, priority)); | 1080 http_only, priority)); |
1108 | 1081 |
1109 if (!cc.get()) | 1082 if (!cc.get()) |
1110 return false; | 1083 return false; |
1111 | 1084 |
1112 CookieOptions options; | 1085 CookieOptions options; |
1113 options.set_include_httponly(); | 1086 options.set_include_httponly(); |
1114 return SetCanonicalCookie(&cc, creation_time, options); | 1087 return SetCanonicalCookie(&cc, creation_time, options); |
1115 } | 1088 } |
1116 | 1089 |
1117 bool CookieMonster::ImportCookies(const CookieList& list) { | 1090 bool CookieMonster::ImportCookies(const CookieList& list) { |
1118 base::AutoLock autolock(lock_); | 1091 base::AutoLock autolock(lock_); |
1119 InitIfNecessary(); | 1092 InitIfNecessary(); |
1120 for (net::CookieList::const_iterator iter = list.begin(); | 1093 for (net::CookieList::const_iterator iter = list.begin(); iter != list.end(); |
1121 iter != list.end(); ++iter) { | 1094 ++iter) { |
1122 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); | 1095 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); |
1123 net::CookieOptions options; | 1096 net::CookieOptions options; |
1124 options.set_include_httponly(); | 1097 options.set_include_httponly(); |
1125 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) | 1098 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) |
1126 return false; | 1099 return false; |
1127 } | 1100 } |
1128 return true; | 1101 return true; |
1129 } | 1102 } |
1130 | 1103 |
1131 CookieList CookieMonster::GetAllCookies() { | 1104 CookieList CookieMonster::GetAllCookies() { |
1132 base::AutoLock autolock(lock_); | 1105 base::AutoLock autolock(lock_); |
1133 | 1106 |
1134 // This function is being called to scrape the cookie list for management UI | 1107 // This function is being called to scrape the cookie list for management UI |
1135 // or similar. We shouldn't show expired cookies in this list since it will | 1108 // or similar. We shouldn't show expired cookies in this list since it will |
1136 // just be confusing to users, and this function is called rarely enough (and | 1109 // just be confusing to users, and this function is called rarely enough (and |
1137 // is already slow enough) that it's OK to take the time to garbage collect | 1110 // is already slow enough) that it's OK to take the time to garbage collect |
1138 // the expired cookies now. | 1111 // the expired cookies now. |
1139 // | 1112 // |
1140 // Note that this does not prune cookies to be below our limits (if we've | 1113 // Note that this does not prune cookies to be below our limits (if we've |
1141 // exceeded them) the way that calling GarbageCollect() would. | 1114 // exceeded them) the way that calling GarbageCollect() would. |
1142 GarbageCollectExpired(Time::Now(), | 1115 GarbageCollectExpired( |
1143 CookieMapItPair(cookies_.begin(), cookies_.end()), | 1116 Time::Now(), CookieMapItPair(cookies_.begin(), cookies_.end()), NULL); |
1144 NULL); | |
1145 | 1117 |
1146 // Copy the CanonicalCookie pointers from the map so that we can use the same | 1118 // Copy the CanonicalCookie pointers from the map so that we can use the same |
1147 // sorter as elsewhere, then copy the result out. | 1119 // sorter as elsewhere, then copy the result out. |
1148 std::vector<CanonicalCookie*> cookie_ptrs; | 1120 std::vector<CanonicalCookie*> cookie_ptrs; |
1149 cookie_ptrs.reserve(cookies_.size()); | 1121 cookie_ptrs.reserve(cookies_.size()); |
1150 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end(); ++it) | 1122 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end(); ++it) |
1151 cookie_ptrs.push_back(it->second); | 1123 cookie_ptrs.push_back(it->second); |
1152 std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); | 1124 std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); |
1153 | 1125 |
1154 CookieList cookie_list; | 1126 CookieList cookie_list; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 } | 1158 } |
1187 | 1159 |
1188 int CookieMonster::DeleteAll(bool sync_to_store) { | 1160 int CookieMonster::DeleteAll(bool sync_to_store) { |
1189 base::AutoLock autolock(lock_); | 1161 base::AutoLock autolock(lock_); |
1190 | 1162 |
1191 int num_deleted = 0; | 1163 int num_deleted = 0; |
1192 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1164 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
1193 CookieMap::iterator curit = it; | 1165 CookieMap::iterator curit = it; |
1194 ++it; | 1166 ++it; |
1195 InternalDeleteCookie(curit, sync_to_store, | 1167 InternalDeleteCookie(curit, sync_to_store, |
1196 sync_to_store ? DELETE_COOKIE_EXPLICIT : | 1168 sync_to_store |
1197 DELETE_COOKIE_DONT_RECORD /* Destruction. */); | 1169 ? DELETE_COOKIE_EXPLICIT |
| 1170 : DELETE_COOKIE_DONT_RECORD /* Destruction. */); |
1198 ++num_deleted; | 1171 ++num_deleted; |
1199 } | 1172 } |
1200 | 1173 |
1201 return num_deleted; | 1174 return num_deleted; |
1202 } | 1175 } |
1203 | 1176 |
1204 int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin, | 1177 int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin, |
1205 const Time& delete_end) { | 1178 const Time& delete_end) { |
1206 base::AutoLock autolock(lock_); | 1179 base::AutoLock autolock(lock_); |
1207 | 1180 |
1208 int num_deleted = 0; | 1181 int num_deleted = 0; |
1209 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1182 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
1210 CookieMap::iterator curit = it; | 1183 CookieMap::iterator curit = it; |
1211 CanonicalCookie* cc = curit->second; | 1184 CanonicalCookie* cc = curit->second; |
1212 ++it; | 1185 ++it; |
1213 | 1186 |
1214 if (cc->CreationDate() >= delete_begin && | 1187 if (cc->CreationDate() >= delete_begin && |
1215 (delete_end.is_null() || cc->CreationDate() < delete_end)) { | 1188 (delete_end.is_null() || cc->CreationDate() < delete_end)) { |
1216 InternalDeleteCookie(curit, | 1189 InternalDeleteCookie(curit, true, /*sync_to_store*/ |
1217 true, /*sync_to_store*/ | |
1218 DELETE_COOKIE_EXPLICIT); | 1190 DELETE_COOKIE_EXPLICIT); |
1219 ++num_deleted; | 1191 ++num_deleted; |
1220 } | 1192 } |
1221 } | 1193 } |
1222 | 1194 |
1223 return num_deleted; | 1195 return num_deleted; |
1224 } | 1196 } |
1225 | 1197 |
1226 int CookieMonster::DeleteAllCreatedBetweenForHost(const Time delete_begin, | 1198 int CookieMonster::DeleteAllCreatedBetweenForHost(const Time delete_begin, |
1227 const Time delete_end, | 1199 const Time delete_end, |
(...skipping 27 matching lines...) Expand all Loading... |
1255 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); | 1227 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); |
1256 } | 1228 } |
1257 } | 1229 } |
1258 return num_deleted; | 1230 return num_deleted; |
1259 } | 1231 } |
1260 | 1232 |
1261 int CookieMonster::DeleteAllForHost(const GURL& url) { | 1233 int CookieMonster::DeleteAllForHost(const GURL& url) { |
1262 return DeleteAllCreatedBetweenForHost(Time(), Time::Max(), url); | 1234 return DeleteAllCreatedBetweenForHost(Time(), Time::Max(), url); |
1263 } | 1235 } |
1264 | 1236 |
1265 | |
1266 bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { | 1237 bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { |
1267 base::AutoLock autolock(lock_); | 1238 base::AutoLock autolock(lock_); |
1268 | 1239 |
1269 for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain())); | 1240 for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain())); |
1270 its.first != its.second; ++its.first) { | 1241 its.first != its.second; ++its.first) { |
1271 // The creation date acts as our unique index... | 1242 // The creation date acts as our unique index... |
1272 if (its.first->second->CreationDate() == cookie.CreationDate()) { | 1243 if (its.first->second->CreationDate() == cookie.CreationDate()) { |
1273 InternalDeleteCookie(its.first, true, DELETE_COOKIE_EXPLICIT); | 1244 InternalDeleteCookie(its.first, true, DELETE_COOKIE_EXPLICIT); |
1274 return true; | 1245 return true; |
1275 } | 1246 } |
1276 } | 1247 } |
1277 return false; | 1248 return false; |
1278 } | 1249 } |
1279 | 1250 |
1280 void CookieMonster::SetCookieableSchemes(const char* const schemes[], | 1251 void CookieMonster::SetCookieableSchemes(const char* const schemes[], |
1281 size_t num_schemes) { | 1252 size_t num_schemes) { |
1282 base::AutoLock autolock(lock_); | 1253 base::AutoLock autolock(lock_); |
1283 | 1254 |
1284 // Cookieable Schemes must be set before first use of function. | 1255 // Cookieable Schemes must be set before first use of function. |
1285 DCHECK(!initialized_); | 1256 DCHECK(!initialized_); |
1286 | 1257 |
1287 cookieable_schemes_.clear(); | 1258 cookieable_schemes_.clear(); |
1288 cookieable_schemes_.insert(cookieable_schemes_.end(), | 1259 cookieable_schemes_.insert(cookieable_schemes_.end(), schemes, |
1289 schemes, schemes + num_schemes); | 1260 schemes + num_schemes); |
1290 } | 1261 } |
1291 | 1262 |
1292 void CookieMonster::SetEnableFileScheme(bool accept) { | 1263 void CookieMonster::SetEnableFileScheme(bool accept) { |
1293 // This assumes "file" is always at the end of the array. See the comment | 1264 // This assumes "file" is always at the end of the array. See the comment |
1294 // above kDefaultCookieableSchemes. | 1265 // above kDefaultCookieableSchemes. |
1295 int num_schemes = accept ? kDefaultCookieableSchemesCount : | 1266 int num_schemes = accept ? kDefaultCookieableSchemesCount |
1296 kDefaultCookieableSchemesCount - 1; | 1267 : kDefaultCookieableSchemesCount - 1; |
1297 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); | 1268 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); |
1298 } | 1269 } |
1299 | 1270 |
1300 void CookieMonster::SetKeepExpiredCookies() { | 1271 void CookieMonster::SetKeepExpiredCookies() { |
1301 keep_expired_cookies_ = true; | 1272 keep_expired_cookies_ = true; |
1302 } | 1273 } |
1303 | 1274 |
1304 void CookieMonster::FlushStore(const base::Closure& callback) { | 1275 void CookieMonster::FlushStore(const base::Closure& callback) { |
1305 base::AutoLock autolock(lock_); | 1276 base::AutoLock autolock(lock_); |
1306 if (initialized_ && store_.get()) | 1277 if (initialized_ && store_.get()) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 int CookieMonster::DeleteSessionCookies() { | 1345 int CookieMonster::DeleteSessionCookies() { |
1375 base::AutoLock autolock(lock_); | 1346 base::AutoLock autolock(lock_); |
1376 | 1347 |
1377 int num_deleted = 0; | 1348 int num_deleted = 0; |
1378 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1349 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
1379 CookieMap::iterator curit = it; | 1350 CookieMap::iterator curit = it; |
1380 CanonicalCookie* cc = curit->second; | 1351 CanonicalCookie* cc = curit->second; |
1381 ++it; | 1352 ++it; |
1382 | 1353 |
1383 if (!cc->IsPersistent()) { | 1354 if (!cc->IsPersistent()) { |
1384 InternalDeleteCookie(curit, | 1355 InternalDeleteCookie(curit, true, /*sync_to_store*/ |
1385 true, /*sync_to_store*/ | |
1386 DELETE_COOKIE_EXPIRED); | 1356 DELETE_COOKIE_EXPIRED); |
1387 ++num_deleted; | 1357 ++num_deleted; |
1388 } | 1358 } |
1389 } | 1359 } |
1390 | 1360 |
1391 return num_deleted; | 1361 return num_deleted; |
1392 } | 1362 } |
1393 | 1363 |
1394 bool CookieMonster::HasCookiesForETLDP1(const std::string& etldp1) { | 1364 bool CookieMonster::HasCookiesForETLDP1(const std::string& etldp1) { |
1395 base::AutoLock autolock(lock_); | 1365 base::AutoLock autolock(lock_); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 InvokeQueue(); | 1430 InvokeQueue(); |
1461 | 1431 |
1462 ReportLoaded(); | 1432 ReportLoaded(); |
1463 } | 1433 } |
1464 | 1434 |
1465 void CookieMonster::OnKeyLoaded(const std::string& key, | 1435 void CookieMonster::OnKeyLoaded(const std::string& key, |
1466 const std::vector<CanonicalCookie*>& cookies) { | 1436 const std::vector<CanonicalCookie*>& cookies) { |
1467 // This function does its own separate locking. | 1437 // This function does its own separate locking. |
1468 StoreLoadedCookies(cookies); | 1438 StoreLoadedCookies(cookies); |
1469 | 1439 |
1470 std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key; | 1440 std::deque<scoped_refptr<CookieMonsterTask>> tasks_pending_for_key; |
1471 | 1441 |
1472 // We need to do this repeatedly until no more tasks were added to the queue | 1442 // We need to do this repeatedly until no more tasks were added to the queue |
1473 // during the period where we release the lock. | 1443 // during the period where we release the lock. |
1474 while (true) { | 1444 while (true) { |
1475 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is | 1445 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is |
1476 // fixed. | 1446 // fixed. |
1477 tracked_objects::ScopedTracker tracking_profile1( | 1447 tracked_objects::ScopedTracker tracking_profile1( |
1478 FROM_HERE_WITH_EXPLICIT_FUNCTION("456373 CookieMonster::OnKeyLoaded1")); | 1448 FROM_HERE_WITH_EXPLICIT_FUNCTION("456373 CookieMonster::OnKeyLoaded1")); |
1479 { | 1449 { |
1480 base::AutoLock autolock(lock_); | 1450 base::AutoLock autolock(lock_); |
1481 std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > > | 1451 std::map<std::string, |
1482 ::iterator it = tasks_pending_for_key_.find(key); | 1452 std::deque<scoped_refptr<CookieMonsterTask>>>::iterator it = |
| 1453 tasks_pending_for_key_.find(key); |
1483 if (it == tasks_pending_for_key_.end()) { | 1454 if (it == tasks_pending_for_key_.end()) { |
1484 keys_loaded_.insert(key); | 1455 keys_loaded_.insert(key); |
1485 return; | 1456 return; |
1486 } | 1457 } |
1487 if (it->second.empty()) { | 1458 if (it->second.empty()) { |
1488 keys_loaded_.insert(key); | 1459 keys_loaded_.insert(key); |
1489 tasks_pending_for_key_.erase(it); | 1460 tasks_pending_for_key_.erase(it); |
1490 return; | 1461 return; |
1491 } | 1462 } |
1492 it->second.swap(tasks_pending_for_key); | 1463 it->second.swap(tasks_pending_for_key); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1524 if (creation_times_.insert(cookie_creation_time).second) { | 1495 if (creation_times_.insert(cookie_creation_time).second) { |
1525 CookieMap::iterator inserted = | 1496 CookieMap::iterator inserted = |
1526 InternalInsertCookie(GetKey((*it)->Domain()), *it, false); | 1497 InternalInsertCookie(GetKey((*it)->Domain()), *it, false); |
1527 const Time cookie_access_time((*it)->LastAccessDate()); | 1498 const Time cookie_access_time((*it)->LastAccessDate()); |
1528 if (earliest_access_time_.is_null() || | 1499 if (earliest_access_time_.is_null() || |
1529 cookie_access_time < earliest_access_time_) | 1500 cookie_access_time < earliest_access_time_) |
1530 earliest_access_time_ = cookie_access_time; | 1501 earliest_access_time_ = cookie_access_time; |
1531 | 1502 |
1532 if (ContainsControlCharacter((*it)->Name()) || | 1503 if (ContainsControlCharacter((*it)->Name()) || |
1533 ContainsControlCharacter((*it)->Value())) { | 1504 ContainsControlCharacter((*it)->Value())) { |
1534 cookies_with_control_chars.push_back(inserted); | 1505 cookies_with_control_chars.push_back(inserted); |
1535 } | 1506 } |
1536 } else { | 1507 } else { |
1537 LOG(ERROR) << base::StringPrintf("Found cookies with duplicate creation " | 1508 LOG(ERROR) << base::StringPrintf( |
1538 "times in backing store: " | 1509 "Found cookies with duplicate creation " |
1539 "{name='%s', domain='%s', path='%s'}", | 1510 "times in backing store: " |
1540 (*it)->Name().c_str(), | 1511 "{name='%s', domain='%s', path='%s'}", |
1541 (*it)->Domain().c_str(), | 1512 (*it)->Name().c_str(), (*it)->Domain().c_str(), |
1542 (*it)->Path().c_str()); | 1513 (*it)->Path().c_str()); |
1543 // We've been given ownership of the cookie and are throwing it | 1514 // We've been given ownership of the cookie and are throwing it |
1544 // away; reclaim the space. | 1515 // away; reclaim the space. |
1545 delete (*it); | 1516 delete (*it); |
1546 } | 1517 } |
1547 } | 1518 } |
1548 | 1519 |
1549 // Any cookies that contain control characters that we have loaded from the | 1520 // Any cookies that contain control characters that we have loaded from the |
1550 // persistent store should be deleted. See http://crbug.com/238041. | 1521 // persistent store should be deleted. See http://crbug.com/238041. |
1551 for (CookieItVector::iterator it = cookies_with_control_chars.begin(); | 1522 for (CookieItVector::iterator it = cookies_with_control_chars.begin(); |
1552 it != cookies_with_control_chars.end();) { | 1523 it != cookies_with_control_chars.end();) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 // Ensure no equivalent cookies for this host. | 1574 // Ensure no equivalent cookies for this host. |
1604 num_duplicates_trimmed += | 1575 num_duplicates_trimmed += |
1605 TrimDuplicateCookiesForKey(key, cur_range_begin, cur_range_end); | 1576 TrimDuplicateCookiesForKey(key, cur_range_begin, cur_range_end); |
1606 } | 1577 } |
1607 | 1578 |
1608 // Record how many duplicates were found in the database. | 1579 // Record how many duplicates were found in the database. |
1609 // See InitializeHistograms() for details. | 1580 // See InitializeHistograms() for details. |
1610 histogram_cookie_deletion_cause_->Add(num_duplicates_trimmed); | 1581 histogram_cookie_deletion_cause_->Add(num_duplicates_trimmed); |
1611 } | 1582 } |
1612 | 1583 |
1613 int CookieMonster::TrimDuplicateCookiesForKey( | 1584 int CookieMonster::TrimDuplicateCookiesForKey(const std::string& key, |
1614 const std::string& key, | 1585 CookieMap::iterator begin, |
1615 CookieMap::iterator begin, | 1586 CookieMap::iterator end) { |
1616 CookieMap::iterator end) { | |
1617 lock_.AssertAcquired(); | 1587 lock_.AssertAcquired(); |
1618 | 1588 |
1619 // Set of cookies ordered by creation time. | 1589 // Set of cookies ordered by creation time. |
1620 typedef std::set<CookieMap::iterator, OrderByCreationTimeDesc> CookieSet; | 1590 typedef std::set<CookieMap::iterator, OrderByCreationTimeDesc> CookieSet; |
1621 | 1591 |
1622 // Helper map we populate to find the duplicates. | 1592 // Helper map we populate to find the duplicates. |
1623 typedef std::map<CookieSignature, CookieSet> EquivalenceMap; | 1593 typedef std::map<CookieSignature, CookieSet> EquivalenceMap; |
1624 EquivalenceMap equivalent_cookies; | 1594 EquivalenceMap equivalent_cookies; |
1625 | 1595 |
1626 // The number of duplicate cookies that have been found. | 1596 // The number of duplicate cookies that have been found. |
1627 int num_duplicates = 0; | 1597 int num_duplicates = 0; |
1628 | 1598 |
1629 // Iterate through all of the cookies in our range, and insert them into | 1599 // Iterate through all of the cookies in our range, and insert them into |
1630 // the equivalence map. | 1600 // the equivalence map. |
1631 for (CookieMap::iterator it = begin; it != end; ++it) { | 1601 for (CookieMap::iterator it = begin; it != end; ++it) { |
1632 DCHECK_EQ(key, it->first); | 1602 DCHECK_EQ(key, it->first); |
1633 CanonicalCookie* cookie = it->second; | 1603 CanonicalCookie* cookie = it->second; |
1634 | 1604 |
1635 CookieSignature signature(cookie->Name(), cookie->Domain(), | 1605 CookieSignature signature(cookie->Name(), cookie->Domain(), cookie->Path()); |
1636 cookie->Path()); | |
1637 CookieSet& set = equivalent_cookies[signature]; | 1606 CookieSet& set = equivalent_cookies[signature]; |
1638 | 1607 |
1639 // We found a duplicate! | 1608 // We found a duplicate! |
1640 if (!set.empty()) | 1609 if (!set.empty()) |
1641 num_duplicates++; | 1610 num_duplicates++; |
1642 | 1611 |
1643 // We save the iterator into |cookies_| rather than the actual cookie | 1612 // We save the iterator into |cookies_| rather than the actual cookie |
1644 // pointer, since we may need to delete it later. | 1613 // pointer, since we may need to delete it later. |
1645 bool insert_success = set.insert(it).second; | 1614 bool insert_success = set.insert(it).second; |
1646 DCHECK(insert_success) << | 1615 DCHECK(insert_success) |
1647 "Duplicate creation times found in duplicate cookie name scan."; | 1616 << "Duplicate creation times found in duplicate cookie name scan."; |
1648 } | 1617 } |
1649 | 1618 |
1650 // If there were no duplicates, we are done! | 1619 // If there were no duplicates, we are done! |
1651 if (num_duplicates == 0) | 1620 if (num_duplicates == 0) |
1652 return 0; | 1621 return 0; |
1653 | 1622 |
1654 // Make sure we find everything below that we did above. | 1623 // Make sure we find everything below that we did above. |
1655 int num_duplicates_found = 0; | 1624 int num_duplicates_found = 0; |
1656 | 1625 |
1657 // Otherwise, delete all the duplicate cookies, both from our in-memory store | 1626 // Otherwise, delete all the duplicate cookies, both from our in-memory store |
1658 // and from the backing store. | 1627 // and from the backing store. |
1659 for (EquivalenceMap::iterator it = equivalent_cookies.begin(); | 1628 for (EquivalenceMap::iterator it = equivalent_cookies.begin(); |
1660 it != equivalent_cookies.end(); | 1629 it != equivalent_cookies.end(); ++it) { |
1661 ++it) { | |
1662 const CookieSignature& signature = it->first; | 1630 const CookieSignature& signature = it->first; |
1663 CookieSet& dupes = it->second; | 1631 CookieSet& dupes = it->second; |
1664 | 1632 |
1665 if (dupes.size() <= 1) | 1633 if (dupes.size() <= 1) |
1666 continue; // This cookiename/path has no duplicates. | 1634 continue; // This cookiename/path has no duplicates. |
1667 num_duplicates_found += dupes.size() - 1; | 1635 num_duplicates_found += dupes.size() - 1; |
1668 | 1636 |
1669 // Since |dups| is sorted by creation time (descending), the first cookie | 1637 // Since |dups| is sorted by creation time (descending), the first cookie |
1670 // is the most recent one, so we will keep it. The rest are duplicates. | 1638 // is the most recent one, so we will keep it. The rest are duplicates. |
1671 dupes.erase(dupes.begin()); | 1639 dupes.erase(dupes.begin()); |
1672 | 1640 |
1673 LOG(ERROR) << base::StringPrintf( | 1641 LOG(ERROR) << base::StringPrintf( |
1674 "Found %d duplicate cookies for host='%s', " | 1642 "Found %d duplicate cookies for host='%s', " |
1675 "with {name='%s', domain='%s', path='%s'}", | 1643 "with {name='%s', domain='%s', path='%s'}", |
1676 static_cast<int>(dupes.size()), | 1644 static_cast<int>(dupes.size()), key.c_str(), signature.name.c_str(), |
1677 key.c_str(), | 1645 signature.domain.c_str(), signature.path.c_str()); |
1678 signature.name.c_str(), | |
1679 signature.domain.c_str(), | |
1680 signature.path.c_str()); | |
1681 | 1646 |
1682 // Remove all the cookies identified by |dupes|. It is valid to delete our | 1647 // Remove all the cookies identified by |dupes|. It is valid to delete our |
1683 // list of iterators one at a time, since |cookies_| is a multimap (they | 1648 // list of iterators one at a time, since |cookies_| is a multimap (they |
1684 // don't invalidate existing iterators following deletion). | 1649 // don't invalidate existing iterators following deletion). |
1685 for (CookieSet::iterator dupes_it = dupes.begin(); | 1650 for (CookieSet::iterator dupes_it = dupes.begin(); dupes_it != dupes.end(); |
1686 dupes_it != dupes.end(); | |
1687 ++dupes_it) { | 1651 ++dupes_it) { |
1688 InternalDeleteCookie(*dupes_it, true, | 1652 InternalDeleteCookie(*dupes_it, true, |
1689 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE); | 1653 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE); |
1690 } | 1654 } |
1691 } | 1655 } |
1692 DCHECK_EQ(num_duplicates, num_duplicates_found); | 1656 DCHECK_EQ(num_duplicates, num_duplicates_found); |
1693 | 1657 |
1694 return num_duplicates; | 1658 return num_duplicates; |
1695 } | 1659 } |
1696 | 1660 |
1697 // Note: file must be the last scheme. | 1661 // Note: file must be the last scheme. |
1698 const char* const CookieMonster::kDefaultCookieableSchemes[] = | 1662 const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", |
1699 { "http", "https", "ws", "wss", "file" }; | 1663 "https", |
| 1664 "ws", |
| 1665 "wss", |
| 1666 "file"}; |
1700 const int CookieMonster::kDefaultCookieableSchemesCount = | 1667 const int CookieMonster::kDefaultCookieableSchemesCount = |
1701 arraysize(kDefaultCookieableSchemes); | 1668 arraysize(kDefaultCookieableSchemes); |
1702 | 1669 |
1703 void CookieMonster::SetDefaultCookieableSchemes() { | 1670 void CookieMonster::SetDefaultCookieableSchemes() { |
1704 // Always disable file scheme unless SetEnableFileScheme(true) is called. | 1671 // Always disable file scheme unless SetEnableFileScheme(true) is called. |
1705 SetCookieableSchemes(kDefaultCookieableSchemes, | 1672 SetCookieableSchemes(kDefaultCookieableSchemes, |
1706 kDefaultCookieableSchemesCount - 1); | 1673 kDefaultCookieableSchemesCount - 1); |
1707 } | 1674 } |
1708 | 1675 |
1709 void CookieMonster::FindCookiesForHostAndDomain( | 1676 void CookieMonster::FindCookiesForHostAndDomain( |
1710 const GURL& url, | 1677 const GURL& url, |
1711 const CookieOptions& options, | 1678 const CookieOptions& options, |
1712 bool update_access_time, | 1679 bool update_access_time, |
1713 std::vector<CanonicalCookie*>* cookies) { | 1680 std::vector<CanonicalCookie*>* cookies) { |
1714 lock_.AssertAcquired(); | 1681 lock_.AssertAcquired(); |
1715 | 1682 |
1716 const Time current_time(CurrentTime()); | 1683 const Time current_time(CurrentTime()); |
1717 | 1684 |
1718 // Probe to save statistics relatively frequently. We do it here rather | 1685 // Probe to save statistics relatively frequently. We do it here rather |
1719 // than in the set path as many websites won't set cookies, and we | 1686 // than in the set path as many websites won't set cookies, and we |
1720 // want to collect statistics whenever the browser's being used. | 1687 // want to collect statistics whenever the browser's being used. |
1721 RecordPeriodicStats(current_time); | 1688 RecordPeriodicStats(current_time); |
1722 | 1689 |
1723 // Can just dispatch to FindCookiesForKey | 1690 // Can just dispatch to FindCookiesForKey |
1724 const std::string key(GetKey(url.host())); | 1691 const std::string key(GetKey(url.host())); |
1725 FindCookiesForKey(key, url, options, current_time, | 1692 FindCookiesForKey(key, url, options, current_time, update_access_time, |
1726 update_access_time, cookies); | 1693 cookies); |
1727 } | 1694 } |
1728 | 1695 |
1729 void CookieMonster::FindCookiesForKey(const std::string& key, | 1696 void CookieMonster::FindCookiesForKey(const std::string& key, |
1730 const GURL& url, | 1697 const GURL& url, |
1731 const CookieOptions& options, | 1698 const CookieOptions& options, |
1732 const Time& current, | 1699 const Time& current, |
1733 bool update_access_time, | 1700 bool update_access_time, |
1734 std::vector<CanonicalCookie*>* cookies) { | 1701 std::vector<CanonicalCookie*>* cookies) { |
1735 lock_.AssertAcquired(); | 1702 lock_.AssertAcquired(); |
1736 | 1703 |
1737 for (CookieMapItPair its = cookies_.equal_range(key); | 1704 for (CookieMapItPair its = cookies_.equal_range(key); |
1738 its.first != its.second; ) { | 1705 its.first != its.second;) { |
1739 CookieMap::iterator curit = its.first; | 1706 CookieMap::iterator curit = its.first; |
1740 CanonicalCookie* cc = curit->second; | 1707 CanonicalCookie* cc = curit->second; |
1741 ++its.first; | 1708 ++its.first; |
1742 | 1709 |
1743 // If the cookie is expired, delete it. | 1710 // If the cookie is expired, delete it. |
1744 if (cc->IsExpired(current) && !keep_expired_cookies_) { | 1711 if (cc->IsExpired(current) && !keep_expired_cookies_) { |
1745 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); | 1712 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); |
1746 continue; | 1713 continue; |
1747 } | 1714 } |
1748 | 1715 |
(...skipping 14 matching lines...) Expand all Loading... |
1763 | 1730 |
1764 bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, | 1731 bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, |
1765 const CanonicalCookie& ecc, | 1732 const CanonicalCookie& ecc, |
1766 bool skip_httponly, | 1733 bool skip_httponly, |
1767 bool already_expired) { | 1734 bool already_expired) { |
1768 lock_.AssertAcquired(); | 1735 lock_.AssertAcquired(); |
1769 | 1736 |
1770 bool found_equivalent_cookie = false; | 1737 bool found_equivalent_cookie = false; |
1771 bool skipped_httponly = false; | 1738 bool skipped_httponly = false; |
1772 for (CookieMapItPair its = cookies_.equal_range(key); | 1739 for (CookieMapItPair its = cookies_.equal_range(key); |
1773 its.first != its.second; ) { | 1740 its.first != its.second;) { |
1774 CookieMap::iterator curit = its.first; | 1741 CookieMap::iterator curit = its.first; |
1775 CanonicalCookie* cc = curit->second; | 1742 CanonicalCookie* cc = curit->second; |
1776 ++its.first; | 1743 ++its.first; |
1777 | 1744 |
1778 if (ecc.IsEquivalent(*cc)) { | 1745 if (ecc.IsEquivalent(*cc)) { |
1779 // We should never have more than one equivalent cookie, since they should | 1746 // We should never have more than one equivalent cookie, since they should |
1780 // overwrite each other. | 1747 // overwrite each other. |
1781 CHECK(!found_equivalent_cookie) << | 1748 CHECK(!found_equivalent_cookie) |
1782 "Duplicate equivalent cookies found, cookie store is corrupted."; | 1749 << "Duplicate equivalent cookies found, cookie store is corrupted."; |
1783 if (skip_httponly && cc->IsHttpOnly()) { | 1750 if (skip_httponly && cc->IsHttpOnly()) { |
1784 skipped_httponly = true; | 1751 skipped_httponly = true; |
1785 } else { | 1752 } else { |
1786 InternalDeleteCookie(curit, true, already_expired ? | 1753 InternalDeleteCookie(curit, true, already_expired |
1787 DELETE_COOKIE_EXPIRED_OVERWRITE : DELETE_COOKIE_OVERWRITE); | 1754 ? DELETE_COOKIE_EXPIRED_OVERWRITE |
| 1755 : DELETE_COOKIE_OVERWRITE); |
1788 } | 1756 } |
1789 found_equivalent_cookie = true; | 1757 found_equivalent_cookie = true; |
1790 } | 1758 } |
1791 } | 1759 } |
1792 return skipped_httponly; | 1760 return skipped_httponly; |
1793 } | 1761 } |
1794 | 1762 |
1795 CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( | 1763 CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( |
1796 const std::string& key, | 1764 const std::string& key, |
1797 CanonicalCookie* cc, | 1765 CanonicalCookie* cc, |
1798 bool sync_to_store) { | 1766 bool sync_to_store) { |
1799 lock_.AssertAcquired(); | 1767 lock_.AssertAcquired(); |
1800 | 1768 |
1801 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && | 1769 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
1802 sync_to_store) | 1770 sync_to_store) |
1803 store_->AddCookie(*cc); | 1771 store_->AddCookie(*cc); |
1804 CookieMap::iterator inserted = | 1772 CookieMap::iterator inserted = |
1805 cookies_.insert(CookieMap::value_type(key, cc)); | 1773 cookies_.insert(CookieMap::value_type(key, cc)); |
1806 if (delegate_.get()) { | 1774 if (delegate_.get()) { |
1807 delegate_->OnCookieChanged( | 1775 delegate_->OnCookieChanged(*cc, false, |
1808 *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); | 1776 CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); |
1809 } | 1777 } |
1810 RunCallbacks(*cc, false); | 1778 RunCallbacks(*cc, false); |
1811 | 1779 |
1812 return inserted; | 1780 return inserted; |
1813 } | 1781 } |
1814 | 1782 |
1815 bool CookieMonster::SetCookieWithCreationTimeAndOptions( | 1783 bool CookieMonster::SetCookieWithCreationTimeAndOptions( |
1816 const GURL& url, | 1784 const GURL& url, |
1817 const std::string& cookie_line, | 1785 const std::string& cookie_line, |
1818 const Time& creation_time_or_null, | 1786 const Time& creation_time_or_null, |
(...skipping 23 matching lines...) Expand all Loading... |
1842 const CookieOptions& options) { | 1810 const CookieOptions& options) { |
1843 const std::string key(GetKey((*cc)->Domain())); | 1811 const std::string key(GetKey((*cc)->Domain())); |
1844 bool already_expired = (*cc)->IsExpired(creation_time); | 1812 bool already_expired = (*cc)->IsExpired(creation_time); |
1845 | 1813 |
1846 if (DeleteAnyEquivalentCookie(key, **cc, options.exclude_httponly(), | 1814 if (DeleteAnyEquivalentCookie(key, **cc, options.exclude_httponly(), |
1847 already_expired)) { | 1815 already_expired)) { |
1848 VLOG(kVlogSetCookies) << "SetCookie() not clobbering httponly cookie"; | 1816 VLOG(kVlogSetCookies) << "SetCookie() not clobbering httponly cookie"; |
1849 return false; | 1817 return false; |
1850 } | 1818 } |
1851 | 1819 |
1852 VLOG(kVlogSetCookies) << "SetCookie() key: " << key << " cc: " | 1820 VLOG(kVlogSetCookies) << "SetCookie() key: " << key |
1853 << (*cc)->DebugString(); | 1821 << " cc: " << (*cc)->DebugString(); |
1854 | 1822 |
1855 // Realize that we might be setting an expired cookie, and the only point | 1823 // Realize that we might be setting an expired cookie, and the only point |
1856 // was to delete the cookie which we've already done. | 1824 // was to delete the cookie which we've already done. |
1857 if (!already_expired || keep_expired_cookies_) { | 1825 if (!already_expired || keep_expired_cookies_) { |
1858 // See InitializeHistograms() for details. | 1826 // See InitializeHistograms() for details. |
1859 if ((*cc)->IsPersistent()) { | 1827 if ((*cc)->IsPersistent()) { |
1860 histogram_expiration_duration_minutes_->Add( | 1828 histogram_expiration_duration_minutes_->Add( |
1861 ((*cc)->ExpiryDate() - creation_time).InMinutes()); | 1829 ((*cc)->ExpiryDate() - creation_time).InMinutes()); |
1862 } | 1830 } |
1863 | 1831 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 if (mapping.notify) | 1896 if (mapping.notify) |
1929 delegate_->OnCookieChanged(*cc, true, mapping.cause); | 1897 delegate_->OnCookieChanged(*cc, true, mapping.cause); |
1930 } | 1898 } |
1931 RunCallbacks(*cc, true); | 1899 RunCallbacks(*cc, true); |
1932 cookies_.erase(it); | 1900 cookies_.erase(it); |
1933 delete cc; | 1901 delete cc; |
1934 } | 1902 } |
1935 | 1903 |
1936 // Domain expiry behavior is unchanged by key/expiry scheme (the | 1904 // Domain expiry behavior is unchanged by key/expiry scheme (the |
1937 // meaning of the key is different, but that's not visible to this routine). | 1905 // meaning of the key is different, but that's not visible to this routine). |
1938 int CookieMonster::GarbageCollect(const Time& current, | 1906 int CookieMonster::GarbageCollect(const Time& current, const std::string& key) { |
1939 const std::string& key) { | |
1940 lock_.AssertAcquired(); | 1907 lock_.AssertAcquired(); |
1941 | 1908 |
1942 int num_deleted = 0; | 1909 int num_deleted = 0; |
1943 Time safe_date( | 1910 Time safe_date(Time::Now() - TimeDelta::FromDays(kSafeFromGlobalPurgeDays)); |
1944 Time::Now() - TimeDelta::FromDays(kSafeFromGlobalPurgeDays)); | |
1945 | 1911 |
1946 // Collect garbage for this key, minding cookie priorities. | 1912 // Collect garbage for this key, minding cookie priorities. |
1947 if (cookies_.count(key) > kDomainMaxCookies) { | 1913 if (cookies_.count(key) > kDomainMaxCookies) { |
1948 VLOG(kVlogGarbageCollection) << "GarbageCollect() key: " << key; | 1914 VLOG(kVlogGarbageCollection) << "GarbageCollect() key: " << key; |
1949 | 1915 |
1950 CookieItVector cookie_its; | 1916 CookieItVector cookie_its; |
1951 num_deleted += GarbageCollectExpired( | 1917 num_deleted += |
1952 current, cookies_.equal_range(key), &cookie_its); | 1918 GarbageCollectExpired(current, cookies_.equal_range(key), &cookie_its); |
1953 if (cookie_its.size() > kDomainMaxCookies) { | 1919 if (cookie_its.size() > kDomainMaxCookies) { |
1954 VLOG(kVlogGarbageCollection) << "Deep Garbage Collect domain."; | 1920 VLOG(kVlogGarbageCollection) << "Deep Garbage Collect domain."; |
1955 size_t purge_goal = | 1921 size_t purge_goal = |
1956 cookie_its.size() - (kDomainMaxCookies - kDomainPurgeCookies); | 1922 cookie_its.size() - (kDomainMaxCookies - kDomainPurgeCookies); |
1957 DCHECK(purge_goal > kDomainPurgeCookies); | 1923 DCHECK(purge_goal > kDomainPurgeCookies); |
1958 | 1924 |
1959 // Boundary iterators into |cookie_its| for different priorities. | 1925 // Boundary iterators into |cookie_its| for different priorities. |
1960 CookieItVector::iterator it_bdd[4]; | 1926 CookieItVector::iterator it_bdd[4]; |
1961 // Intialize |it_bdd| while sorting |cookie_its| by priorities. | 1927 // Intialize |it_bdd| while sorting |cookie_its| by priorities. |
1962 // Schematic: [MLLHMHHLMM] => [LLL|MMMM|HHH], with 4 boundaries. | 1928 // Schematic: [MLLHMHHLMM] => [LLL|MMMM|HHH], with 4 boundaries. |
1963 it_bdd[0] = cookie_its.begin(); | 1929 it_bdd[0] = cookie_its.begin(); |
1964 it_bdd[3] = cookie_its.end(); | 1930 it_bdd[3] = cookie_its.end(); |
1965 it_bdd[1] = PartitionCookieByPriority(it_bdd[0], it_bdd[3], | 1931 it_bdd[1] = |
1966 COOKIE_PRIORITY_LOW); | 1932 PartitionCookieByPriority(it_bdd[0], it_bdd[3], COOKIE_PRIORITY_LOW); |
1967 it_bdd[2] = PartitionCookieByPriority(it_bdd[1], it_bdd[3], | 1933 it_bdd[2] = PartitionCookieByPriority(it_bdd[1], it_bdd[3], |
1968 COOKIE_PRIORITY_MEDIUM); | 1934 COOKIE_PRIORITY_MEDIUM); |
1969 size_t quota[3] = { | 1935 size_t quota[3] = {kDomainCookiesQuotaLow, |
1970 kDomainCookiesQuotaLow, | 1936 kDomainCookiesQuotaMedium, |
1971 kDomainCookiesQuotaMedium, | 1937 kDomainCookiesQuotaHigh}; |
1972 kDomainCookiesQuotaHigh | |
1973 }; | |
1974 | 1938 |
1975 // Purge domain cookies in 3 rounds. | 1939 // Purge domain cookies in 3 rounds. |
1976 // Round 1: consider low-priority cookies only: evict least-recently | 1940 // Round 1: consider low-priority cookies only: evict least-recently |
1977 // accessed, while protecting quota[0] of these from deletion. | 1941 // accessed, while protecting quota[0] of these from deletion. |
1978 // Round 2: consider {low, medium}-priority cookies, evict least-recently | 1942 // Round 2: consider {low, medium}-priority cookies, evict least-recently |
1979 // accessed, while protecting quota[0] + quota[1]. | 1943 // accessed, while protecting quota[0] + quota[1]. |
1980 // Round 3: consider all cookies, evict least-recently accessed. | 1944 // Round 3: consider all cookies, evict least-recently accessed. |
1981 size_t accumulated_quota = 0; | 1945 size_t accumulated_quota = 0; |
1982 CookieItVector::iterator it_purge_begin = it_bdd[0]; | 1946 CookieItVector::iterator it_purge_begin = it_bdd[0]; |
1983 for (int i = 0; i < 3 && purge_goal > 0; ++i) { | 1947 for (int i = 0; i < 3 && purge_goal > 0; ++i) { |
1984 accumulated_quota += quota[i]; | 1948 accumulated_quota += quota[i]; |
1985 | 1949 |
1986 size_t num_considered = it_bdd[i + 1] - it_purge_begin; | 1950 size_t num_considered = it_bdd[i + 1] - it_purge_begin; |
1987 if (num_considered <= accumulated_quota) | 1951 if (num_considered <= accumulated_quota) |
1988 continue; | 1952 continue; |
1989 | 1953 |
1990 // Number of cookies that will be purged in this round. | 1954 // Number of cookies that will be purged in this round. |
1991 size_t round_goal = | 1955 size_t round_goal = |
1992 std::min(purge_goal, num_considered - accumulated_quota); | 1956 std::min(purge_goal, num_considered - accumulated_quota); |
1993 purge_goal -= round_goal; | 1957 purge_goal -= round_goal; |
1994 | 1958 |
1995 SortLeastRecentlyAccessed(it_purge_begin, it_bdd[i + 1], round_goal); | 1959 SortLeastRecentlyAccessed(it_purge_begin, it_bdd[i + 1], round_goal); |
1996 // Cookies accessed on or after |safe_date| would have been safe from | 1960 // Cookies accessed on or after |safe_date| would have been safe from |
1997 // global purge, and we want to keep track of this. | 1961 // global purge, and we want to keep track of this. |
1998 CookieItVector::iterator it_purge_end = it_purge_begin + round_goal; | 1962 CookieItVector::iterator it_purge_end = it_purge_begin + round_goal; |
1999 CookieItVector::iterator it_purge_middle = | 1963 CookieItVector::iterator it_purge_middle = |
2000 LowerBoundAccessDate(it_purge_begin, it_purge_end, safe_date); | 1964 LowerBoundAccessDate(it_purge_begin, it_purge_end, safe_date); |
2001 // Delete cookies accessed before |safe_date|. | 1965 // Delete cookies accessed before |safe_date|. |
2002 num_deleted += GarbageCollectDeleteRange( | 1966 num_deleted += GarbageCollectDeleteRange( |
2003 current, | 1967 current, DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE, it_purge_begin, |
2004 DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE, | |
2005 it_purge_begin, | |
2006 it_purge_middle); | 1968 it_purge_middle); |
2007 // Delete cookies accessed on or after |safe_date|. | 1969 // Delete cookies accessed on or after |safe_date|. |
2008 num_deleted += GarbageCollectDeleteRange( | 1970 num_deleted += GarbageCollectDeleteRange( |
2009 current, | 1971 current, DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE, it_purge_middle, |
2010 DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE, | |
2011 it_purge_middle, | |
2012 it_purge_end); | 1972 it_purge_end); |
2013 it_purge_begin = it_purge_end; | 1973 it_purge_begin = it_purge_end; |
2014 } | 1974 } |
2015 DCHECK_EQ(0U, purge_goal); | 1975 DCHECK_EQ(0U, purge_goal); |
2016 } | 1976 } |
2017 } | 1977 } |
2018 | 1978 |
2019 // Collect garbage for everything. With firefox style we want to preserve | 1979 // Collect garbage for everything. With firefox style we want to preserve |
2020 // cookies accessed in kSafeFromGlobalPurgeDays, otherwise evict. | 1980 // cookies accessed in kSafeFromGlobalPurgeDays, otherwise evict. |
2021 if (cookies_.size() > kMaxCookies && | 1981 if (cookies_.size() > kMaxCookies && earliest_access_time_ < safe_date) { |
2022 earliest_access_time_ < safe_date) { | |
2023 VLOG(kVlogGarbageCollection) << "GarbageCollect() everything"; | 1982 VLOG(kVlogGarbageCollection) << "GarbageCollect() everything"; |
2024 CookieItVector cookie_its; | 1983 CookieItVector cookie_its; |
2025 num_deleted += GarbageCollectExpired( | 1984 num_deleted += GarbageCollectExpired( |
2026 current, CookieMapItPair(cookies_.begin(), cookies_.end()), | 1985 current, CookieMapItPair(cookies_.begin(), cookies_.end()), |
2027 &cookie_its); | 1986 &cookie_its); |
2028 if (cookie_its.size() > kMaxCookies) { | 1987 if (cookie_its.size() > kMaxCookies) { |
2029 VLOG(kVlogGarbageCollection) << "Deep Garbage Collect everything."; | 1988 VLOG(kVlogGarbageCollection) << "Deep Garbage Collect everything."; |
2030 size_t purge_goal = cookie_its.size() - (kMaxCookies - kPurgeCookies); | 1989 size_t purge_goal = cookie_its.size() - (kMaxCookies - kPurgeCookies); |
2031 DCHECK(purge_goal > kPurgeCookies); | 1990 DCHECK(purge_goal > kPurgeCookies); |
2032 // Sorts up to *and including* |cookie_its[purge_goal]|, so | 1991 // Sorts up to *and including* |cookie_its[purge_goal]|, so |
2033 // |earliest_access_time| will be properly assigned even if | 1992 // |earliest_access_time| will be properly assigned even if |
2034 // |global_purge_it| == |cookie_its.begin() + purge_goal|. | 1993 // |global_purge_it| == |cookie_its.begin() + purge_goal|. |
2035 SortLeastRecentlyAccessed(cookie_its.begin(), cookie_its.end(), | 1994 SortLeastRecentlyAccessed(cookie_its.begin(), cookie_its.end(), |
2036 purge_goal); | 1995 purge_goal); |
2037 // Find boundary to cookies older than safe_date. | 1996 // Find boundary to cookies older than safe_date. |
2038 CookieItVector::iterator global_purge_it = | 1997 CookieItVector::iterator global_purge_it = LowerBoundAccessDate( |
2039 LowerBoundAccessDate(cookie_its.begin(), | 1998 cookie_its.begin(), cookie_its.begin() + purge_goal, safe_date); |
2040 cookie_its.begin() + purge_goal, | |
2041 safe_date); | |
2042 // Only delete the old cookies. | 1999 // Only delete the old cookies. |
2043 num_deleted += GarbageCollectDeleteRange( | 2000 num_deleted += |
2044 current, | 2001 GarbageCollectDeleteRange(current, DELETE_COOKIE_EVICTED_GLOBAL, |
2045 DELETE_COOKIE_EVICTED_GLOBAL, | 2002 cookie_its.begin(), global_purge_it); |
2046 cookie_its.begin(), | |
2047 global_purge_it); | |
2048 // Set access day to the oldest cookie that wasn't deleted. | 2003 // Set access day to the oldest cookie that wasn't deleted. |
2049 earliest_access_time_ = (*global_purge_it)->second->LastAccessDate(); | 2004 earliest_access_time_ = (*global_purge_it)->second->LastAccessDate(); |
2050 } | 2005 } |
2051 } | 2006 } |
2052 | 2007 |
2053 return num_deleted; | 2008 return num_deleted; |
2054 } | 2009 } |
2055 | 2010 |
2056 int CookieMonster::GarbageCollectExpired( | 2011 int CookieMonster::GarbageCollectExpired(const Time& current, |
2057 const Time& current, | 2012 const CookieMapItPair& itpair, |
2058 const CookieMapItPair& itpair, | 2013 CookieItVector* cookie_its) { |
2059 CookieItVector* cookie_its) { | |
2060 if (keep_expired_cookies_) | 2014 if (keep_expired_cookies_) |
2061 return 0; | 2015 return 0; |
2062 | 2016 |
2063 lock_.AssertAcquired(); | 2017 lock_.AssertAcquired(); |
2064 | 2018 |
2065 int num_deleted = 0; | 2019 int num_deleted = 0; |
2066 for (CookieMap::iterator it = itpair.first, end = itpair.second; it != end;) { | 2020 for (CookieMap::iterator it = itpair.first, end = itpair.second; it != end;) { |
2067 CookieMap::iterator curit = it; | 2021 CookieMap::iterator curit = it; |
2068 ++it; | 2022 ++it; |
2069 | 2023 |
2070 if (curit->second->IsExpired(current)) { | 2024 if (curit->second->IsExpired(current)) { |
2071 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); | 2025 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); |
2072 ++num_deleted; | 2026 ++num_deleted; |
2073 } else if (cookie_its) { | 2027 } else if (cookie_its) { |
2074 cookie_its->push_back(curit); | 2028 cookie_its->push_back(curit); |
2075 } | 2029 } |
2076 } | 2030 } |
2077 | 2031 |
2078 return num_deleted; | 2032 return num_deleted; |
2079 } | 2033 } |
2080 | 2034 |
2081 int CookieMonster::GarbageCollectDeleteRange( | 2035 int CookieMonster::GarbageCollectDeleteRange(const Time& current, |
2082 const Time& current, | 2036 DeletionCause cause, |
2083 DeletionCause cause, | 2037 CookieItVector::iterator it_begin, |
2084 CookieItVector::iterator it_begin, | 2038 CookieItVector::iterator it_end) { |
2085 CookieItVector::iterator it_end) { | |
2086 for (CookieItVector::iterator it = it_begin; it != it_end; it++) { | 2039 for (CookieItVector::iterator it = it_begin; it != it_end; it++) { |
2087 histogram_evicted_last_access_minutes_->Add( | 2040 histogram_evicted_last_access_minutes_->Add( |
2088 (current - (*it)->second->LastAccessDate()).InMinutes()); | 2041 (current - (*it)->second->LastAccessDate()).InMinutes()); |
2089 InternalDeleteCookie((*it), true, cause); | 2042 InternalDeleteCookie((*it), true, cause); |
2090 } | 2043 } |
2091 return it_end - it_begin; | 2044 return it_end - it_begin; |
2092 } | 2045 } |
2093 | 2046 |
2094 // A wrapper around registry_controlled_domains::GetDomainAndRegistry | 2047 // A wrapper around registry_controlled_domains::GetDomainAndRegistry |
2095 // to make clear we're creating a key for our local map. Here and | 2048 // to make clear we're creating a key for our local map. Here and |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2139 // Make sure the request is on a cookie-able url scheme. | 2092 // Make sure the request is on a cookie-able url scheme. |
2140 for (size_t i = 0; i < cookieable_schemes_.size(); ++i) { | 2093 for (size_t i = 0; i < cookieable_schemes_.size(); ++i) { |
2141 // We matched a scheme. | 2094 // We matched a scheme. |
2142 if (url.SchemeIs(cookieable_schemes_[i].c_str())) { | 2095 if (url.SchemeIs(cookieable_schemes_[i].c_str())) { |
2143 // We've matched a supported scheme. | 2096 // We've matched a supported scheme. |
2144 return true; | 2097 return true; |
2145 } | 2098 } |
2146 } | 2099 } |
2147 | 2100 |
2148 // The scheme didn't match any in our whitelist. | 2101 // The scheme didn't match any in our whitelist. |
2149 VLOG(kVlogPerCookieMonster) << "WARNING: Unsupported cookie scheme: " | 2102 VLOG(kVlogPerCookieMonster) |
2150 << url.scheme(); | 2103 << "WARNING: Unsupported cookie scheme: " << url.scheme(); |
2151 return false; | 2104 return false; |
2152 } | 2105 } |
2153 | 2106 |
2154 // Test to see if stats should be recorded, and record them if so. | 2107 // Test to see if stats should be recorded, and record them if so. |
2155 // The goal here is to get sampling for the average browser-hour of | 2108 // The goal here is to get sampling for the average browser-hour of |
2156 // activity. We won't take samples when the web isn't being surfed, | 2109 // activity. We won't take samples when the web isn't being surfed, |
2157 // and when the web is being surfed, we'll take samples about every | 2110 // and when the web is being surfed, we'll take samples about every |
2158 // kRecordStatisticsIntervalSeconds. | 2111 // kRecordStatisticsIntervalSeconds. |
2159 // last_statistic_record_time_ is initialized to Now() rather than null | 2112 // last_statistic_record_time_ is initialized to Now() rather than null |
2160 // in the constructor so that we won't take statistics right after | 2113 // in the constructor so that we won't take statistics right after |
2161 // startup, to avoid bias from browsers that are started but not used. | 2114 // startup, to avoid bias from browsers that are started but not used. |
2162 void CookieMonster::RecordPeriodicStats(const base::Time& current_time) { | 2115 void CookieMonster::RecordPeriodicStats(const base::Time& current_time) { |
2163 const base::TimeDelta kRecordStatisticsIntervalTime( | 2116 const base::TimeDelta kRecordStatisticsIntervalTime( |
2164 base::TimeDelta::FromSeconds(kRecordStatisticsIntervalSeconds)); | 2117 base::TimeDelta::FromSeconds(kRecordStatisticsIntervalSeconds)); |
2165 | 2118 |
2166 // If we've taken statistics recently, return. | 2119 // If we've taken statistics recently, return. |
2167 if (current_time - last_statistic_record_time_ <= | 2120 if (current_time - last_statistic_record_time_ <= |
2168 kRecordStatisticsIntervalTime) { | 2121 kRecordStatisticsIntervalTime) { |
2169 return; | 2122 return; |
2170 } | 2123 } |
2171 | 2124 |
2172 // See InitializeHistograms() for details. | 2125 // See InitializeHistograms() for details. |
2173 histogram_count_->Add(cookies_.size()); | 2126 histogram_count_->Add(cookies_.size()); |
2174 | 2127 |
2175 // More detailed statistics on cookie counts at different granularities. | 2128 // More detailed statistics on cookie counts at different granularities. |
2176 TimeTicks beginning_of_time(TimeTicks::Now()); | 2129 TimeTicks beginning_of_time(TimeTicks::Now()); |
2177 | 2130 |
2178 for (CookieMap::const_iterator it_key = cookies_.begin(); | 2131 for (CookieMap::const_iterator it_key = cookies_.begin(); |
2179 it_key != cookies_.end(); ) { | 2132 it_key != cookies_.end();) { |
2180 const std::string& key(it_key->first); | 2133 const std::string& key(it_key->first); |
2181 | 2134 |
2182 int key_count = 0; | 2135 int key_count = 0; |
2183 typedef std::map<std::string, unsigned int> DomainMap; | 2136 typedef std::map<std::string, unsigned int> DomainMap; |
2184 DomainMap domain_map; | 2137 DomainMap domain_map; |
2185 CookieMapItPair its_cookies = cookies_.equal_range(key); | 2138 CookieMapItPair its_cookies = cookies_.equal_range(key); |
2186 while (its_cookies.first != its_cookies.second) { | 2139 while (its_cookies.first != its_cookies.second) { |
2187 key_count++; | 2140 key_count++; |
2188 const std::string& cookie_domain(its_cookies.first->second->Domain()); | 2141 const std::string& cookie_domain(its_cookies.first->second->Domain()); |
2189 domain_map[cookie_domain]++; | 2142 domain_map[cookie_domain]++; |
2190 | 2143 |
2191 its_cookies.first++; | 2144 its_cookies.first++; |
2192 } | 2145 } |
2193 histogram_etldp1_count_->Add(key_count); | 2146 histogram_etldp1_count_->Add(key_count); |
2194 histogram_domain_per_etldp1_count_->Add(domain_map.size()); | 2147 histogram_domain_per_etldp1_count_->Add(domain_map.size()); |
2195 for (DomainMap::const_iterator domain_map_it = domain_map.begin(); | 2148 for (DomainMap::const_iterator domain_map_it = domain_map.begin(); |
2196 domain_map_it != domain_map.end(); domain_map_it++) | 2149 domain_map_it != domain_map.end(); domain_map_it++) |
2197 histogram_domain_count_->Add(domain_map_it->second); | 2150 histogram_domain_count_->Add(domain_map_it->second); |
2198 | 2151 |
2199 it_key = its_cookies.second; | 2152 it_key = its_cookies.second; |
2200 } | 2153 } |
2201 | 2154 |
2202 VLOG(kVlogPeriodic) | 2155 VLOG(kVlogPeriodic) << "Time for recording cookie stats (us): " |
2203 << "Time for recording cookie stats (us): " | 2156 << (TimeTicks::Now() - beginning_of_time) |
2204 << (TimeTicks::Now() - beginning_of_time).InMicroseconds(); | 2157 .InMicroseconds(); |
2205 | 2158 |
2206 last_statistic_record_time_ = current_time; | 2159 last_statistic_record_time_ = current_time; |
2207 } | 2160 } |
2208 | 2161 |
2209 // Initialize all histogram counter variables used in this class. | 2162 // Initialize all histogram counter variables used in this class. |
2210 // | 2163 // |
2211 // Normal histogram usage involves using the macros defined in | 2164 // Normal histogram usage involves using the macros defined in |
2212 // histogram.h, which automatically takes care of declaring these | 2165 // histogram.h, which automatically takes care of declaring these |
2213 // variables (as statics), initializing them, and accumulating into | 2166 // variables (as statics), initializing them, and accumulating into |
2214 // them, all from a single entry point. Unfortunately, that solution | 2167 // them, all from a single entry point. Unfortunately, that solution |
(...skipping 10 matching lines...) Expand all Loading... |
2225 // for accumulation. | 2178 // for accumulation. |
2226 // | 2179 // |
2227 // To do this we've expanded out the individual histogram macros calls, | 2180 // To do this we've expanded out the individual histogram macros calls, |
2228 // with declarations of the variables in the class decl, initialization here | 2181 // with declarations of the variables in the class decl, initialization here |
2229 // (done from the class constructor) and direct calls to the accumulation | 2182 // (done from the class constructor) and direct calls to the accumulation |
2230 // methods where needed. The specific histogram macro calls on which the | 2183 // methods where needed. The specific histogram macro calls on which the |
2231 // initialization is based are included in comments below. | 2184 // initialization is based are included in comments below. |
2232 void CookieMonster::InitializeHistograms() { | 2185 void CookieMonster::InitializeHistograms() { |
2233 // From UMA_HISTOGRAM_CUSTOM_COUNTS | 2186 // From UMA_HISTOGRAM_CUSTOM_COUNTS |
2234 histogram_expiration_duration_minutes_ = base::Histogram::FactoryGet( | 2187 histogram_expiration_duration_minutes_ = base::Histogram::FactoryGet( |
2235 "Cookie.ExpirationDurationMinutes", | 2188 "Cookie.ExpirationDurationMinutes", 1, kMinutesInTenYears, 50, |
2236 1, kMinutesInTenYears, 50, | |
2237 base::Histogram::kUmaTargetedHistogramFlag); | 2189 base::Histogram::kUmaTargetedHistogramFlag); |
2238 histogram_between_access_interval_minutes_ = base::Histogram::FactoryGet( | 2190 histogram_between_access_interval_minutes_ = base::Histogram::FactoryGet( |
2239 "Cookie.BetweenAccessIntervalMinutes", | 2191 "Cookie.BetweenAccessIntervalMinutes", 1, kMinutesInTenYears, 50, |
2240 1, kMinutesInTenYears, 50, | |
2241 base::Histogram::kUmaTargetedHistogramFlag); | 2192 base::Histogram::kUmaTargetedHistogramFlag); |
2242 histogram_evicted_last_access_minutes_ = base::Histogram::FactoryGet( | 2193 histogram_evicted_last_access_minutes_ = base::Histogram::FactoryGet( |
2243 "Cookie.EvictedLastAccessMinutes", | 2194 "Cookie.EvictedLastAccessMinutes", 1, kMinutesInTenYears, 50, |
2244 1, kMinutesInTenYears, 50, | |
2245 base::Histogram::kUmaTargetedHistogramFlag); | 2195 base::Histogram::kUmaTargetedHistogramFlag); |
2246 histogram_count_ = base::Histogram::FactoryGet( | 2196 histogram_count_ = base::Histogram::FactoryGet( |
2247 "Cookie.Count", 1, 4000, 50, | 2197 "Cookie.Count", 1, 4000, 50, base::Histogram::kUmaTargetedHistogramFlag); |
2248 base::Histogram::kUmaTargetedHistogramFlag); | 2198 histogram_domain_count_ = |
2249 histogram_domain_count_ = base::Histogram::FactoryGet( | 2199 base::Histogram::FactoryGet("Cookie.DomainCount", 1, 4000, 50, |
2250 "Cookie.DomainCount", 1, 4000, 50, | 2200 base::Histogram::kUmaTargetedHistogramFlag); |
2251 base::Histogram::kUmaTargetedHistogramFlag); | 2201 histogram_etldp1_count_ = |
2252 histogram_etldp1_count_ = base::Histogram::FactoryGet( | 2202 base::Histogram::FactoryGet("Cookie.Etldp1Count", 1, 4000, 50, |
2253 "Cookie.Etldp1Count", 1, 4000, 50, | 2203 base::Histogram::kUmaTargetedHistogramFlag); |
2254 base::Histogram::kUmaTargetedHistogramFlag); | 2204 histogram_domain_per_etldp1_count_ = |
2255 histogram_domain_per_etldp1_count_ = base::Histogram::FactoryGet( | 2205 base::Histogram::FactoryGet("Cookie.DomainPerEtldp1Count", 1, 4000, 50, |
2256 "Cookie.DomainPerEtldp1Count", 1, 4000, 50, | 2206 base::Histogram::kUmaTargetedHistogramFlag); |
2257 base::Histogram::kUmaTargetedHistogramFlag); | |
2258 | 2207 |
2259 // From UMA_HISTOGRAM_COUNTS_10000 & UMA_HISTOGRAM_CUSTOM_COUNTS | 2208 // From UMA_HISTOGRAM_COUNTS_10000 & UMA_HISTOGRAM_CUSTOM_COUNTS |
2260 histogram_number_duplicate_db_cookies_ = base::Histogram::FactoryGet( | 2209 histogram_number_duplicate_db_cookies_ = |
2261 "Net.NumDuplicateCookiesInDb", 1, 10000, 50, | 2210 base::Histogram::FactoryGet("Net.NumDuplicateCookiesInDb", 1, 10000, 50, |
2262 base::Histogram::kUmaTargetedHistogramFlag); | 2211 base::Histogram::kUmaTargetedHistogramFlag); |
2263 | 2212 |
2264 // From UMA_HISTOGRAM_ENUMERATION | 2213 // From UMA_HISTOGRAM_ENUMERATION |
2265 histogram_cookie_deletion_cause_ = base::LinearHistogram::FactoryGet( | 2214 histogram_cookie_deletion_cause_ = base::LinearHistogram::FactoryGet( |
2266 "Cookie.DeletionCause", 1, | 2215 "Cookie.DeletionCause", 1, DELETE_COOKIE_LAST_ENTRY - 1, |
2267 DELETE_COOKIE_LAST_ENTRY - 1, DELETE_COOKIE_LAST_ENTRY, | 2216 DELETE_COOKIE_LAST_ENTRY, base::Histogram::kUmaTargetedHistogramFlag); |
2268 base::Histogram::kUmaTargetedHistogramFlag); | |
2269 | 2217 |
2270 // From UMA_HISTOGRAM_{CUSTOM_,}TIMES | 2218 // From UMA_HISTOGRAM_{CUSTOM_,}TIMES |
2271 histogram_time_blocked_on_load_ = base::Histogram::FactoryTimeGet( | 2219 histogram_time_blocked_on_load_ = base::Histogram::FactoryTimeGet( |
2272 "Cookie.TimeBlockedOnLoad", | 2220 "Cookie.TimeBlockedOnLoad", base::TimeDelta::FromMilliseconds(1), |
2273 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(1), | 2221 base::TimeDelta::FromMinutes(1), 50, |
2274 50, base::Histogram::kUmaTargetedHistogramFlag); | 2222 base::Histogram::kUmaTargetedHistogramFlag); |
2275 } | 2223 } |
2276 | 2224 |
2277 | |
2278 // The system resolution is not high enough, so we can have multiple | 2225 // The system resolution is not high enough, so we can have multiple |
2279 // set cookies that result in the same system time. When this happens, we | 2226 // set cookies that result in the same system time. When this happens, we |
2280 // increment by one Time unit. Let's hope computers don't get too fast. | 2227 // increment by one Time unit. Let's hope computers don't get too fast. |
2281 Time CookieMonster::CurrentTime() { | 2228 Time CookieMonster::CurrentTime() { |
2282 return std::max(Time::Now(), | 2229 return std::max(Time::Now(), Time::FromInternalValue( |
2283 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2230 last_time_seen_.ToInternalValue() + 1)); |
2284 } | 2231 } |
2285 | 2232 |
2286 bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster( | 2233 bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster( |
2287 std::string key, | 2234 std::string key, |
2288 CookieMonster* other) { | 2235 CookieMonster* other) { |
2289 ScopedVector<CanonicalCookie> duplicated_cookies; | 2236 ScopedVector<CanonicalCookie> duplicated_cookies; |
2290 | 2237 |
2291 { | 2238 { |
2292 base::AutoLock autolock(lock_); | 2239 base::AutoLock autolock(lock_); |
2293 DCHECK(other); | 2240 DCHECK(other); |
2294 if (!loaded_) | 2241 if (!loaded_) |
2295 return false; | 2242 return false; |
2296 | 2243 |
2297 for (CookieMapItPair its = cookies_.equal_range(key); | 2244 for (CookieMapItPair its = cookies_.equal_range(key); |
2298 its.first != its.second; | 2245 its.first != its.second; ++its.first) { |
2299 ++its.first) { | |
2300 CookieMap::iterator curit = its.first; | 2246 CookieMap::iterator curit = its.first; |
2301 CanonicalCookie* cc = curit->second; | 2247 CanonicalCookie* cc = curit->second; |
2302 | 2248 |
2303 duplicated_cookies.push_back(cc->Duplicate()); | 2249 duplicated_cookies.push_back(cc->Duplicate()); |
2304 } | 2250 } |
2305 } | 2251 } |
2306 | 2252 |
2307 { | 2253 { |
2308 base::AutoLock autolock(other->lock_); | 2254 base::AutoLock autolock(other->lock_); |
2309 if (!other->loaded_) | 2255 if (!other->loaded_) |
2310 return false; | 2256 return false; |
2311 | 2257 |
2312 // There must not exist any entries for the key to be copied in |other|. | 2258 // There must not exist any entries for the key to be copied in |other|. |
2313 CookieMapItPair its = other->cookies_.equal_range(key); | 2259 CookieMapItPair its = other->cookies_.equal_range(key); |
2314 if (its.first != its.second) | 2260 if (its.first != its.second) |
2315 return false; | 2261 return false; |
2316 | 2262 |
2317 // Store the copied cookies in |other|. | 2263 // Store the copied cookies in |other|. |
2318 for (ScopedVector<CanonicalCookie>::const_iterator it = | 2264 for (ScopedVector<CanonicalCookie>::const_iterator it = |
2319 duplicated_cookies.begin(); | 2265 duplicated_cookies.begin(); |
2320 it != duplicated_cookies.end(); | 2266 it != duplicated_cookies.end(); ++it) { |
2321 ++it) { | |
2322 other->InternalInsertCookie(key, *it, true); | 2267 other->InternalInsertCookie(key, *it, true); |
2323 } | 2268 } |
2324 | 2269 |
2325 // Since the cookies are owned by |other| now, weak clear must be used. | 2270 // Since the cookies are owned by |other| now, weak clear must be used. |
2326 duplicated_cookies.weak_clear(); | 2271 duplicated_cookies.weak_clear(); |
2327 } | 2272 } |
2328 | 2273 |
2329 return true; | 2274 return true; |
2330 } | 2275 } |
2331 | 2276 |
2332 bool CookieMonster::loaded() { | 2277 bool CookieMonster::loaded() { |
2333 base::AutoLock autolock(lock_); | 2278 base::AutoLock autolock(lock_); |
2334 return loaded_; | 2279 return loaded_; |
2335 } | 2280 } |
2336 | 2281 |
2337 scoped_ptr<CookieStore::CookieChangedSubscription> | 2282 scoped_ptr<CookieStore::CookieChangedSubscription> |
2338 CookieMonster::AddCallbackForCookie( | 2283 CookieMonster::AddCallbackForCookie(const GURL& gurl, |
2339 const GURL& gurl, | 2284 const std::string& name, |
2340 const std::string& name, | 2285 const CookieChangedCallback& callback) { |
2341 const CookieChangedCallback& callback) { | |
2342 base::AutoLock autolock(lock_); | 2286 base::AutoLock autolock(lock_); |
2343 std::pair<GURL, std::string> key(gurl, name); | 2287 std::pair<GURL, std::string> key(gurl, name); |
2344 if (hook_map_.count(key) == 0) | 2288 if (hook_map_.count(key) == 0) |
2345 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); | 2289 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); |
2346 return hook_map_[key]->Add( | 2290 return hook_map_[key]->Add( |
2347 base::Bind(&RunAsync, base::MessageLoopProxy::current(), callback)); | 2291 base::Bind(&RunAsync, base::MessageLoopProxy::current(), callback)); |
2348 } | 2292 } |
2349 | 2293 |
2350 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { | 2294 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { |
2351 lock_.AssertAcquired(); | 2295 lock_.AssertAcquired(); |
2352 CookieOptions opts; | 2296 CookieOptions opts; |
2353 opts.set_include_httponly(); | 2297 opts.set_include_httponly(); |
2354 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they | 2298 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they |
2355 // are guaranteed to not take long - they just post a RunAsync task back to | 2299 // are guaranteed to not take long - they just post a RunAsync task back to |
2356 // the appropriate thread's message loop and return. It is important that this | 2300 // the appropriate thread's message loop and return. It is important that this |
2357 // method not run user-supplied callbacks directly, since the CookieMonster | 2301 // method not run user-supplied callbacks directly, since the CookieMonster |
2358 // lock is held and it is easy to accidentally introduce deadlocks. | 2302 // lock is held and it is easy to accidentally introduce deadlocks. |
2359 for (CookieChangedHookMap::iterator it = hook_map_.begin(); | 2303 for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
2360 it != hook_map_.end(); ++it) { | 2304 it != hook_map_.end(); ++it) { |
2361 std::pair<GURL, std::string> key = it->first; | 2305 std::pair<GURL, std::string> key = it->first; |
2362 if (cookie.IncludeForRequestURL(key.first, opts) && | 2306 if (cookie.IncludeForRequestURL(key.first, opts) && |
2363 cookie.Name() == key.second) { | 2307 cookie.Name() == key.second) { |
2364 it->second->Notify(cookie, removed); | 2308 it->second->Notify(cookie, removed); |
2365 } | 2309 } |
2366 } | 2310 } |
2367 } | 2311 } |
2368 | 2312 |
2369 } // namespace net | 2313 } // namespace net |
OLD | NEW |