| 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> |  | 
|   11 #include <map> |   10 #include <map> | 
|   12 #include <string> |   11 #include <string> | 
|   13 #include <utility> |   12 #include <utility> | 
|   14 #include <vector> |   13 #include <vector> | 
|   15  |   14  | 
|   16 #include "base/bind.h" |   15 #include "base/bind.h" | 
 |   16 #include "base/files/file_util.h" | 
|   17 #include "base/guid.h" |   17 #include "base/guid.h" | 
|   18 #include "base/location.h" |   18 #include "base/location.h" | 
|   19 #include "base/single_thread_task_runner.h" |   19 #include "base/single_thread_task_runner.h" | 
|   20 #include "base/strings/stringprintf.h" |   20 #include "base/strings/stringprintf.h" | 
 |   21 #include "base/task_runner.h" | 
 |   22 #include "base/task_runner_util.h" | 
|   21 #include "base/threading/thread_task_runner_handle.h" |   23 #include "base/threading/thread_task_runner_handle.h" | 
|   22 #include "base/time/time.h" |   24 #include "base/time/time.h" | 
|   23 #include "content/browser/resource_context_impl.h" |   25 #include "content/browser/resource_context_impl.h" | 
|   24 #include "content/browser/service_worker/embedded_worker_instance.h" |   26 #include "content/browser/service_worker/embedded_worker_instance.h" | 
|   25 #include "content/browser/service_worker/service_worker_blob_reader.h" |   27 #include "content/browser/service_worker/service_worker_blob_reader.h" | 
|   26 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |   28 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" | 
|   27 #include "content/browser/service_worker/service_worker_provider_host.h" |   29 #include "content/browser/service_worker/service_worker_provider_host.h" | 
|   28 #include "content/browser/service_worker/service_worker_response_info.h" |   30 #include "content/browser/service_worker/service_worker_response_info.h" | 
|   29 #include "content/browser/service_worker/service_worker_stream_reader.h" |   31 #include "content/browser/service_worker/service_worker_stream_reader.h" | 
|   30 #include "content/common/resource_request_body_impl.h" |   32 #include "content/common/resource_request_body_impl.h" | 
|   31 #include "content/common/service_worker/service_worker_types.h" |   33 #include "content/common/service_worker/service_worker_types.h" | 
|   32 #include "content/common/service_worker/service_worker_utils.h" |   34 #include "content/common/service_worker/service_worker_utils.h" | 
|   33 #include "content/public/browser/blob_handle.h" |   35 #include "content/public/browser/blob_handle.h" | 
 |   36 #include "content/public/browser/browser_thread.h" | 
