OLD | NEW |
---|---|
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 controller->registration_id(); | 167 controller->registration_id(); |
168 | 168 |
169 DCHECK_GT(active_fetches_.count(registration_id), 0u); | 169 DCHECK_GT(active_fetches_.count(registration_id), 0u); |
170 | 170 |
171 // TODO(peter): Fire `backgroundfetchabort` if the |controller|'s state is | 171 // TODO(peter): Fire `backgroundfetchabort` if the |controller|'s state is |
172 // ABORTED, which does not require a sequence of the settled fetches. | 172 // ABORTED, which does not require a sequence of the settled fetches. |
173 | 173 |
174 // The `backgroundfetched` and/or `backgroundfetchfail` event will only be | 174 // The `backgroundfetched` and/or `backgroundfetchfail` event will only be |
175 // invoked for Background Fetch jobs which have been completed. | 175 // invoked for Background Fetch jobs which have been completed. |
176 if (controller->state() != BackgroundFetchJobController::State::COMPLETED) { | 176 if (controller->state() != BackgroundFetchJobController::State::COMPLETED) { |
177 DeleteRegistration(registration_id); | 177 DeleteRegistration(registration_id, |
178 std::vector<std::unique_ptr<BlobHandle>>()); | |
178 return; | 179 return; |
179 } | 180 } |
180 | 181 |
181 // Get the sequence of settled fetches from the data manager. | 182 // Get the sequence of settled fetches from the data manager. |
182 data_manager_->GetSettledFetchesForRegistration( | 183 data_manager_->GetSettledFetchesForRegistration( |
183 registration_id, | 184 registration_id, |
184 base::BindOnce(&BackgroundFetchContext::DidGetSettledFetches, this, | 185 base::BindOnce(&BackgroundFetchContext::DidGetSettledFetches, this, |
185 registration_id)); | 186 registration_id)); |
186 } | 187 } |
187 | 188 |
188 void BackgroundFetchContext::DidGetSettledFetches( | 189 void BackgroundFetchContext::DidGetSettledFetches( |
189 const BackgroundFetchRegistrationId& registration_id, | 190 const BackgroundFetchRegistrationId& registration_id, |
190 blink::mojom::BackgroundFetchError error, | 191 blink::mojom::BackgroundFetchError error, |
191 std::vector<BackgroundFetchSettledFetch> settled_fetches, | 192 std::vector<BackgroundFetchSettledFetch> settled_fetches, |
192 std::vector<std::unique_ptr<BlobHandle>> blob_handles) { | 193 std::vector<std::unique_ptr<BlobHandle>> blob_handles) { |
193 if (error != blink::mojom::BackgroundFetchError::NONE) { | 194 if (error != blink::mojom::BackgroundFetchError::NONE) { |
194 DeleteRegistration(registration_id); | 195 DeleteRegistration(registration_id, std::move(blob_handles)); |
195 return; | 196 return; |
196 } | 197 } |
197 | 198 |
198 // TODO(peter): Distinguish between the `backgroundfetched` and | 199 // TODO(peter): Distinguish between the `backgroundfetched` and |
199 // `backgroundfetchfail` events based on the status code of all fetches. We | 200 // `backgroundfetchfail` events based on the status code of all fetches. We |
200 // don't populate that field yet, so always assume it's successful for now. | 201 // don't populate that field yet, so always assume it's successful for now. |
201 | 202 |
202 event_dispatcher_->DispatchBackgroundFetchedEvent( | 203 event_dispatcher_->DispatchBackgroundFetchedEvent( |
203 registration_id, std::move(settled_fetches), | 204 registration_id, std::move(settled_fetches), |
204 base::Bind(&BackgroundFetchContext::DeleteRegistration, this, | 205 base::Bind(&BackgroundFetchContext::DeleteRegistration, this, |
205 registration_id)); | 206 registration_id, std::move(blob_handles))); |
206 } | 207 } |
207 | 208 |
208 void BackgroundFetchContext::DeleteRegistration( | 209 void BackgroundFetchContext::DeleteRegistration( |
209 const BackgroundFetchRegistrationId& registration_id) { | 210 const BackgroundFetchRegistrationId& registration_id, |
211 const std::vector<std::unique_ptr<BlobHandle>>& blob_handles) { | |
harkness
2017/04/05 09:26:00
Why do you think we're going to need the blob hand
Peter Beverloo
2017/04/05 09:39:27
We don't, but we need to keep the handles alive fo
| |
210 DCHECK_GT(active_fetches_.count(registration_id), 0u); | 212 DCHECK_GT(active_fetches_.count(registration_id), 0u); |
211 | 213 |
212 // Delete all persistent information associated with the |registration_id|. | 214 // Delete all persistent information associated with the |registration_id|. |
213 data_manager_->DeleteRegistration( | 215 data_manager_->DeleteRegistration( |
214 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); | 216 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); |
215 | 217 |
216 // Delete the local state associated with the |registration_id|. | 218 // Delete the local state associated with the |registration_id|. |
217 active_fetches_.erase(registration_id); | 219 active_fetches_.erase(registration_id); |
218 } | 220 } |
219 | 221 |
220 } // namespace content | 222 } // namespace content |
OLD | NEW |