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

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

Issue 2008613002: ABANDONED CL: Making ResourceRequestBody part of //content's public API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@post-data-my-stuff
Patch Set: Rebasing... Created 4 years, 6 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 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 10 matching lines...) Expand all
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/time.h" 23 #include "base/time/time.h"
24 #include "content/browser/resource_context_impl.h" 24 #include "content/browser/resource_context_impl.h"
25 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" 25 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
26 #include "content/browser/service_worker/service_worker_provider_host.h" 26 #include "content/browser/service_worker/service_worker_provider_host.h"
27 #include "content/browser/service_worker/service_worker_response_info.h" 27 #include "content/browser/service_worker/service_worker_response_info.h"
28 #include "content/browser/streams/stream.h" 28 #include "content/browser/streams/stream.h"
29 #include "content/browser/streams/stream_context.h" 29 #include "content/browser/streams/stream_context.h"
30 #include "content/browser/streams/stream_registry.h" 30 #include "content/browser/streams/stream_registry.h"
31 #include "content/common/resource_request_body.h" 31 #include "content/common/resource_request_body_impl.h"
32 #include "content/common/service_worker/service_worker_types.h" 32 #include "content/common/service_worker/service_worker_types.h"
33 #include "content/common/service_worker/service_worker_utils.h" 33 #include "content/common/service_worker/service_worker_utils.h"
34 #include "content/public/browser/blob_handle.h" 34 #include "content/public/browser/blob_handle.h"
35 #include "content/public/browser/resource_request_info.h" 35 #include "content/public/browser/resource_request_info.h"
36 #include "content/public/browser/service_worker_context.h" 36 #include "content/public/browser/service_worker_context.h"
37 #include "content/public/common/referrer.h" 37 #include "content/public/common/referrer.h"
38 #include "net/base/net_errors.h" 38 #include "net/base/net_errors.h"
39 #include "net/http/http_request_headers.h" 39 #include "net/http/http_request_headers.h"
40 #include "net/http/http_response_headers.h" 40 #include "net/http/http_response_headers.h"
41 #include "net/http/http_response_info.h" 41 #include "net/http/http_response_info.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 TRACE_EVENT_ASYNC_END1("ServiceWorker", "BlobConstructionWaiter", this, 123 TRACE_EVENT_ASYNC_END1("ServiceWorker", "BlobConstructionWaiter", this,
124 "Success", phase_ == Phase::SUCCESS); 124 "Success", phase_ == Phase::SUCCESS);
125 } 125 }
126 126
127 void RunOnComplete(const base::Callback<void(bool)>& callback) { 127 void RunOnComplete(const base::Callback<void(bool)>& callback) {
128 DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_)); 128 DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_));
129 phase_ = Phase::WAITING; 129 phase_ = Phase::WAITING;
130 num_pending_request_body_blobs_ = 0; 130 num_pending_request_body_blobs_ = 0;
131 callback_ = callback; 131 callback_ = callback;
132 132
133 for (const ResourceRequestBody::Element& element : 133 for (const ResourceRequestBodyImpl::Element& element :
134 *(owner_->body_->elements())) { 134 *(owner_->body_->elements())) {
135 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) 135 if (element.type() != ResourceRequestBodyImpl::Element::TYPE_BLOB)
136 continue; 136 continue;
137 137
138 std::unique_ptr<storage::BlobDataHandle> handle = 138 std::unique_ptr<storage::BlobDataHandle> handle =
139 owner_->blob_storage_context_->GetBlobDataFromUUID( 139 owner_->blob_storage_context_->GetBlobDataFromUUID(
140 element.blob_uuid()); 140 element.blob_uuid());
141 if (handle->IsBroken()) { 141 if (handle->IsBroken()) {
142 Complete(false); 142 Complete(false);
143 return; 143 return;
144 } 144 }
145 if (handle->IsBeingBuilt()) { 145 if (handle->IsBeingBuilt()) {
(...skipping 28 matching lines...) Expand all
174 void Complete(bool success) { 174 void Complete(bool success) {
175 DCHECK_EQ(static_cast<int>(Phase::WAITING), static_cast<int>(phase_)); 175 DCHECK_EQ(static_cast<int>(Phase::WAITING), static_cast<int>(phase_));
176 phase_ = success ? Phase::SUCCESS : Phase::FAIL; 176 phase_ = success ? Phase::SUCCESS : Phase::FAIL;
177 // Destroys |this|. 177 // Destroys |this|.
178 callback_.Run(success); 178 callback_.Run(success);
179 } 179 }
180 180
181 // Owns and must outlive |this|. 181 // Owns and must outlive |this|.
182 ServiceWorkerURLRequestJob* owner_; 182 ServiceWorkerURLRequestJob* owner_;
183 183
184 scoped_refptr<ResourceRequestBody> body_; 184 scoped_refptr<ResourceRequestBodyImpl> body_;
185 base::Callback<void(bool)> callback_; 185 base::Callback<void(bool)> callback_;
186 size_t num_pending_request_body_blobs_ = 0; 186 size_t num_pending_request_body_blobs_ = 0;
187 Phase phase_ = Phase::INITIAL; 187 Phase phase_ = Phase::INITIAL;
188 base::WeakPtrFactory<BlobConstructionWaiter> weak_factory_; 188 base::WeakPtrFactory<BlobConstructionWaiter> weak_factory_;
189 189
190 DISALLOW_COPY_AND_ASSIGN(BlobConstructionWaiter); 190 DISALLOW_COPY_AND_ASSIGN(BlobConstructionWaiter);
191 }; 191 };
192 192
193 bool ServiceWorkerURLRequestJob::Delegate::RequestStillValid( 193 bool ServiceWorkerURLRequestJob::Delegate::RequestStillValid(
194 ServiceWorkerMetrics::URLRequestJobResult* result) { 194 ServiceWorkerMetrics::URLRequestJobResult* result) {
195 return true; 195 return true;
196 } 196 }
197 197
198 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( 198 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob(
199 net::URLRequest* request, 199 net::URLRequest* request,
200 net::NetworkDelegate* network_delegate, 200 net::NetworkDelegate* network_delegate,
201 const std::string& client_id, 201 const std::string& client_id,
202 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 202 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
203 const ResourceContext* resource_context, 203 const ResourceContext* resource_context,
204 FetchRequestMode request_mode, 204 FetchRequestMode request_mode,
205 FetchCredentialsMode credentials_mode, 205 FetchCredentialsMode credentials_mode,
206 FetchRedirectMode redirect_mode, 206 FetchRedirectMode redirect_mode,
207 ResourceType resource_type, 207 ResourceType resource_type,
208 RequestContextType request_context_type, 208 RequestContextType request_context_type,
209 RequestContextFrameType frame_type, 209 RequestContextFrameType frame_type,
210 scoped_refptr<ResourceRequestBody> body, 210 scoped_refptr<ResourceRequestBodyImpl> body,
211 ServiceWorkerFetchType fetch_type, 211 ServiceWorkerFetchType fetch_type,
212 Delegate* delegate) 212 Delegate* delegate)
213 : net::URLRequestJob(request, network_delegate), 213 : net::URLRequestJob(request, network_delegate),
214 delegate_(delegate), 214 delegate_(delegate),
215 response_type_(NOT_DETERMINED), 215 response_type_(NOT_DETERMINED),
216 is_started_(false), 216 is_started_(false),
217 service_worker_response_type_(blink::WebServiceWorkerResponseTypeDefault), 217 service_worker_response_type_(blink::WebServiceWorkerResponseTypeDefault),
218 client_id_(client_id), 218 client_id_(client_id),
219 blob_storage_context_(blob_storage_context), 219 blob_storage_context_(blob_storage_context),
220 resource_context_(resource_context), 220 resource_context_(resource_context),
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 564 }
565 565
566 void ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, 566 void ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid,
567 uint64_t* blob_size) { 567 uint64_t* blob_size) {
568 DCHECK(HasRequestBody()); 568 DCHECK(HasRequestBody());
569 // To ensure the blobs stick around until the end of the reading. 569 // To ensure the blobs stick around until the end of the reading.
570 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; 570 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
571 std::vector<std::unique_ptr<storage::BlobDataSnapshot>> snapshots; 571 std::vector<std::unique_ptr<storage::BlobDataSnapshot>> snapshots;
572 // TODO(dmurph): Allow blobs to be added below, so that the context can 572 // TODO(dmurph): Allow blobs to be added below, so that the context can
573 // efficiently re-use blob items for the new blob. 573 // efficiently re-use blob items for the new blob.
574 std::vector<const ResourceRequestBody::Element*> resolved_elements; 574 std::vector<const ResourceRequestBodyImpl::Element*> resolved_elements;
575 for (const ResourceRequestBody::Element& element : (*body_->elements())) { 575 for (const ResourceRequestBodyImpl::Element& element : (*body_->elements())) {
576 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) { 576 if (element.type() != ResourceRequestBodyImpl::Element::TYPE_BLOB) {
577 resolved_elements.push_back(&element); 577 resolved_elements.push_back(&element);
578 continue; 578 continue;
579 } 579 }
580 std::unique_ptr<storage::BlobDataHandle> handle = 580 std::unique_ptr<storage::BlobDataHandle> handle =
581 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); 581 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid());
582 std::unique_ptr<storage::BlobDataSnapshot> snapshot = 582 std::unique_ptr<storage::BlobDataSnapshot> snapshot =
583 handle->CreateSnapshot(); 583 handle->CreateSnapshot();
584 if (snapshot->items().empty()) 584 if (snapshot->items().empty())
585 continue; 585 continue;
586 const auto& items = snapshot->items(); 586 const auto& items = snapshot->items();
587 for (const auto& item : items) { 587 for (const auto& item : items) {
588 DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type()); 588 DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type());
589 resolved_elements.push_back(item->data_element_ptr()); 589 resolved_elements.push_back(item->data_element_ptr());
590 } 590 }
591 handles.push_back(std::move(handle)); 591 handles.push_back(std::move(handle));
592 snapshots.push_back(std::move(snapshot)); 592 snapshots.push_back(std::move(snapshot));
593 } 593 }
594 594
595 const std::string uuid(base::GenerateGUID()); 595 const std::string uuid(base::GenerateGUID());
596 uint64_t total_size = 0; 596 uint64_t total_size = 0;
597 597
598 storage::BlobDataBuilder blob_builder(uuid); 598 storage::BlobDataBuilder blob_builder(uuid);
599 for (size_t i = 0; i < resolved_elements.size(); ++i) { 599 for (size_t i = 0; i < resolved_elements.size(); ++i) {
600 const ResourceRequestBody::Element& element = *resolved_elements[i]; 600 const ResourceRequestBodyImpl::Element& element = *resolved_elements[i];
601 if (total_size != std::numeric_limits<uint64_t>::max() && 601 if (total_size != std::numeric_limits<uint64_t>::max() &&
602 element.length() != std::numeric_limits<uint64_t>::max()) 602 element.length() != std::numeric_limits<uint64_t>::max())
603 total_size += element.length(); 603 total_size += element.length();
604 else 604 else
605 total_size = std::numeric_limits<uint64_t>::max(); 605 total_size = std::numeric_limits<uint64_t>::max();
606 switch (element.type()) { 606 switch (element.type()) {
607 case ResourceRequestBody::Element::TYPE_BYTES: 607 case ResourceRequestBodyImpl::Element::TYPE_BYTES:
608 blob_builder.AppendData(element.bytes(), element.length()); 608 blob_builder.AppendData(element.bytes(), element.length());
609 break; 609 break;
610 case ResourceRequestBody::Element::TYPE_FILE: 610 case ResourceRequestBodyImpl::Element::TYPE_FILE:
611 blob_builder.AppendFile(element.path(), element.offset(), 611 blob_builder.AppendFile(element.path(), element.offset(),
612 element.length(), 612 element.length(),
613 element.expected_modification_time()); 613 element.expected_modification_time());
614 break; 614 break;
615 case ResourceRequestBody::Element::TYPE_BLOB: 615 case ResourceRequestBodyImpl::Element::TYPE_BLOB:
616 // Blob elements should be resolved beforehand. 616 // Blob elements should be resolved beforehand.
617 NOTREACHED(); 617 NOTREACHED();
618 break; 618 break;
619 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: 619 case ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM:
620 blob_builder.AppendFileSystemFile(element.filesystem_url(), 620 blob_builder.AppendFileSystemFile(element.filesystem_url(),
621 element.offset(), element.length(), 621 element.offset(), element.length(),
622 element.expected_modification_time()); 622 element.expected_modification_time());
623 break; 623 break;
624 default: 624 default:
625 NOTIMPLEMENTED(); 625 NOTIMPLEMENTED();
626 } 626 }
627 } 627 }
628 628
629 request_body_blob_data_handle_ = 629 request_body_blob_data_handle_ =
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 CreateFetchRequest(), active_worker, resource_type_, 967 CreateFetchRequest(), active_worker, resource_type_,
968 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, 968 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent,
969 weak_factory_.GetWeakPtr()), 969 weak_factory_.GetWeakPtr()),
970 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, 970 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent,
971 weak_factory_.GetWeakPtr()))); 971 weak_factory_.GetWeakPtr())));
972 worker_start_time_ = base::TimeTicks::Now(); 972 worker_start_time_ = base::TimeTicks::Now();
973 fetch_dispatcher_->Run(); 973 fetch_dispatcher_->Run();
974 } 974 }
975 975
976 } // namespace content 976 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698