|   34 #include "content/public/browser/resource_request_info.h" |   37 #include "content/public/browser/resource_request_info.h" | 
|   35 #include "content/public/browser/service_worker_context.h" |   38 #include "content/public/browser/service_worker_context.h" | 
|   36 #include "content/public/common/referrer.h" |   39 #include "content/public/common/referrer.h" | 
|   37 #include "net/base/net_errors.h" |   40 #include "net/base/net_errors.h" | 
|   38 #include "net/http/http_request_headers.h" |   41 #include "net/http/http_request_headers.h" | 
|   39 #include "net/http/http_response_headers.h" |   42 #include "net/http/http_response_headers.h" | 
|   40 #include "net/http/http_response_info.h" |   43 #include "net/http/http_response_info.h" | 
|   41 #include "net/http/http_util.h" |   44 #include "net/http/http_util.h" | 
|   42 #include "net/log/net_log.h" |   45 #include "net/log/net_log.h" | 
|   43 #include "net/log/net_log_event_type.h" |   46 #include "net/log/net_log_event_type.h" | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   97     case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB: |  100     case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB: | 
|   98     case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM: |  101     case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM: | 
|   99     // Invalid type. |  102     // Invalid type. | 
|  100     case m::NUM_REQUEST_JOB_RESULT_TYPES: |  103     case m::NUM_REQUEST_JOB_RESULT_TYPES: | 
|  101       NOTREACHED() << result; |  104       NOTREACHED() << result; | 
|  102   } |  105   } | 
|  103   NOTREACHED() << result; |  106   NOTREACHED() << result; | 
|  104   return n::FAILED; |  107   return n::FAILED; | 
|  105 } |  108 } | 
|  106  |  109  | 
 |  110 int64_t GetFileSizeOnBlockingPool(const base::FilePath& path) { | 
 |  111   base::File::Info file_info; | 
 |  112   if (!base::GetFileInfo(path, &file_info)) | 
 |  113     return -1; | 
 |  114   return file_info.size; | 
 |  115 } | 
 |  116  | 
 |  117 bool PopulateUnknownFileLengths( | 
 |  118     std::vector<ResourceRequestBodyImpl::Element>* elements) { | 
 |  119   for (ResourceRequestBodyImpl::Element& element : *elements) { | 
 |  120     if (element.type() == ResourceRequestBodyImpl::Element::TYPE_FILE && | 
 |  121         element.length() == ResourceRequestBodyImpl::Element::kUnknownSize) { | 
 |  122       base::File::Info file_info; | 
 |  123       if (!base::GetFileInfo(element.path(), &file_info)) | 
 |  124         return false; | 
 |  125  | 
 |  126       element.SetToFilePathRange(element.path(), element.offset(), | 
 |  127                                  file_info.size, | 
 |  128                                  element.expected_modification_time()); | 
 |  129     } | 
 |  130   } | 
 |  131   return true; | 
 |  132 } | 
 |  133  | 
