Chromium Code Reviews| 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 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 for (std::set<int64>::const_iterator itr = ids.begin(); | 971 for (std::set<int64>::const_iterator itr = ids.begin(); |
| 972 itr != ids.end(); ++itr) { | 972 itr != ids.end(); ++itr) { |
| 973 // Value should be empty. | 973 // Value should be empty. |
| 974 batch->Put(CreateResourceIdKey(id_key_prefix, *itr), ""); | 974 batch->Put(CreateResourceIdKey(id_key_prefix, *itr), ""); |
| 975 } | 975 } |
| 976 BumpNextResourceIdIfNeeded(ids, batch); | |
|
michaeln
2014/07/09 02:36:10
lions and tigers and bears, thnx for fixing this
nhiroki
2014/07/09 03:43:10
Great catch! Thank you :)
| |
| 976 return STATUS_OK; | 977 return STATUS_OK; |
| 977 } | 978 } |
| 978 | 979 |
| 979 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteResourceIds( | 980 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteResourceIds( |
| 980 const char* id_key_prefix, | 981 const char* id_key_prefix, |
| 981 const std::set<int64>& ids) { | 982 const std::set<int64>& ids) { |
| 982 leveldb::WriteBatch batch; | 983 leveldb::WriteBatch batch; |
| 983 Status status = DeleteResourceIdsInBatch(id_key_prefix, ids, &batch); | 984 Status status = DeleteResourceIdsInBatch(id_key_prefix, ids, &batch); |
| 984 if (status != STATUS_OK) | 985 if (status != STATUS_OK) |
| 985 return status; | 986 return status; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 | 1048 |
| 1048 void ServiceWorkerDatabase::BumpNextRegistrationIdIfNeeded( | 1049 void ServiceWorkerDatabase::BumpNextRegistrationIdIfNeeded( |
| 1049 int64 used_id, leveldb::WriteBatch* batch) { | 1050 int64 used_id, leveldb::WriteBatch* batch) { |
| 1050 DCHECK(batch); | 1051 DCHECK(batch); |
| 1051 if (next_avail_registration_id_ <= used_id) { | 1052 if (next_avail_registration_id_ <= used_id) { |
| 1052 next_avail_registration_id_ = used_id + 1; | 1053 next_avail_registration_id_ = used_id + 1; |
| 1053 batch->Put(kNextRegIdKey, base::Int64ToString(next_avail_registration_id_)); | 1054 batch->Put(kNextRegIdKey, base::Int64ToString(next_avail_registration_id_)); |
| 1054 } | 1055 } |
| 1055 } | 1056 } |
| 1056 | 1057 |
| 1058 void ServiceWorkerDatabase::BumpNextResourceIdIfNeeded( | |
| 1059 const std::set<int64>& used_ids, | |
| 1060 leveldb::WriteBatch* batch) { | |
| 1061 DCHECK(batch); | |
| 1062 int64 old_id = next_avail_resource_id_; | |
| 1063 for (std::set<int64>::const_iterator itr = used_ids.begin(); | |
|
nhiroki
2014/07/09 03:43:10
IIUC, std::set is always sorted and the last eleme
falken
2014/07/09 04:31:14
Ah, looks right. Switched to look at the last elem
| |
| 1064 itr != used_ids.end(); | |
| 1065 ++itr) { | |
| 1066 if (next_avail_resource_id_ <= *itr) | |
| 1067 next_avail_resource_id_ = *itr + 1; | |
| 1068 } | |
| 1069 | |
| 1070 if (next_avail_resource_id_ != old_id) | |
| 1071 batch->Put(kNextResIdKey, base::Int64ToString(next_avail_resource_id_)); | |
| 1072 } | |
| 1073 | |
| 1057 void ServiceWorkerDatabase::BumpNextVersionIdIfNeeded( | 1074 void ServiceWorkerDatabase::BumpNextVersionIdIfNeeded( |
| 1058 int64 used_id, leveldb::WriteBatch* batch) { | 1075 int64 used_id, leveldb::WriteBatch* batch) { |
| 1059 DCHECK(batch); | 1076 DCHECK(batch); |
| 1060 if (next_avail_version_id_ <= used_id) { | 1077 if (next_avail_version_id_ <= used_id) { |
| 1061 next_avail_version_id_ = used_id + 1; | 1078 next_avail_version_id_ = used_id + 1; |
| 1062 batch->Put(kNextVerIdKey, base::Int64ToString(next_avail_version_id_)); | 1079 batch->Put(kNextVerIdKey, base::Int64ToString(next_avail_version_id_)); |
| 1063 } | 1080 } |
| 1064 } | 1081 } |
| 1065 | 1082 |
| 1066 bool ServiceWorkerDatabase::IsOpen() { | 1083 bool ServiceWorkerDatabase::IsOpen() { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1097 | 1114 |
| 1098 void ServiceWorkerDatabase::HandleWriteResult( | 1115 void ServiceWorkerDatabase::HandleWriteResult( |
| 1099 const tracked_objects::Location& from_here, | 1116 const tracked_objects::Location& from_here, |
| 1100 Status status) { | 1117 Status status) { |
| 1101 if (status != STATUS_OK) | 1118 if (status != STATUS_OK) |
| 1102 Disable(from_here, status); | 1119 Disable(from_here, status); |
| 1103 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1120 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1104 } | 1121 } |
| 1105 | 1122 |
| 1106 } // namespace content | 1123 } // namespace content |
| OLD | NEW |