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