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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 GURL sub_scope_url(data.foreign_fetch_scope(i)); | 1186 GURL sub_scope_url(data.foreign_fetch_scope(i)); |
1187 if (!sub_scope_url.is_valid() || | 1187 if (!sub_scope_url.is_valid() || |
1188 !ServiceWorkerUtils::ScopeMatches(scope_url, sub_scope_url)) { | 1188 !ServiceWorkerUtils::ScopeMatches(scope_url, sub_scope_url)) { |
1189 DLOG(ERROR) << "Foreign fetch scope '" << data.foreign_fetch_scope(i) | 1189 DLOG(ERROR) << "Foreign fetch scope '" << data.foreign_fetch_scope(i) |
1190 << "' is not valid or does not match Scope URL '" << scope_url | 1190 << "' is not valid or does not match Scope URL '" << scope_url |
1191 << "'."; | 1191 << "'."; |
1192 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; | 1192 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; |
1193 } | 1193 } |
1194 out->foreign_fetch_scopes.push_back(sub_scope_url); | 1194 out->foreign_fetch_scopes.push_back(sub_scope_url); |
1195 } | 1195 } |
| 1196 for (int i = 0; i < data.foreign_fetch_origin_size(); ++i) { |
| 1197 GURL origin_url(data.foreign_fetch_origin(i)); |
| 1198 if (!origin_url.is_valid()) { |
| 1199 DLOG(ERROR) << "Foreign fetch origin '" << data.foreign_fetch_origin(i) |
| 1200 << "' is not valid."; |
| 1201 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; |
| 1202 } |
| 1203 out->foreign_fetch_origins.push_back(origin_url); |
| 1204 } |
1196 | 1205 |
1197 return ServiceWorkerDatabase::STATUS_OK; | 1206 return ServiceWorkerDatabase::STATUS_OK; |
1198 } | 1207 } |
1199 | 1208 |
1200 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( | 1209 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( |
1201 const RegistrationData& registration, | 1210 const RegistrationData& registration, |
1202 leveldb::WriteBatch* batch) { | 1211 leveldb::WriteBatch* batch) { |
1203 DCHECK(batch); | 1212 DCHECK(batch); |
1204 | 1213 |
1205 // The registration id and version id should be bumped before this. | 1214 // The registration id and version id should be bumped before this. |
(...skipping 11 matching lines...) Expand all Loading... |
1217 data.set_last_update_check_time( | 1226 data.set_last_update_check_time( |
1218 registration.last_update_check.ToInternalValue()); | 1227 registration.last_update_check.ToInternalValue()); |
1219 data.set_resources_total_size_bytes(registration.resources_total_size_bytes); | 1228 data.set_resources_total_size_bytes(registration.resources_total_size_bytes); |
1220 for (const GURL& url : registration.foreign_fetch_scopes) { | 1229 for (const GURL& url : registration.foreign_fetch_scopes) { |
1221 DCHECK(ServiceWorkerUtils::ScopeMatches(registration.scope, url)) | 1230 DCHECK(ServiceWorkerUtils::ScopeMatches(registration.scope, url)) |
1222 << "Foreign fetch scope '" << url | 1231 << "Foreign fetch scope '" << url |
1223 << "' does not match service worker scope '" << registration.scope | 1232 << "' does not match service worker scope '" << registration.scope |
1224 << "'."; | 1233 << "'."; |
1225 data.add_foreign_fetch_scope(url.spec()); | 1234 data.add_foreign_fetch_scope(url.spec()); |
1226 } | 1235 } |
| 1236 for (const GURL& url : registration.foreign_fetch_origins) |
| 1237 data.add_foreign_fetch_origin(url.spec()); |
1227 | 1238 |
1228 std::string value; | 1239 std::string value; |
1229 bool success = data.SerializeToString(&value); | 1240 bool success = data.SerializeToString(&value); |
1230 DCHECK(success); | 1241 DCHECK(success); |
1231 GURL origin = registration.scope.GetOrigin(); | 1242 GURL origin = registration.scope.GetOrigin(); |
1232 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); | 1243 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); |
1233 } | 1244 } |
1234 | 1245 |
1235 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( | 1246 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( |
1236 int64_t version_id, | 1247 int64_t version_id, |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 if (status != STATUS_OK) | 1596 if (status != STATUS_OK) |
1586 Disable(from_here, status); | 1597 Disable(from_here, status); |
1587 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1598 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1588 } | 1599 } |
1589 | 1600 |
1590 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1601 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
1591 return path_.empty(); | 1602 return path_.empty(); |
1592 } | 1603 } |
1593 | 1604 |
1594 } // namespace content | 1605 } // namespace content |
OLD | NEW |