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" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/optional.h" | 14 #include "base/optional.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "content/browser/service_worker/service_worker_metrics.h" | 16 #include "content/browser/service_worker/service_worker_metrics.h" |
16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" | 18 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
18 #include "content/common/service_worker/service_worker_status_code.h" | 19 #include "content/common/service_worker/service_worker_status_code.h" |
19 #include "content/common/service_worker/service_worker_types.h" | 20 #include "content/common/service_worker/service_worker_types.h" |
20 #include "content/common/url_loader.mojom.h" | 21 #include "content/common/url_loader.mojom.h" |
21 #include "content/common/url_loader_factory.mojom.h" | 22 #include "content/common/url_loader_factory.mojom.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 bool MaybeStartNavigationPreload(net::URLRequest* original_request); | 55 bool MaybeStartNavigationPreload(net::URLRequest* original_request); |
55 | 56 |
56 // Dispatches a fetch event to the |version| given in ctor, and fires | 57 // Dispatches a fetch event to the |version| given in ctor, and fires |
57 // |fetch_callback| (also given in ctor) when finishes. It runs | 58 // |fetch_callback| (also given in ctor) when finishes. It runs |
58 // |prepare_callback| as an intermediate step once the version is activated | 59 // |prepare_callback| as an intermediate step once the version is activated |
59 // and running. | 60 // and running. |
60 void Run(); | 61 void Run(); |
61 | 62 |
62 private: | 63 private: |
63 class ResponseCallback; | 64 class ResponseCallback; |
| 65 class URLLoaderAssets; |
64 | 66 |
65 void DidWaitForActivation(); | 67 void DidWaitForActivation(); |
66 void StartWorker(); | 68 void StartWorker(); |
67 void DidStartWorker(); | 69 void DidStartWorker(); |
68 void DidFailToStartWorker(ServiceWorkerStatusCode status); | 70 void DidFailToStartWorker(ServiceWorkerStatusCode status); |
69 void DispatchFetchEvent(); | 71 void DispatchFetchEvent(); |
70 void DidFailToDispatch(ServiceWorkerStatusCode status); | 72 void DidFailToDispatch(ServiceWorkerStatusCode status); |
71 void DidFail(ServiceWorkerStatusCode status); | 73 void DidFail(ServiceWorkerStatusCode status); |
72 void DidFinish(int request_id, | 74 void DidFinish(int request_id, |
73 ServiceWorkerFetchEventResult fetch_result, | 75 ServiceWorkerFetchEventResult fetch_result, |
74 const ServiceWorkerResponse& response); | 76 const ServiceWorkerResponse& response); |
75 void Complete(ServiceWorkerStatusCode status, | 77 void Complete(ServiceWorkerStatusCode status, |
76 ServiceWorkerFetchEventResult fetch_result, | 78 ServiceWorkerFetchEventResult fetch_result, |
77 const ServiceWorkerResponse& response); | 79 const ServiceWorkerResponse& response); |
78 | 80 |
| 81 static void OnFetchEventFinished( |
| 82 ServiceWorkerVersion* version, |
| 83 int event_finish_id, |
| 84 scoped_refptr<URLLoaderAssets> url_loader_assets, |
| 85 ServiceWorkerStatusCode status, |
| 86 base::Time dispatch_event_time); |
| 87 |
79 ServiceWorkerMetrics::EventType GetEventType() const; | 88 ServiceWorkerMetrics::EventType GetEventType() const; |
80 | 89 |
81 scoped_refptr<ServiceWorkerVersion> version_; | 90 scoped_refptr<ServiceWorkerVersion> version_; |
82 net::NetLogWithSource net_log_; | 91 net::NetLogWithSource net_log_; |
83 base::Closure prepare_callback_; | 92 base::Closure prepare_callback_; |
84 FetchCallback fetch_callback_; | 93 FetchCallback fetch_callback_; |
85 std::unique_ptr<ServiceWorkerFetchRequest> request_; | 94 std::unique_ptr<ServiceWorkerFetchRequest> request_; |
86 ResourceType resource_type_; | 95 ResourceType resource_type_; |
87 base::Optional<base::TimeDelta> timeout_; | 96 base::Optional<base::TimeDelta> timeout_; |
88 bool did_complete_; | 97 bool did_complete_; |
89 mojom::URLLoaderFactoryPtr url_loader_factory_; | 98 |
90 std::unique_ptr<mojom::URLLoader> url_loader_; | 99 scoped_refptr<URLLoaderAssets> url_loader_assets_; |
91 std::unique_ptr<mojom::URLLoaderClient> url_loader_client_; | 100 |
92 mojom::FetchEventPreloadHandlePtr preload_handle_; | 101 mojom::FetchEventPreloadHandlePtr preload_handle_; |
93 | 102 |
94 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; | 103 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; |
95 | 104 |
96 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); | 105 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); |
97 }; | 106 }; |
98 | 107 |
99 } // namespace content | 108 } // namespace content |
100 | 109 |
101 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 110 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
OLD | NEW |