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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 const char* id_key_prefix, | 961 const char* id_key_prefix, |
962 const std::set<int64>& ids, | 962 const std::set<int64>& ids, |
963 leveldb::WriteBatch* batch) { | 963 leveldb::WriteBatch* batch) { |
964 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 964 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
965 DCHECK(id_key_prefix); | 965 DCHECK(id_key_prefix); |
966 | 966 |
967 Status status = LazyOpen(true); | 967 Status status = LazyOpen(true); |
968 if (status != STATUS_OK) | 968 if (status != STATUS_OK) |
969 return status; | 969 return status; |
970 | 970 |
| 971 if (ids.empty()) |
| 972 return STATUS_OK; |
971 for (std::set<int64>::const_iterator itr = ids.begin(); | 973 for (std::set<int64>::const_iterator itr = ids.begin(); |
972 itr != ids.end(); ++itr) { | 974 itr != ids.end(); ++itr) { |
973 // Value should be empty. | 975 // Value should be empty. |
974 batch->Put(CreateResourceIdKey(id_key_prefix, *itr), ""); | 976 batch->Put(CreateResourceIdKey(id_key_prefix, *itr), ""); |
975 } | 977 } |
| 978 // std::set is sorted, so the last element is the largest. |
| 979 BumpNextResourceIdIfNeeded(*ids.rbegin(), batch); |
976 return STATUS_OK; | 980 return STATUS_OK; |
977 } | 981 } |
978 | 982 |
979 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteResourceIds( | 983 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteResourceIds( |
980 const char* id_key_prefix, | 984 const char* id_key_prefix, |
981 const std::set<int64>& ids) { | 985 const std::set<int64>& ids) { |
982 leveldb::WriteBatch batch; | 986 leveldb::WriteBatch batch; |
983 Status status = DeleteResourceIdsInBatch(id_key_prefix, ids, &batch); | 987 Status status = DeleteResourceIdsInBatch(id_key_prefix, ids, &batch); |
984 if (status != STATUS_OK) | 988 if (status != STATUS_OK) |
985 return status; | 989 return status; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 | 1051 |
1048 void ServiceWorkerDatabase::BumpNextRegistrationIdIfNeeded( | 1052 void ServiceWorkerDatabase::BumpNextRegistrationIdIfNeeded( |
1049 int64 used_id, leveldb::WriteBatch* batch) { | 1053 int64 used_id, leveldb::WriteBatch* batch) { |
1050 DCHECK(batch); | 1054 DCHECK(batch); |
1051 if (next_avail_registration_id_ <= used_id) { | 1055 if (next_avail_registration_id_ <= used_id) { |
1052 next_avail_registration_id_ = used_id + 1; | 1056 next_avail_registration_id_ = used_id + 1; |
1053 batch->Put(kNextRegIdKey, base::Int64ToString(next_avail_registration_id_)); | 1057 batch->Put(kNextRegIdKey, base::Int64ToString(next_avail_registration_id_)); |
1054 } | 1058 } |
1055 } | 1059 } |
1056 | 1060 |
| 1061 void ServiceWorkerDatabase::BumpNextResourceIdIfNeeded( |
| 1062 int64 used_id, leveldb::WriteBatch* batch) { |
| 1063 DCHECK(batch); |
| 1064 if (next_avail_resource_id_ <= used_id) { |
| 1065 next_avail_resource_id_ = used_id + 1; |
| 1066 batch->Put(kNextResIdKey, base::Int64ToString(next_avail_resource_id_)); |
| 1067 } |
| 1068 } |
| 1069 |
1057 void ServiceWorkerDatabase::BumpNextVersionIdIfNeeded( | 1070 void ServiceWorkerDatabase::BumpNextVersionIdIfNeeded( |
1058 int64 used_id, leveldb::WriteBatch* batch) { | 1071 int64 used_id, leveldb::WriteBatch* batch) { |
1059 DCHECK(batch); | 1072 DCHECK(batch); |
1060 if (next_avail_version_id_ <= used_id) { | 1073 if (next_avail_version_id_ <= used_id) { |
1061 next_avail_version_id_ = used_id + 1; | 1074 next_avail_version_id_ = used_id + 1; |
1062 batch->Put(kNextVerIdKey, base::Int64ToString(next_avail_version_id_)); | 1075 batch->Put(kNextVerIdKey, base::Int64ToString(next_avail_version_id_)); |
1063 } | 1076 } |
1064 } | 1077 } |
1065 | 1078 |
1066 bool ServiceWorkerDatabase::IsOpen() { | 1079 bool ServiceWorkerDatabase::IsOpen() { |
(...skipping 30 matching lines...) Expand all Loading... |
1097 | 1110 |
1098 void ServiceWorkerDatabase::HandleWriteResult( | 1111 void ServiceWorkerDatabase::HandleWriteResult( |
1099 const tracked_objects::Location& from_here, | 1112 const tracked_objects::Location& from_here, |
1100 Status status) { | 1113 Status status) { |
1101 if (status != STATUS_OK) | 1114 if (status != STATUS_OK) |
1102 Disable(from_here, status); | 1115 Disable(from_here, status); |
1103 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1116 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1104 } | 1117 } |
1105 | 1118 |
1106 } // namespace content | 1119 } // namespace content |
OLD | NEW |