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 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" | 5 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/service_worker/service_worker_version.h" | 8 #include "content/browser/service_worker/service_worker_version.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 ServiceWorkerFetchDispatcher::ServiceWorkerFetchDispatcher( | 12 ServiceWorkerFetchDispatcher::ServiceWorkerFetchDispatcher( |
13 scoped_ptr<ServiceWorkerFetchRequest> request, | 13 scoped_ptr<ServiceWorkerFetchRequest> request, |
14 ServiceWorkerVersion* version, | 14 ServiceWorkerVersion* version, |
15 const FetchCallback& callback) | 15 const base::Closure& prepare_callback, |
| 16 const FetchCallback& fetch_callback) |
16 : version_(version), | 17 : version_(version), |
17 callback_(callback), | 18 prepare_callback_(prepare_callback), |
| 19 fetch_callback_(fetch_callback), |
18 request_(request.Pass()), | 20 request_(request.Pass()), |
19 weak_factory_(this) { | 21 weak_factory_(this) { |
20 } | 22 } |
21 | 23 |
22 ServiceWorkerFetchDispatcher::~ServiceWorkerFetchDispatcher() {} | 24 ServiceWorkerFetchDispatcher::~ServiceWorkerFetchDispatcher() {} |
23 | 25 |
24 void ServiceWorkerFetchDispatcher::Run() { | 26 void ServiceWorkerFetchDispatcher::Run() { |
25 DCHECK(version_->status() == ServiceWorkerVersion::ACTIVATING || | 27 DCHECK(version_->status() == ServiceWorkerVersion::ACTIVATING || |
26 version_->status() == ServiceWorkerVersion::ACTIVATED) | 28 version_->status() == ServiceWorkerVersion::ACTIVATED) |
27 << version_->status(); | 29 << version_->status(); |
(...skipping 22 matching lines...) Expand all Loading... |
50 // to the associated documents and association must be dropped | 52 // to the associated documents and association must be dropped |
51 // at this point) | 53 // at this point) |
52 DidFinish(SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED, | 54 DidFinish(SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED, |
53 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, | 55 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
54 ServiceWorkerResponse()); | 56 ServiceWorkerResponse()); |
55 } | 57 } |
56 | 58 |
57 void ServiceWorkerFetchDispatcher::DispatchFetchEvent() { | 59 void ServiceWorkerFetchDispatcher::DispatchFetchEvent() { |
58 version_->DispatchFetchEvent( | 60 version_->DispatchFetchEvent( |
59 *request_.get(), | 61 *request_.get(), |
| 62 base::Bind(&ServiceWorkerFetchDispatcher::DidPrepare, |
| 63 weak_factory_.GetWeakPtr()), |
60 base::Bind(&ServiceWorkerFetchDispatcher::DidFinish, | 64 base::Bind(&ServiceWorkerFetchDispatcher::DidFinish, |
61 weak_factory_.GetWeakPtr())); | 65 weak_factory_.GetWeakPtr())); |
62 } | 66 } |
63 | 67 |
| 68 void ServiceWorkerFetchDispatcher::DidPrepare() { |
| 69 DCHECK(!prepare_callback_.is_null()); |
| 70 base::Closure prepare_callback = prepare_callback_; |
| 71 prepare_callback.Run(); |
| 72 } |
| 73 |
64 void ServiceWorkerFetchDispatcher::DidFinish( | 74 void ServiceWorkerFetchDispatcher::DidFinish( |
65 ServiceWorkerStatusCode status, | 75 ServiceWorkerStatusCode status, |
66 ServiceWorkerFetchEventResult fetch_result, | 76 ServiceWorkerFetchEventResult fetch_result, |
67 const ServiceWorkerResponse& response) { | 77 const ServiceWorkerResponse& response) { |
68 DCHECK(!callback_.is_null()); | 78 DCHECK(!fetch_callback_.is_null()); |
69 FetchCallback callback = callback_; | 79 FetchCallback fetch_callback = fetch_callback_; |
70 callback.Run(status, fetch_result, response); | 80 fetch_callback.Run(status, fetch_result, response); |
71 } | 81 } |
72 | 82 |
73 } // namespace content | 83 } // namespace content |
OLD | NEW |