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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // first iterator with access date >= |access_date|, or cookie_its_end if this | 258 // first iterator with access date >= |access_date|, or cookie_its_end if this |
259 // holds for all. | 259 // holds for all. |
260 CookieMonster::CookieItVector::iterator LowerBoundAccessDate( | 260 CookieMonster::CookieItVector::iterator LowerBoundAccessDate( |
261 const CookieMonster::CookieItVector::iterator its_begin, | 261 const CookieMonster::CookieItVector::iterator its_begin, |
262 const CookieMonster::CookieItVector::iterator its_end, | 262 const CookieMonster::CookieItVector::iterator its_end, |
263 const Time& access_date) { | 263 const Time& access_date) { |
264 return std::lower_bound(its_begin, its_end, access_date, | 264 return std::lower_bound(its_begin, its_end, access_date, |
265 LowerBoundAccessDateComparator); | 265 LowerBoundAccessDateComparator); |
266 } | 266 } |
267 | 267 |
268 // Mapping between DeletionCause and CookieMonsterDelegate::ChangeCause; the | 268 // Mapping between DeletionCause and CookieStore::ChangeCause; the |
269 // mapping also provides a boolean that specifies whether or not an | 269 // mapping also provides a boolean that specifies whether or not an |
270 // OnCookieChanged notification ought to be generated. | 270 // OnCookieChanged notification ought to be generated. |
271 typedef struct ChangeCausePair_struct { | 271 typedef struct ChangeCausePair_struct { |
272 CookieMonsterDelegate::ChangeCause cause; | 272 CookieStore::ChangeCause cause; |
273 bool notify; | 273 bool notify; |
274 } ChangeCausePair; | 274 } ChangeCausePair; |
275 ChangeCausePair ChangeCauseMapping[] = { | 275 const ChangeCausePair kChangeCauseMapping[] = { |
276 // DELETE_COOKIE_EXPLICIT | 276 // DELETE_COOKIE_EXPLICIT |
277 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true}, | 277 {CookieStore::ChangeCause::EXPLICIT, true}, |
278 // DELETE_COOKIE_OVERWRITE | 278 // DELETE_COOKIE_OVERWRITE |
279 {CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true}, | 279 {CookieStore::ChangeCause::OVERWRITE, true}, |
280 // DELETE_COOKIE_EXPIRED | 280 // DELETE_COOKIE_EXPIRED |
281 {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true}, | 281 {CookieStore::ChangeCause::EXPIRED, true}, |
282 // DELETE_COOKIE_EVICTED | 282 // DELETE_COOKIE_EVICTED |
283 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 283 {CookieStore::ChangeCause::EVICTED, true}, |
284 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE | 284 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE |
285 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, | 285 {CookieStore::ChangeCause::EXPLICIT, false}, |
286 // DELETE_COOKIE_DONT_RECORD | 286 // DELETE_COOKIE_DONT_RECORD |
287 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, | 287 {CookieStore::ChangeCause::EXPLICIT, false}, |
288 // DELETE_COOKIE_EVICTED_DOMAIN | 288 // DELETE_COOKIE_EVICTED_DOMAIN |
289 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 289 {CookieStore::ChangeCause::EVICTED, true}, |
290 // DELETE_COOKIE_EVICTED_GLOBAL | 290 // DELETE_COOKIE_EVICTED_GLOBAL |
291 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 291 {CookieStore::ChangeCause::EVICTED, true}, |
292 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE | 292 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE |
293 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 293 {CookieStore::ChangeCause::EVICTED, true}, |
294 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE | 294 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE |
295 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 295 {CookieStore::ChangeCause::EVICTED, true}, |
296 // DELETE_COOKIE_EXPIRED_OVERWRITE | 296 // DELETE_COOKIE_EXPIRED_OVERWRITE |
297 {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true}, | 297 {CookieStore::ChangeCause::EXPIRED_OVERWRITE, true}, |
298 // DELETE_COOKIE_CONTROL_CHAR | 298 // DELETE_COOKIE_CONTROL_CHAR |
299 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 299 {CookieStore::ChangeCause::EVICTED, true}, |
300 // DELETE_COOKIE_NON_SECURE | 300 // DELETE_COOKIE_NON_SECURE |
301 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 301 {CookieStore::ChangeCause::EVICTED, true}, |
302 // DELETE_COOKIE_LAST_ENTRY | 302 // DELETE_COOKIE_LAST_ENTRY |
303 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}}; | 303 {CookieStore::ChangeCause::EXPLICIT, false}}; |
304 | 304 |
305 void RunAsync(scoped_refptr<base::TaskRunner> proxy, | 305 void RunAsync(scoped_refptr<base::TaskRunner> proxy, |
306 const CookieStore::CookieChangedCallback& callback, | 306 const CookieStore::CookieChangedCallback& callback, |
307 const CanonicalCookie& cookie, | 307 const CanonicalCookie& cookie, |
308 bool removed) { | 308 CookieStore::ChangeCause cause) { |
309 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed)); | 309 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, cause)); |
310 } | 310 } |
311 | 311 |
312 bool IsCookieEligibleForEviction(CookiePriority current_priority_level, | 312 bool IsCookieEligibleForEviction(CookiePriority current_priority_level, |
313 bool protect_secure_cookies, | 313 bool protect_secure_cookies, |
314 const CanonicalCookie* cookie) { | 314 const CanonicalCookie* cookie) { |
315 if (cookie->Priority() == current_priority_level && protect_secure_cookies) | 315 if (cookie->Priority() == current_priority_level && protect_secure_cookies) |
316 return !cookie->IsSecure(); | 316 return !cookie->IsSecure(); |
317 | 317 |
318 return cookie->Priority() == current_priority_level; | 318 return cookie->Priority() == current_priority_level; |
319 } | 319 } |
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 CanonicalCookie* cc, | 1677 CanonicalCookie* cc, |
1678 const GURL& source_url, | 1678 const GURL& source_url, |
1679 bool sync_to_store) { | 1679 bool sync_to_store) { |
1680 DCHECK(thread_checker_.CalledOnValidThread()); | 1680 DCHECK(thread_checker_.CalledOnValidThread()); |
1681 | 1681 |
1682 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && | 1682 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
1683 sync_to_store) | 1683 sync_to_store) |
1684 store_->AddCookie(*cc); | 1684 store_->AddCookie(*cc); |
1685 CookieMap::iterator inserted = | 1685 CookieMap::iterator inserted = |
1686 cookies_.insert(CookieMap::value_type(key, cc)); | 1686 cookies_.insert(CookieMap::value_type(key, cc)); |
1687 if (delegate_.get()) { | 1687 if (delegate_.get()) |
1688 delegate_->OnCookieChanged(*cc, false, | 1688 delegate_->OnCookieChanged(*cc, false, CookieStore::ChangeCause::INSERTED); |
1689 CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); | |
1690 } | |
1691 | 1689 |
1692 // See InitializeHistograms() for details. | 1690 // See InitializeHistograms() for details. |
1693 int32_t type_sample = cc->SameSite() != CookieSameSite::NO_RESTRICTION | 1691 int32_t type_sample = cc->SameSite() != CookieSameSite::NO_RESTRICTION |
1694 ? 1 << COOKIE_TYPE_SAME_SITE | 1692 ? 1 << COOKIE_TYPE_SAME_SITE |
1695 : 0; | 1693 : 0; |
1696 type_sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; | 1694 type_sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; |
1697 type_sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; | 1695 type_sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; |
1698 histogram_cookie_type_->Add(type_sample); | 1696 histogram_cookie_type_->Add(type_sample); |
1699 | 1697 |
1700 // Histogram the type of scheme used on URLs that set cookies. This | 1698 // Histogram the type of scheme used on URLs that set cookies. This |
1701 // intentionally includes cookies that are set or overwritten by | 1699 // intentionally includes cookies that are set or overwritten by |
1702 // http:// URLs, but not cookies that are cleared by http:// URLs, to | 1700 // http:// URLs, but not cookies that are cleared by http:// URLs, to |
1703 // understand if the former behavior can be deprecated for Secure | 1701 // understand if the former behavior can be deprecated for Secure |
1704 // cookies. | 1702 // cookies. |
1705 if (!source_url.is_empty()) { | 1703 if (!source_url.is_empty()) { |
1706 CookieSource cookie_source_sample; | 1704 CookieSource cookie_source_sample; |
1707 if (source_url.SchemeIsCryptographic()) { | 1705 if (source_url.SchemeIsCryptographic()) { |
1708 cookie_source_sample = | 1706 cookie_source_sample = |
1709 cc->IsSecure() ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME | 1707 cc->IsSecure() ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME |
1710 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME; | 1708 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME; |
1711 } else { | 1709 } else { |
1712 cookie_source_sample = | 1710 cookie_source_sample = |
1713 cc->IsSecure() | 1711 cc->IsSecure() |
1714 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME | 1712 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME |
1715 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME; | 1713 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME; |
1716 } | 1714 } |
1717 histogram_cookie_source_scheme_->Add(cookie_source_sample); | 1715 histogram_cookie_source_scheme_->Add(cookie_source_sample); |
1718 } | 1716 } |
1719 | 1717 |
1720 RunCookieChangedCallbacks(*cc, false); | 1718 RunCookieChangedCallbacks(*cc, CookieStore::ChangeCause::INSERTED); |
1721 | 1719 |
1722 return inserted; | 1720 return inserted; |
1723 } | 1721 } |
1724 | 1722 |
1725 bool CookieMonster::SetCookieWithCreationTimeAndOptions( | 1723 bool CookieMonster::SetCookieWithCreationTimeAndOptions( |
1726 const GURL& url, | 1724 const GURL& url, |
1727 const std::string& cookie_line, | 1725 const std::string& cookie_line, |
1728 const Time& creation_time_or_null, | 1726 const Time& creation_time_or_null, |
1729 const CookieOptions& options) { | 1727 const CookieOptions& options) { |
1730 DCHECK(thread_checker_.CalledOnValidThread()); | 1728 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 store_->UpdateCookieAccessTime(*cc); | 1830 store_->UpdateCookieAccessTime(*cc); |
1833 } | 1831 } |
1834 | 1832 |
1835 // InternalDeleteCookies must not invalidate iterators other than the one being | 1833 // InternalDeleteCookies must not invalidate iterators other than the one being |
1836 // deleted. | 1834 // deleted. |
1837 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, | 1835 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, |
1838 bool sync_to_store, | 1836 bool sync_to_store, |
1839 DeletionCause deletion_cause) { | 1837 DeletionCause deletion_cause) { |
1840 DCHECK(thread_checker_.CalledOnValidThread()); | 1838 DCHECK(thread_checker_.CalledOnValidThread()); |
1841 | 1839 |
1842 // Ideally, this would be asserted up where we define ChangeCauseMapping, | 1840 // Ideally, this would be asserted up where we define kChangeCauseMapping, |
1843 // but DeletionCause's visibility (or lack thereof) forces us to make | 1841 // but DeletionCause's visibility (or lack thereof) forces us to make |
1844 // this check here. | 1842 // this check here. |
1845 static_assert(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, | 1843 static_assert(arraysize(kChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, |
1846 "ChangeCauseMapping size should match DeletionCause size"); | 1844 "kChangeCauseMapping size should match DeletionCause size"); |
1847 | 1845 |
1848 // See InitializeHistograms() for details. | 1846 // See InitializeHistograms() for details. |
1849 if (deletion_cause != DELETE_COOKIE_DONT_RECORD) | 1847 if (deletion_cause != DELETE_COOKIE_DONT_RECORD) |
1850 histogram_cookie_deletion_cause_->Add(deletion_cause); | 1848 histogram_cookie_deletion_cause_->Add(deletion_cause); |
1851 | 1849 |
1852 CanonicalCookie* cc = it->second; | 1850 CanonicalCookie* cc = it->second; |
1853 VLOG(kVlogSetCookies) << "InternalDeleteCookie()" | 1851 VLOG(kVlogSetCookies) << "InternalDeleteCookie()" |
1854 << ", cause:" << deletion_cause | 1852 << ", cause:" << deletion_cause |
1855 << ", cc: " << cc->DebugString(); | 1853 << ", cc: " << cc->DebugString(); |
1856 | 1854 |
1857 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && | 1855 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
1858 sync_to_store) | 1856 sync_to_store) |
1859 store_->DeleteCookie(*cc); | 1857 store_->DeleteCookie(*cc); |
1860 if (delegate_.get()) { | 1858 ChangeCausePair mapping = kChangeCauseMapping[deletion_cause]; |
1861 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; | 1859 if (delegate_.get() && mapping.notify) |
1862 | 1860 delegate_->OnCookieChanged(*cc, true, mapping.cause); |
1863 if (mapping.notify) | 1861 RunCookieChangedCallbacks(*cc, mapping.cause); |
1864 delegate_->OnCookieChanged(*cc, true, mapping.cause); | |
1865 } | |
1866 RunCookieChangedCallbacks(*cc, true); | |
1867 cookies_.erase(it); | 1862 cookies_.erase(it); |
1868 delete cc; | 1863 delete cc; |
1869 } | 1864 } |
1870 | 1865 |
1871 // Domain expiry behavior is unchanged by key/expiry scheme (the | 1866 // Domain expiry behavior is unchanged by key/expiry scheme (the |
1872 // meaning of the key is different, but that's not visible to this routine). | 1867 // meaning of the key is different, but that's not visible to this routine). |
1873 size_t CookieMonster::GarbageCollect(const Time& current, | 1868 size_t CookieMonster::GarbageCollect(const Time& current, |
1874 const std::string& key, | 1869 const std::string& key, |
1875 bool enforce_strict_secure) { | 1870 bool enforce_strict_secure) { |
1876 DCHECK(thread_checker_.CalledOnValidThread()); | 1871 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2368 std::inserter(*cookies_to_add, cookies_to_add->begin()), | 2363 std::inserter(*cookies_to_add, cookies_to_add->begin()), |
2369 FullDiffCookieSorter); | 2364 FullDiffCookieSorter); |
2370 } | 2365 } |
2371 | 2366 |
2372 void CookieMonster::RunCallback(const base::Closure& callback) { | 2367 void CookieMonster::RunCallback(const base::Closure& callback) { |
2373 DCHECK(thread_checker_.CalledOnValidThread()); | 2368 DCHECK(thread_checker_.CalledOnValidThread()); |
2374 callback.Run(); | 2369 callback.Run(); |
2375 } | 2370 } |
2376 | 2371 |
2377 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, | 2372 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, |
2378 bool removed) { | 2373 ChangeCause cause) { |
2379 DCHECK(thread_checker_.CalledOnValidThread()); | 2374 DCHECK(thread_checker_.CalledOnValidThread()); |
2380 | 2375 |
2381 CookieOptions opts; | 2376 CookieOptions opts; |
2382 opts.set_include_httponly(); | 2377 opts.set_include_httponly(); |
2383 opts.set_same_site_cookie_mode( | 2378 opts.set_same_site_cookie_mode( |
2384 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); | 2379 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); |
2385 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they | 2380 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they |
2386 // are guaranteed to not take long - they just post a RunAsync task back to | 2381 // are guaranteed to not take long - they just post a RunAsync task back to |
2387 // the appropriate thread's message loop and return. | 2382 // the appropriate thread's message loop and return. |
2388 // TODO(mmenke): Consider running these synchronously? | 2383 // TODO(mmenke): Consider running these synchronously? |
2389 for (CookieChangedHookMap::iterator it = hook_map_.begin(); | 2384 for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
2390 it != hook_map_.end(); ++it) { | 2385 it != hook_map_.end(); ++it) { |
2391 std::pair<GURL, std::string> key = it->first; | 2386 std::pair<GURL, std::string> key = it->first; |
2392 if (cookie.IncludeForRequestURL(key.first, opts) && | 2387 if (cookie.IncludeForRequestURL(key.first, opts) && |
2393 cookie.Name() == key.second) { | 2388 cookie.Name() == key.second) { |
2394 it->second->Notify(cookie, removed); | 2389 it->second->Notify(cookie, cause); |
2395 } | 2390 } |
2396 } | 2391 } |
2397 } | 2392 } |
2398 | 2393 |
2399 } // namespace net | 2394 } // namespace net |
OLD | NEW |