| Index: content/browser/background_fetch/background_fetch_context.cc
|
| diff --git a/content/browser/background_fetch/background_fetch_context.cc b/content/browser/background_fetch/background_fetch_context.cc
|
| index 4facffeac426a3d758822190ff7538302bea81c6..a24c1c0535983d086ea73742630f5b0fd48c0cb8 100644
|
| --- a/content/browser/background_fetch/background_fetch_context.cc
|
| +++ b/content/browser/background_fetch/background_fetch_context.cc
|
| @@ -44,29 +44,19 @@ BackgroundFetchContext::BackgroundFetchContext(
|
| base::MakeUnique<BackgroundFetchDataManager>(browser_context)),
|
| event_dispatcher_(base::MakeUnique<BackgroundFetchEventDispatcher>(
|
| std::move(service_worker_context))) {
|
| + // Although this lives only on the IO thread, it is constructed on UI thread.
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| }
|
|
|
| BackgroundFetchContext::~BackgroundFetchContext() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| }
|
|
|
| void BackgroundFetchContext::InitializeOnIOThread(
|
| scoped_refptr<net::URLRequestContextGetter> request_context_getter) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| - request_context_getter_ = request_context_getter;
|
| -}
|
|
|
| -void BackgroundFetchContext::Shutdown() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - BrowserThread::PostTask(
|
| - BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&BackgroundFetchContext::ShutdownOnIO, this));
|
| -}
|
| -
|
| -void BackgroundFetchContext::ShutdownOnIO() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| - active_fetches_.clear();
|
| + request_context_getter_ = request_context_getter;
|
| }
|
|
|
| void BackgroundFetchContext::StartFetch(
|
| @@ -75,6 +65,7 @@ void BackgroundFetchContext::StartFetch(
|
| const BackgroundFetchOptions& options,
|
| blink::mojom::BackgroundFetchService::FetchCallback callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| data_manager_->CreateRegistration(
|
| registration_id, requests, options,
|
| base::BindOnce(&BackgroundFetchContext::DidCreateRegistration, this,
|
| @@ -87,6 +78,8 @@ void BackgroundFetchContext::DidCreateRegistration(
|
| blink::mojom::BackgroundFetchService::FetchCallback callback,
|
| blink::mojom::BackgroundFetchError error,
|
| std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| RecordRegistrationCreatedError(error);
|
| if (error != blink::mojom::BackgroundFetchError::NONE) {
|
| std::move(callback).Run(error, base::nullopt /* registration */);
|
| @@ -112,6 +105,8 @@ std::vector<std::string>
|
| BackgroundFetchContext::GetActiveTagsForServiceWorkerRegistration(
|
| int64_t service_worker_registration_id,
|
| const url::Origin& origin) const {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| std::vector<std::string> tags;
|
| for (const auto& pair : active_fetches_) {
|
| const BackgroundFetchRegistrationId& registration_id =
|
| @@ -149,6 +144,8 @@ void BackgroundFetchContext::CreateController(
|
| const BackgroundFetchRegistrationId& registration_id,
|
| const BackgroundFetchOptions& options,
|
| std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| net::NetworkTrafficAnnotationTag traffic_annotation =
|
| net::DefineNetworkTrafficAnnotation("background_fetch_context", R"(
|
| semantics {
|
| @@ -196,6 +193,8 @@ void BackgroundFetchContext::CreateController(
|
|
|
| void BackgroundFetchContext::DidCompleteJob(
|
| BackgroundFetchJobController* controller) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| const BackgroundFetchRegistrationId& registration_id =
|
| controller->registration_id();
|
|
|
| @@ -229,6 +228,8 @@ void BackgroundFetchContext::DidGetSettledFetches(
|
| bool background_fetch_succeeded,
|
| std::vector<BackgroundFetchSettledFetch> settled_fetches,
|
| std::vector<std::unique_ptr<BlobHandle>> blob_handles) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| if (error != blink::mojom::BackgroundFetchError::NONE) {
|
| DeleteRegistration(registration_id, std::move(blob_handles));
|
| return;
|
| @@ -253,6 +254,7 @@ void BackgroundFetchContext::DidGetSettledFetches(
|
| void BackgroundFetchContext::DeleteRegistration(
|
| const BackgroundFetchRegistrationId& registration_id,
|
| const std::vector<std::unique_ptr<BlobHandle>>& blob_handles) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| DCHECK_GT(active_fetches_.count(registration_id), 0u);
|
|
|
| // Delete all persistent information associated with the |registration_id|.
|
|
|