Commit e205bc26 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Fetch] Respond to service worker database deletion.

by abandoning all ongoing fetches for the storage partition.

Bug: 841385
Change-Id: I6fc990304272832fe0e8d993281a0aa06d083e75
Reviewed-on: https://chromium-review.googlesource.com/1087065
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566039}
parent 8f5c116d
...@@ -183,10 +183,8 @@ void BackgroundFetchContext::UpdateUI( ...@@ -183,10 +183,8 @@ void BackgroundFetchContext::UpdateUI(
title, std::move(callback))); title, std::move(callback)));
} }
void BackgroundFetchContext::OnRegistrationDeleted( void BackgroundFetchContext::AbandonFetches(
int64_t service_worker_registration_id, int64_t service_worker_registration_id) {
const GURL& pattern) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// Abandon all active fetches associated with this service worker. // Abandon all active fetches associated with this service worker.
// BackgroundFetchJobController::Abort() will eventually lead to deletion of // BackgroundFetchJobController::Abort() will eventually lead to deletion of
// the controller from job_controllers, hence we can't use a range based // the controller from job_controllers, hence we can't use a range based
...@@ -195,9 +193,12 @@ void BackgroundFetchContext::OnRegistrationDeleted( ...@@ -195,9 +193,12 @@ void BackgroundFetchContext::OnRegistrationDeleted(
/* no_increment */) { /* no_increment */) {
auto saved_iter = iter; auto saved_iter = iter;
iter++; iter++;
if (saved_iter->second->registration_id() if (service_worker_registration_id ==
blink::mojom::kInvalidServiceWorkerRegistrationId ||
saved_iter->second->registration_id()
.service_worker_registration_id() == .service_worker_registration_id() ==
service_worker_registration_id) { service_worker_registration_id) {
DCHECK(saved_iter->second);
saved_iter->second->Abort( saved_iter->second->Abort(
BackgroundFetchReasonToAbort::SERVICE_WORKER_UNAVAILABLE); BackgroundFetchReasonToAbort::SERVICE_WORKER_UNAVAILABLE);
} }
...@@ -205,7 +206,9 @@ void BackgroundFetchContext::OnRegistrationDeleted( ...@@ -205,7 +206,9 @@ void BackgroundFetchContext::OnRegistrationDeleted(
for (auto iter = fetch_callbacks_.begin(); iter != fetch_callbacks_.end(); for (auto iter = fetch_callbacks_.begin(); iter != fetch_callbacks_.end();
/* no increment */) { /* no increment */) {
if (iter->first.service_worker_registration_id() == if (service_worker_registration_id ==
blink::mojom::kInvalidServiceWorkerRegistrationId ||
iter->first.service_worker_registration_id() ==
service_worker_registration_id) { service_worker_registration_id) {
DCHECK(iter->second); DCHECK(iter->second);
std::move(iter->second) std::move(iter->second)
...@@ -217,8 +220,16 @@ void BackgroundFetchContext::OnRegistrationDeleted( ...@@ -217,8 +220,16 @@ void BackgroundFetchContext::OnRegistrationDeleted(
} }
} }
void BackgroundFetchContext::OnRegistrationDeleted(
int64_t service_worker_registration_id,
const GURL& pattern) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
AbandonFetches(service_worker_registration_id);
}
void BackgroundFetchContext::OnStorageWiped() { void BackgroundFetchContext::OnStorageWiped() {
// TODO(nator): abort all active fetches for storage partition. DCHECK_CURRENTLY_ON(BrowserThread::IO);
AbandonFetches(blink::mojom::kInvalidServiceWorkerRegistrationId);
} }
void BackgroundFetchContext::DidUpdateStoredUI( void BackgroundFetchContext::DidUpdateStoredUI(
......
...@@ -205,6 +205,11 @@ class CONTENT_EXPORT BackgroundFetchContext ...@@ -205,6 +205,11 @@ class CONTENT_EXPORT BackgroundFetchContext
void SetDataManagerForTesting( void SetDataManagerForTesting(
std::unique_ptr<BackgroundFetchDataManager> data_manager); std::unique_ptr<BackgroundFetchDataManager> data_manager);
// Helper method to abandon ongoing fetches for a given service worker.
// Abandons all of them if |service_worker_registration_id| is set to
// blink::mojom::kInvalidServiceWorkerRegistrationId.
void AbandonFetches(int64_t service_worker_registration_id);
// |this| is owned, indirectly, by the BrowserContext. // |this| is owned, indirectly, by the BrowserContext.
BrowserContext* browser_context_; BrowserContext* browser_context_;
......
...@@ -297,9 +297,6 @@ TEST_F(BackgroundFetchJobControllerTest, Abort) { ...@@ -297,9 +297,6 @@ TEST_F(BackgroundFetchJobControllerTest, Abort) {
controller->StartRequest(requests[0]); controller->StartRequest(requests[0]);
controller->Abort(BackgroundFetchReasonToAbort::CANCELLED_FROM_UI); controller->Abort(BackgroundFetchReasonToAbort::CANCELLED_FROM_UI);
// Tell the delegate to abort the job as well so it doesn't send completed
// messages to the JobController.
delegate_->Abort(registration_id.unique_id());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -357,9 +354,28 @@ TEST_F(BackgroundFetchJobControllerTest, ServiceWorkerRegistrationDeleted) { ...@@ -357,9 +354,28 @@ TEST_F(BackgroundFetchJobControllerTest, ServiceWorkerRegistrationDeleted) {
context_->OnRegistrationDeleted(kExampleServiceWorkerRegistrationId, context_->OnRegistrationDeleted(kExampleServiceWorkerRegistrationId,
GURL("https://example.com/funny_cat.png")); GURL("https://example.com/funny_cat.png"));
// Tell the delegate to abort the job as well so it doesn't send completed base::RunLoop().RunUntilIdle();
// messages to the JobController.
delegate_->Abort(registration_id.unique_id()); EXPECT_EQ(JobCompletionStatus::kAborted,
request_manager_.GetCompletionStatus(registration_id));
}
TEST_F(BackgroundFetchJobControllerTest, ServiceWorkerDatabaseDeleted) {
BackgroundFetchRegistrationId registration_id;
auto requests = CreateRegistrationForRequests(
&registration_id, {{GURL("https://example.com/funny_cat.png"), "GET"}},
true /* auto_complete_requests */);
EXPECT_EQ(JobCompletionStatus::kRunning,
request_manager_.GetCompletionStatus(registration_id));
std::unique_ptr<BackgroundFetchJobController> controller =
CreateJobController(registration_id, requests.size());
AddControllerToContextMap(registration_id.unique_id(), std::move(controller));
context_->OnStorageWiped();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
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