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/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 #include "content/common/service_worker/service_worker_status_code.h" | 12 #include "content/common/service_worker/service_worker_status_code.h" |
13 #include "content/common/service_worker/service_worker_types.h" | 13 #include "content/common/service_worker/service_worker_types.h" |
| 14 #include "content/public/common/resource_type.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 class ServiceWorkerVersion; | 18 class ServiceWorkerVersion; |
18 | 19 |
19 // A helper class to dispatch fetch event to a service worker. | 20 // A helper class to dispatch fetch event to a service worker. |
20 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { | 21 class CONTENT_EXPORT ServiceWorkerFetchDispatcher { |
21 public: | 22 public: |
22 typedef base::Callback<void(ServiceWorkerStatusCode, | 23 typedef base::Callback<void(ServiceWorkerStatusCode, |
23 ServiceWorkerFetchEventResult, | 24 ServiceWorkerFetchEventResult, |
24 const ServiceWorkerResponse&, | 25 const ServiceWorkerResponse&, |
25 const scoped_refptr<ServiceWorkerVersion>&)> | 26 const scoped_refptr<ServiceWorkerVersion>&)> |
26 FetchCallback; | 27 FetchCallback; |
27 | 28 |
28 ServiceWorkerFetchDispatcher(scoped_ptr<ServiceWorkerFetchRequest> request, | 29 ServiceWorkerFetchDispatcher(scoped_ptr<ServiceWorkerFetchRequest> request, |
29 ServiceWorkerVersion* version, | 30 ServiceWorkerVersion* version, |
| 31 ResourceType resource_type, |
30 const base::Closure& prepare_callback, | 32 const base::Closure& prepare_callback, |
31 const FetchCallback& fetch_callback); | 33 const FetchCallback& fetch_callback); |
32 ~ServiceWorkerFetchDispatcher(); | 34 ~ServiceWorkerFetchDispatcher(); |
33 | 35 |
34 // Dispatches a fetch event to the |version| given in ctor, and fires | 36 // Dispatches a fetch event to the |version| given in ctor, and fires |
35 // |callback| (also given in ctor) when finishes. | 37 // |callback| (also given in ctor) when finishes. |
36 void Run(); | 38 void Run(); |
37 | 39 |
38 private: | 40 private: |
39 void DidWaitActivation(); | 41 void DidWaitActivation(); |
40 void DidFailActivation(); | 42 void DidFailActivation(); |
41 void DispatchFetchEvent(); | 43 void DispatchFetchEvent(); |
42 void DidPrepare(); | 44 void DidPrepare(); |
43 void DidFail(ServiceWorkerStatusCode status); | 45 void DidFail(ServiceWorkerStatusCode status); |
44 void DidFinish(int request_id, | 46 void DidFinish(int request_id, |
45 ServiceWorkerFetchEventResult fetch_result, | 47 ServiceWorkerFetchEventResult fetch_result, |
46 const ServiceWorkerResponse& response); | 48 const ServiceWorkerResponse& response); |
47 | 49 |
48 scoped_refptr<ServiceWorkerVersion> version_; | 50 scoped_refptr<ServiceWorkerVersion> version_; |
49 base::Closure prepare_callback_; | 51 base::Closure prepare_callback_; |
50 FetchCallback fetch_callback_; | 52 FetchCallback fetch_callback_; |
51 scoped_ptr<ServiceWorkerFetchRequest> request_; | 53 scoped_ptr<ServiceWorkerFetchRequest> request_; |
| 54 ResourceType resource_type_; |
52 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; | 55 base::WeakPtrFactory<ServiceWorkerFetchDispatcher> weak_factory_; |
53 | 56 |
54 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); | 57 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher); |
55 }; | 58 }; |
56 | 59 |
57 } // namespace content | 60 } // namespace content |
58 | 61 |
59 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ | 62 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_ |
OLD | NEW |