| 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // |preload_handle_|. Returns true if it started navigation preload. | 54 // |preload_handle_|. Returns true if it started navigation preload. |
| 55 // |on_response| is invoked in OnReceiveResponse(). | 55 // |on_response| is invoked in OnReceiveResponse(). |
| 56 bool MaybeStartNavigationPreload(net::URLRequest* original_request, | 56 bool MaybeStartNavigationPreload(net::URLRequest* original_request, |
| 57 base::OnceClosure on_response); | 57 base::OnceClosure on_response); |
| 58 | 58 |
| 59 // Dispatches a fetch event to the |version| given in ctor, and fires | 59 // Dispatches a fetch event to the |version| given in ctor, and fires |
| 60 // |fetch_callback| (also given in ctor) when finishes. It runs | 60 // |fetch_callback| (also given in ctor) when finishes. It runs |
| 61 // |prepare_callback| as an intermediate step once the version is activated | 61 // |prepare_callback| as an intermediate step once the version is activated |
| 62 // and running. | 62 // and running. |
| 63 void Run(); | 63 void Run(); |
| 64 void set_renderer_request_time(base::TimeTicks t) { |
| 65 renderer_request_time_ = t; |
| 66 } |
| 67 void set_handler_creation_time(base::TimeTicks t) { |
| 68 handler_creation_time_ = t; |
| 69 } |
| 70 void set_job_creation_time(base::TimeTicks t) { job_creation_time_ = t; } |
| 71 void set_worker_start_time(base::TimeTicks t) { worker_start_time_ = t; } |
| 64 | 72 |
| 65 private: | 73 private: |
| 66 class ResponseCallback; | 74 class ResponseCallback; |
| 67 class URLLoaderAssets; | 75 class URLLoaderAssets; |
| 68 | 76 |
| 69 void DidWaitForActivation(); | 77 void DidWaitForActivation(); |
| 70 void StartWorker(); | 78 void StartWorker(); |
| 71 void DidStartWorker(); | 79 void DidStartWorker(); |
| 72 void DidFailToStartWorker(ServiceWorkerStatusCode status); | 80 void DidFailToStartWorker(ServiceWorkerStatusCode status); |
| 73 void DispatchFetchEvent(); | 81 void DispatchFetchEvent(); |
| 74 void DidFailToDispatch(ServiceWorkerStatusCode status); | 82 void DidFailToDispatch(ServiceWorkerStatusCode status); |
| 75 void DidFail(ServiceWorkerStatusCode status); | 83 void DidFail(ServiceWorkerStatusCode status); |
| 76 void DidFinish(int request_id, | 84 void DidFinish(int request_id, |
| 77 ServiceWorkerFetchEventResult fetch_result, | 85 ServiceWorkerFetchEventResult fetch_result, |
| 78 const ServiceWorkerResponse& response); | 86 const ServiceWorkerResponse& response, |
| 87 base::TimeTicks response_time); |
| 79 void Complete(ServiceWorkerStatusCode status, | 88 void Complete(ServiceWorkerStatusCode status, |
| 80 ServiceWorkerFetchEventResult fetch_result, | 89 ServiceWorkerFetchEventResult fetch_result, |
| 81 const ServiceWorkerResponse& response); | 90 const ServiceWorkerResponse& response); |
| 82 | 91 |
| 83 static void OnFetchEventFinished( | 92 static void OnFetchEventFinished( |
| 84 ServiceWorkerVersion* version, | 93 ServiceWorkerVersion* version, |
| 85 int event_finish_id, | 94 int event_finish_id, |
| 86 scoped_refptr<URLLoaderAssets> url_loader_assets, | 95 scoped_refptr<URLLoaderAssets> url_loader_assets, |
| 96 base::TimeTicks renderer_request_time, |
| 97 base::TimeTicks handler_creation_time, |
| 98 base::TimeTicks job_creation_time, |
| 99 base::TimeTicks worker_start_time, |
| 100 base::TimeTicks worker_ready_time, |
| 101 base::TimeTicks dispatch_event_time_ticks, |
| 87 ServiceWorkerStatusCode status, | 102 ServiceWorkerStatusCode status, |
| 88 base::Time dispatch_event_time); | 103 base::Time dispatch_event_time); |
| 89 | 104 |
| 90 ServiceWorkerMetrics::EventType GetEventType() const; | 105 ServiceWorkerMetrics::EventType GetEventType() const; |
| 91 | 106 |
| 92 scoped_refptr<ServiceWorkerVersion> version_; | 107 scoped_refptr<ServiceWorkerVersion> version_; |
| 93 net::NetLogWithSource net_log_; | 108 net::NetLogWithSource net_log_; |
| 94 base::Closure prepare_callback_; | 109 base::Closure prepare_callback_; |
| 95 FetchCallback fetch_callback_; | 110 FetchCallback fetch_callback_; |
| 96 std::unique_ptr<ServiceWorkerFetchRequest> request_; | 111 std::unique_ptr<ServiceWorkerFetchRequest> request_; |
| 97 ResourceType resource_type_; | 112 ResourceType resource_type_; |
| 98 base::Optional<base::TimeDelta> timeout_; | 113 base::Optional<base::TimeDelta> timeout_; |
| 99 bool did_complete_; | 114 bool did_complete_; |
| 100 | 115 |
| 101 scoped_refptr<URLLoaderAssets> url_loader_assets_; | 116 scoped_refptr<URLLoaderAssets> url_loader_assets_; |
| 102 | 117 |
| 103 mojom::FetchEventPreloadHandlePtr preload_handle_; | 118 mojom::FetchEventPreloadHandlePtr preload_handle_; |
| 104 | 119 |
| 120 base::TimeTicks renderer_request_time_; |
| 121 base::TimeTicks handler_creation_time_; |
| 122 base::TimeTicks job_creation_time_; |
| 123 base::TimeTicks worker_start_time_; |
| 124 base::TimeTicks worker_ready_time_; |
| 105 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; | 125 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; |
| 106 | 126 |
| 107 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); | 127 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); |
| 108 }; | 128 }; |
| 109 | 129 |
| 110 } // namespace content | 130 } // namespace content |
| 111 | 131 |
| 112 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 132 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
| OLD | NEW |