Chromium Code Reviews| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 | 417 |
| 418 void OnStartLoadingResponseBody( | 418 void OnStartLoadingResponseBody( |
| 419 mojo::ScopedDataPipeConsumerHandle body) override { | 419 mojo::ScopedDataPipeConsumerHandle body) override { |
| 420 DCHECK(!body_.is_valid()); | 420 DCHECK(!body_.is_valid()); |
| 421 body_ = std::move(body); | 421 body_ = std::move(body); |
| 422 MaybeReportResponseToClient(); | 422 MaybeReportResponseToClient(); |
| 423 } | 423 } |
| 424 | 424 |
| 425 void OnComplete(const ResourceRequestCompletionStatus& status) override { | 425 void OnComplete(const ResourceRequestCompletionStatus& status) override { |
| 426 if (status.error_code != net::OK) { | 426 if (status.error_code != net::OK) { |
| 427 std::string error_message; | |
| 428 if (status.error_code == net::ERR_ABORTED) { | |
| 429 error_message = | |
| 430 "The service worker navigation preload request was cancelled " | |
| 431 "before 'preloadResponse' settled. If you intend to use " | |
| 432 "'preloadResponse', use waitUntil() or respondWith() to wait for " | |
| 433 "the promise to settle."; | |
| 434 } else { | |
| 435 error_message = base::StringPrintf( | |
| 436 "The service worker navigation preload request failed with network " | |
| 437 "error code %d.", | |
| 438 status.error_code); | |
|
horo
2017/04/12 00:32:03
I think we should not expose the error code for se
| |
| 439 } | |
| 427 // This will delete |this|. | 440 // This will delete |this|. |
| 428 ReportErrorToClient("Service Worker navigation preload network error."); | 441 ReportErrorToClient(error_message); |
| 429 return; | 442 return; |
| 430 } | 443 } |
| 431 | 444 |
| 432 ServiceWorkerContextClient* client = | 445 ServiceWorkerContextClient* client = |
| 433 ServiceWorkerContextClient::ThreadSpecificInstance(); | 446 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 434 if (!client) | 447 if (!client) |
| 435 return; | 448 return; |
| 436 if (response_) { | 449 if (response_) { |
| 437 // When the response body from the server is empty, OnComplete() is called | 450 // When the response body from the server is empty, OnComplete() is called |
| 438 // without OnStartLoadingResponseBody(). | 451 // without OnStartLoadingResponseBody(). |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 451 ServiceWorkerContextClient* client = | 464 ServiceWorkerContextClient* client = |
| 452 ServiceWorkerContextClient::ThreadSpecificInstance(); | 465 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 453 if (!client) | 466 if (!client) |
| 454 return; | 467 return; |
| 455 | 468 |
| 456 client->OnNavigationPreloadResponse( | 469 client->OnNavigationPreloadResponse( |
| 457 fetch_event_id_, std::move(response_), | 470 fetch_event_id_, std::move(response_), |
| 458 base::MakeUnique<WebDataConsumerHandleImpl>(std::move(body_))); | 471 base::MakeUnique<WebDataConsumerHandleImpl>(std::move(body_))); |
| 459 } | 472 } |
| 460 | 473 |
| 461 void ReportErrorToClient(const char* error_message) { | 474 void ReportErrorToClient(const std::string& error_message) { |
| 462 ServiceWorkerContextClient* client = | 475 ServiceWorkerContextClient* client = |
| 463 ServiceWorkerContextClient::ThreadSpecificInstance(); | 476 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 464 if (!client) | 477 if (!client) |
| 465 return; | 478 return; |
| 466 // This will delete |this|. | 479 // This will delete |this|. |
| 467 client->OnNavigationPreloadError( | 480 client->OnNavigationPreloadError( |
| 468 fetch_event_id_, base::MakeUnique<blink::WebServiceWorkerError>( | 481 fetch_event_id_, base::MakeUnique<blink::WebServiceWorkerError>( |
| 469 blink::WebServiceWorkerError::kErrorTypeNetwork, | 482 blink::WebServiceWorkerError::kErrorTypeNetwork, |
| 470 blink::WebString::FromUTF8(error_message))); | 483 blink::WebString::FromUTF8(error_message))); |
| 471 } | 484 } |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1521 } | 1534 } |
| 1522 | 1535 |
| 1523 base::WeakPtr<ServiceWorkerContextClient> | 1536 base::WeakPtr<ServiceWorkerContextClient> |
| 1524 ServiceWorkerContextClient::GetWeakPtr() { | 1537 ServiceWorkerContextClient::GetWeakPtr() { |
| 1525 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1538 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1526 DCHECK(context_); | 1539 DCHECK(context_); |
| 1527 return context_->weak_factory.GetWeakPtr(); | 1540 return context_->weak_factory.GetWeakPtr(); |
| 1528 } | 1541 } |
| 1529 | 1542 |
| 1530 } // namespace content | 1543 } // namespace content |
| OLD | NEW |