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

Side by Side Diff: content/browser/service_worker/service_worker_url_request_job.cc

Issue 517543002: [ServiceWorker] Set blob_size of ServiceWorkerFetchRequest as kuint64max when it is unknown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add blank lines Created 6 years, 3 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/service_worker/service_worker_url_request_job.h" 5 #include "content/browser/service_worker/service_worker_url_request_job.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 request->is_reload = PageTransitionCoreTypeIs(info->GetPageTransition(), 261 request->is_reload = PageTransitionCoreTypeIs(info->GetPageTransition(),
262 PAGE_TRANSITION_RELOAD); 262 PAGE_TRANSITION_RELOAD);
263 } 263 }
264 return request.Pass(); 264 return request.Pass();
265 } 265 }
266 266
267 bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, 267 bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid,
268 uint64* blob_size) { 268 uint64* blob_size) {
269 if (!body_.get() || !blob_storage_context_) 269 if (!body_.get() || !blob_storage_context_)
270 return false; 270 return false;
271 const std::string uuid(base::GenerateGUID()); 271
272 uint64 size = 0;
273 std::vector<const ResourceRequestBody::Element*> resolved_elements; 272 std::vector<const ResourceRequestBody::Element*> resolved_elements;
274 for (size_t i = 0; i < body_->elements()->size(); ++i) { 273 for (size_t i = 0; i < body_->elements()->size(); ++i) {
275 const ResourceRequestBody::Element& element = (*body_->elements())[i]; 274 const ResourceRequestBody::Element& element = (*body_->elements())[i];
276 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) { 275 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) {
277 resolved_elements.push_back(&element); 276 resolved_elements.push_back(&element);
278 continue; 277 continue;
279 } 278 }
280 scoped_ptr<storage::BlobDataHandle> handle = 279 scoped_ptr<storage::BlobDataHandle> handle =
281 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); 280 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid());
282 if (handle->data()->items().empty()) 281 if (handle->data()->items().empty())
283 continue; 282 continue;
284 for (size_t i = 0; i < handle->data()->items().size(); ++i) { 283 for (size_t i = 0; i < handle->data()->items().size(); ++i) {
285 const storage::BlobData::Item& item = handle->data()->items().at(i); 284 const storage::BlobData::Item& item = handle->data()->items().at(i);
286 DCHECK_NE(storage::BlobData::Item::TYPE_BLOB, item.type()); 285 DCHECK_NE(storage::BlobData::Item::TYPE_BLOB, item.type());
287 resolved_elements.push_back(&item); 286 resolved_elements.push_back(&item);
288 } 287 }
289 } 288 }
289
290 const std::string uuid(base::GenerateGUID());
291 uint64 total_size = 0;
290 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); 292 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid);
291 for (size_t i = 0; i < resolved_elements.size(); ++i) { 293 for (size_t i = 0; i < resolved_elements.size(); ++i) {
292 const ResourceRequestBody::Element& element = *resolved_elements[i]; 294 const ResourceRequestBody::Element& element = *resolved_elements[i];
293 size += element.length(); 295 if (total_size != kuint64max && element.length() != kuint64max)
296 total_size += element.length();
297 else
298 total_size = kuint64max;
294 switch (element.type()) { 299 switch (element.type()) {
295 case ResourceRequestBody::Element::TYPE_BYTES: 300 case ResourceRequestBody::Element::TYPE_BYTES:
296 blob_data->AppendData(element.bytes(), element.length()); 301 blob_data->AppendData(element.bytes(), element.length());
297 break; 302 break;
298 case ResourceRequestBody::Element::TYPE_FILE: 303 case ResourceRequestBody::Element::TYPE_FILE:
299 blob_data->AppendFile(element.path(), 304 blob_data->AppendFile(element.path(),
300 element.offset(), 305 element.offset(),
301 element.length(), 306 element.length(),
302 element.expected_modification_time()); 307 element.expected_modification_time());
303 break; 308 break;
304 case ResourceRequestBody::Element::TYPE_BLOB: 309 case ResourceRequestBody::Element::TYPE_BLOB:
305 // Blob elements should be resolved beforehand. 310 // Blob elements should be resolved beforehand.
306 NOTREACHED(); 311 NOTREACHED();
307 break; 312 break;
308 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: 313 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM:
309 blob_data->AppendFileSystemFile(element.filesystem_url(), 314 blob_data->AppendFileSystemFile(element.filesystem_url(),
310 element.offset(), 315 element.offset(),
311 element.length(), 316 element.length(),
312 element.expected_modification_time()); 317 element.expected_modification_time());
313 break; 318 break;
314 default: 319 default:
315 NOTIMPLEMENTED(); 320 NOTIMPLEMENTED();
316 } 321 }
317 } 322 }
318 323
319 request_body_blob_data_handle_ = 324 request_body_blob_data_handle_ =
320 blob_storage_context_->AddFinishedBlob(blob_data.get()); 325 blob_storage_context_->AddFinishedBlob(blob_data.get());
321 *blob_uuid = uuid; 326 *blob_uuid = uuid;
322 *blob_size = size; 327 *blob_size = total_size;
323 return true; 328 return true;
324 } 329 }
325 330
326 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() { 331 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() {
327 // TODO(shimazu): Set the timestamp to measure the time to launch SW 332 // TODO(shimazu): Set the timestamp to measure the time to launch SW
328 // This is related to this (http://crbug.com/401389) 333 // This is related to this (http://crbug.com/401389)
329 } 334 }
330 335
331 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( 336 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent(
332 ServiceWorkerStatusCode status, 337 ServiceWorkerStatusCode status,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { 417 void ServiceWorkerURLRequestJob::DeliverErrorResponse() {
413 // TODO(falken): Print an error to the console of the ServiceWorker and of 418 // TODO(falken): Print an error to the console of the ServiceWorker and of
414 // the requesting page. 419 // the requesting page.
415 CreateResponseHeader(500, 420 CreateResponseHeader(500,
416 "Service Worker Response Error", 421 "Service Worker Response Error",
417 std::map<std::string, std::string>()); 422 std::map<std::string, std::string>());
418 CommitResponseHeader(); 423 CommitResponseHeader();
419 } 424 }
420 425
421 } // namespace content 426 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698