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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 | 523 |
524 RegistrationData value; | 524 RegistrationData value; |
525 status = ReadRegistrationData(registration_id, origin, &value); | 525 status = ReadRegistrationData(registration_id, origin, &value); |
526 if (status != STATUS_OK) | 526 if (status != STATUS_OK) |
527 return status; | 527 return status; |
528 | 528 |
529 status = ReadResourceRecords(value.version_id, resources); | 529 status = ReadResourceRecords(value.version_id, resources); |
530 if (status != STATUS_OK) | 530 if (status != STATUS_OK) |
531 return status; | 531 return status; |
532 | 532 |
533 // ResourceRecord must contain the ServiceWorker's main script. | |
534 if (resources->empty()) | |
535 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; | |
536 | |
533 *registration = value; | 537 *registration = value; |
534 return STATUS_OK; | 538 return STATUS_OK; |
535 } | 539 } |
536 | 540 |
537 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadRegistrationOrigin( | 541 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadRegistrationOrigin( |
538 int64 registration_id, | 542 int64 registration_id, |
539 GURL* origin) { | 543 GURL* origin) { |
540 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 544 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
541 DCHECK(origin); | 545 DCHECK(origin); |
542 | 546 |
(...skipping 25 matching lines...) Expand all Loading... | |
568 return STATUS_OK; | 572 return STATUS_OK; |
569 } | 573 } |
570 | 574 |
571 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration( | 575 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteRegistration( |
572 const RegistrationData& registration, | 576 const RegistrationData& registration, |
573 const std::vector<ResourceRecord>& resources, | 577 const std::vector<ResourceRecord>& resources, |
574 RegistrationData* old_registration, | 578 RegistrationData* old_registration, |
575 std::vector<int64>* newly_purgeable_resources) { | 579 std::vector<int64>* newly_purgeable_resources) { |
576 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 580 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
577 DCHECK(old_registration); | 581 DCHECK(old_registration); |
582 DCHECK(!resources.empty()); | |
michaeln
2015/05/08 20:41:08
Should an attempt to write a reg with an empty res
horo
2015/05/11 03:10:20
When WriteRegistration() is called, the registrati
| |
578 Status status = LazyOpen(true); | 583 Status status = LazyOpen(true); |
579 old_registration->version_id = kInvalidServiceWorkerVersionId; | 584 old_registration->version_id = kInvalidServiceWorkerVersionId; |
580 if (status != STATUS_OK) | 585 if (status != STATUS_OK) |
581 return status; | 586 return status; |
582 | 587 |
583 leveldb::WriteBatch batch; | 588 leveldb::WriteBatch batch; |
584 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); | 589 BumpNextRegistrationIdIfNeeded(registration.registration_id, &batch); |
585 BumpNextVersionIdIfNeeded(registration.version_id, &batch); | 590 BumpNextVersionIdIfNeeded(registration.version_id, &batch); |
586 | 591 |
587 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); | 592 PutUniqueOriginToBatch(registration.scope.GetOrigin(), &batch); |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1447 | 1452 |
1448 void ServiceWorkerDatabase::HandleWriteResult( | 1453 void ServiceWorkerDatabase::HandleWriteResult( |
1449 const tracked_objects::Location& from_here, | 1454 const tracked_objects::Location& from_here, |
1450 Status status) { | 1455 Status status) { |
1451 if (status != STATUS_OK) | 1456 if (status != STATUS_OK) |
1452 Disable(from_here, status); | 1457 Disable(from_here, status); |
1453 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1458 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1454 } | 1459 } |
1455 | 1460 |
1456 } // namespace content | 1461 } // namespace content |
OLD | NEW |