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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadRegistration( | 498 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadRegistration( |
499 int64 registration_id, | 499 int64 registration_id, |
500 const GURL& origin, | 500 const GURL& origin, |
501 RegistrationData* registration, | 501 RegistrationData* registration, |
502 std::vector<ResourceRecord>* resources) { | 502 std::vector<ResourceRecord>* resources) { |
503 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 503 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
504 DCHECK(registration); | 504 DCHECK(registration); |
505 DCHECK(resources); | 505 DCHECK(resources); |
506 | 506 |
507 Status status = LazyOpen(false); | 507 Status status = LazyOpen(false); |
508 if (IsNewOrNonexistentDatabase(status) || status != STATUS_OK) | 508 if (IsNewOrNonexistentDatabase(status)) |
| 509 return STATUS_ERROR_NOT_FOUND; |
| 510 if (status != STATUS_OK) |
509 return status; | 511 return status; |
510 | 512 |
511 RegistrationData value; | 513 RegistrationData value; |
512 status = ReadRegistrationData(registration_id, origin, &value); | 514 status = ReadRegistrationData(registration_id, origin, &value); |
513 if (status != STATUS_OK) | 515 if (status != STATUS_OK) |
514 return status; | 516 return status; |
515 | 517 |
516 status = ReadResourceRecords(value.version_id, resources); | 518 status = ReadResourceRecords(value.version_id, resources); |
517 if (status != STATUS_OK) | 519 if (status != STATUS_OK) |
518 return status; | 520 return status; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadUserData( | 703 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadUserData( |
702 int64 registration_id, | 704 int64 registration_id, |
703 const std::string& user_data_name, | 705 const std::string& user_data_name, |
704 std::string* user_data) { | 706 std::string* user_data) { |
705 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 707 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
706 DCHECK_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 708 DCHECK_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
707 DCHECK(!user_data_name.empty()); | 709 DCHECK(!user_data_name.empty()); |
708 DCHECK(user_data); | 710 DCHECK(user_data); |
709 | 711 |
710 Status status = LazyOpen(false); | 712 Status status = LazyOpen(false); |
711 if (IsNewOrNonexistentDatabase(status) || status != STATUS_OK) | 713 if (IsNewOrNonexistentDatabase(status)) |
| 714 return STATUS_ERROR_NOT_FOUND; |
| 715 if (status != STATUS_OK) |
712 return status; | 716 return status; |
713 | 717 |
714 const std::string key = CreateUserDataKey(registration_id, user_data_name); | 718 const std::string key = CreateUserDataKey(registration_id, user_data_name); |
715 status = LevelDBStatusToStatus( | 719 status = LevelDBStatusToStatus( |
716 db_->Get(leveldb::ReadOptions(), key, user_data)); | 720 db_->Get(leveldb::ReadOptions(), key, user_data)); |
717 HandleReadResult(FROM_HERE, | 721 HandleReadResult(FROM_HERE, |
718 status == STATUS_ERROR_NOT_FOUND ? STATUS_OK : status); | 722 status == STATUS_ERROR_NOT_FOUND ? STATUS_OK : status); |
719 return status; | 723 return status; |
720 } | 724 } |
721 | 725 |
722 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteUserData( | 726 ServiceWorkerDatabase::Status ServiceWorkerDatabase::WriteUserData( |
723 int64 registration_id, | 727 int64 registration_id, |
724 const GURL& origin, | 728 const GURL& origin, |
725 const std::string& user_data_name, | 729 const std::string& user_data_name, |
726 const std::string& user_data) { | 730 const std::string& user_data) { |
727 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 731 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
728 DCHECK_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 732 DCHECK_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
729 DCHECK(!user_data_name.empty()); | 733 DCHECK(!user_data_name.empty()); |
730 | 734 |
731 Status status = LazyOpen(false); | 735 Status status = LazyOpen(false); |
732 if (IsNewOrNonexistentDatabase(status) || status != STATUS_OK) | 736 if (IsNewOrNonexistentDatabase(status)) |
| 737 return STATUS_ERROR_NOT_FOUND; |
| 738 if (status != STATUS_OK) |
733 return status; | 739 return status; |
734 | 740 |
735 // There should be the registration specified by |registration_id|. | 741 // There should be the registration specified by |registration_id|. |
736 RegistrationData registration; | 742 RegistrationData registration; |
737 status = ReadRegistrationData(registration_id, origin, ®istration); | 743 status = ReadRegistrationData(registration_id, origin, ®istration); |
738 if (status != STATUS_OK) | 744 if (status != STATUS_OK) |
739 return status; | 745 return status; |
740 | 746 |
741 leveldb::WriteBatch batch; | 747 leveldb::WriteBatch batch; |
742 batch.Put(CreateUserDataKey(registration_id, user_data_name), user_data); | 748 batch.Put(CreateUserDataKey(registration_id, user_data_name), user_data); |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 | 1335 |
1330 void ServiceWorkerDatabase::HandleWriteResult( | 1336 void ServiceWorkerDatabase::HandleWriteResult( |
1331 const tracked_objects::Location& from_here, | 1337 const tracked_objects::Location& from_here, |
1332 Status status) { | 1338 Status status) { |
1333 if (status != STATUS_OK) | 1339 if (status != STATUS_OK) |
1334 Disable(from_here, status); | 1340 Disable(from_here, status); |
1335 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1341 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1336 } | 1342 } |
1337 | 1343 |
1338 } // namespace content | 1344 } // namespace content |
OLD | NEW |