Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_fetch_dispatcher.h
blobf0165b6cccb7fa710edda3538a254e80c912bfe8
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"
14 namespace content {
16 class ServiceWorkerVersion;
18 // A helper class to dispatch fetch event to a service worker.
19 class ServiceWorkerFetchDispatcher {
20 public:
21 typedef base::Callback<void(ServiceWorkerStatusCode,
22 ServiceWorkerFetchEventResult,
23 const ServiceWorkerResponse&,
24 scoped_refptr<ServiceWorkerVersion>)>
25 FetchCallback;
27 ServiceWorkerFetchDispatcher(scoped_ptr<ServiceWorkerFetchRequest> request,
28 ServiceWorkerVersion* version,
29 const base::Closure& prepare_callback,
30 const FetchCallback& fetch_callback);
31 ~ServiceWorkerFetchDispatcher();
33 // Dispatches a fetch event to the |version| given in ctor, and fires
34 // |callback| (also given in ctor) when finishes.
35 void Run();
37 private:
38 void DidWaitActivation();
39 void DidFailActivation();
40 void DispatchFetchEvent();
41 void DidPrepare();
42 void DidFinish(ServiceWorkerStatusCode status,
43 ServiceWorkerFetchEventResult fetch_result,
44 const ServiceWorkerResponse& response);
46 scoped_refptr<ServiceWorkerVersion> version_;
47 base::Closure prepare_callback_;
48 FetchCallback fetch_callback_;
49 scoped_ptr<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_