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

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

Issue 1502503004: Remove kuint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8
Patch Set: rebase Created 5 years 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 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 <stdint.h>
8
9 #include <limits>
7 #include <map> 10 #include <map>
8 #include <string> 11 #include <string>
9 #include <vector> 12 #include <vector>
10 13
11 #include "base/bind.h" 14 #include "base/bind.h"
12 #include "base/guid.h" 15 #include "base/guid.h"
13 #include "base/location.h" 16 #include "base/location.h"
14 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
15 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
16 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 fetch_dispatcher_->Run(); 432 fetch_dispatcher_->Run();
430 return; 433 return;
431 } 434 }
432 435
433 NOTREACHED(); 436 NOTREACHED();
434 } 437 }
435 438
436 scoped_ptr<ServiceWorkerFetchRequest> 439 scoped_ptr<ServiceWorkerFetchRequest>
437 ServiceWorkerURLRequestJob::CreateFetchRequest() { 440 ServiceWorkerURLRequestJob::CreateFetchRequest() {
438 std::string blob_uuid; 441 std::string blob_uuid;
439 uint64 blob_size = 0; 442 uint64_t blob_size = 0;
440 CreateRequestBodyBlob(&blob_uuid, &blob_size); 443 CreateRequestBodyBlob(&blob_uuid, &blob_size);
441 scoped_ptr<ServiceWorkerFetchRequest> request( 444 scoped_ptr<ServiceWorkerFetchRequest> request(
442 new ServiceWorkerFetchRequest()); 445 new ServiceWorkerFetchRequest());
443 request->mode = request_mode_; 446 request->mode = request_mode_;
444 request->request_context_type = request_context_type_; 447 request->request_context_type = request_context_type_;
445 request->frame_type = frame_type_; 448 request->frame_type = frame_type_;
446 request->url = request_->url(); 449 request->url = request_->url();
447 request->method = request_->method(); 450 request->method = request_->method();
448 const net::HttpRequestHeaders& headers = request_->extra_request_headers(); 451 const net::HttpRequestHeaders& headers = request_->extra_request_headers();
449 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { 452 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) {
(...skipping 15 matching lines...) Expand all
465 CHECK( 468 CHECK(
466 request_->referrer_policy() == 469 request_->referrer_policy() ==
467 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE); 470 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE);
468 request->referrer = 471 request->referrer =
469 Referrer(GURL(request_->referrer()), blink::WebReferrerPolicyDefault); 472 Referrer(GURL(request_->referrer()), blink::WebReferrerPolicyDefault);
470 } 473 }
471 return request.Pass(); 474 return request.Pass();
472 } 475 }
473 476
474 bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, 477 bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid,
475 uint64* blob_size) { 478 uint64_t* blob_size) {
476 if (!body_.get() || !blob_storage_context_) 479 if (!body_.get() || !blob_storage_context_)
477 return false; 480 return false;
478 481
479 // To ensure the blobs stick around until the end of the reading. 482 // To ensure the blobs stick around until the end of the reading.
480 std::vector<scoped_ptr<storage::BlobDataHandle>> handles; 483 std::vector<scoped_ptr<storage::BlobDataHandle>> handles;
481 std::vector<scoped_ptr<storage::BlobDataSnapshot>> snapshots; 484 std::vector<scoped_ptr<storage::BlobDataSnapshot>> snapshots;
482 // TODO(dmurph): Allow blobs to be added below, so that the context can 485 // TODO(dmurph): Allow blobs to be added below, so that the context can
483 // efficiently re-use blob items for the new blob. 486 // efficiently re-use blob items for the new blob.
484 std::vector<const ResourceRequestBody::Element*> resolved_elements; 487 std::vector<const ResourceRequestBody::Element*> resolved_elements;
485 for (const ResourceRequestBody::Element& element : (*body_->elements())) { 488 for (const ResourceRequestBody::Element& element : (*body_->elements())) {
486 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) { 489 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) {
487 resolved_elements.push_back(&element); 490 resolved_elements.push_back(&element);
488 continue; 491 continue;
489 } 492 }
490 scoped_ptr<storage::BlobDataHandle> handle = 493 scoped_ptr<storage::BlobDataHandle> handle =
491 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); 494 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid());
492 scoped_ptr<storage::BlobDataSnapshot> snapshot = handle->CreateSnapshot(); 495 scoped_ptr<storage::BlobDataSnapshot> snapshot = handle->CreateSnapshot();
493 if (snapshot->items().empty()) 496 if (snapshot->items().empty())
494 continue; 497 continue;
495 const auto& items = snapshot->items(); 498 const auto& items = snapshot->items();
496 for (const auto& item : items) { 499 for (const auto& item : items) {
497 DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type()); 500 DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type());
498 resolved_elements.push_back(item->data_element_ptr()); 501 resolved_elements.push_back(item->data_element_ptr());
499 } 502 }
500 handles.push_back(handle.Pass()); 503 handles.push_back(handle.Pass());
501 snapshots.push_back(snapshot.Pass()); 504 snapshots.push_back(snapshot.Pass());
502 } 505 }
503 506
504 const std::string uuid(base::GenerateGUID()); 507 const std::string uuid(base::GenerateGUID());
505 uint64 total_size = 0; 508 uint64_t total_size = 0;
506 509
507 storage::BlobDataBuilder blob_builder(uuid); 510 storage::BlobDataBuilder blob_builder(uuid);
508 for (size_t i = 0; i < resolved_elements.size(); ++i) { 511 for (size_t i = 0; i < resolved_elements.size(); ++i) {
509 const ResourceRequestBody::Element& element = *resolved_elements[i]; 512 const ResourceRequestBody::Element& element = *resolved_elements[i];
510 if (total_size != kuint64max && element.length() != kuint64max) 513 if (total_size != std::numeric_limits<uint64_t>::max() &&
514 element.length() != std::numeric_limits<uint64_t>::max())
511 total_size += element.length(); 515 total_size += element.length();
512 else 516 else
513 total_size = kuint64max; 517 total_size = std::numeric_limits<uint64_t>::max();
514 switch (element.type()) { 518 switch (element.type()) {
515 case ResourceRequestBody::Element::TYPE_BYTES: 519 case ResourceRequestBody::Element::TYPE_BYTES:
516 blob_builder.AppendData(element.bytes(), element.length()); 520 blob_builder.AppendData(element.bytes(), element.length());
517 break; 521 break;
518 case ResourceRequestBody::Element::TYPE_FILE: 522 case ResourceRequestBody::Element::TYPE_FILE:
519 blob_builder.AppendFile(element.path(), element.offset(), 523 blob_builder.AppendFile(element.path(), element.offset(),
520 element.length(), 524 element.length(),
521 element.expected_modification_time()); 525 element.expected_modification_time());
522 break; 526 break;
523 case ResourceRequestBody::Element::TYPE_BLOB: 527 case ResourceRequestBody::Element::TYPE_BLOB:
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 base::TimeTicks() /* service_worker_ready_time */); 820 base::TimeTicks() /* service_worker_ready_time */);
817 return; 821 return;
818 } 822 }
819 on_start_completed_callback_.Run(true /* was_fetched_via_service_worker */, 823 on_start_completed_callback_.Run(true /* was_fetched_via_service_worker */,
820 fall_back_required_, response_url_, 824 fall_back_required_, response_url_,
821 service_worker_response_type_, 825 service_worker_response_type_,
822 worker_start_time_, worker_ready_time_); 826 worker_start_time_, worker_ready_time_);
823 } 827 }
824 828
825 } // namespace content 829 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698