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 "mojo/public/cpp/bindings/interface_request.h" | |
17 #include "net/log/net_log_with_source.h" | 18 #include "net/log/net_log_with_source.h" |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 class URLRequest; | 21 class URLRequest; |
21 } // namespace net | 22 } // namespace net |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 | 25 |
26 namespace mojom { | |
27 class URLLoaderFactory; | |
28 } // namespace mojom | |
29 | |
25 class ServiceWorkerVersion; | 30 class ServiceWorkerVersion; |
26 | 31 |
27 // A helper class to dispatch fetch event to a service worker. | 32 // A helper class to dispatch fetch event to a service worker. |
28 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { | 33 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { |
29 public: | 34 public: |
30 typedef base::Callback<void(ServiceWorkerStatusCode, | 35 using URLLoaderFactoryCallback = |
31 ServiceWorkerFetchEventResult, | 36 base::Callback<bool(mojo::InterfaceRequest<mojom::URLLoaderFactory>)>; |
falken
2016/10/19 05:11:28
Can we move this declaration to service_worker_typ
horo
2016/10/19 06:22:52
Done.
| |
32 const ServiceWorkerResponse&, | 37 using FetchCallback = |
33 const scoped_refptr<ServiceWorkerVersion>&)> | 38 base::Callback<void(ServiceWorkerStatusCode, |
34 FetchCallback; | 39 ServiceWorkerFetchEventResult, |
40 const ServiceWorkerResponse&, | |
41 const scoped_refptr<ServiceWorkerVersion>&)>; | |
35 | 42 |
36 ServiceWorkerFetchDispatcher( | 43 ServiceWorkerFetchDispatcher( |
37 std::unique_ptr<ServiceWorkerFetchRequest> request, | 44 std::unique_ptr<ServiceWorkerFetchRequest> request, |
38 ServiceWorkerVersion* version, | 45 ServiceWorkerVersion* version, |
39 ResourceType resource_type, | 46 ResourceType resource_type, |
40 const net::NetLogWithSource& net_log, | 47 const net::NetLogWithSource& net_log, |
41 const base::Closure& prepare_callback, | 48 const base::Closure& prepare_callback, |
42 const FetchCallback& fetch_callback); | 49 const FetchCallback& fetch_callback); |
43 ~ServiceWorkerFetchDispatcher(); | 50 ~ServiceWorkerFetchDispatcher(); |
44 | 51 |
45 // If appropriate, starts the navigation preload request and creates | 52 // If appropriate, starts the navigation preload request and creates |
46 // |preload_handle_|. | 53 // |preload_handle_|. |
47 void MaybeStartNavigationPreload(net::URLRequest* original_request); | 54 void MaybeStartNavigationPreload( |
55 net::URLRequest* original_request, | |
56 const URLLoaderFactoryCallback& url_loader_factory_callback); | |
48 | 57 |
49 // Dispatches a fetch event to the |version| given in ctor, and fires | 58 // Dispatches a fetch event to the |version| given in ctor, and fires |
50 // |fetch_callback| (also given in ctor) when finishes. It runs | 59 // |fetch_callback| (also given in ctor) when finishes. It runs |
51 // |prepare_callback| as an intermediate step once the version is activated | 60 // |prepare_callback| as an intermediate step once the version is activated |
52 // and running. | 61 // and running. |
53 void Run(); | 62 void Run(); |
54 | 63 |
55 private: | 64 private: |
56 class ResponseCallback; | 65 class ResponseCallback; |
57 | 66 |
(...skipping 23 matching lines...) Expand all Loading... | |
81 mojom::FetchEventPreloadHandlePtr preload_handle_; | 90 mojom::FetchEventPreloadHandlePtr preload_handle_; |
82 | 91 |
83 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; | 92 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; |
84 | 93 |
85 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); | 94 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); |
86 }; | 95 }; |
87 | 96 |
88 } // namespace content | 97 } // namespace content |
89 | 98 |
90 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 99 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
OLD | NEW |