Commit 77357f49 authored by mrefaat's avatar mrefaat Committed by Commit Bot

Fix Crash when closing incognito

WebSiteDataStore crashed during the destructing of WKHTTPCookieStore
The reason:
 WKHTTPCookieStore can't be deleted in IO Thread (undocumented behavior).
The solution:
 Make WKHTTPCookieStore instance in WKHTTPSystemCookieStore as weak, so
 it's not retained in WKHTTPSystemCookieStore and it's deleted/released
 when WebSiteDataStore is deleted.

Bug: 817460, 816879
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I15b384f41496df6d0af9c550b7b13e67a75d236b
Reviewed-on: https://chromium-review.googlesource.com/955547
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541973}
parent 491be184
...@@ -50,7 +50,10 @@ class API_AVAILABLE(ios(11.0)) WKHTTPSystemCookieStore ...@@ -50,7 +50,10 @@ class API_AVAILABLE(ios(11.0)) WKHTTPSystemCookieStore
net::SystemCookieStore::SystemCookieCallbackForCookies callback, net::SystemCookieStore::SystemCookieCallbackForCookies callback,
NSArray<NSHTTPCookie*>* cookies); NSArray<NSHTTPCookie*>* cookies);
WKHTTPCookieStore* cookie_store_; // cookie_store_ must be deleted in the UI thread, So by making it weak
// WKHTTPSystemCookieStore will not retain the WKHTTPCookieStore instance, and
// it will be deleted with the owning WKWebSiteDataStore.
__weak WKHTTPCookieStore* cookie_store_;
DISALLOW_COPY_AND_ASSIGN(WKHTTPSystemCookieStore); DISALLOW_COPY_AND_ASSIGN(WKHTTPSystemCookieStore);
}; };
......
...@@ -63,6 +63,8 @@ WKHTTPSystemCookieStore::~WKHTTPSystemCookieStore() = default; ...@@ -63,6 +63,8 @@ WKHTTPSystemCookieStore::~WKHTTPSystemCookieStore() = default;
void WKHTTPSystemCookieStore::GetCookiesForURLAsync( void WKHTTPSystemCookieStore::GetCookiesForURLAsync(
const GURL& url, const GURL& url,
SystemCookieCallbackForCookies callback) { SystemCookieCallbackForCookies callback) {
// This function shouldn't be called if cookie_store_ is deleted.
DCHECK(cookie_store_);
__block SystemCookieCallbackForCookies shared_callback = std::move(callback); __block SystemCookieCallbackForCookies shared_callback = std::move(callback);
GURL block_url = url; GURL block_url = url;
web::WebThread::PostTask( web::WebThread::PostTask(
...@@ -81,6 +83,8 @@ void WKHTTPSystemCookieStore::GetCookiesForURLAsync( ...@@ -81,6 +83,8 @@ void WKHTTPSystemCookieStore::GetCookiesForURLAsync(
void WKHTTPSystemCookieStore::GetAllCookiesAsync( void WKHTTPSystemCookieStore::GetAllCookiesAsync(
SystemCookieCallbackForCookies callback) { SystemCookieCallbackForCookies callback) {
// This function shouldn't be called if cookie_store_ is deleted.
DCHECK(cookie_store_);
__block SystemCookieCallbackForCookies shared_callback = std::move(callback); __block SystemCookieCallbackForCookies shared_callback = std::move(callback);
web::WebThread::PostTask( web::WebThread::PostTask(
web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{ web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
...@@ -93,6 +97,8 @@ void WKHTTPSystemCookieStore::GetAllCookiesAsync( ...@@ -93,6 +97,8 @@ void WKHTTPSystemCookieStore::GetAllCookiesAsync(
void WKHTTPSystemCookieStore::DeleteCookieAsync(NSHTTPCookie* cookie, void WKHTTPSystemCookieStore::DeleteCookieAsync(NSHTTPCookie* cookie,
SystemCookieCallback callback) { SystemCookieCallback callback) {
// This function shouldn't be called if cookie_store_ is deleted.
DCHECK(cookie_store_);
__block SystemCookieCallback shared_callback = std::move(callback); __block SystemCookieCallback shared_callback = std::move(callback);
NSHTTPCookie* block_cookie = cookie; NSHTTPCookie* block_cookie = cookie;
web::WebThread::PostTask( web::WebThread::PostTask(
...@@ -111,6 +117,8 @@ void WKHTTPSystemCookieStore::SetCookieAsync( ...@@ -111,6 +117,8 @@ void WKHTTPSystemCookieStore::SetCookieAsync(
NSHTTPCookie* cookie, NSHTTPCookie* cookie,
const base::Time* optional_creation_time, const base::Time* optional_creation_time,
SystemCookieCallback callback) { SystemCookieCallback callback) {
// cookies can't be set if cookie_store_ is deleted.
DCHECK(cookie_store_);
__block SystemCookieCallback shared_callback = std::move(callback); __block SystemCookieCallback shared_callback = std::move(callback);
NSHTTPCookie* block_cookie = cookie; NSHTTPCookie* block_cookie = cookie;
base::Time cookie_time = base::Time::Now(); base::Time cookie_time = base::Time::Now();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment