Commit 76e240cc authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[Background Fetch] Cleanup after large refactor.

Few more minor changes that didn't make it in cr/1297412.

Bug: 850512
Change-Id: I7a1070135aa4d10a238c8c12fd4a95ffeac34343
Reviewed-on: https://chromium-review.googlesource.com/c/1320130
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606026}
parent db720b4a
......@@ -107,6 +107,8 @@ void BackgroundFetchContext::GetDeveloperIdsForServiceWorker(
int64_t service_worker_registration_id,
const url::Origin& origin,
blink::mojom::BackgroundFetchService::GetDeveloperIdsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
data_manager_->GetDeveloperIdsForServiceWorker(service_worker_registration_id,
origin, std::move(callback));
}
......@@ -203,6 +205,7 @@ void BackgroundFetchContext::DidGetPermission(
std::move(fetch_callbacks_[registration_id])
.Run(blink::mojom::BackgroundFetchError::PERMISSION_DENIED,
base::nullopt);
fetch_callbacks_.erase(registration_id);
}
void BackgroundFetchContext::GetIconDisplaySize(
......@@ -277,10 +280,8 @@ void BackgroundFetchContext::DidGetMatchingRequests(
std::vector<BackgroundFetchSettledFetch> settled_fetches) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(crbug.com/863016): Update to 0u once we've stopped sending an
// uncached response.
if (error != blink::mojom::BackgroundFetchError::NONE)
DCHECK_EQ(settled_fetches.size(), 1u);
DCHECK(settled_fetches.empty());
std::move(callback).Run(std::move(settled_fetches));
}
......
......@@ -58,7 +58,7 @@ void BackgroundFetchDataManager::InitializeOnIOThread() {
cache_manager_ =
base::WrapRefCounted(cache_storage_context_->cache_manager());
// TODO(crbug.com/855199): Persist which registrations to cleanup on startup.
// Delete inactive registrations still in the DB.
Cleanup();
DCHECK(cache_manager_);
......@@ -197,7 +197,7 @@ void BackgroundFetchDataManager::AddDatabaseTask(
return;
database_tasks_.push(std::move(task));
if (database_tasks_.size() == 1)
if (database_tasks_.size() == 1u)
database_tasks_.front()->Start();
}
......
......@@ -5,6 +5,7 @@
#include "content/browser/background_fetch/background_fetch_scheduler.h"
#include "base/guid.h"
#include "base/stl_util.h"
#include "content/browser/background_fetch/background_fetch_data_manager.h"
#include "content/browser/background_fetch/background_fetch_delegate_proxy.h"
#include "content/browser/background_fetch/background_fetch_job_controller.h"
......@@ -39,21 +40,15 @@ BackgroundFetchScheduler::~BackgroundFetchScheduler() = default;
void BackgroundFetchScheduler::ScheduleDownload() {
DCHECK(!active_controller_);
if (job_controllers_.empty())
return;
while (controller_ids_.size() &&
!job_controllers_.count(controller_ids_.front())) {
// Remove aborted controller ids.
controller_ids_.pop_front();
}
if (controller_ids_.empty())
return;
DCHECK(!job_controllers_.empty());
std::string controller_id = controller_ids_.front();
controller_ids_.pop_front();
active_controller_ = job_controllers_[controller_id].get();
DCHECK(active_controller_);
data_manager_->PopNextRequest(
active_controller_->registration_id(),
......@@ -68,6 +63,8 @@ void BackgroundFetchScheduler::Abort(
DCHECK_EQ(failure_reason,
BackgroundFetchFailureReason::CANCELLED_BY_DEVELOPER);
base::Erase(controller_ids_, registration_id.unique_id());
auto it = job_controllers_.find(registration_id.unique_id());
if (it == job_controllers_.end()) {
std::move(callback).Run(BackgroundFetchError::INVALID_ID);
......@@ -296,6 +293,8 @@ void BackgroundFetchScheduler::AbortFetches(
}
for (auto* controller : to_abort) {
// Erase it from |controller_ids_| first to avoid rescheduling.
base::Erase(controller_ids_, controller->registration_id().unique_id());
controller->Abort(BackgroundFetchFailureReason::SERVICE_WORKER_UNAVAILABLE,
base::DoNothing());
}
......
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