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

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

Issue 2816403004: Fire the `backgroundfetchfail` event for failed 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
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Get the sequence of settled fetches from the data manager. 186 // Get the sequence of settled fetches from the data manager.
187 data_manager_->GetSettledFetchesForRegistration( 187 data_manager_->GetSettledFetchesForRegistration(
188 registration_id, 188 registration_id,
189 base::BindOnce(&BackgroundFetchContext::DidGetSettledFetches, this, 189 base::BindOnce(&BackgroundFetchContext::DidGetSettledFetches, this,
190 registration_id)); 190 registration_id));
191 } 191 }
192 192
193 void BackgroundFetchContext::DidGetSettledFetches( 193 void BackgroundFetchContext::DidGetSettledFetches(
194 const BackgroundFetchRegistrationId& registration_id, 194 const BackgroundFetchRegistrationId& registration_id,
195 blink::mojom::BackgroundFetchError error, 195 blink::mojom::BackgroundFetchError error,
196 bool background_fetch_succeeded,
196 std::vector<BackgroundFetchSettledFetch> settled_fetches, 197 std::vector<BackgroundFetchSettledFetch> settled_fetches,
197 std::vector<std::unique_ptr<BlobHandle>> blob_handles) { 198 std::vector<std::unique_ptr<BlobHandle>> blob_handles) {
198 if (error != blink::mojom::BackgroundFetchError::NONE) { 199 if (error != blink::mojom::BackgroundFetchError::NONE) {
199 DeleteRegistration(registration_id, std::move(blob_handles)); 200 DeleteRegistration(registration_id, std::move(blob_handles));
200 return; 201 return;
201 } 202 }
202 203
203 // TODO(peter): Distinguish between the `backgroundfetched` and 204 // The `backgroundfetched` event will be invoked when all requests in the
204 // `backgroundfetchfail` events based on the status code of all fetches. We 205 // registration have completed successfully. In all other cases, the
205 // don't populate that field yet, so always assume it's successful for now. 206 // `backgroundfetchfail` event will be invoked instead.
206 207 if (background_fetch_succeeded) {
207 event_dispatcher_->DispatchBackgroundFetchedEvent( 208 event_dispatcher_->DispatchBackgroundFetchedEvent(
208 registration_id, std::move(settled_fetches), 209 registration_id, std::move(settled_fetches),
209 base::Bind(&BackgroundFetchContext::DeleteRegistration, this, 210 base::Bind(&BackgroundFetchContext::DeleteRegistration, this,
210 registration_id, std::move(blob_handles))); 211 registration_id, std::move(blob_handles)));
212 } else {
213 event_dispatcher_->DispatchBackgroundFetchFailEvent(
214 registration_id, std::move(settled_fetches),
215 base::Bind(&BackgroundFetchContext::DeleteRegistration, this,
216 registration_id, std::move(blob_handles)));
217 }
211 } 218 }
212 219
213 void BackgroundFetchContext::DeleteRegistration( 220 void BackgroundFetchContext::DeleteRegistration(
214 const BackgroundFetchRegistrationId& registration_id, 221 const BackgroundFetchRegistrationId& registration_id,
215 const std::vector<std::unique_ptr<BlobHandle>>& blob_handles) { 222 const std::vector<std::unique_ptr<BlobHandle>>& blob_handles) {
216 DCHECK_GT(active_fetches_.count(registration_id), 0u); 223 DCHECK_GT(active_fetches_.count(registration_id), 0u);
217 224
218 // Delete all persistent information associated with the |registration_id|. 225 // Delete all persistent information associated with the |registration_id|.
219 data_manager_->DeleteRegistration( 226 data_manager_->DeleteRegistration(
220 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); 227 registration_id, base::BindOnce(&RecordRegistrationDeletedError));
221 228
222 // Delete the local state associated with the |registration_id|. 229 // Delete the local state associated with the |registration_id|.
223 active_fetches_.erase(registration_id); 230 active_fetches_.erase(registration_id);
224 } 231 }
225 232
226 } // namespace content 233 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698