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

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

Issue 2954343005: Merge ResourceRequestBodyImpl and ResourceRequestBody. (Closed)
Patch Set: Remove comment Created 3 years, 5 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 <map> 10 #include <map>
(...skipping 15 matching lines...) Expand all
26 #include "base/threading/sequenced_worker_pool.h" 26 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/time/time.h" 28 #include "base/time/time.h"
29 #include "content/browser/resource_context_impl.h" 29 #include "content/browser/resource_context_impl.h"
30 #include "content/browser/service_worker/embedded_worker_instance.h" 30 #include "content/browser/service_worker/embedded_worker_instance.h"
31 #include "content/browser/service_worker/service_worker_blob_reader.h" 31 #include "content/browser/service_worker/service_worker_blob_reader.h"
32 #include "content/browser/service_worker/service_worker_data_pipe_reader.h" 32 #include "content/browser/service_worker/service_worker_data_pipe_reader.h"
33 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" 33 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
34 #include "content/browser/service_worker/service_worker_provider_host.h" 34 #include "content/browser/service_worker/service_worker_provider_host.h"
35 #include "content/browser/service_worker/service_worker_response_info.h" 35 #include "content/browser/service_worker/service_worker_response_info.h"
36 #include "content/common/resource_request_body_impl.h"
37 #include "content/common/service_worker/service_worker_types.h" 36 #include "content/common/service_worker/service_worker_types.h"
38 #include "content/common/service_worker/service_worker_utils.h" 37 #include "content/common/service_worker/service_worker_utils.h"
39 #include "content/public/browser/blob_handle.h" 38 #include "content/public/browser/blob_handle.h"
40 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/resource_request_info.h" 40 #include "content/public/browser/resource_request_info.h"
42 #include "content/public/browser/service_worker_context.h" 41 #include "content/public/browser/service_worker_context.h"
43 #include "content/public/common/referrer.h" 42 #include "content/public/common/referrer.h"
43 #include "content/public/common/resource_request_body.h"
44 #include "net/base/net_errors.h" 44 #include "net/base/net_errors.h"
45 #include "net/http/http_request_headers.h" 45 #include "net/http/http_request_headers.h"
46 #include "net/http/http_response_headers.h" 46 #include "net/http/http_response_headers.h"
47 #include "net/http/http_response_info.h" 47 #include "net/http/http_response_info.h"
48 #include "net/http/http_util.h" 48 #include "net/http/http_util.h"
49 #include "net/log/net_log.h" 49 #include "net/log/net_log.h"
50 #include "net/log/net_log_event_type.h" 50 #include "net/log/net_log_event_type.h"
51 #include "net/log/net_log_with_source.h" 51 #include "net/log/net_log_with_source.h"
52 #include "storage/browser/blob/blob_data_builder.h" 52 #include "storage/browser/blob/blob_data_builder.h"
53 #include "storage/browser/blob/blob_data_handle.h" 53 #include "storage/browser/blob/blob_data_handle.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 void Resolve(base::TaskRunner* file_runner, 151 void Resolve(base::TaskRunner* file_runner,
152 const base::Callback<void(bool)>& callback) { 152 const base::Callback<void(bool)>& callback) {
153 DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_)); 153 DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_));
154 DCHECK(file_elements_.empty()); 154 DCHECK(file_elements_.empty());
155 phase_ = Phase::WAITING; 155 phase_ = Phase::WAITING;
156 body_ = owner_->body_; 156 body_ = owner_->body_;
157 callback_ = callback; 157 callback_ = callback;
158 158
159 std::vector<base::FilePath> file_paths; 159 std::vector<base::FilePath> file_paths;
160 for (ResourceRequestBodyImpl::Element& element : 160 for (ResourceRequestBody::Element& element : *body_->elements_mutable()) {
161 *body_->elements_mutable()) { 161 if (element.type() == ResourceRequestBody::Element::TYPE_FILE &&
162 if (element.type() == ResourceRequestBodyImpl::Element::TYPE_FILE && 162 element.length() == ResourceRequestBody::Element::kUnknownSize) {
163 element.length() == ResourceRequestBodyImpl::Element::kUnknownSize) {
164 file_elements_.push_back(&element); 163 file_elements_.push_back(&element);
165 file_paths.push_back(element.path()); 164 file_paths.push_back(element.path());
166 } 165 }
167 } 166 }
168 if (file_elements_.empty()) { 167 if (file_elements_.empty()) {
169 Complete(true); 168 Complete(true);
170 return; 169 return;
171 } 170 }
172 171
173 PostTaskAndReplyWithResult( 172 PostTaskAndReplyWithResult(
174 file_runner, FROM_HERE, 173 file_runner, FROM_HERE,
175 base::Bind(&GetFileSizesOnBlockingPool, base::Passed(&file_paths)), 174 base::Bind(&GetFileSizesOnBlockingPool, base::Passed(&file_paths)),
176 base::Bind( 175 base::Bind(
177 &ServiceWorkerURLRequestJob::FileSizeResolver::OnFileSizesResolved, 176 &ServiceWorkerURLRequestJob::FileSizeResolver::OnFileSizesResolved,
178 weak_factory_.GetWeakPtr())); 177 weak_factory_.GetWeakPtr()));
179 } 178 }
180 179
181 private: 180 private:
182 enum class Phase { INITIAL, WAITING, SUCCESS, FAIL }; 181 enum class Phase { INITIAL, WAITING, SUCCESS, FAIL };
183 182
184 void OnFileSizesResolved(std::vector<int64_t> sizes) { 183 void OnFileSizesResolved(std::vector<int64_t> sizes) {
185 bool success = !sizes.empty(); 184 bool success = !sizes.empty();
186 if (success) { 185 if (success) {
187 DCHECK_EQ(sizes.size(), file_elements_.size()); 186 DCHECK_EQ(sizes.size(), file_elements_.size());
188 size_t num_elements = file_elements_.size(); 187 size_t num_elements = file_elements_.size();
189 for (size_t i = 0; i < num_elements; i++) { 188 for (size_t i = 0; i < num_elements; i++) {
190 ResourceRequestBodyImpl::Element* element = file_elements_[i]; 189 ResourceRequestBody::Element* element = file_elements_[i];
191 element->SetToFilePathRange(element->path(), element->offset(), 190 element->SetToFilePathRange(element->path(), element->offset(),
192 base::checked_cast<uint64_t>(sizes[i]), 191 base::checked_cast<uint64_t>(sizes[i]),
193 element->expected_modification_time()); 192 element->expected_modification_time());
194 } 193 }
195 file_elements_.clear(); 194 file_elements_.clear();
196 } 195 }
197 Complete(success); 196 Complete(success);
198 } 197 }
199 198
200 void Complete(bool success) { 199 void Complete(bool success) {
201 DCHECK_EQ(static_cast<int>(Phase::WAITING), static_cast<int>(phase_)); 200 DCHECK_EQ(static_cast<int>(Phase::WAITING), static_cast<int>(phase_));
202 phase_ = success ? Phase::SUCCESS : Phase::FAIL; 201 phase_ = success ? Phase::SUCCESS : Phase::FAIL;
203 // Destroys |this|, so we use a copy. 202 // Destroys |this|, so we use a copy.
204 base::ResetAndReturn(&callback_).Run(success); 203 base::ResetAndReturn(&callback_).Run(success);
205 } 204 }
206 205
207 // Owns and must outlive |this|. 206 // Owns and must outlive |this|.
208 ServiceWorkerURLRequestJob* owner_; 207 ServiceWorkerURLRequestJob* owner_;
209 208
210 scoped_refptr<ResourceRequestBodyImpl> body_; 209 scoped_refptr<ResourceRequestBody> body_;
211 std::vector<ResourceRequestBodyImpl::Element*> file_elements_; 210 std::vector<ResourceRequestBody::Element*> file_elements_;
212 base::Callback<void(bool)> callback_; 211 base::Callback<void(bool)> callback_;
213 Phase phase_ = Phase::INITIAL; 212 Phase phase_ = Phase::INITIAL;
214 base::WeakPtrFactory<FileSizeResolver> weak_factory_; 213 base::WeakPtrFactory<FileSizeResolver> weak_factory_;
215 214
216 DISALLOW_COPY_AND_ASSIGN(FileSizeResolver); 215 DISALLOW_COPY_AND_ASSIGN(FileSizeResolver);
217 }; 216 };
218 217
219 // A helper for recording navigation preload UMA. The UMA is recorded 218 // A helper for recording navigation preload UMA. The UMA is recorded
220 // after both service worker preparation finished and the 219 // after both service worker preparation finished and the
221 // navigation preload response arrived. 220 // navigation preload response arrived.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 net::NetworkDelegate* network_delegate, 311 net::NetworkDelegate* network_delegate,
313 const std::string& client_id, 312 const std::string& client_id,
314 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 313 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
315 const ResourceContext* resource_context, 314 const ResourceContext* resource_context,
316 FetchRequestMode request_mode, 315 FetchRequestMode request_mode,
317 FetchCredentialsMode credentials_mode, 316 FetchCredentialsMode credentials_mode,
318 FetchRedirectMode redirect_mode, 317 FetchRedirectMode redirect_mode,
319 ResourceType resource_type, 318 ResourceType resource_type,
320 RequestContextType request_context_type, 319 RequestContextType request_context_type,
321 RequestContextFrameType frame_type, 320 RequestContextFrameType frame_type,
322 scoped_refptr<ResourceRequestBodyImpl> body, 321 scoped_refptr<ResourceRequestBody> body,
323 ServiceWorkerFetchType fetch_type, 322 ServiceWorkerFetchType fetch_type,
324 const base::Optional<base::TimeDelta>& timeout, 323 const base::Optional<base::TimeDelta>& timeout,
325 Delegate* delegate) 324 Delegate* delegate)
326 : net::URLRequestJob(request, network_delegate), 325 : net::URLRequestJob(request, network_delegate),
327 delegate_(delegate), 326 delegate_(delegate),
328 response_type_(NOT_DETERMINED), 327 response_type_(NOT_DETERMINED),
329 is_started_(false), 328 is_started_(false),
330 service_worker_response_type_( 329 service_worker_response_type_(
331 blink::kWebServiceWorkerResponseTypeDefault), 330 blink::kWebServiceWorkerResponseTypeDefault),
332 client_id_(client_id), 331 client_id_(client_id),
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 Referrer(GURL(request_->referrer()), blink::kWebReferrerPolicyDefault); 586 Referrer(GURL(request_->referrer()), blink::kWebReferrerPolicyDefault);
588 } 587 }
589 request->fetch_type = fetch_type_; 588 request->fetch_type = fetch_type_;
590 return request; 589 return request;
591 } 590 }
592 591
593 void ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, 592 void ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid,
594 uint64_t* blob_size) { 593 uint64_t* blob_size) {
595 DCHECK(HasRequestBody()); 594 DCHECK(HasRequestBody());
596 storage::BlobDataBuilder blob_builder(base::GenerateGUID()); 595 storage::BlobDataBuilder blob_builder(base::GenerateGUID());
597 for (const ResourceRequestBodyImpl::Element& element : (*body_->elements())) { 596 for (const ResourceRequestBody::Element& element : (*body_->elements())) {
598 blob_builder.AppendIPCDataElement(element); 597 blob_builder.AppendIPCDataElement(element);
599 } 598 }
600 599
601 request_body_blob_data_handle_ = 600 request_body_blob_data_handle_ =
602 blob_storage_context_->AddFinishedBlob(&blob_builder); 601 blob_storage_context_->AddFinishedBlob(&blob_builder);
603 *blob_uuid = blob_builder.uuid(); 602 *blob_uuid = blob_builder.uuid();
604 *blob_size = request_body_blob_data_handle_->size(); 603 *blob_size = request_body_blob_data_handle_->size();
605 } 604 }
606 605
607 bool ServiceWorkerURLRequestJob::ShouldRecordNavigationMetrics( 606 bool ServiceWorkerURLRequestJob::ShouldRecordNavigationMetrics(
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 weak_factory_.GetWeakPtr())); 992 weak_factory_.GetWeakPtr()));
994 } 993 }
995 fetch_dispatcher_->Run(); 994 fetch_dispatcher_->Run();
996 } 995 }
997 996
998 void ServiceWorkerURLRequestJob::OnNavigationPreloadResponse() { 997 void ServiceWorkerURLRequestJob::OnNavigationPreloadResponse() {
999 nav_preload_metrics_->ReportNavigationPreloadFinished(); 998 nav_preload_metrics_->ReportNavigationPreloadFinished();
1000 } 999 }
1001 1000
1002 } // namespace content 1001 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698