| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "content/browser/service_worker/embedded_worker_status.h" |
| 11 #include "content/browser/service_worker/service_worker_version.h" | 12 #include "content/browser/service_worker/service_worker_version.h" |
| 12 #include "content/common/service_worker/service_worker_messages.h" | 13 #include "content/common/service_worker/service_worker_messages.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 using EventType = ServiceWorkerMetrics::EventType; | 18 using EventType = ServiceWorkerMetrics::EventType; |
| 18 EventType ResourceTypeToEventType(ResourceType resource_type) { | 19 EventType ResourceTypeToEventType(ResourceType resource_type) { |
| 19 switch (resource_type) { | 20 switch (resource_type) { |
| 20 case RESOURCE_TYPE_MAIN_FRAME: | 21 case RESOURCE_TYPE_MAIN_FRAME: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // The previous activation seems to have failed, abort the step | 81 // The previous activation seems to have failed, abort the step |
| 81 // with activate error. (The error should be separately reported | 82 // with activate error. (The error should be separately reported |
| 82 // to the associated documents and association must be dropped | 83 // to the associated documents and association must be dropped |
| 83 // at this point) | 84 // at this point) |
| 84 DidFinish(SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED, | 85 DidFinish(SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED, |
| 85 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, | 86 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
| 86 ServiceWorkerResponse()); | 87 ServiceWorkerResponse()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void ServiceWorkerFetchDispatcher::DispatchFetchEvent() { | 90 void ServiceWorkerFetchDispatcher::DispatchFetchEvent() { |
| 90 DCHECK_EQ(ServiceWorkerVersion::RUNNING, version_->running_status()) | 91 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()) |
| 91 << "Worker stopped too soon after it was started."; | 92 << "Worker stopped too soon after it was started."; |
| 92 | 93 |
| 93 DCHECK(!prepare_callback_.is_null()); | 94 DCHECK(!prepare_callback_.is_null()); |
| 94 base::Closure prepare_callback = prepare_callback_; | 95 base::Closure prepare_callback = prepare_callback_; |
| 95 prepare_callback.Run(); | 96 prepare_callback.Run(); |
| 96 | 97 |
| 97 int request_id = version_->StartRequest( | 98 int request_id = version_->StartRequest( |
| 98 GetEventType(), base::Bind(&ServiceWorkerFetchDispatcher::DidFail, | 99 GetEventType(), base::Bind(&ServiceWorkerFetchDispatcher::DidFail, |
| 99 weak_factory_.GetWeakPtr())); | 100 weak_factory_.GetWeakPtr())); |
| 100 version_->DispatchEvent<ServiceWorkerHostMsg_FetchEventFinished>( | 101 version_->DispatchEvent<ServiceWorkerHostMsg_FetchEventFinished>( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 134 } |
| 134 | 135 |
| 135 ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType() | 136 ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType() |
| 136 const { | 137 const { |
| 137 if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) | 138 if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) |
| 138 return ServiceWorkerMetrics::EventType::FOREIGN_FETCH; | 139 return ServiceWorkerMetrics::EventType::FOREIGN_FETCH; |
| 139 return ResourceTypeToEventType(resource_type_); | 140 return ResourceTypeToEventType(resource_type_); |
| 140 } | 141 } |
| 141 | 142 |
| 142 } // namespace content | 143 } // namespace content |
| OLD | NEW |