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 ChangeCausePair ChangeCauseMapping[] = { |
mmenke
2016/09/26 18:29:26
While you're here, mind fixing this? Should be "c
nharper
2016/09/26 21:09:10
Done.
| |
276 // DELETE_COOKIE_EXPLICIT | 276 // DELETE_COOKIE_EXPLICIT |
277 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true}, | 277 {CookieStore::CHANGE_COOKIE_EXPLICIT, true}, |
278 // DELETE_COOKIE_OVERWRITE | 278 // DELETE_COOKIE_OVERWRITE |
279 {CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true}, | 279 {CookieStore::CHANGE_COOKIE_OVERWRITE, true}, |
280 // DELETE_COOKIE_EXPIRED | 280 // DELETE_COOKIE_EXPIRED |
281 {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true}, | 281 {CookieStore::CHANGE_COOKIE_EXPIRED, true}, |
282 // DELETE_COOKIE_EVICTED | 282 // DELETE_COOKIE_EVICTED |
283 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 283 {CookieStore::CHANGE_COOKIE_EVICTED, true}, |
284 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE | 284 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE |
285 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, | 285 {CookieStore::CHANGE_COOKIE_EXPLICIT, false}, |
286 // DELETE_COOKIE_DONT_RECORD | 286 // DELETE_COOKIE_DONT_RECORD |
287 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, | 287 {CookieStore::CHANGE_COOKIE_EXPLICIT, false}, |
288 // DELETE_COOKIE_EVICTED_DOMAIN | 288 // DELETE_COOKIE_EVICTED_DOMAIN |
289 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 289 {CookieStore::CHANGE_COOKIE_EVICTED, true}, |
290 // DELETE_COOKIE_EVICTED_GLOBAL | 290 // DELETE_COOKIE_EVICTED_GLOBAL |
291 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 291 {CookieStore::CHANGE_COOKIE_EVICTED, true}, |
292 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE | 292 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE |
293 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 293 {CookieStore::CHANGE_COOKIE_EVICTED, true}, |
294 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE | 294 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE |
295 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 295 {CookieStore::CHANGE_COOKIE_EVICTED, true}, |
296 // DELETE_COOKIE_EXPIRED_OVERWRITE | 296 // DELETE_COOKIE_EXPIRED_OVERWRITE |
297 {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true}, | 297 {CookieStore::CHANGE_COOKIE_EXPIRED_OVERWRITE, true}, |
298 // DELETE_COOKIE_CONTROL_CHAR | 298 // DELETE_COOKIE_CONTROL_CHAR |
299 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 299 {CookieStore::CHANGE_COOKIE_EVICTED, true}, |
300 // DELETE_COOKIE_NON_SECURE | 300 // DELETE_COOKIE_NON_SECURE |
301 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, | 301 {CookieStore::CHANGE_COOKIE_EVICTED, true}, |
302 // DELETE_COOKIE_LAST_ENTRY | 302 // DELETE_COOKIE_LAST_ENTRY |
303 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}}; | 303 {CookieStore::CHANGE_COOKIE_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 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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::CHANGE_COOKIE_INSERTED); |
1689 CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); | |
1690 } | 1689 } |
mmenke
2016/09/26 18:29:26
nit: Remove braces
nharper
2016/09/26 21:09:10
Done.
| |
1691 | 1690 |
1692 // See InitializeHistograms() for details. | 1691 // See InitializeHistograms() for details. |
1693 int32_t type_sample = cc->SameSite() != CookieSameSite::NO_RESTRICTION | 1692 int32_t type_sample = cc->SameSite() != CookieSameSite::NO_RESTRICTION |
1694 ? 1 << COOKIE_TYPE_SAME_SITE | 1693 ? 1 << COOKIE_TYPE_SAME_SITE |
1695 : 0; | 1694 : 0; |
1696 type_sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; | 1695 type_sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; |
1697 type_sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; | 1696 type_sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; |
1698 histogram_cookie_type_->Add(type_sample); | 1697 histogram_cookie_type_->Add(type_sample); |
1699 | 1698 |
1700 // Histogram the type of scheme used on URLs that set cookies. This | 1699 // Histogram the type of scheme used on URLs that set cookies. This |
1701 // intentionally includes cookies that are set or overwritten by | 1700 // intentionally includes cookies that are set or overwritten by |
1702 // http:// URLs, but not cookies that are cleared by http:// URLs, to | 1701 // http:// URLs, but not cookies that are cleared by http:// URLs, to |
1703 // understand if the former behavior can be deprecated for Secure | 1702 // understand if the former behavior can be deprecated for Secure |
1704 // cookies. | 1703 // cookies. |
1705 if (!source_url.is_empty()) { | 1704 if (!source_url.is_empty()) { |
1706 CookieSource cookie_source_sample; | 1705 CookieSource cookie_source_sample; |
1707 if (source_url.SchemeIsCryptographic()) { | 1706 if (source_url.SchemeIsCryptographic()) { |
1708 cookie_source_sample = | 1707 cookie_source_sample = |
1709 cc->IsSecure() ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME | 1708 cc->IsSecure() ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME |
1710 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME; | 1709 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME; |
1711 } else { | 1710 } else { |
1712 cookie_source_sample = | 1711 cookie_source_sample = |
1713 cc->IsSecure() | 1712 cc->IsSecure() |
1714 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME | 1713 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME |
1715 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME; | 1714 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME; |
1716 } | 1715 } |
1717 histogram_cookie_source_scheme_->Add(cookie_source_sample); | 1716 histogram_cookie_source_scheme_->Add(cookie_source_sample); |
1718 } | 1717 } |
1719 | 1718 |
1720 RunCookieChangedCallbacks(*cc, false); | 1719 RunCookieChangedCallbacks(*cc, CookieStore::CHANGE_COOKIE_INSERTED); |
1721 | 1720 |
1722 return inserted; | 1721 return inserted; |
1723 } | 1722 } |
1724 | 1723 |
1725 bool CookieMonster::SetCookieWithCreationTimeAndOptions( | 1724 bool CookieMonster::SetCookieWithCreationTimeAndOptions( |
1726 const GURL& url, | 1725 const GURL& url, |
1727 const std::string& cookie_line, | 1726 const std::string& cookie_line, |
1728 const Time& creation_time_or_null, | 1727 const Time& creation_time_or_null, |
1729 const CookieOptions& options) { | 1728 const CookieOptions& options) { |
1730 DCHECK(thread_checker_.CalledOnValidThread()); | 1729 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1850 histogram_cookie_deletion_cause_->Add(deletion_cause); | 1849 histogram_cookie_deletion_cause_->Add(deletion_cause); |
1851 | 1850 |
1852 CanonicalCookie* cc = it->second; | 1851 CanonicalCookie* cc = it->second; |
1853 VLOG(kVlogSetCookies) << "InternalDeleteCookie()" | 1852 VLOG(kVlogSetCookies) << "InternalDeleteCookie()" |
1854 << ", cause:" << deletion_cause | 1853 << ", cause:" << deletion_cause |
1855 << ", cc: " << cc->DebugString(); | 1854 << ", cc: " << cc->DebugString(); |
1856 | 1855 |
1857 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && | 1856 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
1858 sync_to_store) | 1857 sync_to_store) |
1859 store_->DeleteCookie(*cc); | 1858 store_->DeleteCookie(*cc); |
1860 if (delegate_.get()) { | 1859 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; |
1861 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; | 1860 if (delegate_.get() && mapping.notify) |
1862 | 1861 delegate_->OnCookieChanged(*cc, true, mapping.cause); |
1863 if (mapping.notify) | 1862 RunCookieChangedCallbacks(*cc, mapping.cause); |
1864 delegate_->OnCookieChanged(*cc, true, mapping.cause); | |
1865 } | |
1866 RunCookieChangedCallbacks(*cc, true); | |
1867 cookies_.erase(it); | 1863 cookies_.erase(it); |
1868 delete cc; | 1864 delete cc; |
1869 } | 1865 } |
1870 | 1866 |
1871 // Domain expiry behavior is unchanged by key/expiry scheme (the | 1867 // 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). | 1868 // meaning of the key is different, but that's not visible to this routine). |
1873 size_t CookieMonster::GarbageCollect(const Time& current, | 1869 size_t CookieMonster::GarbageCollect(const Time& current, |
1874 const std::string& key, | 1870 const std::string& key, |
1875 bool enforce_strict_secure) { | 1871 bool enforce_strict_secure) { |
1876 DCHECK(thread_checker_.CalledOnValidThread()); | 1872 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()), | 2364 std::inserter(*cookies_to_add, cookies_to_add->begin()), |
2369 FullDiffCookieSorter); | 2365 FullDiffCookieSorter); |
2370 } | 2366 } |
2371 | 2367 |
2372 void CookieMonster::RunCallback(const base::Closure& callback) { | 2368 void CookieMonster::RunCallback(const base::Closure& callback) { |
2373 DCHECK(thread_checker_.CalledOnValidThread()); | 2369 DCHECK(thread_checker_.CalledOnValidThread()); |
2374 callback.Run(); | 2370 callback.Run(); |
2375 } | 2371 } |
2376 | 2372 |
2377 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, | 2373 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, |
2378 bool removed) { | 2374 ChangeCause cause) { |
2379 DCHECK(thread_checker_.CalledOnValidThread()); | 2375 DCHECK(thread_checker_.CalledOnValidThread()); |
2380 | 2376 |
2381 CookieOptions opts; | 2377 CookieOptions opts; |
2382 opts.set_include_httponly(); | 2378 opts.set_include_httponly(); |
2383 opts.set_same_site_cookie_mode( | 2379 opts.set_same_site_cookie_mode( |
2384 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); | 2380 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); |
2385 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they | 2381 // 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 | 2382 // are guaranteed to not take long - they just post a RunAsync task back to |
2387 // the appropriate thread's message loop and return. | 2383 // the appropriate thread's message loop and return. |
2388 // TODO(mmenke): Consider running these synchronously? | 2384 // TODO(mmenke): Consider running these synchronously? |
2389 for (CookieChangedHookMap::iterator it = hook_map_.begin(); | 2385 for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
2390 it != hook_map_.end(); ++it) { | 2386 it != hook_map_.end(); ++it) { |
2391 std::pair<GURL, std::string> key = it->first; | 2387 std::pair<GURL, std::string> key = it->first; |
2392 if (cookie.IncludeForRequestURL(key.first, opts) && | 2388 if (cookie.IncludeForRequestURL(key.first, opts) && |
2393 cookie.Name() == key.second) { | 2389 cookie.Name() == key.second) { |
2394 it->second->Notify(cookie, removed); | 2390 it->second->Notify(cookie, cause); |
2395 } | 2391 } |
2396 } | 2392 } |
2397 } | 2393 } |
2398 | 2394 |
2399 } // namespace net | 2395 } // namespace net |
OLD | NEW |