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

Unified Diff: net/cookies/cookie_monster.cc

Issue 1701063002: CookieStore: Remove reference counting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@threadsafe
Patch Set: Fix leak Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: net/cookies/cookie_monster.cc
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc
index 01513f98194a66c73866dd1569b50ebf0eed8b08..13f128cec83451f887bf75d425f712440d737581 100644
--- a/net/cookies/cookie_monster.cc
+++ b/net/cookies/cookie_monster.cc
@@ -352,6 +352,20 @@ CookieMonster::CookieMonster(PersistentCookieStore* store,
kDefaultCookieableSchemes + kDefaultCookieableSchemesCount);
}
+CookieMonster::~CookieMonster() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // TODO(mmenke): Does it really make sense to run |delegate_| and
+ // CookieChanged callbacks when the CookieStore is destroyed?
+ for (CookieMap::iterator cookie_it = cookies_.begin();
+ cookie_it != cookies_.end();) {
+ CookieMap::iterator current_cookie_it = cookie_it;
+ ++cookie_it;
+ InternalDeleteCookie(current_cookie_it, false /* sync_to_store */,
+ DELETE_COOKIE_DONT_RECORD);
+ }
+}
+
// Task classes for queueing the coming request.
class CookieMonster::CookieMonsterTask
@@ -853,6 +867,7 @@ void CookieMonster::SetCookieWithDetailsAsync(
void CookieMonster::FlushStore(const base::Closure& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
+
if (initialized_ && store_.get())
store_->Flush(callback);
else if (!callback.is_null())
@@ -861,6 +876,7 @@ void CookieMonster::FlushStore(const base::Closure& callback) {
void CookieMonster::SetForceKeepSessionState() {
DCHECK(thread_checker_.CalledOnValidThread());
+
if (store_)
store_->SetForceKeepSessionState();
}
@@ -992,6 +1008,7 @@ CookieMonster::AddCallbackForCookie(const GURL& gurl,
const std::string& name,
const CookieChangedCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
+
std::pair<GURL, std::string> key(gurl, name);
if (hook_map_.count(key) == 0)
hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList());
@@ -999,18 +1016,6 @@ CookieMonster::AddCallbackForCookie(const GURL& gurl,
base::Bind(&RunAsync, base::ThreadTaskRunnerHandle::Get(), callback));
}
-CookieMonster::~CookieMonster() {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- for (CookieMap::iterator cookie_it = cookies_.begin();
- cookie_it != cookies_.end();) {
- CookieMap::iterator current_cookie_it = cookie_it;
- ++cookie_it;
- InternalDeleteCookie(current_cookie_it, false /* sync_to_store */,
- DELETE_COOKIE_DONT_RECORD);
- }
-}
-
bool CookieMonster::SetCookieWithDetails(const GURL& url,
const std::string& name,
const std::string& value,
@@ -2405,7 +2410,8 @@ void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie,
// Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they
// are guaranteed to not take long - they just post a RunAsync task back to
// the appropriate thread's message loop and return.
- // TODO(mmenke): Consider running these synchronously?
+ // TODO(mmenke): Consider running these synchronously, and/or cancelling them
+ // when the CookieMonster is destroyed?
for (CookieChangedHookMap::iterator it = hook_map_.begin();
it != hook_map_.end(); ++it) {
std::pair<GURL, std::string> key = it->first;

Powered by Google App Engine
This is Rietveld 408576698