Chromium Code Reviews| 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 238e31ca920da9535beb5e5e8381f931e80c25ed..52978d0bd2c7d297783d490585ca98c47ac737e2 100644 |
| --- a/content/browser/background_fetch/background_fetch_context.cc |
| +++ b/content/browser/background_fetch/background_fetch_context.cc |
| @@ -107,7 +107,13 @@ BackgroundFetchJobController* BackgroundFetchContext::GetActiveFetch( |
| if (iter == active_fetches_.end()) |
| return nullptr; |
| - return iter->second.get(); |
| + BackgroundFetchJobController* controller = iter->second.get(); |
| + if (controller->state() == BackgroundFetchJobController::State::ABORTED || |
| + controller->state() == BackgroundFetchJobController::State::COMPLETED) { |
| + return nullptr; |
| + } |
| + |
| + return controller; |
| } |
| void BackgroundFetchContext::CreateController( |
| @@ -117,19 +123,23 @@ void BackgroundFetchContext::CreateController( |
| base::MakeUnique<BackgroundFetchJobController>( |
| registration_id, options, browser_context_, storage_partition_, |
| background_fetch_data_manager_.get(), |
| - base::BindOnce(&BackgroundFetchContext::DidFinishFetch, this)); |
| + base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this)); |
| active_fetches_.insert( |
| std::make_pair(registration_id, std::move(controller))); |
| } |
| -void BackgroundFetchContext::DidFinishFetch( |
| - const BackgroundFetchRegistrationId& registration_id, |
| - bool aborted_by_developer) { |
| +void BackgroundFetchContext::DidCompleteJob( |
| + BackgroundFetchJobController* controller) { |
| + const BackgroundFetchRegistrationId& registration_id = |
| + controller->registration_id(); |
| + |
| DCHECK_GT(active_fetches_.count(registration_id), 0u); |
| - // TODO(peter): Dispatch the `backgroundfetched` or the `backgroundfetchfail` |
| - // event to the Service Worker when |aborted_by_developer| is not set. |
| + if (controller->state() == BackgroundFetchJobController::State::COMPLETED) { |
| + // TODO(peter): Dispatch the `backgroundfetched` or `backgroundfetchfail` |
| + // event to the Service Worker when |aborted_by_developer| is not set. |
|
harkness
2017/03/28 14:55:43
remove |aborted_by_developer| from comment.
Peter Beverloo
2017/03/29 13:05:22
Done.
|
| + } |
| active_fetches_.erase(registration_id); |
| } |