|  107 }  // namespace |  134 }  // namespace | 
|  108  |  135  | 
|  109 class ServiceWorkerURLRequestJob::BlobConstructionWaiter { |  136 class ServiceWorkerURLRequestJob::FileSizeResolver { | 
|  110  public: |  137  public: | 
|  111   explicit BlobConstructionWaiter(ServiceWorkerURLRequestJob* owner) |  138   explicit FileSizeResolver(ServiceWorkerURLRequestJob* owner) | 
|  112       : owner_(owner), weak_factory_(this) { |  139       : owner_(owner), weak_factory_(this) { | 
|  113     TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "BlobConstructionWaiter", this, |  140     TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "BlobFilesWaiter", this, "URL", | 
|  114                              "URL", owner_->request()->url().spec()); |  141                              owner_->request()->url().spec()); | 
|  115     owner_->request()->net_log().BeginEvent( |  142     owner_->request()->net_log().BeginEvent( | 
|  116         net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_BLOB); |  143         net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_FILES); | 
|  117   } |  144   } | 
|  118  |  145  | 
|  119   ~BlobConstructionWaiter() { |  146   ~FileSizeResolver() { | 
|  120     owner_->request()->net_log().EndEvent( |  147     owner_->request()->net_log().EndEvent( | 
|  121         net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_BLOB, |  148         net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_FILES, | 
|  122         net::NetLog::BoolCallback("success", phase_ == Phase::SUCCESS)); |  149         net::NetLog::BoolCallback("success", phase_ == Phase::SUCCESS)); | 
|  123     TRACE_EVENT_ASYNC_END1("ServiceWorker", "BlobConstructionWaiter", this, |  150     TRACE_EVENT_ASYNC_END1("ServiceWorker", "BlobFilesWaiter", this, "Success", | 
|  124                            "Success", phase_ == Phase::SUCCESS); |  151                            phase_ == Phase::SUCCESS); | 
|  125   } |  152   } | 
|  126  |  153  | 
|  127   void RunOnComplete(const base::Callback<void(bool)>& callback) { |  154   void RunOnComplete(base::TaskRunner* file_runner, | 
 |  155                      const base::Callback<void(bool)>& callback) { | 
|  128     DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_)); |  156     DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_)); | 
|  129     phase_ = Phase::WAITING; |  157     phase_ = Phase::WAITING; | 
|  130     num_pending_request_body_blobs_ = 0; |  158     body_ = owner_->body_; | 
|  131     callback_ = callback; |  159     callback_ = callback; | 
|  132  |  160  | 
|  133     for (const ResourceRequestBodyImpl::Element& element : |  161     bool needs_file_stats = false; | 
|  134          *(owner_->body_->elements())) { |  162     size_t i = 0; | 
|  135       if (element.type() != ResourceRequestBodyImpl::Element::TYPE_BLOB) |  163     for (const ResourceRequestBodyImpl::Element& element : *body_->elements()) { | 
|  136         continue; |  164       if (element.type() == ResourceRequestBodyImpl::Element::TYPE_FILE && | 
 |  165           element.length() == ResourceRequestBodyImpl::Element::kUnknownSize) { | 
 |  166         needs_file_stats = true; | 
|  137  |  167  | 
|  138       std::unique_ptr<storage::BlobDataHandle> handle = |  168         PostTaskAndReplyWithResult( | 
|  139           owner_->blob_storage_context_->GetBlobDataFromUUID( |  169             file_runner, FROM_HERE, | 
|  140               element.blob_uuid()); |  170             base::Bind(&GetFileSizeOnBlockingPool, element.path()), | 
|  141       if (handle->IsBroken()) { |  171             base::Bind(&ServiceWorkerURLRequestJob::FileSizeResolver:: | 
|  142         Complete(false); |  172                            OnFileSizeResolved, | 
|  143         return; |  173                        weak_factory_.GetWeakPtr(), i)); | 
|  144       } |  174       } | 
|  145       if (handle->IsBeingBuilt()) { |  175       i++; | 
|  146         ++num_pending_request_body_blobs_; |  | 
|  147         handle->RunOnConstructionComplete( |  | 
|  148             base::Bind(&BlobConstructionWaiter::OneRequestBodyBlobCompleted, |  | 
|  149                        weak_factory_.GetWeakPtr())); |  | 
|  150       } |  | 
|  151     } |  176     } | 
|  152  |  177  | 
|  153     if (num_pending_request_body_blobs_ == 0) |  178     if (!needs_file_stats) { | 
|  154       Complete(true); |  179       Complete(true); | 
 |  180       return; | 
 |  181     } | 
