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 "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/browser/service_worker/service_worker_metrics.h" | 11 #include "content/browser/service_worker/service_worker_metrics.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" | 13 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" |
14 #include "content/common/service_worker/service_worker_status_code.h" | 14 #include "content/common/service_worker/service_worker_status_code.h" |
15 #include "content/common/service_worker/service_worker_types.h" | 15 #include "content/common/service_worker/service_worker_types.h" |
16 #include "content/public/common/resource_type.h" | 16 #include "content/public/common/resource_type.h" |
17 #include "net/log/net_log_with_source.h" | 17 #include "net/log/net_log_with_source.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 class URLRequest; | 20 class URLRequest; |
21 } // namespace net | 21 } // namespace net |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 class ServiceWorkerVersion; | 25 class ServiceWorkerVersion; |
26 | 26 |
27 // A helper class to dispatch fetch event to a service worker. | 27 // A helper class to dispatch fetch event to a service worker. |
28 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { | 28 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { |
29 public: | 29 public: |
30 typedef base::Callback<void(ServiceWorkerStatusCode, | 30 using FetchCallback = |
31 ServiceWorkerFetchEventResult, | 31 base::Callback<void(ServiceWorkerStatusCode, |
32 const ServiceWorkerResponse&, | 32 ServiceWorkerFetchEventResult, |
33 const scoped_refptr<ServiceWorkerVersion>&)> | 33 const ServiceWorkerResponse&, |
34 FetchCallback; | 34 const scoped_refptr<ServiceWorkerVersion>&)>; |
35 | 35 |
36 ServiceWorkerFetchDispatcher( | 36 ServiceWorkerFetchDispatcher( |
37 std::unique_ptr<ServiceWorkerFetchRequest> request, | 37 std::unique_ptr<ServiceWorkerFetchRequest> request, |
38 ServiceWorkerVersion* version, | 38 ServiceWorkerVersion* version, |
39 ResourceType resource_type, | 39 ResourceType resource_type, |
40 const net::NetLogWithSource& net_log, | 40 const net::NetLogWithSource& net_log, |
41 const base::Closure& prepare_callback, | 41 const base::Closure& prepare_callback, |
42 const FetchCallback& fetch_callback); | 42 const FetchCallback& fetch_callback); |
43 ~ServiceWorkerFetchDispatcher(); | 43 ~ServiceWorkerFetchDispatcher(); |
44 | 44 |
45 // If appropriate, starts the navigation preload request and creates | 45 // If appropriate, starts the navigation preload request and creates |
46 // |preload_handle_|. | 46 // |preload_handle_|. |
47 void MaybeStartNavigationPreload(net::URLRequest* original_request); | 47 void MaybeStartNavigationPreload( |
| 48 net::URLRequest* original_request, |
| 49 const MojoURLLoaderFactoryGetter& url_loader_factory_getter); |
48 | 50 |
49 // Dispatches a fetch event to the |version| given in ctor, and fires | 51 // Dispatches a fetch event to the |version| given in ctor, and fires |
50 // |fetch_callback| (also given in ctor) when finishes. It runs | 52 // |fetch_callback| (also given in ctor) when finishes. It runs |
51 // |prepare_callback| as an intermediate step once the version is activated | 53 // |prepare_callback| as an intermediate step once the version is activated |
52 // and running. | 54 // and running. |
53 void Run(); | 55 void Run(); |
54 | 56 |
55 private: | 57 private: |
56 class ResponseCallback; | 58 class ResponseCallback; |
57 | 59 |
(...skipping 23 matching lines...) Expand all Loading... |
81 mojom::FetchEventPreloadHandlePtr preload_handle_; | 83 mojom::FetchEventPreloadHandlePtr preload_handle_; |
82 | 84 |
83 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; | 85 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; |
84 | 86 |
85 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); | 87 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); |
86 }; | 88 }; |
87 | 89 |
88 } // namespace content | 90 } // namespace content |
89 | 91 |
90 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 92 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
OLD | NEW |