Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 if (info) { | 260 if (info) { |
| 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; |
|
michaeln
2014/08/28 22:46:34
nit: maybe a blank line here
horo
2014/08/29 01:13:04
Done.
| |
| 271 const std::string uuid(base::GenerateGUID()); | |
| 272 uint64 size = 0; | |
| 273 std::vector<const ResourceRequestBody::Element*> resolved_elements; | 271 std::vector<const ResourceRequestBody::Element*> resolved_elements; |
| 274 for (size_t i = 0; i < body_->elements()->size(); ++i) { | 272 for (size_t i = 0; i < body_->elements()->size(); ++i) { |
| 275 const ResourceRequestBody::Element& element = (*body_->elements())[i]; | 273 const ResourceRequestBody::Element& element = (*body_->elements())[i]; |
| 276 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) { | 274 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) { |
| 277 resolved_elements.push_back(&element); | 275 resolved_elements.push_back(&element); |
| 278 continue; | 276 continue; |
| 279 } | 277 } |
| 280 scoped_ptr<storage::BlobDataHandle> handle = | 278 scoped_ptr<storage::BlobDataHandle> handle = |
| 281 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); | 279 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); |
| 282 if (handle->data()->items().empty()) | 280 if (handle->data()->items().empty()) |
| 283 continue; | 281 continue; |
| 284 for (size_t i = 0; i < handle->data()->items().size(); ++i) { | 282 for (size_t i = 0; i < handle->data()->items().size(); ++i) { |
| 285 const storage::BlobData::Item& item = handle->data()->items().at(i); | 283 const storage::BlobData::Item& item = handle->data()->items().at(i); |
| 286 DCHECK_NE(storage::BlobData::Item::TYPE_BLOB, item.type()); | 284 DCHECK_NE(storage::BlobData::Item::TYPE_BLOB, item.type()); |
| 287 resolved_elements.push_back(&item); | 285 resolved_elements.push_back(&item); |
| 288 } | 286 } |
| 289 } | 287 } |
|
michaeln
2014/08/28 22:46:34
nit: and here
horo
2014/08/29 01:13:04
Done.
| |
| 288 const std::string uuid(base::GenerateGUID()); | |
| 289 uint64 total_size = 0; | |
| 290 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); | 290 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); |
| 291 for (size_t i = 0; i < resolved_elements.size(); ++i) { | 291 for (size_t i = 0; i < resolved_elements.size(); ++i) { |
| 292 const ResourceRequestBody::Element& element = *resolved_elements[i]; | 292 const ResourceRequestBody::Element& element = *resolved_elements[i]; |
| 293 size += element.length(); | 293 if (total_size != kuint64max && element.length() != kuint64max) |
| 294 total_size += element.length(); | |
| 295 else | |
| 296 total_size = kuint64max; | |
| 294 switch (element.type()) { | 297 switch (element.type()) { |
| 295 case ResourceRequestBody::Element::TYPE_BYTES: | 298 case ResourceRequestBody::Element::TYPE_BYTES: |
| 296 blob_data->AppendData(element.bytes(), element.length()); | 299 blob_data->AppendData(element.bytes(), element.length()); |
| 297 break; | 300 break; |
| 298 case ResourceRequestBody::Element::TYPE_FILE: | 301 case ResourceRequestBody::Element::TYPE_FILE: |
| 299 blob_data->AppendFile(element.path(), | 302 blob_data->AppendFile(element.path(), |
| 300 element.offset(), | 303 element.offset(), |
| 301 element.length(), | 304 element.length(), |
| 302 element.expected_modification_time()); | 305 element.expected_modification_time()); |
| 303 break; | 306 break; |
| 304 case ResourceRequestBody::Element::TYPE_BLOB: | 307 case ResourceRequestBody::Element::TYPE_BLOB: |
| 305 // Blob elements should be resolved beforehand. | 308 // Blob elements should be resolved beforehand. |
| 306 NOTREACHED(); | 309 NOTREACHED(); |
| 307 break; | 310 break; |
| 308 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: | 311 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: |
| 309 blob_data->AppendFileSystemFile(element.filesystem_url(), | 312 blob_data->AppendFileSystemFile(element.filesystem_url(), |
| 310 element.offset(), | 313 element.offset(), |
| 311 element.length(), | 314 element.length(), |
| 312 element.expected_modification_time()); | 315 element.expected_modification_time()); |
| 313 break; | 316 break; |
| 314 default: | 317 default: |
| 315 NOTIMPLEMENTED(); | 318 NOTIMPLEMENTED(); |
| 316 } | 319 } |
| 317 } | 320 } |
| 318 | 321 |
| 319 request_body_blob_data_handle_ = | 322 request_body_blob_data_handle_ = |
| 320 blob_storage_context_->AddFinishedBlob(blob_data.get()); | 323 blob_storage_context_->AddFinishedBlob(blob_data.get()); |
| 321 *blob_uuid = uuid; | 324 *blob_uuid = uuid; |
| 322 *blob_size = size; | 325 *blob_size = total_size; |
| 323 return true; | 326 return true; |
| 324 } | 327 } |
| 325 | 328 |
| 326 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() { | 329 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() { |
| 327 // TODO(shimazu): Set the timestamp to measure the time to launch SW | 330 // TODO(shimazu): Set the timestamp to measure the time to launch SW |
| 328 // This is related to this (http://crbug.com/401389) | 331 // This is related to this (http://crbug.com/401389) |
| 329 } | 332 } |
| 330 | 333 |
| 331 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( | 334 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( |
| 332 ServiceWorkerStatusCode status, | 335 ServiceWorkerStatusCode status, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { | 415 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { |
| 413 // TODO(falken): Print an error to the console of the ServiceWorker and of | 416 // TODO(falken): Print an error to the console of the ServiceWorker and of |
| 414 // the requesting page. | 417 // the requesting page. |
| 415 CreateResponseHeader(500, | 418 CreateResponseHeader(500, |
| 416 "Service Worker Response Error", | 419 "Service Worker Response Error", |
| 417 std::map<std::string, std::string>()); | 420 std::map<std::string, std::string>()); |
| 418 CommitResponseHeader(); | 421 CommitResponseHeader(); |
| 419 } | 422 } |
| 420 | 423 |
| 421 } // namespace content | 424 } // namespace content |
| OLD | NEW |