|  155   } |  182   } | 
|  156  |  183  | 
|  157  private: |  184  private: | 
|  158   enum class Phase { INITIAL, WAITING, SUCCESS, FAIL }; |  185   enum class Phase { INITIAL, WAITING, SUCCESS, FAIL }; | 
|  159  |  186  | 
|  160   void OneRequestBodyBlobCompleted( |  187   void OnFileSizeResolved(int element_index, int64_t file_size) { | 
|  161       bool success, |  188     bool success = file_size >= 0; | 
|  162       storage::IPCBlobCreationCancelCode cancel_code) { |  189     if (success) { | 
|  163     DCHECK_GT(num_pending_request_body_blobs_, 0UL); |  190       auto& element = (*body_->elements_mutable())[element_index]; | 
 |  191       element.SetToFilePathRange(element.path(), element.offset(), | 
 |  192                                  static_cast<uint64_t>(file_size), | 
 |  193                                  element.expected_modification_time()); | 
 |  194       --num_pending_file_size_tasks_; | 
 |  195     } else { | 
 |  196       num_pending_file_size_tasks_ = 0; | 
 |  197     } | 
|  164  |  198  | 
|  165     if (success) |  199     if (num_pending_file_size_tasks_) | 
|  166       --num_pending_request_body_blobs_; |  | 
|  167     else |  | 
|  168       num_pending_request_body_blobs_ = 0; |  | 
|  169  |  | 
|  170     if (num_pending_request_body_blobs_ == 0) |  | 
|  171       Complete(success); |  200       Complete(success); | 
|  172   } |  201   } | 
|  173  |  202  | 
|  174   void Complete(bool success) { |  203   void Complete(bool success) { | 
|  175     DCHECK_EQ(static_cast<int>(Phase::WAITING), static_cast<int>(phase_)); |  204     DCHECK_EQ(static_cast<int>(Phase::WAITING), static_cast<int>(phase_)); | 
|  176     phase_ = success ? Phase::SUCCESS : Phase::FAIL; |  205     phase_ = success ? Phase::SUCCESS : Phase::FAIL; | 
|  177     // Destroys |this|. |  206     // Destroys |this|. | 
|  178     callback_.Run(success); |  207     callback_.Run(success); | 
|  179   } |  208   } | 
|  180  |  209  | 
|  181   // Owns and must outlive |this|. |  210   // Owns and must outlive |this|. | 
|  182   ServiceWorkerURLRequestJob* owner_; |  211   ServiceWorkerURLRequestJob* owner_; | 
|  183  |  212  | 
|  184   scoped_refptr<ResourceRequestBodyImpl> body_; |  213   scoped_refptr<ResourceRequestBodyImpl> body_; | 
|  185   base::Callback<void(bool)> callback_; |  214   base::Callback<void(bool)> callback_; | 
|  186   size_t num_pending_request_body_blobs_ = 0; |  | 
|  187   Phase phase_ = Phase::INITIAL; |  215   Phase phase_ = Phase::INITIAL; | 
|  188   base::WeakPtrFactory<BlobConstructionWaiter> weak_factory_; |  216   size_t num_pending_file_size_tasks_ = 0; | 
 |  217   base::WeakPtrFactory<FileSizeResolver> weak_factory_; | 
