| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // and a value of AAAA. When it sends the cookie back, it will send AAAA, | 300 // and a value of AAAA. When it sends the cookie back, it will send AAAA, |
| 301 // so we need to avoid sending =AAAA for a blank token value. | 301 // so we need to avoid sending =AAAA for a blank token value. |
| 302 if (!(*it)->Name().empty()) | 302 if (!(*it)->Name().empty()) |
| 303 cookie_line += (*it)->Name() + "="; | 303 cookie_line += (*it)->Name() + "="; |
| 304 cookie_line += (*it)->Value(); | 304 cookie_line += (*it)->Value(); |
| 305 } | 305 } |
| 306 return cookie_line; | 306 return cookie_line; |
| 307 } | 307 } |
| 308 | 308 |
| 309 void RunAsync(scoped_refptr<base::TaskRunner> proxy, | 309 void RunAsync(scoped_refptr<base::TaskRunner> proxy, |
| 310 const CookieStore::CookieChangedCallback& callback) { | 310 const CookieStore::CookieChangedCallback& callback, |
| 311 proxy->PostTask(FROM_HERE, callback); | 311 const CanonicalCookie& cookie, |
| 312 bool removed) { |
| 313 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed)); |
| 312 } | 314 } |
| 313 | 315 |
| 314 } // namespace | 316 } // namespace |
| 315 | 317 |
| 316 CookieMonster::CookieMonster(PersistentCookieStore* store, | 318 CookieMonster::CookieMonster(PersistentCookieStore* store, |
| 317 CookieMonsterDelegate* delegate) | 319 CookieMonsterDelegate* delegate) |
| 318 : initialized_(false), | 320 : initialized_(false), |
| 319 loaded_(store == NULL), | 321 loaded_(store == NULL), |
| 320 store_(store), | 322 store_(store), |
| 321 last_access_threshold_( | 323 last_access_threshold_( |
| (...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 | 1777 |
| 1776 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && | 1778 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
| 1777 sync_to_store) | 1779 sync_to_store) |
| 1778 store_->AddCookie(*cc); | 1780 store_->AddCookie(*cc); |
| 1779 CookieMap::iterator inserted = | 1781 CookieMap::iterator inserted = |
| 1780 cookies_.insert(CookieMap::value_type(key, cc)); | 1782 cookies_.insert(CookieMap::value_type(key, cc)); |
| 1781 if (delegate_.get()) { | 1783 if (delegate_.get()) { |
| 1782 delegate_->OnCookieChanged( | 1784 delegate_->OnCookieChanged( |
| 1783 *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); | 1785 *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); |
| 1784 } | 1786 } |
| 1787 RunCallbacks(*cc, false); |
| 1785 | 1788 |
| 1786 return inserted; | 1789 return inserted; |
| 1787 } | 1790 } |
| 1788 | 1791 |
| 1789 bool CookieMonster::SetCookieWithCreationTimeAndOptions( | 1792 bool CookieMonster::SetCookieWithCreationTimeAndOptions( |
| 1790 const GURL& url, | 1793 const GURL& url, |
| 1791 const std::string& cookie_line, | 1794 const std::string& cookie_line, |
| 1792 const Time& creation_time_or_null, | 1795 const Time& creation_time_or_null, |
| 1793 const CookieOptions& options) { | 1796 const CookieOptions& options) { |
| 1794 lock_.AssertAcquired(); | 1797 lock_.AssertAcquired(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 if (!already_expired || keep_expired_cookies_) { | 1834 if (!already_expired || keep_expired_cookies_) { |
| 1832 // See InitializeHistograms() for details. | 1835 // See InitializeHistograms() for details. |
| 1833 if ((*cc)->IsPersistent()) { | 1836 if ((*cc)->IsPersistent()) { |
| 1834 histogram_expiration_duration_minutes_->Add( | 1837 histogram_expiration_duration_minutes_->Add( |
| 1835 ((*cc)->ExpiryDate() - creation_time).InMinutes()); | 1838 ((*cc)->ExpiryDate() - creation_time).InMinutes()); |
| 1836 } | 1839 } |
| 1837 | 1840 |
| 1838 { | 1841 { |
| 1839 CanonicalCookie cookie = *(cc->get()); | 1842 CanonicalCookie cookie = *(cc->get()); |
| 1840 InternalInsertCookie(key, cc->release(), true); | 1843 InternalInsertCookie(key, cc->release(), true); |
| 1841 RunCallbacks(cookie); | |
| 1842 } | 1844 } |
| 1843 } else { | 1845 } else { |
| 1844 VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie."; | 1846 VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie."; |
| 1845 } | 1847 } |
| 1846 | 1848 |
| 1847 // We assume that hopefully setting a cookie will be less common than | 1849 // We assume that hopefully setting a cookie will be less common than |
| 1848 // querying a cookie. Since setting a cookie can put us over our limits, | 1850 // querying a cookie. Since setting a cookie can put us over our limits, |
| 1849 // make sure that we garbage collect... We can also make the assumption that | 1851 // make sure that we garbage collect... We can also make the assumption that |
| 1850 // if a cookie was set, in the common case it will be used soon after, | 1852 // if a cookie was set, in the common case it will be used soon after, |
| 1851 // and we will purge the expired cookies in GetCookies(). | 1853 // and we will purge the expired cookies in GetCookies(). |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1896 | 1898 |
| 1897 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && | 1899 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
| 1898 sync_to_store) | 1900 sync_to_store) |
| 1899 store_->DeleteCookie(*cc); | 1901 store_->DeleteCookie(*cc); |
| 1900 if (delegate_.get()) { | 1902 if (delegate_.get()) { |
| 1901 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; | 1903 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; |
| 1902 | 1904 |
| 1903 if (mapping.notify) | 1905 if (mapping.notify) |
| 1904 delegate_->OnCookieChanged(*cc, true, mapping.cause); | 1906 delegate_->OnCookieChanged(*cc, true, mapping.cause); |
| 1905 } | 1907 } |
| 1908 RunCallbacks(*cc, true); |
| 1906 cookies_.erase(it); | 1909 cookies_.erase(it); |
| 1907 RunCallbacks(*cc); | |
| 1908 delete cc; | 1910 delete cc; |
| 1909 } | 1911 } |
| 1910 | 1912 |
| 1911 // Domain expiry behavior is unchanged by key/expiry scheme (the | 1913 // Domain expiry behavior is unchanged by key/expiry scheme (the |
| 1912 // meaning of the key is different, but that's not visible to this routine). | 1914 // meaning of the key is different, but that's not visible to this routine). |
| 1913 int CookieMonster::GarbageCollect(const Time& current, | 1915 int CookieMonster::GarbageCollect(const Time& current, |
| 1914 const std::string& key) { | 1916 const std::string& key) { |
| 1915 lock_.AssertAcquired(); | 1917 lock_.AssertAcquired(); |
| 1916 | 1918 |
| 1917 int num_deleted = 0; | 1919 int num_deleted = 0; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2314 | 2316 |
| 2315 scoped_ptr<CookieStore::CookieChangedSubscription> | 2317 scoped_ptr<CookieStore::CookieChangedSubscription> |
| 2316 CookieMonster::AddCallbackForCookie( | 2318 CookieMonster::AddCallbackForCookie( |
| 2317 const GURL& gurl, | 2319 const GURL& gurl, |
| 2318 const std::string& name, | 2320 const std::string& name, |
| 2319 const CookieChangedCallback& callback) { | 2321 const CookieChangedCallback& callback) { |
| 2320 base::AutoLock autolock(lock_); | 2322 base::AutoLock autolock(lock_); |
| 2321 std::pair<GURL, std::string> key(gurl, name); | 2323 std::pair<GURL, std::string> key(gurl, name); |
| 2322 if (hook_map_.count(key) == 0) | 2324 if (hook_map_.count(key) == 0) |
| 2323 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); | 2325 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); |
| 2324 return hook_map_[key]->Add(base::Bind( | 2326 return hook_map_[key]->Add( |
| 2325 &RunAsync, base::MessageLoopProxy::current(), callback)); | 2327 base::Bind(&RunAsync, base::MessageLoopProxy::current(), callback)); |
| 2326 } | 2328 } |
| 2327 | 2329 |
| 2328 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie) { | 2330 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { |
| 2329 lock_.AssertAcquired(); | 2331 lock_.AssertAcquired(); |
| 2330 CookieOptions opts; | 2332 CookieOptions opts; |
| 2331 opts.set_include_httponly(); | 2333 opts.set_include_httponly(); |
| 2332 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they | 2334 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they |
| 2333 // are guaranteed to not take long - they just post a RunAsync task back to | 2335 // are guaranteed to not take long - they just post a RunAsync task back to |
| 2334 // the appropriate thread's message loop and return. It is important that this | 2336 // the appropriate thread's message loop and return. It is important that this |
| 2335 // method not run user-supplied callbacks directly, since the CookieMonster | 2337 // method not run user-supplied callbacks directly, since the CookieMonster |
| 2336 // lock is held and it is easy to accidentally introduce deadlocks. | 2338 // lock is held and it is easy to accidentally introduce deadlocks. |
| 2337 for (CookieChangedHookMap::iterator it = hook_map_.begin(); | 2339 for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
| 2338 it != hook_map_.end(); ++it) { | 2340 it != hook_map_.end(); ++it) { |
| 2339 std::pair<GURL, std::string> key = it->first; | 2341 std::pair<GURL, std::string> key = it->first; |
| 2340 if (cookie.IncludeForRequestURL(key.first, opts) && | 2342 if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2341 cookie.Name() == key.second) { | 2343 cookie.Name() == key.second) { |
| 2342 it->second->Notify(); | 2344 it->second->Notify(cookie, removed); |
| 2343 } | 2345 } |
| 2344 } | 2346 } |
| 2345 } | 2347 } |
| 2346 | 2348 |
| 2347 } // namespace net | 2349 } // namespace net |
| OLD | NEW |