| 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/service_worker_status_code.h" | 14 #include "content/common/service_worker/service_worker_status_code.h" |
| 14 #include "content/common/service_worker/service_worker_types.h" | 15 #include "content/common/service_worker/service_worker_types.h" |
| 15 #include "content/public/common/resource_type.h" | 16 #include "content/public/common/resource_type.h" |
| 16 #include "net/log/net_log_with_source.h" | 17 #include "net/log/net_log_with_source.h" |
| 17 | 18 |
| 19 namespace net { |
| 20 class URLRequest; |
| 21 } // namespace net |
| 22 |
| 18 namespace content { | 23 namespace content { |
| 19 | 24 |
| 20 class ServiceWorkerVersion; | 25 class ServiceWorkerVersion; |
| 21 | 26 |
| 22 // A helper class to dispatch fetch event to a service worker. | 27 // A helper class to dispatch fetch event to a service worker. |
| 23 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { | 28 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { |
| 24 public: | 29 public: |
| 25 typedef base::Callback<void(ServiceWorkerStatusCode, | 30 typedef base::Callback<void(ServiceWorkerStatusCode, |
| 26 ServiceWorkerFetchEventResult, | 31 ServiceWorkerFetchEventResult, |
| 27 const ServiceWorkerResponse&, | 32 const ServiceWorkerResponse&, |
| 28 const scoped_refptr<ServiceWorkerVersion>&)> | 33 const scoped_refptr<ServiceWorkerVersion>&)> |
| 29 FetchCallback; | 34 FetchCallback; |
| 30 | 35 |
| 31 ServiceWorkerFetchDispatcher( | 36 ServiceWorkerFetchDispatcher( |
| 32 std::unique_ptr<ServiceWorkerFetchRequest> request, | 37 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 33 ServiceWorkerVersion* version, | 38 ServiceWorkerVersion* version, |
| 34 ResourceType resource_type, | 39 ResourceType resource_type, |
| 35 const net::NetLogWithSource& net_log, | 40 const net::NetLogWithSource& net_log, |
| 36 const base::Closure& prepare_callback, | 41 const base::Closure& prepare_callback, |
| 37 const FetchCallback& fetch_callback); | 42 const FetchCallback& fetch_callback); |
| 38 ~ServiceWorkerFetchDispatcher(); | 43 ~ServiceWorkerFetchDispatcher(); |
| 39 | 44 |
| 45 // If appropriate, starts the navigation preload request and creates |
| 46 // |preload_handle_|. |
| 47 void MaybeStartNavigationPreload(net::URLRequest* original_request); |
| 48 |
| 40 // Dispatches a fetch event to the |version| given in ctor, and fires | 49 // Dispatches a fetch event to the |version| given in ctor, and fires |
| 41 // |fetch_callback| (also given in ctor) when finishes. It runs | 50 // |fetch_callback| (also given in ctor) when finishes. It runs |
| 42 // |prepare_callback| as an intermediate step once the version is activated | 51 // |prepare_callback| as an intermediate step once the version is activated |
| 43 // and running. | 52 // and running. |
| 44 void Run(); | 53 void Run(); |
| 45 | 54 |
| 46 private: | 55 private: |
| 47 class ResponseCallback; | 56 class ResponseCallback; |
| 48 | 57 |
| 49 void DidWaitForActivation(); | 58 void DidWaitForActivation(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 | 71 |
| 63 ServiceWorkerMetrics::EventType GetEventType() const; | 72 ServiceWorkerMetrics::EventType GetEventType() const; |
| 64 | 73 |
| 65 scoped_refptr<ServiceWorkerVersion> version_; | 74 scoped_refptr<ServiceWorkerVersion> version_; |
| 66 net::NetLogWithSource net_log_; | 75 net::NetLogWithSource net_log_; |
| 67 base::Closure prepare_callback_; | 76 base::Closure prepare_callback_; |
| 68 FetchCallback fetch_callback_; | 77 FetchCallback fetch_callback_; |
| 69 std::unique_ptr<ServiceWorkerFetchRequest> request_; | 78 std::unique_ptr<ServiceWorkerFetchRequest> request_; |
| 70 ResourceType resource_type_; | 79 ResourceType resource_type_; |
| 71 bool did_complete_; | 80 bool did_complete_; |
| 81 mojom::FetchEventPreloadHandlePtr preload_handle_; |
| 82 |
| 72 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; | 83 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; |
| 73 | 84 |
| 74 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); | 85 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); |
| 75 }; | 86 }; |
| 76 | 87 |
| 77 } // namespace content | 88 } // namespace content |
| 78 | 89 |
| 79 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 90 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
| OLD | NEW |