|  189  |  218  | 
|  190   DISALLOW_COPY_AND_ASSIGN(BlobConstructionWaiter); |  219   DISALLOW_COPY_AND_ASSIGN(FileSizeResolver); | 
|  191 }; |  220 }; | 
|  192  |  221  | 
|  193 bool ServiceWorkerURLRequestJob::Delegate::RequestStillValid( |  222 bool ServiceWorkerURLRequestJob::Delegate::RequestStillValid( | 
|  194     ServiceWorkerMetrics::URLRequestJobResult* result) { |  223     ServiceWorkerMetrics::URLRequestJobResult* result) { | 
|  195   return true; |  224   return true; | 
|  196 } |  225 } | 
|  197  |  226  | 
|  198 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( |  227 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( | 
|  199     net::URLRequest* request, |  228     net::URLRequest* request, | 
|  200     net::NetworkDelegate* network_delegate, |  229     net::NetworkDelegate* network_delegate, | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|  228       fall_back_required_(false), |  257       fall_back_required_(false), | 
|  229       body_(body), |  258       body_(body), | 
|  230       fetch_type_(fetch_type), |  259       fetch_type_(fetch_type), | 
|  231       url_loader_factory_getter_(url_loader_factory_getter), |  260       url_loader_factory_getter_(url_loader_factory_getter), | 
|  232       weak_factory_(this) { |  261       weak_factory_(this) { | 
|  233   DCHECK(delegate_) << "ServiceWorkerURLRequestJob requires a delegate"; |  262   DCHECK(delegate_) << "ServiceWorkerURLRequestJob requires a delegate"; | 
|  234 } |  263 } | 
|  235  |  264  | 
|  236 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { |  265 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { | 
|  237   stream_reader_.reset(); |  266   stream_reader_.reset(); | 
|  238   blob_construction_waiter_.reset(); |  267   file_size_resolver_.reset(); | 
|  239  |  268  | 
|  240   if (!ShouldRecordResult()) |  269   if (!ShouldRecordResult()) | 
|  241     return; |  270     return; | 
|  242   ServiceWorkerMetrics::URLRequestJobResult result = |  271   ServiceWorkerMetrics::URLRequestJobResult result = | 
|  243       ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED; |  272       ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED; | 
|  244   if (response_body_type_ == STREAM) |  273   if (response_body_type_ == STREAM) | 
|  245     result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM; |  274     result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM; | 
|  246   else if (response_body_type_ == BLOB) |  275   else if (response_body_type_ == BLOB) | 
|  247     result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB; |  276     result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB; | 
|  248   RecordResult(result); |  277   RecordResult(result); | 
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  407     case FALLBACK_TO_NETWORK: |  436     case FALLBACK_TO_NETWORK: | 
|  408       FinalizeFallbackToNetwork(); |  437       FinalizeFallbackToNetwork(); | 
|  409       return; |  438       return; | 
|  410  |  439  | 
|  411     case FALLBACK_TO_RENDERER: |  440     case FALLBACK_TO_RENDERER: | 
|  412       FinalizeFallbackToRenderer(); |  441       FinalizeFallbackToRenderer(); | 
|  413       return; |  442       return; | 
|  414  |  443  | 
|  415     case FORWARD_TO_SERVICE_WORKER: |  444     case FORWARD_TO_SERVICE_WORKER: | 
|  416       if (HasRequestBody()) { |  445       if (HasRequestBody()) { | 
|  417         DCHECK(!blob_construction_waiter_); |  446         DCHECK(!file_size_resolver_); | 
|  418         blob_construction_waiter_.reset(new BlobConstructionWaiter(this)); |  447         file_size_resolver_.reset(new FileSizeResolver(this)); | 
|  419         blob_construction_waiter_->RunOnComplete( |  448         file_size_resolver_->RunOnComplete( | 
 |  449             BrowserThread::GetBlockingPool(), | 
|  420             base::Bind(&ServiceWorkerURLRequestJob::RequestBodyBlobsCompleted, |  450             base::Bind(&ServiceWorkerURLRequestJob::RequestBodyBlobsCompleted, | 
|  421                        GetWeakPtr())); |  451                        GetWeakPtr())); | 
|  422         return; |  452         return; | 
|  423       } |  453       } | 
|  424  |  454  | 
|  425       RequestBodyBlobsCompleted(true); |  455       RequestBodyBlobsCompleted(true); | 
|  426       return; |  456       return; | 
|  427   } |  457   } | 
|  428  |  458  | 
|  429   NOTREACHED(); |  459   NOTREACHED(); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  467     request->referrer = |  497     request->referrer = | 
|  468         Referrer(GURL(request_->referrer()), blink::WebReferrerPolicyDefault); |  498         Referrer(GURL(request_->referrer()), blink::WebReferrerPolicyDefault); | 
|  469   } |  499   } | 
|  470   request->fetch_type = fetch_type_; |  500   request->fetch_type = fetch_type_; | 
|  471   return request; |  501   return request; | 
|  472 } |  502 } | 
|  473  |  503  | 
|  474 void ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, |  504 void ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, | 
|  475                                                        uint64_t* blob_size) { |  505                                                        uint64_t* blob_size) { | 
|  476   DCHECK(HasRequestBody()); |  506   DCHECK(HasRequestBody()); | 
|  477   // To ensure the blobs stick around until the end of the reading. |  507   const std::string uuid(base::GenerateGUID()); | 
|  478   std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |  508   storage::BlobDataBuilder blob_builder(uuid); | 
|  479   std::vector<std::unique_ptr<storage::BlobDataSnapshot>> snapshots; |  | 
|  480   // TODO(dmurph): Allow blobs to be added below, so that the context can |  | 
|  481   // efficiently re-use blob items for the new blob. |  | 
|  482   std::vector<const ResourceRequestBodyImpl::Element*> resolved_elements; |  | 
|  483   for (const ResourceRequestBodyImpl::Element& element : (*body_->elements())) { |  509   for (const ResourceRequestBodyImpl::Element& element : (*body_->elements())) { | 
|  484     if (element.type() != ResourceRequestBodyImpl::Element::TYPE_BLOB) { |  510     blob_builder.AppendIPCDataElement(element); | 
|  485       resolved_elements.push_back(&element); |  | 
|  486       continue; |  | 
|  487     } |  | 
|  488     std::unique_ptr<storage::BlobDataHandle> handle = |  | 
|  489         blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); |  | 
|  490     std::unique_ptr<storage::BlobDataSnapshot> snapshot = |  | 
|  491         handle->CreateSnapshot(); |  | 
|  492     if (snapshot->items().empty()) |  | 
|  493       continue; |  | 
|  494     const auto& items = snapshot->items(); |  | 
|  495     for (const auto& item : items) { |  | 
|  496       DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type()); |  | 
|  497       resolved_elements.push_back(item->data_element_ptr()); |  | 
|  498     } |  | 
|  499     handles.push_back(std::move(handle)); |  | 
|  500     snapshots.push_back(std::move(snapshot)); |  | 
|  501   } |  | 
|  502  |  | 
|  503   const std::string uuid(base::GenerateGUID()); |  | 
|  504   uint64_t total_size = 0; |  | 
|  505  |  | 
|  506   storage::BlobDataBuilder blob_builder(uuid); |  | 
|  507   for (size_t i = 0; i < resolved_elements.size(); ++i) { |  | 
|  508     const ResourceRequestBodyImpl::Element& element = *resolved_elements[i]; |  | 
|  509     if (total_size != std::numeric_limits<uint64_t>::max() && |  | 
|  510         element.length() != std::numeric_limits<uint64_t>::max()) |  | 
|  511       total_size += element.length(); |  | 
|  512     else |  | 
|  513       total_size = std::numeric_limits<uint64_t>::max(); |  | 
|  514     switch (element.type()) { |  | 
|  515       case ResourceRequestBodyImpl::Element::TYPE_BYTES: |  | 
|  516         blob_builder.AppendData(element.bytes(), element.length()); |  | 
|  517         break; |  | 
|  518       case ResourceRequestBodyImpl::Element::TYPE_FILE: |  | 
|  519         blob_builder.AppendFile(element.path(), element.offset(), |  | 
|  520                                 element.length(), |  | 
|  521                                 element.expected_modification_time()); |  | 
|  522         break; |  | 
|  523       case ResourceRequestBodyImpl::Element::TYPE_BLOB: |  | 
|  524         // Blob elements should be resolved beforehand. |  | 
|  525         NOTREACHED(); |  | 
|  526         break; |  | 
|  527       case ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM: |  | 
|  528         blob_builder.AppendFileSystemFile(element.filesystem_url(), |  | 
|  529                                           element.offset(), element.length(), |  | 
|  530                                           element.expected_modification_time()); |  | 
|  531         break; |  | 
|  532       default: |  | 
|  533         NOTIMPLEMENTED(); |  | 
|  534     } |  | 
|  535   } |  511   } | 
|  536  |  512  | 
|  537   request_body_blob_data_handle_ = |  513   request_body_blob_data_handle_ = | 
|  538       blob_storage_context_->AddFinishedBlob(&blob_builder); |  514       blob_storage_context_->AddFinishedBlob(&blob_builder); | 
|  539   *blob_uuid = uuid; |  515   *blob_uuid = blob_builder.uuid(); | 
|  540   *blob_size = total_size; |  516   *blob_size = request_body_blob_data_handle_->size(); | 
|  541 } |  517 } | 
|  542  |  518  | 
|  543 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent( |  519 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent( | 
|  544     scoped_refptr<ServiceWorkerVersion> version) { |  520     scoped_refptr<ServiceWorkerVersion> version) { | 
|  545   worker_ready_time_ = base::TimeTicks::Now(); |  521   worker_ready_time_ = base::TimeTicks::Now(); | 
|  546   load_timing_info_.send_start = worker_ready_time_; |  522   load_timing_info_.send_start = worker_ready_time_; | 
|  547  |  523  | 
|  548   // Record the time taken for the browser to find and possibly start an active |  524   // Record the time taken for the browser to find and possibly start an active | 
|  549   // worker to which to dispatch a FetchEvent for a main frame resource request. |  525   // worker to which to dispatch a FetchEvent for a main frame resource request. | 
|  550   // For context, a FetchEvent can only be dispatched to an ACTIVATED worker |  526   // For context, a FetchEvent can only be dispatched to an ACTIVATED worker | 
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  854   return ServiceWorkerUtils::IsMainResourceType(resource_type_); |  830   return ServiceWorkerUtils::IsMainResourceType(resource_type_); | 
|  855 } |  831 } | 
|  856  |  832  | 
|  857 bool ServiceWorkerURLRequestJob::HasRequestBody() { |  833 bool ServiceWorkerURLRequestJob::HasRequestBody() { | 
|  858   // URLRequest::has_upload() must be checked since its upload data may have |  834   // URLRequest::has_upload() must be checked since its upload data may have | 
|  859   // been cleared while handling a redirect. |  835   // been cleared while handling a redirect. | 
|  860   return request_->has_upload() && body_.get() && blob_storage_context_; |  836   return request_->has_upload() && body_.get() && blob_storage_context_; | 
|  861 } |  837 } | 
|  862  |  838  | 
|  863 void ServiceWorkerURLRequestJob::RequestBodyBlobsCompleted(bool success) { |  839 void ServiceWorkerURLRequestJob::RequestBodyBlobsCompleted(bool success) { | 
|  864   blob_construction_waiter_.reset(); |  840   file_size_resolver_.reset(); | 
|  865   if (!success) { |  841   if (!success) { | 
|  866     RecordResult( |  842     RecordResult( | 
|  867         ServiceWorkerMetrics::REQUEST_JOB_ERROR_REQUEST_BODY_BLOB_FAILED); |  843         ServiceWorkerMetrics::REQUEST_JOB_ERROR_REQUEST_BODY_BLOB_FAILED); | 
|  868     // TODO(falken): This and below should probably be NotifyStartError, not |  844     // TODO(falken): This and below should probably be NotifyStartError, not | 
|  869     // DeliverErrorResponse. But changing it causes |  845     // DeliverErrorResponse. But changing it causes | 
|  870     // ServiceWorkerURLRequestJobTest.DeletedProviderHostBeforeFetchEvent to |  846     // ServiceWorkerURLRequestJobTest.DeletedProviderHostBeforeFetchEvent to | 
|  871     // fail. |  847     // fail. | 
|  872     DeliverErrorResponse(); |  848     DeliverErrorResponse(); | 
|  873     return; |  849     return; | 
|  874   } |  850   } | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  894                  weak_factory_.GetWeakPtr(), active_worker), |  870                  weak_factory_.GetWeakPtr(), active_worker), | 
|  895       base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, |  871       base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, | 
|  896                  weak_factory_.GetWeakPtr()))); |  872                  weak_factory_.GetWeakPtr()))); | 
|  897   worker_start_time_ = base::TimeTicks::Now(); |  873   worker_start_time_ = base::TimeTicks::Now(); | 
|  898   fetch_dispatcher_->MaybeStartNavigationPreload(request(), |  874   fetch_dispatcher_->MaybeStartNavigationPreload(request(), | 
|  899                                                  url_loader_factory_getter_); |  875                                                  url_loader_factory_getter_); | 
|  900   fetch_dispatcher_->Run(); |  876   fetch_dispatcher_->Run(); | 
|  901 } |  877 } | 
|  902  |  878  | 
|  903 }  // namespace content |  879 }  // namespace content | 
| OLD | NEW |