| 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_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 <limits> |   10 #include <limits> | 
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  361 void ServiceWorkerURLRequestJob::RecordResult( |  361 void ServiceWorkerURLRequestJob::RecordResult( | 
|  362     ServiceWorkerMetrics::URLRequestJobResult result) { |  362     ServiceWorkerMetrics::URLRequestJobResult result) { | 
|  363   // It violates style guidelines to handle a NOTREACHED() failure but if there |  363   // It violates style guidelines to handle a NOTREACHED() failure but if there | 
|  364   // is a bug don't let it corrupt UMA results by double-counting. |  364   // is a bug don't let it corrupt UMA results by double-counting. | 
|  365   if (!ShouldRecordResult()) { |  365   if (!ShouldRecordResult()) { | 
|  366     NOTREACHED(); |  366     NOTREACHED(); | 
|  367     return; |  367     return; | 
|  368   } |  368   } | 
|  369   did_record_result_ = true; |  369   did_record_result_ = true; | 
|  370   ServiceWorkerMetrics::RecordURLRequestJobResult(IsMainResourceLoad(), result); |  370   ServiceWorkerMetrics::RecordURLRequestJobResult(IsMainResourceLoad(), result); | 
|  371   if (request()) { |  371   request()->net_log().AddEvent(RequestJobResultToNetEventType(result)); | 
|  372     request()->net_log().AddEvent(RequestJobResultToNetEventType(result)); |  | 
|  373   } |  | 
|  374 } |  372 } | 
|  375  |  373  | 
|  376 base::WeakPtr<ServiceWorkerURLRequestJob> |  374 base::WeakPtr<ServiceWorkerURLRequestJob> | 
|  377 ServiceWorkerURLRequestJob::GetWeakPtr() { |  375 ServiceWorkerURLRequestJob::GetWeakPtr() { | 
|  378   return weak_factory_.GetWeakPtr(); |  376   return weak_factory_.GetWeakPtr(); | 
|  379 } |  377 } | 
|  380  |  378  | 
|  381 const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const { |  379 const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const { | 
|  382   if (!http_response_info_) |  380   if (!http_response_info_) | 
|  383     return nullptr; |  381     return nullptr; | 
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  579 } |  577 } | 
|  580  |  578  | 
|  581 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( |  579 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( | 
|  582     ServiceWorkerStatusCode status, |  580     ServiceWorkerStatusCode status, | 
|  583     ServiceWorkerFetchEventResult fetch_result, |  581     ServiceWorkerFetchEventResult fetch_result, | 
|  584     const ServiceWorkerResponse& response, |  582     const ServiceWorkerResponse& response, | 
|  585     const scoped_refptr<ServiceWorkerVersion>& version) { |  583     const scoped_refptr<ServiceWorkerVersion>& version) { | 
|  586   fetch_dispatcher_.reset(); |  584   fetch_dispatcher_.reset(); | 
|  587   ServiceWorkerMetrics::RecordFetchEventStatus(IsMainResourceLoad(), status); |  585   ServiceWorkerMetrics::RecordFetchEventStatus(IsMainResourceLoad(), status); | 
|  588  |  586  | 
|  589   // Check if we're not orphaned. |  | 
|  590   if (!request()) { |  | 
|  591     RecordResult(ServiceWorkerMetrics::REQUEST_JOB_ERROR_NO_REQUEST); |  | 
|  592     return; |  | 
|  593   } |  | 
|  594  |  | 
|  595   ServiceWorkerMetrics::URLRequestJobResult result = |  587   ServiceWorkerMetrics::URLRequestJobResult result = | 
|  596       ServiceWorkerMetrics::REQUEST_JOB_ERROR_BAD_DELEGATE; |  588       ServiceWorkerMetrics::REQUEST_JOB_ERROR_BAD_DELEGATE; | 
|  597   if (!delegate_->RequestStillValid(&result)) { |  589   if (!delegate_->RequestStillValid(&result)) { | 
|  598     RecordResult(result); |  590     RecordResult(result); | 
|  599     DeliverErrorResponse(); |  591     DeliverErrorResponse(); | 
|  600     return; |  592     return; | 
|  601   } |  593   } | 
|  602  |  594  | 
|  603   if (status != SERVICE_WORKER_OK) { |  595   if (status != SERVICE_WORKER_OK) { | 
|  604     RecordResult(ServiceWorkerMetrics::REQUEST_JOB_ERROR_FETCH_EVENT_DISPATCH); |  596     RecordResult(ServiceWorkerMetrics::REQUEST_JOB_ERROR_FETCH_EVENT_DISPATCH); | 
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  894                  weak_factory_.GetWeakPtr(), active_worker), |  886                  weak_factory_.GetWeakPtr(), active_worker), | 
|  895       base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, |  887       base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, | 
|  896                  weak_factory_.GetWeakPtr()))); |  888                  weak_factory_.GetWeakPtr()))); | 
|  897   worker_start_time_ = base::TimeTicks::Now(); |  889   worker_start_time_ = base::TimeTicks::Now(); | 
|  898   fetch_dispatcher_->MaybeStartNavigationPreload(request(), |  890   fetch_dispatcher_->MaybeStartNavigationPreload(request(), | 
|  899                                                  url_loader_factory_getter_); |  891                                                  url_loader_factory_getter_); | 
|  900   fetch_dispatcher_->Run(); |  892   fetch_dispatcher_->Run(); | 
|  901 } |  893 } | 
|  902  |  894  | 
|  903 }  // namespace content |  895 }  // namespace content | 
| OLD | NEW |