| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/containers/scoped_ptr_hash_map.h" | 10 #include "base/containers/scoped_ptr_hash_map.h" |
| 11 #include "content/browser/service_worker/embedded_worker_status.h" |
| 11 #include "content/browser/service_worker/service_worker_context_observer.h" | 12 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 13 #include "content/browser/service_worker/service_worker_version.h" | 14 #include "content/browser/service_worker/service_worker_version.h" |
| 14 #include "content/common/service_worker/service_worker_types.h" | 15 #include "content/common/service_worker/service_worker_types.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/common/console_message_level.h" | 17 #include "content/public/common/console_message_level.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 bool IsStoppedAndRedundant(const ServiceWorkerVersionInfo& version_info) { | 23 bool IsStoppedAndRedundant(const ServiceWorkerVersionInfo& version_info) { |
| 23 return version_info.running_status == | 24 return version_info.running_status == EmbeddedWorkerStatus::STOPPED && |
| 24 content::ServiceWorkerVersion::STOPPED && | |
| 25 version_info.status == content::ServiceWorkerVersion::REDUNDANT; | 25 version_info.status == content::ServiceWorkerVersion::REDUNDANT; |
| 26 } | 26 } |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 ServiceWorkerContextWatcher::ServiceWorkerContextWatcher( | 30 ServiceWorkerContextWatcher::ServiceWorkerContextWatcher( |
| 31 scoped_refptr<ServiceWorkerContextWrapper> context, | 31 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 32 const WorkerRegistrationUpdatedCallback& registration_callback, | 32 const WorkerRegistrationUpdatedCallback& registration_callback, |
| 33 const WorkerVersionUpdatedCallback& version_callback, | 33 const WorkerVersionUpdatedCallback& version_callback, |
| 34 const WorkerErrorReportedCallback& error_callback) | 34 const WorkerErrorReportedCallback& error_callback) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 version->version_id = version_id; | 179 version->version_id = version_id; |
| 180 version->registration_id = registration_id; | 180 version->registration_id = registration_id; |
| 181 version->script_url = script_url; | 181 version->script_url = script_url; |
| 182 SendVersionInfo(*version); | 182 SendVersionInfo(*version); |
| 183 if (!IsStoppedAndRedundant(*version)) | 183 if (!IsStoppedAndRedundant(*version)) |
| 184 version_info_map_.set(version_id, std::move(version)); | 184 version_info_map_.set(version_id, std::move(version)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void ServiceWorkerContextWatcher::OnRunningStateChanged( | 187 void ServiceWorkerContextWatcher::OnRunningStateChanged( |
| 188 int64_t version_id, | 188 int64_t version_id, |
| 189 content::ServiceWorkerVersion::RunningStatus running_status) { | 189 content::EmbeddedWorkerStatus running_status) { |
| 190 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); | 190 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); |
| 191 DCHECK(version); | 191 DCHECK(version); |
| 192 if (version->running_status == running_status) | 192 if (version->running_status == running_status) |
| 193 return; | 193 return; |
| 194 version->running_status = running_status; | 194 version->running_status = running_status; |
| 195 SendVersionInfo(*version); | 195 SendVersionInfo(*version); |
| 196 if (IsStoppedAndRedundant(*version)) | 196 if (IsStoppedAndRedundant(*version)) |
| 197 version_info_map_.erase(version_id); | 197 version_info_map_.erase(version_id); |
| 198 } | 198 } |
| 199 | 199 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); | 278 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64_t registration_id, | 281 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64_t registration_id, |
| 282 const GURL& pattern) { | 282 const GURL& pattern) { |
| 283 SendRegistrationInfo(registration_id, pattern, | 283 SendRegistrationInfo(registration_id, pattern, |
| 284 ServiceWorkerRegistrationInfo::IS_DELETED); | 284 ServiceWorkerRegistrationInfo::IS_DELETED); |
| 285 } | 285 } |
| 286 | 286 |
| 287 } // namespace content | 287 } // namespace content |
| OLD | NEW |