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

Side by Side Diff: net/cookies/cookie_monster.cc

Issue 2349823003: Pass a RemovalCause to CookieChangedCallback (Closed)
Patch Set: Fix compilation errors Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, 295 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
296 // DELETE_COOKIE_EXPIRED_OVERWRITE 296 // DELETE_COOKIE_EXPIRED_OVERWRITE
297 {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true}, 297 {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true},
298 // DELETE_COOKIE_CONTROL_CHAR 298 // DELETE_COOKIE_CONTROL_CHAR
299 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, 299 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
300 // DELETE_COOKIE_NON_SECURE 300 // DELETE_COOKIE_NON_SECURE
301 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, 301 {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
302 // DELETE_COOKIE_LAST_ENTRY 302 // DELETE_COOKIE_LAST_ENTRY
303 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}}; 303 {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}};
304 304
305 CookieStore::RemovalCause RemovalCauseMap[] = {
306 // DELETE_COOKIE_EXPLICIT
307 CookieStore::RemovalCause::EXPLICIT,
308 // DELETE_COOKIE_OVERWRITE
309 CookieStore::RemovalCause::OVERWRITE,
310 // DELETE_COOKIE_EXPIRED
311 CookieStore::RemovalCause::EXPIRED,
312 // DELETE_COOKIE_EVICTED
313 CookieStore::RemovalCause::EVICTED,
314 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE
315 CookieStore::RemovalCause::EXPLICIT,
316 // DELETE_COOKIE_DONT_RECORD
317 CookieStore::RemovalCause::EXPLICIT,
318 // DELETE_COOKIE_EVICTED_DOMAIN
319 CookieStore::RemovalCause::EVICTED,
320 // DELETE_COOKIE_EVICTED_GLOBAL
321 CookieStore::RemovalCause::EVICTED,
322 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE
323 CookieStore::RemovalCause::EVICTED,
324 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE
325 CookieStore::RemovalCause::EVICTED,
326 // DELETE_COOKIE_EXPIRED_OVERWRITE
327 CookieStore::RemovalCause::EXPIRED_OVERWRITE,
328 // DELETE_COOKIE_CONTROL_CHAR
329 CookieStore::RemovalCause::EVICTED,
330 // DELETE_COOKIE_NON_SECURE
331 CookieStore::RemovalCause::EVICTED,
332 // DELETE_COOKIE_LAST_ENTRY
333 CookieStore::RemovalCause::EXPLICIT,
334 };
335
305 void RunAsync(scoped_refptr<base::TaskRunner> proxy, 336 void RunAsync(scoped_refptr<base::TaskRunner> proxy,
306 const CookieStore::CookieChangedCallback& callback, 337 const CookieStore::CookieChangedCallback& callback,
307 const CanonicalCookie& cookie, 338 const CanonicalCookie& cookie,
308 bool removed) { 339 bool removed,
309 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed)); 340 CookieStore::RemovalCause cause) {
341 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed, cause));
310 } 342 }
311 343
312 bool IsCookieEligibleForEviction(CookiePriority current_priority_level, 344 bool IsCookieEligibleForEviction(CookiePriority current_priority_level,
313 bool protect_secure_cookies, 345 bool protect_secure_cookies,
314 const CanonicalCookie* cookie) { 346 const CanonicalCookie* cookie) {
315 if (cookie->Priority() == current_priority_level && protect_secure_cookies) 347 if (cookie->Priority() == current_priority_level && protect_secure_cookies)
316 return !cookie->IsSecure(); 348 return !cookie->IsSecure();
317 349
318 return cookie->Priority() == current_priority_level; 350 return cookie->Priority() == current_priority_level;
319 } 351 }
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME; 1742 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME;
1711 } else { 1743 } else {
1712 cookie_source_sample = 1744 cookie_source_sample =
1713 cc->IsSecure() 1745 cc->IsSecure()
1714 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME 1746 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME
1715 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME; 1747 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME;
1716 } 1748 }
1717 histogram_cookie_source_scheme_->Add(cookie_source_sample); 1749 histogram_cookie_source_scheme_->Add(cookie_source_sample);
1718 } 1750 }
1719 1751
1720 RunCookieChangedCallbacks(*cc, false); 1752 RunCookieChangedCallbacks(*cc, false, CookieStore::RemovalCause::NOT_REMOVED);
1721 1753
1722 return inserted; 1754 return inserted;
1723 } 1755 }
1724 1756
1725 bool CookieMonster::SetCookieWithCreationTimeAndOptions( 1757 bool CookieMonster::SetCookieWithCreationTimeAndOptions(
1726 const GURL& url, 1758 const GURL& url,
1727 const std::string& cookie_line, 1759 const std::string& cookie_line,
1728 const Time& creation_time_or_null, 1760 const Time& creation_time_or_null,
1729 const CookieOptions& options) { 1761 const CookieOptions& options) {
1730 DCHECK(thread_checker_.CalledOnValidThread()); 1762 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 1888
1857 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && 1889 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() &&
1858 sync_to_store) 1890 sync_to_store)
1859 store_->DeleteCookie(*cc); 1891 store_->DeleteCookie(*cc);
1860 if (delegate_.get()) { 1892 if (delegate_.get()) {
1861 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; 1893 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause];
1862 1894
1863 if (mapping.notify) 1895 if (mapping.notify)
1864 delegate_->OnCookieChanged(*cc, true, mapping.cause); 1896 delegate_->OnCookieChanged(*cc, true, mapping.cause);
1865 } 1897 }
1866 RunCookieChangedCallbacks(*cc, true); 1898 RunCookieChangedCallbacks(*cc, true, RemovalCauseMap[deletion_cause]);
1867 cookies_.erase(it); 1899 cookies_.erase(it);
1868 delete cc; 1900 delete cc;
1869 } 1901 }
1870 1902
1871 // Domain expiry behavior is unchanged by key/expiry scheme (the 1903 // 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). 1904 // meaning of the key is different, but that's not visible to this routine).
1873 size_t CookieMonster::GarbageCollect(const Time& current, 1905 size_t CookieMonster::GarbageCollect(const Time& current,
1874 const std::string& key, 1906 const std::string& key,
1875 bool enforce_strict_secure) { 1907 bool enforce_strict_secure) {
1876 DCHECK(thread_checker_.CalledOnValidThread()); 1908 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 std::inserter(*cookies_to_add, cookies_to_add->begin()), 2400 std::inserter(*cookies_to_add, cookies_to_add->begin()),
2369 FullDiffCookieSorter); 2401 FullDiffCookieSorter);
2370 } 2402 }
2371 2403
2372 void CookieMonster::RunCallback(const base::Closure& callback) { 2404 void CookieMonster::RunCallback(const base::Closure& callback) {
2373 DCHECK(thread_checker_.CalledOnValidThread()); 2405 DCHECK(thread_checker_.CalledOnValidThread());
2374 callback.Run(); 2406 callback.Run();
2375 } 2407 }
2376 2408
2377 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, 2409 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie,
2378 bool removed) { 2410 bool removed,
2411 RemovalCause cause) {
2379 DCHECK(thread_checker_.CalledOnValidThread()); 2412 DCHECK(thread_checker_.CalledOnValidThread());
2380 2413
2381 CookieOptions opts; 2414 CookieOptions opts;
2382 opts.set_include_httponly(); 2415 opts.set_include_httponly();
2383 opts.set_same_site_cookie_mode( 2416 opts.set_same_site_cookie_mode(
2384 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); 2417 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
2385 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they 2418 // 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 2419 // are guaranteed to not take long - they just post a RunAsync task back to
2387 // the appropriate thread's message loop and return. 2420 // the appropriate thread's message loop and return.
2388 // TODO(mmenke): Consider running these synchronously? 2421 // TODO(mmenke): Consider running these synchronously?
2389 for (CookieChangedHookMap::iterator it = hook_map_.begin(); 2422 for (CookieChangedHookMap::iterator it = hook_map_.begin();
2390 it != hook_map_.end(); ++it) { 2423 it != hook_map_.end(); ++it) {
2391 std::pair<GURL, std::string> key = it->first; 2424 std::pair<GURL, std::string> key = it->first;
2392 if (cookie.IncludeForRequestURL(key.first, opts) && 2425 if (cookie.IncludeForRequestURL(key.first, opts) &&
2393 cookie.Name() == key.second) { 2426 cookie.Name() == key.second) {
2394 it->second->Notify(cookie, removed); 2427 it->second->Notify(cookie, removed, cause);
2395 } 2428 }
2396 } 2429 }
2397 } 2430 }
2398 2431
2399 } // namespace net 2432 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698