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

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2791963002: Merge to M58: Resolve preloadResponse of Navigation Preload even if the response body is empty. (Closed)
Patch Set: Created 3 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/renderer/service_worker/service_worker_context_client.h" 5 #include "content/renderer/service_worker/service_worker_context_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 : public mojom::URLLoaderClient { 269 : public mojom::URLLoaderClient {
270 public: 270 public:
271 NavigationPreloadRequest(int fetch_event_id, 271 NavigationPreloadRequest(int fetch_event_id,
272 const GURL& url, 272 const GURL& url,
273 mojom::FetchEventPreloadHandlePtr preload_handle) 273 mojom::FetchEventPreloadHandlePtr preload_handle)
274 : fetch_event_id_(fetch_event_id), 274 : fetch_event_id_(fetch_event_id),
275 url_(url), 275 url_(url),
276 url_loader_(std::move(preload_handle->url_loader)), 276 url_loader_(std::move(preload_handle->url_loader)),
277 binding_(this, std::move(preload_handle->url_loader_client_request)) {} 277 binding_(this, std::move(preload_handle->url_loader_client_request)) {}
278 278
279 ~NavigationPreloadRequest() override { 279 ~NavigationPreloadRequest() override {}
280 }
281 280
282 void OnReceiveResponse( 281 void OnReceiveResponse(
283 const ResourceResponseHead& response_head, 282 const ResourceResponseHead& response_head,
284 mojom::DownloadedTempFilePtr downloaded_file) override { 283 mojom::DownloadedTempFilePtr downloaded_file) override {
285 DCHECK(!response_); 284 DCHECK(!response_);
286 DCHECK(!downloaded_file); 285 DCHECK(!downloaded_file);
287 response_ = base::MakeUnique<blink::WebURLResponse>(); 286 response_ = base::MakeUnique<blink::WebURLResponse>();
288 // TODO(horo): Set report_security_info to true when DevTools is attached. 287 // TODO(horo): Set report_security_info to true when DevTools is attached.
289 const bool report_security_info = false; 288 const bool report_security_info = false;
290 WebURLLoaderImpl::PopulateURLResponse(url_, response_head, response_.get(), 289 WebURLLoaderImpl::PopulateURLResponse(url_, response_head, response_.get(),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 if (status.error_code != net::OK) { 325 if (status.error_code != net::OK) {
327 // This will delete |this|. 326 // This will delete |this|.
328 ReportErrorToClient("Service Worker navigation preload network error."); 327 ReportErrorToClient("Service Worker navigation preload network error.");
329 return; 328 return;
330 } 329 }
331 330
332 ServiceWorkerContextClient* client = 331 ServiceWorkerContextClient* client =
333 ServiceWorkerContextClient::ThreadSpecificInstance(); 332 ServiceWorkerContextClient::ThreadSpecificInstance();
334 if (!client) 333 if (!client)
335 return; 334 return;
335 if (response_) {
336 // When the response body from the server is empty, OnComplete() is called
337 // without OnStartLoadingResponseBody().
338 DCHECK(!body_.is_valid());
339 client->OnNavigationPreloadResponse(fetch_event_id_, std::move(response_),
340 nullptr);
341 }
336 // This will delete |this|. 342 // This will delete |this|.
337 client->OnNavigationPreloadComplete(fetch_event_id_); 343 client->OnNavigationPreloadComplete(fetch_event_id_);
338 } 344 }
339 345
340 private: 346 private:
341 void MaybeReportResponseToClient() { 347 void MaybeReportResponseToClient() {
342 if (!response_ || !body_.is_valid()) 348 if (!response_ || !body_.is_valid())
343 return; 349 return;
344 ServiceWorkerContextClient* client = 350 ServiceWorkerContextClient* client =
345 ServiceWorkerContextClient::ThreadSpecificInstance(); 351 ServiceWorkerContextClient::ThreadSpecificInstance();
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 } 1311 }
1306 1312
1307 base::WeakPtr<ServiceWorkerContextClient> 1313 base::WeakPtr<ServiceWorkerContextClient>
1308 ServiceWorkerContextClient::GetWeakPtr() { 1314 ServiceWorkerContextClient::GetWeakPtr() {
1309 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1315 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1310 DCHECK(context_); 1316 DCHECK(context_);
1311 return context_->weak_factory.GetWeakPtr(); 1317 return context_->weak_factory.GetWeakPtr();
1312 } 1318 }
1313 1319
1314 } // namespace content 1320 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/navigation-preload/empty-preload-response-body.https.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698