OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_context_watcher.h" | 5 #include "content/browser/service_worker/service_worker_context_watcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
9 #include "content/browser/service_worker/service_worker_context_observer.h" | 9 #include "content/browser/service_worker/service_worker_context_observer.h" |
10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
11 #include "content/browser/service_worker/service_worker_version.h" | 11 #include "content/browser/service_worker/service_worker_version.h" |
| 12 #include "content/common/service_worker/service_worker_types.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 namespace { | 17 namespace { |
17 | 18 |
18 bool IsStoppedAndRedundant(const ServiceWorkerVersionInfo& version_info) { | 19 bool IsStoppedAndRedundant(const ServiceWorkerVersionInfo& version_info) { |
19 return version_info.running_status == | 20 return version_info.running_status == |
20 content::ServiceWorkerVersion::STOPPED && | 21 content::ServiceWorkerVersion::STOPPED && |
21 version_info.status == content::ServiceWorkerVersion::REDUNDANT; | 22 version_info.status == content::ServiceWorkerVersion::REDUNDANT; |
22 } | 23 } |
23 | 24 |
24 } // namespace | 25 } // namespace |
25 | 26 |
26 ServiceWorkerContextWatcher::ServiceWorkerContextWatcher( | 27 ServiceWorkerContextWatcher::ServiceWorkerContextWatcher( |
27 scoped_refptr<ServiceWorkerContextWrapper> context, | 28 scoped_refptr<ServiceWorkerContextWrapper> context, |
28 const WorkerRegistrationUpdatedCallback& registration_callback, | 29 const WorkerRegistrationUpdatedCallback& registration_callback, |
29 const WorkerVersionUpdatedCallback& version_callback) | 30 const WorkerVersionUpdatedCallback& version_callback, |
| 31 const WorkerErrorReportedCallback& error_callback) |
30 : context_(context), | 32 : context_(context), |
31 registration_callback_(registration_callback), | 33 registration_callback_(registration_callback), |
32 version_callback_(version_callback) { | 34 version_callback_(version_callback), |
| 35 error_callback_(error_callback) { |
33 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
34 } | 37 } |
35 | 38 |
36 void ServiceWorkerContextWatcher::Start() { | 39 void ServiceWorkerContextWatcher::Start() { |
37 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
38 BrowserThread::PostTask( | 41 BrowserThread::PostTask( |
39 BrowserThread::IO, FROM_HERE, | 42 BrowserThread::IO, FROM_HERE, |
40 base::Bind(&ServiceWorkerContextWatcher::GetStoredRegistrationsOnIOThread, | 43 base::Bind(&ServiceWorkerContextWatcher::GetStoredRegistrationsOnIOThread, |
41 this)); | 44 this)); |
42 } | 45 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); | 191 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); |
189 DCHECK(version); | 192 DCHECK(version); |
190 if (version->status == status) | 193 if (version->status == status) |
191 return; | 194 return; |
192 version->status = status; | 195 version->status = status; |
193 SendVersionInfo(*version); | 196 SendVersionInfo(*version); |
194 if (IsStoppedAndRedundant(*version)) | 197 if (IsStoppedAndRedundant(*version)) |
195 version_info_map_.erase(version_id); | 198 version_info_map_.erase(version_id); |
196 } | 199 } |
197 | 200 |
| 201 void ServiceWorkerContextWatcher::OnErrorReported(int64 version_id, |
| 202 int process_id, |
| 203 int thread_id, |
| 204 const ErrorInfo& info) { |
| 205 int64 registration_id = kInvalidServiceWorkerRegistrationId; |
| 206 if (ServiceWorkerVersionInfo* version = version_info_map_.get(version_id)) |
| 207 registration_id = version->registration_id; |
| 208 BrowserThread::PostTask( |
| 209 BrowserThread::UI, FROM_HERE, |
| 210 base::Bind(error_callback_, registration_id, version_id, info)); |
| 211 } |
| 212 |
198 void ServiceWorkerContextWatcher::OnRegistrationStored(int64 registration_id, | 213 void ServiceWorkerContextWatcher::OnRegistrationStored(int64 registration_id, |
199 const GURL& pattern) { | 214 const GURL& pattern) { |
200 SendRegistrationInfo(registration_id, pattern, | 215 SendRegistrationInfo(registration_id, pattern, |
201 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); | 216 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); |
202 } | 217 } |
203 | 218 |
204 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64 registration_id, | 219 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64 registration_id, |
205 const GURL& pattern) { | 220 const GURL& pattern) { |
206 SendRegistrationInfo(registration_id, pattern, | 221 SendRegistrationInfo(registration_id, pattern, |
207 ServiceWorkerRegistrationInfo::IS_DELETED); | 222 ServiceWorkerRegistrationInfo::IS_DELETED); |
208 } | 223 } |
209 | 224 |
210 } // namespace content | 225 } // namespace content |
OLD | NEW |