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_database.h" | 5 #include "content/browser/service_worker/service_worker_database.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 531 |
532 RegistrationData value; | 532 RegistrationData value; |
533 status = ReadRegistrationData(registration_id, origin, &value); | 533 status = ReadRegistrationData(registration_id, origin, &value); |
534 if (status != STATUS_OK) | 534 if (status != STATUS_OK) |
535 return status; | 535 return status; |
536 | 536 |
537 status = ReadResourceRecords(value.version_id, resources); | 537 status = ReadResourceRecords(value.version_id, resources); |
538 if (status != STATUS_OK) | 538 if (status != STATUS_OK) |
539 return status; | 539 return status; |
540 | 540 |
| 541 // ResourceRecord must contain the ServiceWorker's main script. |
| 542 if (resources->empty()) |
| 543 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; |
| 544 |
541 *registration = value; | 545 *registration = value; |
542 return STATUS_OK; | 546 return STATUS_OK; |
543 } | 547 } |
544 | 548 |
545 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadRegistrationOrigin( | 549 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadRegistrationOrigin( |
546 int64 registration_id, | 550 int64 registration_id, |
547 GURL* origin) { | 551 GURL* origin) { |
548 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 552 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
549 DCHECK(origin); | 553 DCHECK(origin); |
550 | 554 |
(...skipping 25 matching lines...) Expand all Loading... |
576 return STATUS_OK; | 580 return STATUS_OK; |
577 } | 581 } |
578 | 582 |
579 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration( | 583 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration( |
580 const RegistrationData& registration, | 584 const RegistrationData& registration, |
581 const std::vector<ResourceRecord>& resources, | 585 const std::vector<ResourceRecord>& resources, |
582 RegistrationData* old_registration, | 586 RegistrationData* old_registration, |
583 std::vector<int64>* newly_purgeable_resources) { | 587 std::vector<int64>* newly_purgeable_resources) { |
584 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 588 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
585 DCHECK(old_registration); | 589 DCHECK(old_registration); |
| 590 DCHECK(!resources.empty()); |
586 Status status = LazyOpen(true); | 591 Status status = LazyOpen(true); |
587 old_registration->version_id = kInvalidServiceWorkerVersionId; | 592 old_registration->version_id = kInvalidServiceWorkerVersionId; |
588 if (status != STATUS_OK) | 593 if (status != STATUS_OK) |
589 return status; | 594 return status; |
590 | 595 |
591 leveldb::WriteBatch batch; | 596 leveldb::WriteBatch batch; |
592 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); | 597 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); |
593 BumpNextVersionIdIfNeeded(registration.version_id, &batch); | 598 BumpNextVersionIdIfNeeded(registration.version_id, &batch); |
594 | 599 |
595 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); | 600 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 | 1457 |
1453 void ServiceWorkerDatabase::HandleWriteResult( | 1458 void ServiceWorkerDatabase::HandleWriteResult( |
1454 const tracked_objects::Location& from_here, | 1459 const tracked_objects::Location& from_here, |
1455 Status status) { | 1460 Status status) { |
1456 if (status != STATUS_OK) | 1461 if (status != STATUS_OK) |
1457 Disable(from_here, status); | 1462 Disable(from_here, status); |
1458 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1463 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1459 } | 1464 } |
1460 | 1465 |
1461 } // namespace content | 1466 } // namespace content |
OLD | NEW |