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