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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #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_types.h"
20 class ServiceWorkerVersion
;
22 // A helper class to dispatch fetch event to a service worker.
23 class ServiceWorkerFetchDispatcher
{
25 typedef base::Callback
<void(ServiceWorkerStatusCode
,
26 ServiceWorkerFetchEventResult
,
27 const ServiceWorkerResponse
&)> FetchCallback
;
29 ServiceWorkerFetchDispatcher(
30 net::URLRequest
* request
,
31 ServiceWorkerVersion
* version
,
32 const FetchCallback
& callback
);
33 ~ServiceWorkerFetchDispatcher();
35 // Dispatches a fetch event to the |version| given in ctor, and fires
36 // |callback| (also given in ctor) when finishes.
40 void DidWaitActivation();
41 void DidFailActivation();
42 void DispatchFetchEvent();
43 void DidFinish(ServiceWorkerStatusCode status
,
44 ServiceWorkerFetchEventResult fetch_result
,
45 const ServiceWorkerResponse
& response
);
47 scoped_refptr
<ServiceWorkerVersion
> version_
;
48 FetchCallback callback_
;
49 ServiceWorkerFetchRequest request_
;
50 base::WeakPtrFactory
<ServiceWorkerFetchDispatcher
> weak_factory_
;
52 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchDispatcher
);
55 } // namespace content
57 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_DISPATCHER_H_