| 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 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 keep_expired_cookies_ = true; | 1215 keep_expired_cookies_ = true; |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 // static | 1218 // static |
| 1219 void CookieMonster::EnableFileScheme() { | 1219 void CookieMonster::EnableFileScheme() { |
| 1220 default_enable_file_scheme_ = true; | 1220 default_enable_file_scheme_ = true; |
| 1221 } | 1221 } |
| 1222 | 1222 |
| 1223 void CookieMonster::FlushStore(const base::Closure& callback) { | 1223 void CookieMonster::FlushStore(const base::Closure& callback) { |
| 1224 base::AutoLock autolock(lock_); | 1224 base::AutoLock autolock(lock_); |
| 1225 if (initialized_ && store_) | 1225 if (initialized_ && store_.get()) |
| 1226 store_->Flush(callback); | 1226 store_->Flush(callback); |
| 1227 else if (!callback.is_null()) | 1227 else if (!callback.is_null()) |
| 1228 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 1228 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 1229 } | 1229 } |
| 1230 | 1230 |
| 1231 bool CookieMonster::SetCookieWithOptions(const GURL& url, | 1231 bool CookieMonster::SetCookieWithOptions(const GURL& url, |
| 1232 const std::string& cookie_line, | 1232 const std::string& cookie_line, |
| 1233 const CookieOptions& options) { | 1233 const CookieOptions& options) { |
| 1234 base::AutoLock autolock(lock_); | 1234 base::AutoLock autolock(lock_); |
| 1235 | 1235 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 // This function must be called before the CookieMonster is used. | 1336 // This function must be called before the CookieMonster is used. |
| 1337 void CookieMonster::SetPriorityAwareGarbageCollection( | 1337 void CookieMonster::SetPriorityAwareGarbageCollection( |
| 1338 bool priority_aware_garbage_collection) { | 1338 bool priority_aware_garbage_collection) { |
| 1339 DCHECK(!initialized_); | 1339 DCHECK(!initialized_); |
| 1340 priority_aware_garbage_collection_ = priority_aware_garbage_collection; | 1340 priority_aware_garbage_collection_ = priority_aware_garbage_collection; |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 void CookieMonster::SetForceKeepSessionState() { | 1343 void CookieMonster::SetForceKeepSessionState() { |
| 1344 if (store_) { | 1344 if (store_.get()) { |
| 1345 store_->SetForceKeepSessionState(); | 1345 store_->SetForceKeepSessionState(); |
| 1346 } | 1346 } |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 CookieMonster::~CookieMonster() { | 1349 CookieMonster::~CookieMonster() { |
| 1350 DeleteAll(false); | 1350 DeleteAll(false); |
| 1351 } | 1351 } |
| 1352 | 1352 |
| 1353 bool CookieMonster::SetCookieWithCreationTime(const GURL& url, | 1353 bool CookieMonster::SetCookieWithCreationTime(const GURL& url, |
| 1354 const std::string& cookie_line, | 1354 const std::string& cookie_line, |
| 1355 const base::Time& creation_time) { | 1355 const base::Time& creation_time) { |
| 1356 DCHECK(!store_) << "This method is only to be used by unit-tests."; | 1356 DCHECK(!store_.get()) << "This method is only to be used by unit-tests."; |
| 1357 base::AutoLock autolock(lock_); | 1357 base::AutoLock autolock(lock_); |
| 1358 | 1358 |
| 1359 if (!HasCookieableScheme(url)) { | 1359 if (!HasCookieableScheme(url)) { |
| 1360 return false; | 1360 return false; |
| 1361 } | 1361 } |
| 1362 | 1362 |
| 1363 InitIfNecessary(); | 1363 InitIfNecessary(); |
| 1364 return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, | 1364 return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, |
| 1365 CookieOptions()); | 1365 CookieOptions()); |
| 1366 } | 1366 } |
| 1367 | 1367 |
| 1368 void CookieMonster::InitStore() { | 1368 void CookieMonster::InitStore() { |
| 1369 DCHECK(store_) << "Store must exist to initialize"; | 1369 DCHECK(store_.get()) << "Store must exist to initialize"; |
| 1370 | 1370 |
| 1371 // We bind in the current time so that we can report the wall-clock time for | 1371 // We bind in the current time so that we can report the wall-clock time for |
| 1372 // loading cookies. | 1372 // loading cookies. |
| 1373 store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now())); | 1373 store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now())); |
| 1374 } | 1374 } |
| 1375 | 1375 |
| 1376 void CookieMonster::OnLoaded(TimeTicks beginning_time, | 1376 void CookieMonster::OnLoaded(TimeTicks beginning_time, |
| 1377 const std::vector<CanonicalCookie*>& cookies) { | 1377 const std::vector<CanonicalCookie*>& cookies) { |
| 1378 StoreLoadedCookies(cookies); | 1378 StoreLoadedCookies(cookies); |
| 1379 histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time); | 1379 histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 } | 1667 } |
| 1668 } | 1668 } |
| 1669 return skipped_httponly; | 1669 return skipped_httponly; |
| 1670 } | 1670 } |
| 1671 | 1671 |
| 1672 void CookieMonster::InternalInsertCookie(const std::string& key, | 1672 void CookieMonster::InternalInsertCookie(const std::string& key, |
| 1673 CanonicalCookie* cc, | 1673 CanonicalCookie* cc, |
| 1674 bool sync_to_store) { | 1674 bool sync_to_store) { |
| 1675 lock_.AssertAcquired(); | 1675 lock_.AssertAcquired(); |
| 1676 | 1676 |
| 1677 if ((cc->IsPersistent() || persist_session_cookies_) && | 1677 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
| 1678 store_ && sync_to_store) | 1678 sync_to_store) |
| 1679 store_->AddCookie(*cc); | 1679 store_->AddCookie(*cc); |
| 1680 cookies_.insert(CookieMap::value_type(key, cc)); | 1680 cookies_.insert(CookieMap::value_type(key, cc)); |
| 1681 if (delegate_.get()) { | 1681 if (delegate_.get()) { |
| 1682 delegate_->OnCookieChanged( | 1682 delegate_->OnCookieChanged( |
| 1683 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT); | 1683 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT); |
| 1684 } | 1684 } |
| 1685 } | 1685 } |
| 1686 | 1686 |
| 1687 bool CookieMonster::SetCookieWithCreationTimeAndOptions( | 1687 bool CookieMonster::SetCookieWithCreationTimeAndOptions( |
| 1688 const GURL& url, | 1688 const GURL& url, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 // updates we do during pageload, which in turn reduces the chance our storage | 1756 // updates we do during pageload, which in turn reduces the chance our storage |
| 1757 // backend will hit its batch thresholds and be forced to update. | 1757 // backend will hit its batch thresholds and be forced to update. |
| 1758 if ((current - cc->LastAccessDate()) < last_access_threshold_) | 1758 if ((current - cc->LastAccessDate()) < last_access_threshold_) |
| 1759 return; | 1759 return; |
| 1760 | 1760 |
| 1761 // See InitializeHistograms() for details. | 1761 // See InitializeHistograms() for details. |
| 1762 histogram_between_access_interval_minutes_->Add( | 1762 histogram_between_access_interval_minutes_->Add( |
| 1763 (current - cc->LastAccessDate()).InMinutes()); | 1763 (current - cc->LastAccessDate()).InMinutes()); |
| 1764 | 1764 |
| 1765 cc->SetLastAccessDate(current); | 1765 cc->SetLastAccessDate(current); |
| 1766 if ((cc->IsPersistent() || persist_session_cookies_) && store_) | 1766 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get()) |
| 1767 store_->UpdateCookieAccessTime(*cc); | 1767 store_->UpdateCookieAccessTime(*cc); |
| 1768 } | 1768 } |
| 1769 | 1769 |
| 1770 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, | 1770 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, |
| 1771 bool sync_to_store, | 1771 bool sync_to_store, |
| 1772 DeletionCause deletion_cause) { | 1772 DeletionCause deletion_cause) { |
| 1773 lock_.AssertAcquired(); | 1773 lock_.AssertAcquired(); |
| 1774 | 1774 |
| 1775 // Ideally, this would be asserted up where we define ChangeCauseMapping, | 1775 // Ideally, this would be asserted up where we define ChangeCauseMapping, |
| 1776 // but DeletionCause's visibility (or lack thereof) forces us to make | 1776 // but DeletionCause's visibility (or lack thereof) forces us to make |
| 1777 // this check here. | 1777 // this check here. |
| 1778 COMPILE_ASSERT(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, | 1778 COMPILE_ASSERT(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, |
| 1779 ChangeCauseMapping_size_not_eq_DeletionCause_enum_size); | 1779 ChangeCauseMapping_size_not_eq_DeletionCause_enum_size); |
| 1780 | 1780 |
| 1781 // See InitializeHistograms() for details. | 1781 // See InitializeHistograms() for details. |
| 1782 if (deletion_cause != DELETE_COOKIE_DONT_RECORD) | 1782 if (deletion_cause != DELETE_COOKIE_DONT_RECORD) |
| 1783 histogram_cookie_deletion_cause_->Add(deletion_cause); | 1783 histogram_cookie_deletion_cause_->Add(deletion_cause); |
| 1784 | 1784 |
| 1785 CanonicalCookie* cc = it->second; | 1785 CanonicalCookie* cc = it->second; |
| 1786 VLOG(kVlogSetCookies) << "InternalDeleteCookie() cc: " << cc->DebugString(); | 1786 VLOG(kVlogSetCookies) << "InternalDeleteCookie() cc: " << cc->DebugString(); |
| 1787 | 1787 |
| 1788 if ((cc->IsPersistent() || persist_session_cookies_) | 1788 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
| 1789 && store_ && sync_to_store) | 1789 sync_to_store) |
| 1790 store_->DeleteCookie(*cc); | 1790 store_->DeleteCookie(*cc); |
| 1791 if (delegate_.get()) { | 1791 if (delegate_.get()) { |
| 1792 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; | 1792 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; |
| 1793 | 1793 |
| 1794 if (mapping.notify) | 1794 if (mapping.notify) |
| 1795 delegate_->OnCookieChanged(*cc, true, mapping.cause); | 1795 delegate_->OnCookieChanged(*cc, true, mapping.cause); |
| 1796 } | 1796 } |
| 1797 cookies_.erase(it); | 1797 cookies_.erase(it); |
| 1798 delete cc; | 1798 delete cc; |
| 1799 } | 1799 } |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 | 2150 |
| 2151 // The system resolution is not high enough, so we can have multiple | 2151 // The system resolution is not high enough, so we can have multiple |
| 2152 // set cookies that result in the same system time. When this happens, we | 2152 // set cookies that result in the same system time. When this happens, we |
| 2153 // increment by one Time unit. Let's hope computers don't get too fast. | 2153 // increment by one Time unit. Let's hope computers don't get too fast. |
| 2154 Time CookieMonster::CurrentTime() { | 2154 Time CookieMonster::CurrentTime() { |
| 2155 return std::max(Time::Now(), | 2155 return std::max(Time::Now(), |
| 2156 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2156 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
| 2157 } | 2157 } |
| 2158 | 2158 |
| 2159 } // namespace net | 2159 } // namespace net |
| OLD | NEW |