Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: content/browser/background_fetch/background_fetch_context.cc

Issue 2824223002: Fire the `backgroundfetchabort` event for aborted fetches (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/background_fetch/background_fetch_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/background_fetch/background_fetch_context.h" 5 #include "content/browser/background_fetch/background_fetch_context.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "content/browser/background_fetch/background_fetch_data_manager.h" 8 #include "content/browser/background_fetch/background_fetch_data_manager.h"
9 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h" 9 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h"
10 #include "content/browser/background_fetch/background_fetch_job_controller.h" 10 #include "content/browser/background_fetch/background_fetch_job_controller.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 active_fetches_.insert( 164 active_fetches_.insert(
165 std::make_pair(registration_id, std::move(controller))); 165 std::make_pair(registration_id, std::move(controller)));
166 } 166 }
167 167
168 void BackgroundFetchContext::DidCompleteJob( 168 void BackgroundFetchContext::DidCompleteJob(
169 BackgroundFetchJobController* controller) { 169 BackgroundFetchJobController* controller) {
170 const BackgroundFetchRegistrationId& registration_id = 170 const BackgroundFetchRegistrationId& registration_id =
171 controller->registration_id(); 171 controller->registration_id();
172 172
173 DCHECK_GT(active_fetches_.count(registration_id), 0u); 173 DCHECK_GT(active_fetches_.count(registration_id), 0u);
174 174 switch (controller->state()) {
175 // TODO(peter): Fire `backgroundfetchabort` if the |controller|'s state is 175 case BackgroundFetchJobController::State::ABORTED:
176 // ABORTED, which does not require a sequence of the settled fetches. 176 event_dispatcher_->DispatchBackgroundFetchAbortEvent(
177 177 registration_id,
178 // The `backgroundfetched` and/or `backgroundfetchfail` event will only be 178 base::Bind(&BackgroundFetchContext::DeleteRegistration, this,
179 // invoked for Background Fetch jobs which have been completed. 179 registration_id,
180 if (controller->state() != BackgroundFetchJobController::State::COMPLETED) { 180 std::vector<std::unique_ptr<BlobHandle>>()));
181 DeleteRegistration(registration_id, 181 return;
182 std::vector<std::unique_ptr<BlobHandle>>()); 182 case BackgroundFetchJobController::State::COMPLETED:
183 return; 183 data_manager_->GetSettledFetchesForRegistration(
184 registration_id,
185 base::BindOnce(&BackgroundFetchContext::DidGetSettledFetches, this,
186 registration_id));
187 return;
188 case BackgroundFetchJobController::State::INITIALIZED:
189 case BackgroundFetchJobController::State::FETCHING:
190 // These cases should not happen. Fall through to the NOTREACHED() below.
191 break;
184 } 192 }
185 193
186 // Get the sequence of settled fetches from the data manager. 194 NOTREACHED();
187 data_manager_->GetSettledFetchesForRegistration(
188 registration_id,
189 base::BindOnce(&BackgroundFetchContext::DidGetSettledFetches, this,
190 registration_id));
191 } 195 }
192 196
193 void BackgroundFetchContext::DidGetSettledFetches( 197 void BackgroundFetchContext::DidGetSettledFetches(
194 const BackgroundFetchRegistrationId& registration_id, 198 const BackgroundFetchRegistrationId& registration_id,
195 blink::mojom::BackgroundFetchError error, 199 blink::mojom::BackgroundFetchError error,
196 std::vector<BackgroundFetchSettledFetch> settled_fetches, 200 std::vector<BackgroundFetchSettledFetch> settled_fetches,
197 std::vector<std::unique_ptr<BlobHandle>> blob_handles) { 201 std::vector<std::unique_ptr<BlobHandle>> blob_handles) {
198 if (error != blink::mojom::BackgroundFetchError::NONE) { 202 if (error != blink::mojom::BackgroundFetchError::NONE) {
199 DeleteRegistration(registration_id, std::move(blob_handles)); 203 DeleteRegistration(registration_id, std::move(blob_handles));
200 return; 204 return;
(...skipping 16 matching lines...) Expand all
217 221
218 // Delete all persistent information associated with the |registration_id|. 222 // Delete all persistent information associated with the |registration_id|.
219 data_manager_->DeleteRegistration( 223 data_manager_->DeleteRegistration(
220 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); 224 registration_id, base::BindOnce(&RecordRegistrationDeletedError));
221 225
222 // Delete the local state associated with the |registration_id|. 226 // Delete the local state associated with the |registration_id|.
223 active_fetches_.erase(registration_id); 227 active_fetches_.erase(registration_id);
224 } 228 }
225 229
226 } // namespace content 230 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/background_fetch/background_fetch_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698