Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: content/browser/service_worker/service_worker_database.cc

Issue 2376403004: Store Origin-Trial tokens to ServiceWorkerDataBase (Closed)
Patch Set: incorporated iclelland's comment Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 } 1216 }
1217 for (int i = 0; i < data.foreign_fetch_origin_size(); ++i) { 1217 for (int i = 0; i < data.foreign_fetch_origin_size(); ++i) {
1218 url::Origin parsed_origin(GURL(data.foreign_fetch_origin(i))); 1218 url::Origin parsed_origin(GURL(data.foreign_fetch_origin(i)));
1219 if (parsed_origin.unique()) { 1219 if (parsed_origin.unique()) {
1220 DLOG(ERROR) << "Foreign fetch origin '" << data.foreign_fetch_origin(i) 1220 DLOG(ERROR) << "Foreign fetch origin '" << data.foreign_fetch_origin(i)
1221 << "' is not valid."; 1221 << "' is not valid.";
1222 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; 1222 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED;
1223 } 1223 }
1224 out->foreign_fetch_origins.push_back(parsed_origin); 1224 out->foreign_fetch_origins.push_back(parsed_origin);
1225 } 1225 }
1226 if (data.has_origin_trial_tokens()) {
1227 const ServiceWorkerOriginTrialInfo& info = data.origin_trial_tokens();
1228 TrialTokenValidator::FeatureToTokensMap origin_trial_tokens;
1229 for (int i = 0; i < info.features_size(); ++i) {
1230 const auto& feature = info.features(i);
1231 for (int j = 0; j < feature.tokens_size(); ++j)
1232 origin_trial_tokens[feature.name()].push_back(feature.tokens(j));
1233 }
1234 out->origin_trial_tokens = origin_trial_tokens;
1235 }
1226 1236
1227 return ServiceWorkerDatabase::STATUS_OK; 1237 return ServiceWorkerDatabase::STATUS_OK;
1228 } 1238 }
1229 1239
1230 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( 1240 void ServiceWorkerDatabase::WriteRegistrationDataInBatch(
1231 const RegistrationData& registration, 1241 const RegistrationData& registration,
1232 leveldb::WriteBatch* batch) { 1242 leveldb::WriteBatch* batch) {
1233 DCHECK(batch); 1243 DCHECK(batch);
1234 1244
1235 // The registration id and version id should be bumped before this. 1245 // The registration id and version id should be bumped before this.
(...skipping 13 matching lines...) Expand all
1249 data.set_resources_total_size_bytes(registration.resources_total_size_bytes); 1259 data.set_resources_total_size_bytes(registration.resources_total_size_bytes);
1250 for (const GURL& url : registration.foreign_fetch_scopes) { 1260 for (const GURL& url : registration.foreign_fetch_scopes) {
1251 DCHECK(ServiceWorkerUtils::ScopeMatches(registration.scope, url)) 1261 DCHECK(ServiceWorkerUtils::ScopeMatches(registration.scope, url))
1252 << "Foreign fetch scope '" << url 1262 << "Foreign fetch scope '" << url
1253 << "' does not match service worker scope '" << registration.scope 1263 << "' does not match service worker scope '" << registration.scope
1254 << "'."; 1264 << "'.";
1255 data.add_foreign_fetch_scope(url.spec()); 1265 data.add_foreign_fetch_scope(url.spec());
1256 } 1266 }
1257 for (const url::Origin& origin : registration.foreign_fetch_origins) 1267 for (const url::Origin& origin : registration.foreign_fetch_origins)
1258 data.add_foreign_fetch_origin(origin.Serialize()); 1268 data.add_foreign_fetch_origin(origin.Serialize());
1269 if (registration.origin_trial_tokens) {
1270 ServiceWorkerOriginTrialInfo* info = data.mutable_origin_trial_tokens();
1271 for (const auto& feature : *registration.origin_trial_tokens) {
1272 ServiceWorkerOriginTrialFeature* feature_out = info->add_features();
1273 feature_out->set_name(feature.first);
1274 for (const auto& token : feature.second)
1275 feature_out->add_tokens(token);
1276 }
1277 }
1259 1278
1260 std::string value; 1279 std::string value;
1261 bool success = data.SerializeToString(&value); 1280 bool success = data.SerializeToString(&value);
1262 DCHECK(success); 1281 DCHECK(success);
1263 GURL origin = registration.scope.GetOrigin(); 1282 GURL origin = registration.scope.GetOrigin();
1264 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); 1283 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value);
1265 } 1284 }
1266 1285
1267 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( 1286 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords(
1268 const RegistrationData& registration, 1287 const RegistrationData& registration,
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 if (status != STATUS_OK) 1653 if (status != STATUS_OK)
1635 Disable(from_here, status); 1654 Disable(from_here, status);
1636 ServiceWorkerMetrics::CountWriteDatabaseResult(status); 1655 ServiceWorkerMetrics::CountWriteDatabaseResult(status);
1637 } 1656 }
1638 1657
1639 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { 1658 bool ServiceWorkerDatabase::IsDatabaseInMemory() const {
1640 return path_.empty(); 1659 return path_.empty();
1641 } 1660 }
1642 1661
1643 } // namespace content 1662 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_database.h ('k') | content/browser/service_worker/service_worker_database.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698