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

Unified Diff: ios/net/cookies/cookie_store_ios.mm

Issue 1701063002: CookieStore: Remove reference counting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@threadsafe
Patch Set: merge Created 4 years, 9 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
« no previous file with comments | « ios/net/cookies/cookie_store_ios.h ('k') | ios/net/cookies/cookie_store_ios_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/net/cookies/cookie_store_ios.mm
diff --git a/ios/net/cookies/cookie_store_ios.mm b/ios/net/cookies/cookie_store_ios.mm
index 8be649ae81d9ef0b9cd7166fb3e564fdbc7faa05..2d3ebdac9f6dfc07d9b737640829253c5bcf79a3 100644
--- a/ios/net/cookies/cookie_store_ios.mm
+++ b/ios/net/cookies/cookie_store_ios.mm
@@ -292,20 +292,27 @@ CookieStoreIOS::CookieStoreIOS(
CookieStoreIOS::CookieStoreIOS(
net::CookieMonster::PersistentCookieStore* persistent_store,
NSHTTPCookieStorage* system_store)
- : system_store_(system_store),
+ : cookie_monster_(new net::CookieMonster(persistent_store, nullptr)),
+ system_store_(system_store),
creation_time_manager_(new CookieCreationTimeManager),
metrics_enabled_(false),
flush_delay_(base::TimeDelta::FromSeconds(10)),
synchronization_state_(NOT_SYNCHRONIZED),
- cookie_cache_(new CookieCache()) {
+ cookie_cache_(new CookieCache()),
+ weak_factory_(this) {
DCHECK(system_store);
NotificationTrampoline::GetInstance()->AddObserver(this);
- cookie_monster_ = new net::CookieMonster(persistent_store, nullptr);
+
cookie_monster_->SetPersistSessionCookies(true);
cookie_monster_->SetForceKeepSessionState();
}
+CookieStoreIOS::~CookieStoreIOS() {
+ NotificationTrampoline::GetInstance()->RemoveObserver(this);
+ STLDeleteContainerPairSecondPointers(hook_map_.begin(), hook_map_.end());
+}
+
// static
void CookieStoreIOS::SetCookiePolicy(CookiePolicy setting) {
NSHTTPCookieAcceptPolicy policy = (setting == ALLOW)
@@ -320,7 +327,7 @@ void CookieStoreIOS::SetCookiePolicy(CookiePolicy setting) {
}
// static
-CookieStoreIOS* CookieStoreIOS::CreateCookieStore(
+scoped_ptr<CookieStoreIOS> CookieStoreIOS::CreateCookieStore(
NSHTTPCookieStorage* cookie_storage) {
DCHECK(cookie_storage);
// TODO(huey): Update this when CrNet supports multiple cookie jars.
@@ -328,7 +335,8 @@ CookieStoreIOS* CookieStoreIOS::CreateCookieStore(
// Create a cookie store with no persistent store backing. Then, populate
// it from the system's cookie jar.
- CookieStoreIOS* cookie_store = new CookieStoreIOS(nullptr, cookie_storage);
+ scoped_ptr<CookieStoreIOS> cookie_store(
+ new CookieStoreIOS(nullptr, cookie_storage));
cookie_store->synchronization_state_ = SYNCHRONIZED;
cookie_store->FlushStore(base::Closure());
return cookie_store;
@@ -378,8 +386,9 @@ void CookieStoreIOS::SetCookieWithOptionsAsync(
break;
case SYNCHRONIZING:
tasks_pending_synchronization_.push_back(
- base::Bind(&CookieStoreIOS::SetCookieWithOptionsAsync, this, url,
- cookie_line, options, WrapSetCallback(callback)));
+ base::Bind(&CookieStoreIOS::SetCookieWithOptionsAsync,
+ weak_factory_.GetWeakPtr(), url, cookie_line, options,
+ WrapSetCallback(callback)));
break;
case SYNCHRONIZED:
// The exclude_httponly() option would only be used by a javascript
@@ -454,11 +463,12 @@ void CookieStoreIOS::SetCookieWithDetailsAsync(
priority, WrapSetCallback(callback));
break;
case SYNCHRONIZING:
- tasks_pending_synchronization_.push_back(base::Bind(
- &CookieStoreIOS::SetCookieWithDetailsAsync, this, url, name, value,
- domain, path, creation_time, expiration_time, last_access_time,
- secure, http_only, same_site, enforce_strict_secure, priority,
- WrapSetCallback(callback)));
+ tasks_pending_synchronization_.push_back(
+ base::Bind(&CookieStoreIOS::SetCookieWithDetailsAsync,
+ weak_factory_.GetWeakPtr(), url, name, value, domain, path,
+ creation_time, expiration_time, last_access_time, secure,
+ http_only, same_site, enforce_strict_secure, priority,
+ WrapSetCallback(callback)));
break;
case SYNCHRONIZED:
// If cookies are not allowed, they are stashed in the CookieMonster, and
@@ -509,8 +519,8 @@ void CookieStoreIOS::GetCookiesWithOptionsAsync(
break;
case SYNCHRONIZING:
tasks_pending_synchronization_.push_back(
- base::Bind(&CookieStoreIOS::GetCookiesWithOptionsAsync, this, url,
- options, callback));
+ base::Bind(&CookieStoreIOS::GetCookiesWithOptionsAsync,
+ weak_factory_.GetWeakPtr(), url, options, callback));
break;
case SYNCHRONIZED:
// If cookies are not allowed, they are stashed in the CookieMonster, and
@@ -542,8 +552,8 @@ void CookieStoreIOS::GetCookieListWithOptionsAsync(
break;
case SYNCHRONIZING:
tasks_pending_synchronization_.push_back(
- base::Bind(&CookieStoreIOS::GetCookieListWithOptionsAsync, this, url,
- options, callback));
+ base::Bind(&CookieStoreIOS::GetCookieListWithOptionsAsync,
+ weak_factory_.GetWeakPtr(), url, options, callback));
break;
case SYNCHRONIZED:
if (!SystemCookiesAllowed()) {
@@ -573,8 +583,9 @@ void CookieStoreIOS::GetAllCookiesAsync(const GetCookieListCallback& callback) {
cookie_monster_->GetAllCookiesAsync(callback);
break;
case SYNCHRONIZING:
- tasks_pending_synchronization_.push_back(base::Bind(
- &CookieStoreIOS::GetAllCookiesAsync, this, callback));
+ tasks_pending_synchronization_.push_back(
+ base::Bind(&CookieStoreIOS::GetAllCookiesAsync,
+ weak_factory_.GetWeakPtr(), callback));
break;
case SYNCHRONIZED:
if (!SystemCookiesAllowed()) {
@@ -606,9 +617,9 @@ void CookieStoreIOS::DeleteCookieAsync(const GURL& url,
WrapClosure(callback));
break;
case SYNCHRONIZING:
- tasks_pending_synchronization_.push_back(
- base::Bind(&CookieStoreIOS::DeleteCookieAsync, this, url, cookie_name,
- WrapClosure(callback)));
+ tasks_pending_synchronization_.push_back(base::Bind(
+ &CookieStoreIOS::DeleteCookieAsync, weak_factory_.GetWeakPtr(), url,
+ cookie_name, WrapClosure(callback)));
break;
case SYNCHRONIZED:
NSArray* cookies = GetCookiesForURL(system_store_,
@@ -637,9 +648,9 @@ void CookieStoreIOS::DeleteCanonicalCookieAsync(
WrapDeleteCallback(callback));
break;
case SYNCHRONIZING:
- tasks_pending_synchronization_.push_back(
- base::Bind(&CookieStoreIOS::DeleteCanonicalCookieAsync, this, cookie,
- WrapDeleteCallback(callback)));
+ tasks_pending_synchronization_.push_back(base::Bind(
+ &CookieStoreIOS::DeleteCanonicalCookieAsync,
+ weak_factory_.GetWeakPtr(), cookie, WrapDeleteCallback(callback)));
break;
case SYNCHRONIZED:
// This relies on the fact cookies are given unique creation dates.
@@ -665,8 +676,9 @@ void CookieStoreIOS::DeleteAllCreatedBetweenAsync(
break;
case SYNCHRONIZING:
tasks_pending_synchronization_.push_back(
- base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenAsync, this,
- delete_begin, delete_end, WrapDeleteCallback(callback)));
+ base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenAsync,
+ weak_factory_.GetWeakPtr(), delete_begin, delete_end,
+ WrapDeleteCallback(callback)));
break;
case SYNCHRONIZED:
CookieFilterFunction filter =
@@ -692,9 +704,10 @@ void CookieStoreIOS::DeleteAllCreatedBetweenForHostAsync(
delete_begin, delete_end, url, WrapDeleteCallback(callback));
break;
case SYNCHRONIZING:
- tasks_pending_synchronization_.push_back(base::Bind(
- &CookieStoreIOS::DeleteAllCreatedBetweenForHostAsync, this,
- delete_begin, delete_end, url, WrapDeleteCallback(callback)));
+ tasks_pending_synchronization_.push_back(
+ base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenForHostAsync,
+ weak_factory_.GetWeakPtr(), delete_begin, delete_end, url,
+ WrapDeleteCallback(callback)));
break;
case SYNCHRONIZED:
NSString* host = base::SysUTF8ToNSString(url.host());
@@ -717,8 +730,8 @@ void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) {
break;
case SYNCHRONIZING:
tasks_pending_synchronization_.push_back(
- base::Bind(&CookieStoreIOS::DeleteSessionCookiesAsync, this,
- WrapDeleteCallback(callback)));
+ base::Bind(&CookieStoreIOS::DeleteSessionCookiesAsync,
+ weak_factory_.GetWeakPtr(), WrapDeleteCallback(callback)));
break;
case SYNCHRONIZED:
CookieFilterFunction filter = base::Bind(&IsCookieSessionCookie);
@@ -740,14 +753,6 @@ void CookieStoreIOS::FlushStore(const base::Closure& closure) {
}
#pragma mark -
-#pragma mark Protected methods
-
-CookieStoreIOS::~CookieStoreIOS() {
- NotificationTrampoline::GetInstance()->RemoveObserver(this);
- STLDeleteContainerPairSecondPointers(hook_map_.begin(), hook_map_.end());
-}
-
-#pragma mark -
#pragma mark Private methods
void CookieStoreIOS::ClearSystemStore() {
@@ -777,8 +782,8 @@ void CookieStoreIOS::OnSystemCookiePolicyChanged() {
DCHECK(![[system_store_ cookies] count]);
DCHECK(synchronization_state_ != SYNCHRONIZING);
synchronization_state_ = SYNCHRONIZING;
- cookie_monster_->GetAllCookiesAsync(
- base::Bind(&CookieStoreIOS::AddCookiesToSystemStore, this));
+ cookie_monster_->GetAllCookiesAsync(base::Bind(
+ &CookieStoreIOS::AddCookiesToSystemStore, weak_factory_.GetWeakPtr()));
} else {
DCHECK_EQ(NSHTTPCookieAcceptPolicyNever, policy);
// FlushStore() does not write the cookies to disk when they are disabled.
@@ -832,7 +837,8 @@ void CookieStoreIOS::SetSynchronizedWithSystemStore(bool synchronized) {
synchronization_state_ = SYNCHRONIZING;
ClearSystemStore();
cookie_monster_->GetAllCookiesAsync(
- base::Bind(&CookieStoreIOS::AddCookiesToSystemStore, this));
+ base::Bind(&CookieStoreIOS::AddCookiesToSystemStore,
+ weak_factory_.GetWeakPtr()));
return;
} else {
// Copy the cookies from the global store to |cookie_monster_|.
@@ -970,7 +976,7 @@ void CookieStoreIOS::OnSystemCookiesChanged() {
return;
flush_closure_.Reset(base::Bind(&CookieStoreIOS::FlushStore,
- base::Unretained(this), base::Closure()));
+ weak_factory_.GetWeakPtr(), base::Closure()));
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, flush_closure_.callback(), flush_delay_);
}
@@ -1065,8 +1071,9 @@ void CookieStoreIOS::DidClearNSHTTPCookieStorageCookies(
DCHECK(client);
auto sequenced_task_runner = client->GetTaskRunner();
DCHECK(sequenced_task_runner);
- auto callback = base::Bind(&CookieStoreIOS::DidClearBinaryCookiesFileCookies,
- this, delete_callback, num_deleted);
+ auto callback =
+ base::Bind(&CookieStoreIOS::DidClearBinaryCookiesFileCookies,
+ weak_factory_.GetWeakPtr(), delete_callback, num_deleted);
sequenced_task_runner.get()->PostTaskAndReply(
FROM_HERE, base::Bind(&ClearAllCookiesFromBinaryCookiesFile), callback);
}
@@ -1087,8 +1094,8 @@ void CookieStoreIOS::UpdateCachesFromCookieMonster() {
DCHECK(thread_checker_.CalledOnValidThread());
for (const auto& hook_map_entry : hook_map_) {
std::pair<GURL, std::string> key = hook_map_entry.first;
- GetCookieListCallback callback =
- base::Bind(&CookieStoreIOS::GotCookieListFor, this, key);
+ GetCookieListCallback callback = base::Bind(
+ &CookieStoreIOS::GotCookieListFor, weak_factory_.GetWeakPtr(), key);
cookie_monster_->GetAllCookiesForURLAsync(key.first, callback);
}
}
@@ -1131,18 +1138,21 @@ CookieStoreIOS::CanonicalCookieListFromSystemCookies(NSArray* cookies) {
CookieStoreIOS::SetCookiesCallback CookieStoreIOS::WrapSetCallback(
const SetCookiesCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- return base::Bind(&CookieStoreIOS::UpdateCachesAfterSet, this, callback);
+ return base::Bind(&CookieStoreIOS::UpdateCachesAfterSet,
+ weak_factory_.GetWeakPtr(), callback);
}
CookieStoreIOS::DeleteCallback CookieStoreIOS::WrapDeleteCallback(
const DeleteCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- return base::Bind(&CookieStoreIOS::UpdateCachesAfterDelete, this, callback);
+ return base::Bind(&CookieStoreIOS::UpdateCachesAfterDelete,
+ weak_factory_.GetWeakPtr(), callback);
}
base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, this, callback);
+ return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure,
+ weak_factory_.GetWeakPtr(), callback);
}
} // namespace net
« no previous file with comments | « ios/net/cookies/cookie_store_ios.h ('k') | ios/net/cookies/cookie_store_ios_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698