| OLD | NEW |
| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 : public mojom::URLLoaderClient { | 357 : public mojom::URLLoaderClient { |
| 358 public: | 358 public: |
| 359 NavigationPreloadRequest(int fetch_event_id, | 359 NavigationPreloadRequest(int fetch_event_id, |
| 360 const GURL& url, | 360 const GURL& url, |
| 361 mojom::FetchEventPreloadHandlePtr preload_handle) | 361 mojom::FetchEventPreloadHandlePtr preload_handle) |
| 362 : fetch_event_id_(fetch_event_id), | 362 : fetch_event_id_(fetch_event_id), |
| 363 url_(url), | 363 url_(url), |
| 364 url_loader_(std::move(preload_handle->url_loader)), | 364 url_loader_(std::move(preload_handle->url_loader)), |
| 365 binding_(this, std::move(preload_handle->url_loader_client_request)) {} | 365 binding_(this, std::move(preload_handle->url_loader_client_request)) {} |
| 366 | 366 |
| 367 ~NavigationPreloadRequest() override { | 367 ~NavigationPreloadRequest() override {} |
| 368 } | |
| 369 | 368 |
| 370 void OnReceiveResponse( | 369 void OnReceiveResponse( |
| 371 const ResourceResponseHead& response_head, | 370 const ResourceResponseHead& response_head, |
| 372 mojom::DownloadedTempFilePtr downloaded_file) override { | 371 mojom::DownloadedTempFilePtr downloaded_file) override { |
| 373 DCHECK(!response_); | 372 DCHECK(!response_); |
| 374 DCHECK(!downloaded_file); | 373 DCHECK(!downloaded_file); |
| 375 response_ = base::MakeUnique<blink::WebURLResponse>(); | 374 response_ = base::MakeUnique<blink::WebURLResponse>(); |
| 376 // TODO(horo): Set report_security_info to true when DevTools is attached. | 375 // TODO(horo): Set report_security_info to true when DevTools is attached. |
| 377 const bool report_security_info = false; | 376 const bool report_security_info = false; |
| 378 WebURLLoaderImpl::PopulateURLResponse(url_, response_head, response_.get(), | 377 WebURLLoaderImpl::PopulateURLResponse(url_, response_head, response_.get(), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 if (status.error_code != net::OK) { | 413 if (status.error_code != net::OK) { |
| 415 // This will delete |this|. | 414 // This will delete |this|. |
| 416 ReportErrorToClient("Service Worker navigation preload network error."); | 415 ReportErrorToClient("Service Worker navigation preload network error."); |
| 417 return; | 416 return; |
| 418 } | 417 } |
| 419 | 418 |
| 420 ServiceWorkerContextClient* client = | 419 ServiceWorkerContextClient* client = |
| 421 ServiceWorkerContextClient::ThreadSpecificInstance(); | 420 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 422 if (!client) | 421 if (!client) |
| 423 return; | 422 return; |
| 423 if (response_) { |
| 424 // When the response body from the server is empty, OnComplete() is called |
| 425 // without OnStartLoadingResponseBody(). |
| 426 DCHECK(!body_.is_valid()); |
| 427 client->OnNavigationPreloadResponse(fetch_event_id_, std::move(response_), |
| 428 nullptr); |
| 429 } |
| 424 // This will delete |this|. | 430 // This will delete |this|. |
| 425 client->OnNavigationPreloadComplete(fetch_event_id_); | 431 client->OnNavigationPreloadComplete(fetch_event_id_); |
| 426 } | 432 } |
| 427 | 433 |
| 428 private: | 434 private: |
| 429 void MaybeReportResponseToClient() { | 435 void MaybeReportResponseToClient() { |
| 430 if (!response_ || !body_.is_valid()) | 436 if (!response_ || !body_.is_valid()) |
| 431 return; | 437 return; |
| 432 ServiceWorkerContextClient* client = | 438 ServiceWorkerContextClient* client = |
| 433 ServiceWorkerContextClient::ThreadSpecificInstance(); | 439 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 } | 1509 } |
| 1504 | 1510 |
| 1505 base::WeakPtr<ServiceWorkerContextClient> | 1511 base::WeakPtr<ServiceWorkerContextClient> |
| 1506 ServiceWorkerContextClient::GetWeakPtr() { | 1512 ServiceWorkerContextClient::GetWeakPtr() { |
| 1507 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1513 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1508 DCHECK(context_); | 1514 DCHECK(context_); |
| 1509 return context_->weak_factory.GetWeakPtr(); | 1515 return context_->weak_factory.GetWeakPtr(); |
| 1510 } | 1516 } |
| 1511 | 1517 |
| 1512 } // namespace content | 1518 } // namespace content |
| OLD | NEW |