| OLD | NEW |
| 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_fetch_dispatcher.h" | 5 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 url_(request.url) { | 125 url_(request.url) { |
| 126 AddDevToolsCallback( | 126 AddDevToolsCallback( |
| 127 base::Bind(&NotifyNavigationPreloadRequestSentOnUI, request)); | 127 base::Bind(&NotifyNavigationPreloadRequestSentOnUI, request)); |
| 128 } | 128 } |
| 129 ~DelegatingURLLoaderClient() override { | 129 ~DelegatingURLLoaderClient() override { |
| 130 if (!completed_) { | 130 if (!completed_) { |
| 131 // Let the service worker know that the request has been canceled. | 131 // Let the service worker know that the request has been canceled. |
| 132 ResourceRequestCompletionStatus status; | 132 ResourceRequestCompletionStatus status; |
| 133 status.error_code = net::ERR_ABORTED; | 133 status.error_code = net::ERR_ABORTED; |
| 134 client_->OnComplete(status); | 134 client_->OnComplete(status); |
| 135 AddDevToolsCallback( |
| 136 base::Bind(&NotifyNavigationPreloadCompletedOnUI, status)); |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 | 139 |
| 138 void MayBeReportToDevTools(WorkerId worker_id, int fetch_event_id) { | 140 void MayBeReportToDevTools(WorkerId worker_id, int fetch_event_id) { |
| 139 worker_id_ = worker_id; | 141 worker_id_ = worker_id; |
| 140 devtools_request_id_ = base::StringPrintf("preload-%d", fetch_event_id); | 142 devtools_request_id_ = base::StringPrintf("preload-%d", fetch_event_id); |
| 141 MayBeRunDevToolsCallbacks(); | 143 MayBeRunDevToolsCallbacks(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override { | 146 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 159 const ResourceResponseHead& head, | 161 const ResourceResponseHead& head, |
| 160 mojom::DownloadedTempFilePtr downloaded_file) override { | 162 mojom::DownloadedTempFilePtr downloaded_file) override { |
| 161 client_->OnReceiveResponse(head, std::move(downloaded_file)); | 163 client_->OnReceiveResponse(head, std::move(downloaded_file)); |
| 162 DCHECK(on_response_); | 164 DCHECK(on_response_); |
| 163 std::move(on_response_).Run(); | 165 std::move(on_response_).Run(); |
| 164 AddDevToolsCallback( | 166 AddDevToolsCallback( |
| 165 base::Bind(&NotifyNavigationPreloadResponseReceivedOnUI, url_, head)); | 167 base::Bind(&NotifyNavigationPreloadResponseReceivedOnUI, url_, head)); |
| 166 } | 168 } |
| 167 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, | 169 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, |
| 168 const ResourceResponseHead& head) override { | 170 const ResourceResponseHead& head) override { |
| 171 completed_ = true; |
| 172 // When the server returns a redirect response, we only send |
| 173 // OnReceiveRedirect IPC and don't send OnComplete IPC. The service worker |
| 174 // will clean up the preload request when OnReceiveRedirect() is called. |
| 169 client_->OnReceiveRedirect(redirect_info, head); | 175 client_->OnReceiveRedirect(redirect_info, head); |
| 176 AddDevToolsCallback( |
| 177 base::Bind(&NotifyNavigationPreloadResponseReceivedOnUI, url_, head)); |
| 178 ResourceRequestCompletionStatus status; |
| 179 AddDevToolsCallback( |
| 180 base::Bind(&NotifyNavigationPreloadCompletedOnUI, status)); |
| 170 } | 181 } |
| 171 void OnStartLoadingResponseBody( | 182 void OnStartLoadingResponseBody( |
| 172 mojo::ScopedDataPipeConsumerHandle body) override { | 183 mojo::ScopedDataPipeConsumerHandle body) override { |
| 173 client_->OnStartLoadingResponseBody(std::move(body)); | 184 client_->OnStartLoadingResponseBody(std::move(body)); |
| 174 } | 185 } |
| 175 void OnComplete( | 186 void OnComplete( |
| 176 const ResourceRequestCompletionStatus& completion_status) override { | 187 const ResourceRequestCompletionStatus& completion_status) override { |
| 188 if (completed_) |
| 189 return; |
| 190 completed_ = true; |
| 177 client_->OnComplete(completion_status); | 191 client_->OnComplete(completion_status); |
| 178 completed_ = true; | |
| 179 AddDevToolsCallback( | 192 AddDevToolsCallback( |
| 180 base::Bind(&NotifyNavigationPreloadCompletedOnUI, completion_status)); | 193 base::Bind(&NotifyNavigationPreloadCompletedOnUI, completion_status)); |
| 181 } | 194 } |
| 182 | 195 |
| 183 void Bind(mojom::URLLoaderClientPtr* ptr_info) { binding_.Bind(ptr_info); } | 196 void Bind(mojom::URLLoaderClientPtr* ptr_info) { binding_.Bind(ptr_info); } |
| 184 | 197 |
| 185 private: | 198 private: |
| 186 void MayBeRunDevToolsCallbacks() { | 199 void MayBeRunDevToolsCallbacks() { |
| 187 if (!worker_id_) | 200 if (!worker_id_) |
| 188 return; | 201 return; |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 ServiceWorkerVersion* version, | 623 ServiceWorkerVersion* version, |
| 611 int event_finish_id, | 624 int event_finish_id, |
| 612 scoped_refptr<URLLoaderAssets> url_loader_assets, | 625 scoped_refptr<URLLoaderAssets> url_loader_assets, |
| 613 ServiceWorkerStatusCode status, | 626 ServiceWorkerStatusCode status, |
| 614 base::Time dispatch_event_time) { | 627 base::Time dispatch_event_time) { |
| 615 version->FinishRequest(event_finish_id, status != SERVICE_WORKER_ERROR_ABORT, | 628 version->FinishRequest(event_finish_id, status != SERVICE_WORKER_ERROR_ABORT, |
| 616 dispatch_event_time); | 629 dispatch_event_time); |
| 617 } | 630 } |
| 618 | 631 |
| 619 } // namespace content | 632 } // namespace content |
| OLD | NEW |