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

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

Issue 2796953003: Populate the response blob for finished Background Fetches (Closed)
Patch Set: Populate the response blob for finished Background Fetches 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_data_manager.h" 5 #include "content/browser/background_fetch/background_fetch_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 std::vector<BackgroundFetchSettledFetch> settled_fetches; 199 std::vector<BackgroundFetchSettledFetch> settled_fetches;
200 settled_fetches.reserve(requests.size()); 200 settled_fetches.reserve(requests.size());
201 201
202 std::vector<std::unique_ptr<BlobHandle>> blob_handles; 202 std::vector<std::unique_ptr<BlobHandle>> blob_handles;
203 203
204 for (const auto& request : requests) { 204 for (const auto& request : requests) {
205 BackgroundFetchSettledFetch settled_fetch; 205 BackgroundFetchSettledFetch settled_fetch;
206 settled_fetch.request = request->fetch_request(); 206 settled_fetch.request = request->fetch_request();
207 207
208 settled_fetch.response.url_list.push_back(request->GetURL()); 208 settled_fetch.response.url_list = request->GetURLChain();
209 // TODO: settled_fetch.response.status_code 209 // TODO: settled_fetch.response.status_code
210 // TODO: settled_fetch.response.status_text 210 // TODO: settled_fetch.response.status_text
211 // TODO: settled_fetch.response.response_type 211 // TODO: settled_fetch.response.response_type
212 // TODO: settled_fetch.response.headers 212 // TODO: settled_fetch.response.headers
213 213
214 if (request->received_bytes() > 0) { 214 if (request->GetFileSize() > 0) {
215 DCHECK(!request->file_path().empty()); 215 DCHECK(!request->GetFilePath().empty());
216 216
217 std::unique_ptr<BlobHandle> blob_handle = 217 std::unique_ptr<BlobHandle> blob_handle =
218 blob_storage_context_->CreateFileBackedBlob( 218 blob_storage_context_->CreateFileBackedBlob(
219 request->file_path(), 0 /* offset */, request->received_bytes(), 219 request->GetFilePath(), 0 /* offset */, request->GetFileSize(),
220 base::Time() /* expected_modification_time */); 220 base::Time() /* expected_modification_time */);
221 221
222 // TODO(peter): Appropriately handle !blob_handle 222 // TODO(peter): Appropriately handle !blob_handle
223 if (blob_handle) { 223 if (blob_handle) {
224 settled_fetch.response.blob_uuid = blob_handle->GetUUID(); 224 settled_fetch.response.blob_uuid = blob_handle->GetUUID();
225 settled_fetch.response.blob_size = request->received_bytes(); 225 settled_fetch.response.blob_size = request->GetFileSize();
226 226
227 blob_handles.push_back(std::move(blob_handle)); 227 blob_handles.push_back(std::move(blob_handle));
228 } 228 }
229 } 229 }
230 230
231 // TODO: settled_fetch.response.error 231 // TODO: settled_fetch.response.error
232 // TODO: settled_fetch.response.response_time 232 settled_fetch.response.response_time = request->GetResponseTime();
233 // TODO: settled_fetch.response.cors_exposed_header_names 233 // TODO: settled_fetch.response.cors_exposed_header_names
234 234
235 settled_fetches.push_back(settled_fetch); 235 settled_fetches.push_back(settled_fetch);
236 } 236 }
237 237
238 std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE, 238 std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE,
239 std::move(settled_fetches), std::move(blob_handles)); 239 std::move(settled_fetches), std::move(blob_handles));
240 } 240 }
241 241
242 void BackgroundFetchDataManager::DeleteRegistration( 242 void BackgroundFetchDataManager::DeleteRegistration(
243 const BackgroundFetchRegistrationId& registration_id, 243 const BackgroundFetchRegistrationId& registration_id,
244 DeleteRegistrationCallback callback) { 244 DeleteRegistrationCallback callback) {
245 auto iter = registrations_.find(registration_id); 245 auto iter = registrations_.find(registration_id);
246 if (iter == registrations_.end()) { 246 if (iter == registrations_.end()) {
247 std::move(callback).Run(blink::mojom::BackgroundFetchError::INVALID_TAG); 247 std::move(callback).Run(blink::mojom::BackgroundFetchError::INVALID_TAG);
248 return; 248 return;
249 } 249 }
250 250
251 registrations_.erase(iter); 251 registrations_.erase(iter);
252 252
253 std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE); 253 std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE);
254 } 254 }
255 255
256 } // namespace content 256 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698