| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_storage.h" | 5 #include "content/browser/service_worker/service_worker_storage.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 const StatusCallback& callback) { | 387 const StatusCallback& callback) { |
| 388 DCHECK(registration); | 388 DCHECK(registration); |
| 389 DCHECK(version); | 389 DCHECK(version); |
| 390 | 390 |
| 391 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; | 391 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; |
| 392 if (IsDisabled()) { | 392 if (IsDisabled()) { |
| 393 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); | 393 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); |
| 394 return; | 394 return; |
| 395 } | 395 } |
| 396 | 396 |
| 397 DCHECK_NE(version->fetch_handler_existence(), |
| 398 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
| 399 |
| 397 ServiceWorkerDatabase::RegistrationData data; | 400 ServiceWorkerDatabase::RegistrationData data; |
| 398 data.registration_id = registration->id(); | 401 data.registration_id = registration->id(); |
| 399 data.scope = registration->pattern(); | 402 data.scope = registration->pattern(); |
| 400 data.script = version->script_url(); | 403 data.script = version->script_url(); |
| 401 data.has_fetch_handler = version->has_fetch_handler(); | 404 data.has_fetch_handler = version->fetch_handler_existence() == |
| 405 ServiceWorkerVersion::FetchHandlerExistence::EXISTS; |
| 402 data.version_id = version->version_id(); | 406 data.version_id = version->version_id(); |
| 403 data.last_update_check = registration->last_update_check(); | 407 data.last_update_check = registration->last_update_check(); |
| 404 data.is_active = (version == registration->active_version()); | 408 data.is_active = (version == registration->active_version()); |
| 405 data.foreign_fetch_scopes = version->foreign_fetch_scopes(); | 409 data.foreign_fetch_scopes = version->foreign_fetch_scopes(); |
| 406 data.foreign_fetch_origins = version->foreign_fetch_origins(); | 410 data.foreign_fetch_origins = version->foreign_fetch_origins(); |
| 407 | 411 |
| 408 ResourceList resources; | 412 ResourceList resources; |
| 409 version->script_cache_map()->GetResources(&resources); | 413 version->script_cache_map()->GetResources(&resources); |
| 410 | 414 |
| 411 if (resources.empty()) { | 415 if (resources.empty()) { |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 registration->set_last_update_check(data.last_update_check); | 1240 registration->set_last_update_check(data.last_update_check); |
| 1237 if (pending_deletions_.find(data.registration_id) != | 1241 if (pending_deletions_.find(data.registration_id) != |
| 1238 pending_deletions_.end()) { | 1242 pending_deletions_.end()) { |
| 1239 registration->set_is_deleted(true); | 1243 registration->set_is_deleted(true); |
| 1240 } | 1244 } |
| 1241 scoped_refptr<ServiceWorkerVersion> version = | 1245 scoped_refptr<ServiceWorkerVersion> version = |
| 1242 context_->GetLiveVersion(data.version_id); | 1246 context_->GetLiveVersion(data.version_id); |
| 1243 if (!version) { | 1247 if (!version) { |
| 1244 version = new ServiceWorkerVersion( | 1248 version = new ServiceWorkerVersion( |
| 1245 registration.get(), data.script, data.version_id, context_); | 1249 registration.get(), data.script, data.version_id, context_); |
| 1250 version->set_fetch_handler_existence( |
| 1251 data.has_fetch_handler |
| 1252 ? ServiceWorkerVersion::FetchHandlerExistence::EXISTS |
| 1253 : ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST); |
| 1246 version->SetStatus(data.is_active ? | 1254 version->SetStatus(data.is_active ? |
| 1247 ServiceWorkerVersion::ACTIVATED : ServiceWorkerVersion::INSTALLED); | 1255 ServiceWorkerVersion::ACTIVATED : ServiceWorkerVersion::INSTALLED); |
| 1248 version->script_cache_map()->SetResources(resources); | 1256 version->script_cache_map()->SetResources(resources); |
| 1249 version->set_foreign_fetch_scopes(data.foreign_fetch_scopes); | 1257 version->set_foreign_fetch_scopes(data.foreign_fetch_scopes); |
| 1250 version->set_foreign_fetch_origins(data.foreign_fetch_origins); | 1258 version->set_foreign_fetch_origins(data.foreign_fetch_origins); |
| 1251 version->set_has_fetch_handler(data.has_fetch_handler); | |
| 1252 } | 1259 } |
| 1253 | 1260 |
| 1254 if (version->status() == ServiceWorkerVersion::ACTIVATED) | 1261 if (version->status() == ServiceWorkerVersion::ACTIVATED) |
| 1255 registration->SetActiveVersion(version); | 1262 registration->SetActiveVersion(version); |
| 1256 else if (version->status() == ServiceWorkerVersion::INSTALLED) | 1263 else if (version->status() == ServiceWorkerVersion::INSTALLED) |
| 1257 registration->SetWaitingVersion(version); | 1264 registration->SetWaitingVersion(version); |
| 1258 else | 1265 else |
| 1259 NOTREACHED(); | 1266 NOTREACHED(); |
| 1260 | 1267 |
| 1261 return registration; | 1268 return registration; |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1777 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
| 1771 return; | 1778 return; |
| 1772 } | 1779 } |
| 1773 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1780 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
| 1774 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( | 1781 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( |
| 1775 ServiceWorkerMetrics::DELETE_OK); | 1782 ServiceWorkerMetrics::DELETE_OK); |
| 1776 callback.Run(SERVICE_WORKER_OK); | 1783 callback.Run(SERVICE_WORKER_OK); |
| 1777 } | 1784 } |
| 1778 | 1785 |
| 1779 } // namespace content | 1786 } // namespace content |
| OLD | NEW |