diff options
Diffstat (limited to 'net/cookies/cookie_monster.cc')
-rw-r--r-- | net/cookies/cookie_monster.cc | 518 |
1 files changed, 231 insertions, 287 deletions
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc index 452ce68..7c2a14c 100644 --- a/net/cookies/cookie_monster.cc +++ b/net/cookies/cookie_monster.cc @@ -97,18 +97,18 @@ namespace net { // See comments at declaration of these variables in cookie_monster.h // for details. -const size_t CookieMonster::kDomainMaxCookies = 180; -const size_t CookieMonster::kDomainPurgeCookies = 30; -const size_t CookieMonster::kMaxCookies = 3300; -const size_t CookieMonster::kPurgeCookies = 300; +const size_t CookieMonster::kDomainMaxCookies = 180; +const size_t CookieMonster::kDomainPurgeCookies = 30; +const size_t CookieMonster::kMaxCookies = 3300; +const size_t CookieMonster::kPurgeCookies = 300; -const size_t CookieMonster::kDomainCookiesQuotaLow = 30; +const size_t CookieMonster::kDomainCookiesQuotaLow = 30; const size_t CookieMonster::kDomainCookiesQuotaMedium = 50; -const size_t CookieMonster::kDomainCookiesQuotaHigh = - kDomainMaxCookies - kDomainPurgeCookies - - kDomainCookiesQuotaLow - kDomainCookiesQuotaMedium; +const size_t CookieMonster::kDomainCookiesQuotaHigh = + kDomainMaxCookies - kDomainPurgeCookies - kDomainCookiesQuotaLow - + kDomainCookiesQuotaMedium; -const int CookieMonster::kSafeFromGlobalPurgeDays = 30; +const int CookieMonster::kSafeFromGlobalPurgeDays = 30; namespace { @@ -177,8 +177,7 @@ struct CookieSignature { CookieSignature(const std::string& name, const std::string& domain, const std::string& path) - : name(name), domain(domain), path(path) { - } + : name(name), domain(domain), path(path) {} // To be a key for a map this class needs to be assignable, copyable, // and have an operator<. The default assignment operator @@ -206,10 +205,9 @@ struct CookieSignature { // sorts the first |num_sort| + 1 elements by LastAccessDate(). // The + 1 element exists so for any interval of length <= |num_sort| starting // from |cookies_its_begin|, a LastAccessDate() bound can be found. -void SortLeastRecentlyAccessed( - CookieMonster::CookieItVector::iterator it_begin, - CookieMonster::CookieItVector::iterator it_end, - size_t num_sort) { +void SortLeastRecentlyAccessed(CookieMonster::CookieItVector::iterator it_begin, + CookieMonster::CookieItVector::iterator it_end, + size_t num_sort) { DCHECK_LT(static_cast<int>(num_sort), it_end - it_begin); std::partial_sort(it_begin, it_begin + num_sort + 1, it_end, LRACookieSorter); } @@ -218,7 +216,7 @@ void SortLeastRecentlyAccessed( struct CookiePriorityEqualsTo : std::unary_function<const CookieMonster::CookieMap::iterator, bool> { explicit CookiePriorityEqualsTo(CookiePriority priority) - : priority_(priority) {} + : priority_(priority) {} bool operator()(const CookieMonster::CookieMap::iterator it) const { return it->second->Priority() == priority_; @@ -238,8 +236,8 @@ CookieMonster::CookieItVector::iterator PartitionCookieByPriority( return std::partition(it_begin, it_end, CookiePriorityEqualsTo(priority)); } -bool LowerBoundAccessDateComparator( - const CookieMonster::CookieMap::iterator it, const Time& access_date) { +bool LowerBoundAccessDateComparator(const CookieMonster::CookieMap::iterator it, + const Time& access_date) { return it->second->LastAccessDate() < access_date; } @@ -263,33 +261,32 @@ typedef struct ChangeCausePair_struct { bool notify; } ChangeCausePair; ChangeCausePair ChangeCauseMapping[] = { - // DELETE_COOKIE_EXPLICIT - { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true }, - // DELETE_COOKIE_OVERWRITE - { CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true }, - // DELETE_COOKIE_EXPIRED - { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true }, - // DELETE_COOKIE_EVICTED - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, - // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE - { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, - // DELETE_COOKIE_DONT_RECORD - { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, - // DELETE_COOKIE_EVICTED_DOMAIN - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, - // DELETE_COOKIE_EVICTED_GLOBAL - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, - // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, - // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, - // DELETE_COOKIE_EXPIRED_OVERWRITE - { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, - // DELETE_COOKIE_CONTROL_CHAR - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, - // DELETE_COOKIE_LAST_ENTRY - { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false } -}; + // DELETE_COOKIE_EXPLICIT + {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true}, + // DELETE_COOKIE_OVERWRITE + {CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true}, + // DELETE_COOKIE_EXPIRED + {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true}, + // DELETE_COOKIE_EVICTED + {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, + // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE + {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, + // DELETE_COOKIE_DONT_RECORD + {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, + // DELETE_COOKIE_EVICTED_DOMAIN + {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, + // DELETE_COOKIE_EVICTED_GLOBAL + {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, + // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE + {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, + // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE + {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, + // DELETE_COOKIE_EXPIRED_OVERWRITE + {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true}, + // DELETE_COOKIE_CONTROL_CHAR + {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, + // DELETE_COOKIE_LAST_ENTRY + {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}}; std::string BuildCookieLine(const CanonicalCookieVector& cookies) { std::string cookie_line; @@ -347,7 +344,6 @@ CookieMonster::CookieMonster(PersistentCookieStore* store, SetDefaultCookieableSchemes(); } - // Task classes for queueing the coming request. class CookieMonster::CookieMonsterTask @@ -367,9 +363,7 @@ class CookieMonster::CookieMonsterTask // instance until the callback completes. void InvokeCallback(base::Closure callback); - CookieMonster* cookie_monster() { - return cookie_monster_; - } + CookieMonster* cookie_monster() { return cookie_monster_; } private: friend class base::RefCountedThreadSafe<CookieMonsterTask>; @@ -386,7 +380,8 @@ CookieMonster::CookieMonsterTask::CookieMonsterTask( thread_(base::MessageLoopProxy::current()) { } -CookieMonster::CookieMonsterTask::~CookieMonsterTask() {} +CookieMonster::CookieMonsterTask::~CookieMonsterTask() { +} // Unfortunately, one cannot re-bind a Callback with parameters into a closure. // Therefore, the closure passed to InvokeCallback is a clumsy binding of @@ -402,8 +397,8 @@ void CookieMonster::CookieMonsterTask::InvokeCallback(base::Closure callback) { if (thread_->BelongsToCurrentThread()) { callback.Run(); } else { - thread_->PostTask(FROM_HERE, base::Bind( - &CookieMonsterTask::InvokeCallback, this, callback)); + thread_->PostTask(FROM_HERE, base::Bind(&CookieMonsterTask::InvokeCallback, + this, callback)); } } @@ -431,8 +426,7 @@ class CookieMonster::SetCookieWithDetailsTask : public CookieMonsterTask { secure_(secure), http_only_(http_only), priority_(priority), - callback_(callback) { - } + callback_(callback) {} // CookieMonsterTask: void Run() override; @@ -456,9 +450,9 @@ class CookieMonster::SetCookieWithDetailsTask : public CookieMonsterTask { }; void CookieMonster::SetCookieWithDetailsTask::Run() { - bool success = this->cookie_monster()-> - SetCookieWithDetails(url_, name_, value_, domain_, path_, - expiration_time_, secure_, http_only_, priority_); + bool success = this->cookie_monster()->SetCookieWithDetails( + url_, name_, value_, domain_, path_, expiration_time_, secure_, + http_only_, priority_); if (!callback_.is_null()) { this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, base::Unretained(&callback_), success)); @@ -470,9 +464,7 @@ class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { public: GetAllCookiesTask(CookieMonster* cookie_monster, const GetCookieListCallback& callback) - : CookieMonsterTask(cookie_monster), - callback_(callback) { - } + : CookieMonsterTask(cookie_monster), callback_(callback) {} // CookieMonsterTask void Run() override; @@ -491,23 +483,21 @@ void CookieMonster::GetAllCookiesTask::Run() { CookieList cookies = this->cookie_monster()->GetAllCookies(); this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback_), cookies)); - } + } } // Task class for GetAllCookiesForURLWithOptions call. class CookieMonster::GetAllCookiesForURLWithOptionsTask : public CookieMonsterTask { public: - GetAllCookiesForURLWithOptionsTask( - CookieMonster* cookie_monster, - const GURL& url, - const CookieOptions& options, - const GetCookieListCallback& callback) + GetAllCookiesForURLWithOptionsTask(CookieMonster* cookie_monster, + const GURL& url, + const CookieOptions& options, + const GetCookieListCallback& callback) : CookieMonsterTask(cookie_monster), url_(url), options_(options), - callback_(callback) { - } + callback_(callback) {} // CookieMonsterTask: void Run() override; @@ -525,18 +515,20 @@ class CookieMonster::GetAllCookiesForURLWithOptionsTask void CookieMonster::GetAllCookiesForURLWithOptionsTask::Run() { if (!callback_.is_null()) { - CookieList cookies = this->cookie_monster()-> - GetAllCookiesForURLWithOptions(url_, options_); + CookieList cookies = + this->cookie_monster()->GetAllCookiesForURLWithOptions(url_, options_); this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback_), cookies)); } } -template <typename Result> struct CallbackType { +template <typename Result> +struct CallbackType { typedef base::Callback<void(Result)> Type; }; -template <> struct CallbackType<void> { +template <> +struct CallbackType<void> { typedef base::Closure Type; }; @@ -546,9 +538,7 @@ class CookieMonster::DeleteTask : public CookieMonsterTask { public: DeleteTask(CookieMonster* cookie_monster, const typename CallbackType<Result>::Type& callback) - : CookieMonsterTask(cookie_monster), - callback_(callback) { - } + : CookieMonsterTask(cookie_monster), callback_(callback) {} // CookieMonsterTask: virtual void Run() override; @@ -588,9 +578,8 @@ base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() { template <typename Result> void CookieMonster::DeleteTask<Result>::Run() { - this->cookie_monster()->FlushStore( - base::Bind(&DeleteTask<Result>::FlushDone, this, - RunDeleteTaskAndBindCallback())); + this->cookie_monster()->FlushStore(base::Bind( + &DeleteTask<Result>::FlushDone, this, RunDeleteTaskAndBindCallback())); } template <typename Result> @@ -604,10 +593,8 @@ void CookieMonster::DeleteTask<Result>::FlushDone( // Task class for DeleteAll call. class CookieMonster::DeleteAllTask : public DeleteTask<int> { public: - DeleteAllTask(CookieMonster* cookie_monster, - const DeleteCallback& callback) - : DeleteTask<int>(cookie_monster, callback) { - } + DeleteAllTask(CookieMonster* cookie_monster, const DeleteCallback& callback) + : DeleteTask<int>(cookie_monster, callback) {} // DeleteTask: int RunDeleteTask() override; @@ -632,8 +619,7 @@ class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { const DeleteCallback& callback) : DeleteTask<int>(cookie_monster, callback), delete_begin_(delete_begin), - delete_end_(delete_end) { - } + delete_end_(delete_end) {} // DeleteTask: int RunDeleteTask() override; @@ -649,8 +635,8 @@ class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { }; int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { - return this->cookie_monster()-> - DeleteAllCreatedBetween(delete_begin_, delete_end_); + return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_, + delete_end_); } // Task class for DeleteAllForHost call. @@ -659,9 +645,7 @@ class CookieMonster::DeleteAllForHostTask : public DeleteTask<int> { DeleteAllForHostTask(CookieMonster* cookie_monster, const GURL& url, const DeleteCallback& callback) - : DeleteTask<int>(cookie_monster, callback), - url_(url) { - } + : DeleteTask<int>(cookie_monster, callback), url_(url) {} // DeleteTask: int RunDeleteTask() override; @@ -683,17 +667,15 @@ int CookieMonster::DeleteAllForHostTask::RunDeleteTask() { class CookieMonster::DeleteAllCreatedBetweenForHostTask : public DeleteTask<int> { public: - DeleteAllCreatedBetweenForHostTask( - CookieMonster* cookie_monster, - Time delete_begin, - Time delete_end, - const GURL& url, - const DeleteCallback& callback) + DeleteAllCreatedBetweenForHostTask(CookieMonster* cookie_monster, + Time delete_begin, + Time delete_end, + const GURL& url, + const DeleteCallback& callback) : DeleteTask<int>(cookie_monster, callback), delete_begin_(delete_begin), delete_end_(delete_end), - url_(url) { - } + url_(url) {} // DeleteTask: int RunDeleteTask() override; @@ -720,9 +702,7 @@ class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<bool> { DeleteCanonicalCookieTask(CookieMonster* cookie_monster, const CanonicalCookie& cookie, const DeleteCookieCallback& callback) - : DeleteTask<bool>(cookie_monster, callback), - cookie_(cookie) { - } + : DeleteTask<bool>(cookie_monster, callback), cookie_(cookie) {} // DeleteTask: bool RunDeleteTask() override; @@ -752,8 +732,7 @@ class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { url_(url), cookie_line_(cookie_line), options_(options), - callback_(callback) { - } + callback_(callback) {} // CookieMonsterTask: void Run() override; @@ -771,8 +750,8 @@ class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { }; void CookieMonster::SetCookieWithOptionsTask::Run() { - bool result = this->cookie_monster()-> - SetCookieWithOptions(url_, cookie_line_, options_); + bool result = this->cookie_monster()->SetCookieWithOptions(url_, cookie_line_, + options_); if (!callback_.is_null()) { this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, base::Unretained(&callback_), result)); @@ -789,8 +768,7 @@ class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { : CookieMonsterTask(cookie_monster), url_(url), options_(options), - callback_(callback) { - } + callback_(callback) {} // CookieMonsterTask: void Run() override; @@ -807,8 +785,8 @@ class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { }; void CookieMonster::GetCookiesWithOptionsTask::Run() { - std::string cookie = this->cookie_monster()-> - GetCookiesWithOptions(url_, options_); + std::string cookie = + this->cookie_monster()->GetCookiesWithOptions(url_, options_); if (!callback_.is_null()) { this->InvokeCallback(base::Bind(&GetCookiesCallback::Run, base::Unretained(&callback_), cookie)); @@ -824,8 +802,7 @@ class CookieMonster::DeleteCookieTask : public DeleteTask<void> { const base::Closure& callback) : DeleteTask<void>(cookie_monster, callback), url_(url), - cookie_name_(cookie_name) { - } + cookie_name_(cookie_name) {} // DeleteTask: void RunDeleteTask() override; @@ -849,8 +826,7 @@ class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { public: DeleteSessionCookiesTask(CookieMonster* cookie_monster, const DeleteCallback& callback) - : DeleteTask<int>(cookie_monster, callback) { - } + : DeleteTask<int>(cookie_monster, callback) {} // DeleteTask: int RunDeleteTask() override; @@ -869,14 +845,12 @@ int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { // Task class for HasCookiesForETLDP1Task call. class CookieMonster::HasCookiesForETLDP1Task : public CookieMonsterTask { public: - HasCookiesForETLDP1Task( - CookieMonster* cookie_monster, - const std::string& etldp1, - const HasCookiesForETLDP1Callback& callback) + HasCookiesForETLDP1Task(CookieMonster* cookie_monster, + const std::string& etldp1, + const HasCookiesForETLDP1Callback& callback) : CookieMonsterTask(cookie_monster), etldp1_(etldp1), - callback_(callback) { - } + callback_(callback) {} // CookieMonsterTask: void Run() override; @@ -894,9 +868,8 @@ class CookieMonster::HasCookiesForETLDP1Task : public CookieMonsterTask { void CookieMonster::HasCookiesForETLDP1Task::Run() { bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_); if (!callback_.is_null()) { - this->InvokeCallback( - base::Bind(&HasCookiesForETLDP1Callback::Run, - base::Unretained(&callback_), result)); + this->InvokeCallback(base::Bind(&HasCookiesForETLDP1Callback::Run, + base::Unretained(&callback_), result)); } } @@ -913,21 +886,18 @@ void CookieMonster::SetCookieWithDetailsAsync( bool http_only, CookiePriority priority, const SetCookiesCallback& callback) { - scoped_refptr<SetCookieWithDetailsTask> task = - new SetCookieWithDetailsTask(this, url, name, value, domain, path, - expiration_time, secure, http_only, priority, - callback); + scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( + this, url, name, value, domain, path, expiration_time, secure, http_only, + priority, callback); DoCookieTaskForURL(task, url); } void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { - scoped_refptr<GetAllCookiesTask> task = - new GetAllCookiesTask(this, callback); + scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); DoCookieTask(task); } - void CookieMonster::GetAllCookiesForURLWithOptionsAsync( const GURL& url, const CookieOptions& options, @@ -939,7 +909,8 @@ void CookieMonster::GetAllCookiesForURLWithOptionsAsync( } void CookieMonster::GetAllCookiesForURLAsync( - const GURL& url, const GetCookieListCallback& callback) { + const GURL& url, + const GetCookieListCallback& callback) { CookieOptions options; options.set_include_httponly(); scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = @@ -958,18 +929,17 @@ void CookieMonster::HasCookiesForETLDP1Async( } void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { - scoped_refptr<DeleteAllTask> task = - new DeleteAllTask(this, callback); + scoped_refptr<DeleteAllTask> task = new DeleteAllTask(this, callback); DoCookieTask(task); } void CookieMonster::DeleteAllCreatedBetweenAsync( - const Time& delete_begin, const Time& delete_end, + const Time& delete_begin, + const Time& delete_end, const DeleteCallback& callback) { scoped_refptr<DeleteAllCreatedBetweenTask> task = - new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, - callback); + new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback); DoCookieTask(task); } @@ -980,14 +950,14 @@ void CookieMonster::DeleteAllCreatedBetweenForHostAsync( const GURL& url, const DeleteCallback& callback) { scoped_refptr<DeleteAllCreatedBetweenForHostTask> task = - new DeleteAllCreatedBetweenForHostTask( - this, delete_begin, delete_end, url, callback); + new DeleteAllCreatedBetweenForHostTask(this, delete_begin, delete_end, + url, callback); DoCookieTaskForURL(task, url); } -void CookieMonster::DeleteAllForHostAsync( - const GURL& url, const DeleteCallback& callback) { +void CookieMonster::DeleteAllForHostAsync(const GURL& url, + const DeleteCallback& callback) { scoped_refptr<DeleteAllForHostTask> task = new DeleteAllForHostTask(this, url, callback); @@ -1065,16 +1035,19 @@ void CookieMonster::DoCookieTaskForURL( // then run the task, otherwise load from DB. if (!loaded_) { // Checks if the domain key has been loaded. - std::string key(cookie_util::GetEffectiveDomain(url.scheme(), - url.host())); + std::string key( + cookie_util::GetEffectiveDomain(url.scheme(), url.host())); if (keys_loaded_.find(key) == keys_loaded_.end()) { - std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > > - ::iterator it = tasks_pending_for_key_.find(key); + std::map<std::string, + std::deque<scoped_refptr<CookieMonsterTask>>>::iterator it = + tasks_pending_for_key_.find(key); if (it == tasks_pending_for_key_.end()) { - store_->LoadCookiesForKey(key, - base::Bind(&CookieMonster::OnKeyLoaded, this, key)); - it = tasks_pending_for_key_.insert(std::make_pair(key, - std::deque<scoped_refptr<CookieMonsterTask> >())).first; + store_->LoadCookiesForKey( + key, base::Bind(&CookieMonster::OnKeyLoaded, this, key)); + it = tasks_pending_for_key_ + .insert(std::make_pair( + key, std::deque<scoped_refptr<CookieMonsterTask>>())) + .first; } it->second.push_back(task_item); return; @@ -1103,8 +1076,8 @@ bool CookieMonster::SetCookieWithDetails(const GURL& url, scoped_ptr<CanonicalCookie> cc; cc.reset(CanonicalCookie::Create(url, name, value, domain, path, - creation_time, expiration_time, - secure, http_only, priority)); + creation_time, expiration_time, secure, + http_only, priority)); if (!cc.get()) return false; @@ -1117,8 +1090,8 @@ bool CookieMonster::SetCookieWithDetails(const GURL& url, bool CookieMonster::ImportCookies(const CookieList& list) { base::AutoLock autolock(lock_); InitIfNecessary(); - for (net::CookieList::const_iterator iter = list.begin(); - iter != list.end(); ++iter) { + for (net::CookieList::const_iterator iter = list.begin(); iter != list.end(); + ++iter) { scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); net::CookieOptions options; options.set_include_httponly(); @@ -1139,9 +1112,8 @@ CookieList CookieMonster::GetAllCookies() { // // Note that this does not prune cookies to be below our limits (if we've // exceeded them) the way that calling GarbageCollect() would. - GarbageCollectExpired(Time::Now(), - CookieMapItPair(cookies_.begin(), cookies_.end()), - NULL); + GarbageCollectExpired( + Time::Now(), CookieMapItPair(cookies_.begin(), cookies_.end()), NULL); // Copy the CanonicalCookie pointers from the map so that we can use the same // sorter as elsewhere, then copy the result out. @@ -1193,8 +1165,9 @@ int CookieMonster::DeleteAll(bool sync_to_store) { CookieMap::iterator curit = it; ++it; InternalDeleteCookie(curit, sync_to_store, - sync_to_store ? DELETE_COOKIE_EXPLICIT : - DELETE_COOKIE_DONT_RECORD /* Destruction. */); + sync_to_store + ? DELETE_COOKIE_EXPLICIT + : DELETE_COOKIE_DONT_RECORD /* Destruction. */); ++num_deleted; } @@ -1213,8 +1186,7 @@ int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin, if (cc->CreationDate() >= delete_begin && (delete_end.is_null() || cc->CreationDate() < delete_end)) { - InternalDeleteCookie(curit, - true, /*sync_to_store*/ + InternalDeleteCookie(curit, true, /*sync_to_store*/ DELETE_COOKIE_EXPLICIT); ++num_deleted; } @@ -1262,7 +1234,6 @@ int CookieMonster::DeleteAllForHost(const GURL& url) { return DeleteAllCreatedBetweenForHost(Time(), Time::Max(), url); } - bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { base::AutoLock autolock(lock_); @@ -1285,15 +1256,15 @@ void CookieMonster::SetCookieableSchemes(const char* const schemes[], DCHECK(!initialized_); cookieable_schemes_.clear(); - cookieable_schemes_.insert(cookieable_schemes_.end(), - schemes, schemes + num_schemes); + cookieable_schemes_.insert(cookieable_schemes_.end(), schemes, + schemes + num_schemes); } void CookieMonster::SetEnableFileScheme(bool accept) { // This assumes "file" is always at the end of the array. See the comment // above kDefaultCookieableSchemes. - int num_schemes = accept ? kDefaultCookieableSchemesCount : - kDefaultCookieableSchemesCount - 1; + int num_schemes = accept ? kDefaultCookieableSchemesCount + : kDefaultCookieableSchemesCount - 1; SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); } @@ -1381,8 +1352,7 @@ int CookieMonster::DeleteSessionCookies() { ++it; if (!cc->IsPersistent()) { - InternalDeleteCookie(curit, - true, /*sync_to_store*/ + InternalDeleteCookie(curit, true, /*sync_to_store*/ DELETE_COOKIE_EXPIRED); ++num_deleted; } @@ -1467,7 +1437,7 @@ void CookieMonster::OnKeyLoaded(const std::string& key, // This function does its own separate locking. StoreLoadedCookies(cookies); - std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key; + std::deque<scoped_refptr<CookieMonsterTask>> tasks_pending_for_key; // We need to do this repeatedly until no more tasks were added to the queue // during the period where we release the lock. @@ -1478,8 +1448,9 @@ void CookieMonster::OnKeyLoaded(const std::string& key, FROM_HERE_WITH_EXPLICIT_FUNCTION("456373 CookieMonster::OnKeyLoaded1")); { base::AutoLock autolock(lock_); - std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > > - ::iterator it = tasks_pending_for_key_.find(key); + std::map<std::string, + std::deque<scoped_refptr<CookieMonsterTask>>>::iterator it = + tasks_pending_for_key_.find(key); if (it == tasks_pending_for_key_.end()) { keys_loaded_.insert(key); return; @@ -1531,15 +1502,15 @@ void CookieMonster::StoreLoadedCookies( if (ContainsControlCharacter((*it)->Name()) || ContainsControlCharacter((*it)->Value())) { - cookies_with_control_chars.push_back(inserted); + cookies_with_control_chars.push_back(inserted); } } else { - LOG(ERROR) << base::StringPrintf("Found cookies with duplicate creation " - "times in backing store: " - "{name='%s', domain='%s', path='%s'}", - (*it)->Name().c_str(), - (*it)->Domain().c_str(), - (*it)->Path().c_str()); + LOG(ERROR) << base::StringPrintf( + "Found cookies with duplicate creation " + "times in backing store: " + "{name='%s', domain='%s', path='%s'}", + (*it)->Name().c_str(), (*it)->Domain().c_str(), + (*it)->Path().c_str()); // We've been given ownership of the cookie and are throwing it // away; reclaim the space. delete (*it); @@ -1610,10 +1581,9 @@ void CookieMonster::EnsureCookiesMapIsValid() { histogram_cookie_deletion_cause_->Add(num_duplicates_trimmed); } -int CookieMonster::TrimDuplicateCookiesForKey( - const std::string& key, - CookieMap::iterator begin, - CookieMap::iterator end) { +int CookieMonster::TrimDuplicateCookiesForKey(const std::string& key, + CookieMap::iterator begin, + CookieMap::iterator end) { lock_.AssertAcquired(); // Set of cookies ordered by creation time. @@ -1632,8 +1602,7 @@ int CookieMonster::TrimDuplicateCookiesForKey( DCHECK_EQ(key, it->first); CanonicalCookie* cookie = it->second; - CookieSignature signature(cookie->Name(), cookie->Domain(), - cookie->Path()); + CookieSignature signature(cookie->Name(), cookie->Domain(), cookie->Path()); CookieSet& set = equivalent_cookies[signature]; // We found a duplicate! @@ -1643,8 +1612,8 @@ int CookieMonster::TrimDuplicateCookiesForKey( // We save the iterator into |cookies_| rather than the actual cookie // pointer, since we may need to delete it later. bool insert_success = set.insert(it).second; - DCHECK(insert_success) << - "Duplicate creation times found in duplicate cookie name scan."; + DCHECK(insert_success) + << "Duplicate creation times found in duplicate cookie name scan."; } // If there were no duplicates, we are done! @@ -1657,8 +1626,7 @@ int CookieMonster::TrimDuplicateCookiesForKey( // Otherwise, delete all the duplicate cookies, both from our in-memory store // and from the backing store. for (EquivalenceMap::iterator it = equivalent_cookies.begin(); - it != equivalent_cookies.end(); - ++it) { + it != equivalent_cookies.end(); ++it) { const CookieSignature& signature = it->first; CookieSet& dupes = it->second; @@ -1673,17 +1641,13 @@ int CookieMonster::TrimDuplicateCookiesForKey( LOG(ERROR) << base::StringPrintf( "Found %d duplicate cookies for host='%s', " "with {name='%s', domain='%s', path='%s'}", - static_cast<int>(dupes.size()), - key.c_str(), - signature.name.c_str(), - signature.domain.c_str(), - signature.path.c_str()); + static_cast<int>(dupes.size()), key.c_str(), signature.name.c_str(), + signature.domain.c_str(), signature.path.c_str()); // Remove all the cookies identified by |dupes|. It is valid to delete our // list of iterators one at a time, since |cookies_| is a multimap (they // don't invalidate existing iterators following deletion). - for (CookieSet::iterator dupes_it = dupes.begin(); - dupes_it != dupes.end(); + for (CookieSet::iterator dupes_it = dupes.begin(); dupes_it != dupes.end(); ++dupes_it) { InternalDeleteCookie(*dupes_it, true, DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE); @@ -1695,8 +1659,11 @@ int CookieMonster::TrimDuplicateCookiesForKey( } // Note: file must be the last scheme. -const char* const CookieMonster::kDefaultCookieableSchemes[] = - { "http", "https", "ws", "wss", "file" }; +const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", + "https", + "ws", + "wss", + "file"}; const int CookieMonster::kDefaultCookieableSchemesCount = arraysize(kDefaultCookieableSchemes); @@ -1722,8 +1689,8 @@ void CookieMonster::FindCookiesForHostAndDomain( // Can just dispatch to FindCookiesForKey const std::string key(GetKey(url.host())); - FindCookiesForKey(key, url, options, current_time, - update_access_time, cookies); + FindCookiesForKey(key, url, options, current_time, update_access_time, + cookies); } void CookieMonster::FindCookiesForKey(const std::string& key, @@ -1735,7 +1702,7 @@ void CookieMonster::FindCookiesForKey(const std::string& key, lock_.AssertAcquired(); for (CookieMapItPair its = cookies_.equal_range(key); - its.first != its.second; ) { + its.first != its.second;) { CookieMap::iterator curit = its.first; CanonicalCookie* cc = curit->second; ++its.first; @@ -1770,7 +1737,7 @@ bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, bool found_equivalent_cookie = false; bool skipped_httponly = false; for (CookieMapItPair its = cookies_.equal_range(key); - its.first != its.second; ) { + its.first != its.second;) { CookieMap::iterator curit = its.first; CanonicalCookie* cc = curit->second; ++its.first; @@ -1778,13 +1745,14 @@ bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, if (ecc.IsEquivalent(*cc)) { // We should never have more than one equivalent cookie, since they should // overwrite each other. - CHECK(!found_equivalent_cookie) << - "Duplicate equivalent cookies found, cookie store is corrupted."; + CHECK(!found_equivalent_cookie) + << "Duplicate equivalent cookies found, cookie store is corrupted."; if (skip_httponly && cc->IsHttpOnly()) { skipped_httponly = true; } else { - InternalDeleteCookie(curit, true, already_expired ? - DELETE_COOKIE_EXPIRED_OVERWRITE : DELETE_COOKIE_OVERWRITE); + InternalDeleteCookie(curit, true, already_expired + ? DELETE_COOKIE_EXPIRED_OVERWRITE + : DELETE_COOKIE_OVERWRITE); } found_equivalent_cookie = true; } @@ -1804,8 +1772,8 @@ CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( CookieMap::iterator inserted = cookies_.insert(CookieMap::value_type(key, cc)); if (delegate_.get()) { - delegate_->OnCookieChanged( - *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); + delegate_->OnCookieChanged(*cc, false, + CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); } RunCallbacks(*cc, false); @@ -1849,8 +1817,8 @@ bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, return false; } - VLOG(kVlogSetCookies) << "SetCookie() key: " << key << " cc: " - << (*cc)->DebugString(); + VLOG(kVlogSetCookies) << "SetCookie() key: " << key + << " cc: " << (*cc)->DebugString(); // Realize that we might be setting an expired cookie, and the only point // was to delete the cookie which we've already done. @@ -1935,21 +1903,19 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, // Domain expiry behavior is unchanged by key/expiry scheme (the // meaning of the key is different, but that's not visible to this routine). -int CookieMonster::GarbageCollect(const Time& current, - const std::string& key) { +int CookieMonster::GarbageCollect(const Time& current, const std::string& key) { lock_.AssertAcquired(); int num_deleted = 0; - Time safe_date( - Time::Now() - TimeDelta::FromDays(kSafeFromGlobalPurgeDays)); + Time safe_date(Time::Now() - TimeDelta::FromDays(kSafeFromGlobalPurgeDays)); // Collect garbage for this key, minding cookie priorities. if (cookies_.count(key) > kDomainMaxCookies) { VLOG(kVlogGarbageCollection) << "GarbageCollect() key: " << key; CookieItVector cookie_its; - num_deleted += GarbageCollectExpired( - current, cookies_.equal_range(key), &cookie_its); + num_deleted += + GarbageCollectExpired(current, cookies_.equal_range(key), &cookie_its); if (cookie_its.size() > kDomainMaxCookies) { VLOG(kVlogGarbageCollection) << "Deep Garbage Collect domain."; size_t purge_goal = @@ -1962,15 +1928,13 @@ int CookieMonster::GarbageCollect(const Time& current, // Schematic: [MLLHMHHLMM] => [LLL|MMMM|HHH], with 4 boundaries. it_bdd[0] = cookie_its.begin(); it_bdd[3] = cookie_its.end(); - it_bdd[1] = PartitionCookieByPriority(it_bdd[0], it_bdd[3], - COOKIE_PRIORITY_LOW); + it_bdd[1] = + PartitionCookieByPriority(it_bdd[0], it_bdd[3], COOKIE_PRIORITY_LOW); it_bdd[2] = PartitionCookieByPriority(it_bdd[1], it_bdd[3], COOKIE_PRIORITY_MEDIUM); - size_t quota[3] = { - kDomainCookiesQuotaLow, - kDomainCookiesQuotaMedium, - kDomainCookiesQuotaHigh - }; + size_t quota[3] = {kDomainCookiesQuotaLow, + kDomainCookiesQuotaMedium, + kDomainCookiesQuotaHigh}; // Purge domain cookies in 3 rounds. // Round 1: consider low-priority cookies only: evict least-recently @@ -2000,15 +1964,11 @@ int CookieMonster::GarbageCollect(const Time& current, LowerBoundAccessDate(it_purge_begin, it_purge_end, safe_date); // Delete cookies accessed before |safe_date|. num_deleted += GarbageCollectDeleteRange( - current, - DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE, - it_purge_begin, + current, DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE, it_purge_begin, it_purge_middle); // Delete cookies accessed on or after |safe_date|. num_deleted += GarbageCollectDeleteRange( - current, - DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE, - it_purge_middle, + current, DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE, it_purge_middle, it_purge_end); it_purge_begin = it_purge_end; } @@ -2018,8 +1978,7 @@ int CookieMonster::GarbageCollect(const Time& current, // Collect garbage for everything. With firefox style we want to preserve // cookies accessed in kSafeFromGlobalPurgeDays, otherwise evict. - if (cookies_.size() > kMaxCookies && - earliest_access_time_ < safe_date) { + if (cookies_.size() > kMaxCookies && earliest_access_time_ < safe_date) { VLOG(kVlogGarbageCollection) << "GarbageCollect() everything"; CookieItVector cookie_its; num_deleted += GarbageCollectExpired( @@ -2035,16 +1994,12 @@ int CookieMonster::GarbageCollect(const Time& current, SortLeastRecentlyAccessed(cookie_its.begin(), cookie_its.end(), purge_goal); // Find boundary to cookies older than safe_date. - CookieItVector::iterator global_purge_it = - LowerBoundAccessDate(cookie_its.begin(), - cookie_its.begin() + purge_goal, - safe_date); + CookieItVector::iterator global_purge_it = LowerBoundAccessDate( + cookie_its.begin(), cookie_its.begin() + purge_goal, safe_date); // Only delete the old cookies. - num_deleted += GarbageCollectDeleteRange( - current, - DELETE_COOKIE_EVICTED_GLOBAL, - cookie_its.begin(), - global_purge_it); + num_deleted += + GarbageCollectDeleteRange(current, DELETE_COOKIE_EVICTED_GLOBAL, + cookie_its.begin(), global_purge_it); // Set access day to the oldest cookie that wasn't deleted. earliest_access_time_ = (*global_purge_it)->second->LastAccessDate(); } @@ -2053,10 +2008,9 @@ int CookieMonster::GarbageCollect(const Time& current, return num_deleted; } -int CookieMonster::GarbageCollectExpired( - const Time& current, - const CookieMapItPair& itpair, - CookieItVector* cookie_its) { +int CookieMonster::GarbageCollectExpired(const Time& current, + const CookieMapItPair& itpair, + CookieItVector* cookie_its) { if (keep_expired_cookies_) return 0; @@ -2078,11 +2032,10 @@ int CookieMonster::GarbageCollectExpired( return num_deleted; } -int CookieMonster::GarbageCollectDeleteRange( - const Time& current, - DeletionCause cause, - CookieItVector::iterator it_begin, - CookieItVector::iterator it_end) { +int CookieMonster::GarbageCollectDeleteRange(const Time& current, + DeletionCause cause, + CookieItVector::iterator it_begin, + CookieItVector::iterator it_end) { for (CookieItVector::iterator it = it_begin; it != it_end; it++) { histogram_evicted_last_access_minutes_->Add( (current - (*it)->second->LastAccessDate()).InMinutes()); @@ -2146,8 +2099,8 @@ bool CookieMonster::HasCookieableScheme(const GURL& url) { } // The scheme didn't match any in our whitelist. - VLOG(kVlogPerCookieMonster) << "WARNING: Unsupported cookie scheme: " - << url.scheme(); + VLOG(kVlogPerCookieMonster) + << "WARNING: Unsupported cookie scheme: " << url.scheme(); return false; } @@ -2176,7 +2129,7 @@ void CookieMonster::RecordPeriodicStats(const base::Time& current_time) { TimeTicks beginning_of_time(TimeTicks::Now()); for (CookieMap::const_iterator it_key = cookies_.begin(); - it_key != cookies_.end(); ) { + it_key != cookies_.end();) { const std::string& key(it_key->first); int key_count = 0; @@ -2199,9 +2152,9 @@ void CookieMonster::RecordPeriodicStats(const base::Time& current_time) { it_key = its_cookies.second; } - VLOG(kVlogPeriodic) - << "Time for recording cookie stats (us): " - << (TimeTicks::Now() - beginning_of_time).InMicroseconds(); + VLOG(kVlogPeriodic) << "Time for recording cookie stats (us): " + << (TimeTicks::Now() - beginning_of_time) + .InMicroseconds(); last_statistic_record_time_ = current_time; } @@ -2232,55 +2185,49 @@ void CookieMonster::RecordPeriodicStats(const base::Time& current_time) { void CookieMonster::InitializeHistograms() { // From UMA_HISTOGRAM_CUSTOM_COUNTS histogram_expiration_duration_minutes_ = base::Histogram::FactoryGet( - "Cookie.ExpirationDurationMinutes", - 1, kMinutesInTenYears, 50, + "Cookie.ExpirationDurationMinutes", 1, kMinutesInTenYears, 50, base::Histogram::kUmaTargetedHistogramFlag); histogram_between_access_interval_minutes_ = base::Histogram::FactoryGet( - "Cookie.BetweenAccessIntervalMinutes", - 1, kMinutesInTenYears, 50, + "Cookie.BetweenAccessIntervalMinutes", 1, kMinutesInTenYears, 50, base::Histogram::kUmaTargetedHistogramFlag); histogram_evicted_last_access_minutes_ = base::Histogram::FactoryGet( - "Cookie.EvictedLastAccessMinutes", - 1, kMinutesInTenYears, 50, + "Cookie.EvictedLastAccessMinutes", 1, kMinutesInTenYears, 50, base::Histogram::kUmaTargetedHistogramFlag); histogram_count_ = base::Histogram::FactoryGet( - "Cookie.Count", 1, 4000, 50, - base::Histogram::kUmaTargetedHistogramFlag); - histogram_domain_count_ = base::Histogram::FactoryGet( - "Cookie.DomainCount", 1, 4000, 50, - base::Histogram::kUmaTargetedHistogramFlag); - histogram_etldp1_count_ = base::Histogram::FactoryGet( - "Cookie.Etldp1Count", 1, 4000, 50, - base::Histogram::kUmaTargetedHistogramFlag); - histogram_domain_per_etldp1_count_ = base::Histogram::FactoryGet( - "Cookie.DomainPerEtldp1Count", 1, 4000, 50, - base::Histogram::kUmaTargetedHistogramFlag); + "Cookie.Count", 1, 4000, 50, base::Histogram::kUmaTargetedHistogramFlag); + histogram_domain_count_ = + base::Histogram::FactoryGet("Cookie.DomainCount", 1, 4000, 50, + base::Histogram::kUmaTargetedHistogramFlag); + histogram_etldp1_count_ = + base::Histogram::FactoryGet("Cookie.Etldp1Count", 1, 4000, 50, + base::Histogram::kUmaTargetedHistogramFlag); + histogram_domain_per_etldp1_count_ = + base::Histogram::FactoryGet("Cookie.DomainPerEtldp1Count", 1, 4000, 50, + base::Histogram::kUmaTargetedHistogramFlag); // From UMA_HISTOGRAM_COUNTS_10000 & UMA_HISTOGRAM_CUSTOM_COUNTS - histogram_number_duplicate_db_cookies_ = base::Histogram::FactoryGet( - "Net.NumDuplicateCookiesInDb", 1, 10000, 50, - base::Histogram::kUmaTargetedHistogramFlag); + histogram_number_duplicate_db_cookies_ = + base::Histogram::FactoryGet("Net.NumDuplicateCookiesInDb", 1, 10000, 50, + base::Histogram::kUmaTargetedHistogramFlag); // From UMA_HISTOGRAM_ENUMERATION histogram_cookie_deletion_cause_ = base::LinearHistogram::FactoryGet( - "Cookie.DeletionCause", 1, - DELETE_COOKIE_LAST_ENTRY - 1, DELETE_COOKIE_LAST_ENTRY, - base::Histogram::kUmaTargetedHistogramFlag); + "Cookie.DeletionCause", 1, DELETE_COOKIE_LAST_ENTRY - 1, + DELETE_COOKIE_LAST_ENTRY, base::Histogram::kUmaTargetedHistogramFlag); // From UMA_HISTOGRAM_{CUSTOM_,}TIMES histogram_time_blocked_on_load_ = base::Histogram::FactoryTimeGet( - "Cookie.TimeBlockedOnLoad", - base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(1), - 50, base::Histogram::kUmaTargetedHistogramFlag); + "Cookie.TimeBlockedOnLoad", base::TimeDelta::FromMilliseconds(1), + base::TimeDelta::FromMinutes(1), 50, + base::Histogram::kUmaTargetedHistogramFlag); } - // The system resolution is not high enough, so we can have multiple // set cookies that result in the same system time. When this happens, we // increment by one Time unit. Let's hope computers don't get too fast. Time CookieMonster::CurrentTime() { - return std::max(Time::Now(), - Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); + return std::max(Time::Now(), Time::FromInternalValue( + last_time_seen_.ToInternalValue() + 1)); } bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster( @@ -2295,8 +2242,7 @@ bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster( return false; for (CookieMapItPair its = cookies_.equal_range(key); - its.first != its.second; - ++its.first) { + its.first != its.second; ++its.first) { CookieMap::iterator curit = its.first; CanonicalCookie* cc = curit->second; @@ -2317,8 +2263,7 @@ bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster( // Store the copied cookies in |other|. for (ScopedVector<CanonicalCookie>::const_iterator it = duplicated_cookies.begin(); - it != duplicated_cookies.end(); - ++it) { + it != duplicated_cookies.end(); ++it) { other->InternalInsertCookie(key, *it, true); } @@ -2335,10 +2280,9 @@ bool CookieMonster::loaded() { } scoped_ptr<CookieStore::CookieChangedSubscription> -CookieMonster::AddCallbackForCookie( - const GURL& gurl, - const std::string& name, - const CookieChangedCallback& callback) { +CookieMonster::AddCallbackForCookie(const GURL& gurl, + const std::string& name, + const CookieChangedCallback& callback) { base::AutoLock autolock(lock_); std::pair<GURL, std::string> key(gurl, name); if (hook_map_.count(key) == 0) |