| 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 ServiceWorkerProviderHost; |
| 25 class ServiceWorkerVersion; | 26 class ServiceWorkerVersion; |
| 26 | 27 |
| 27 // A helper class to dispatch fetch event to a service worker. | 28 // A helper class to dispatch fetch event to a service worker. |
| 28 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { | 29 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { |
| 29 public: | 30 public: |
| 30 using FetchCallback = | 31 using FetchCallback = |
| 31 base::Callback<void(ServiceWorkerStatusCode, | 32 base::Callback<void(ServiceWorkerStatusCode, |
| 32 ServiceWorkerFetchEventResult, | 33 ServiceWorkerFetchEventResult, |
| 33 const ServiceWorkerResponse&, | 34 const ServiceWorkerResponse&, |
| 34 const scoped_refptr<ServiceWorkerVersion>&)>; | 35 const scoped_refptr<ServiceWorkerVersion>&)>; |
| 35 | 36 |
| 36 ServiceWorkerFetchDispatcher( | 37 ServiceWorkerFetchDispatcher( |
| 37 std::unique_ptr<ServiceWorkerFetchRequest> request, | 38 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 38 ServiceWorkerVersion* version, | 39 ServiceWorkerVersion* version, |
| 39 ResourceType resource_type, | 40 ResourceType resource_type, |
| 40 const net::NetLogWithSource& net_log, | 41 const net::NetLogWithSource& net_log, |
| 41 const base::Closure& prepare_callback, | 42 const base::Closure& prepare_callback, |
| 42 const FetchCallback& fetch_callback); | 43 const FetchCallback& fetch_callback); |
| 43 ~ServiceWorkerFetchDispatcher(); | 44 ~ServiceWorkerFetchDispatcher(); |
| 44 | 45 |
| 45 // If appropriate, starts the navigation preload request and creates | 46 // If appropriate, starts the navigation preload request and creates |
| 46 // |preload_handle_|. | 47 // |preload_handle_|. |
| 47 void MaybeStartNavigationPreload(net::URLRequest* original_request); | 48 void MaybeStartNavigationPreload( |
| 49 net::URLRequest* original_request, |
| 50 base::WeakPtr<ServiceWorkerProviderHost> provider_host); |
| 48 | 51 |
| 49 // Dispatches a fetch event to the |version| given in ctor, and fires | 52 // Dispatches a fetch event to the |version| given in ctor, and fires |
| 50 // |fetch_callback| (also given in ctor) when finishes. It runs | 53 // |fetch_callback| (also given in ctor) when finishes. It runs |
| 51 // |prepare_callback| as an intermediate step once the version is activated | 54 // |prepare_callback| as an intermediate step once the version is activated |
| 52 // and running. | 55 // and running. |
| 53 void Run(); | 56 void Run(); |
| 54 | 57 |
| 55 private: | 58 private: |
| 56 class ResponseCallback; | 59 class ResponseCallback; |
| 57 | 60 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 81 mojom::FetchEventPreloadHandlePtr preload_handle_; | 84 mojom::FetchEventPreloadHandlePtr preload_handle_; |
| 82 | 85 |
| 83 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; | 86 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; |
| 84 | 87 |
| 85 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); | 88 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); |
| 86 }; | 89 }; |
| 87 | 90 |
| 88 } // namespace content | 91 } // namespace content |
| 89 | 92 |
| 90 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 93 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
| OLD | NEW |