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

Unified Diff: content/common/origin_trials/trial_token_validator.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 side-by-side diff with in-line comments
Download patch
Index: content/common/origin_trials/trial_token_validator.cc
diff --git a/content/common/origin_trials/trial_token_validator.cc b/content/common/origin_trials/trial_token_validator.cc
index 34ae30448f229c2db29788107a1e79496a7ae803..2cb1dd3d43d1423c21848873a12b7455b41455f2 100644
--- a/content/common/origin_trials/trial_token_validator.cc
+++ b/content/common/origin_trials/trial_token_validator.cc
@@ -5,6 +5,7 @@
#include "content/common/origin_trials/trial_token_validator.h"
#include "base/feature_list.h"
+#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "content/common/origin_trials/trial_token.h"
#include "content/public/common/content_client.h"
@@ -83,4 +84,52 @@ bool TrialTokenValidator::RequestEnablesFeature(
return false;
}
+std::unique_ptr<TrialTokenValidator::FeatureToTokensMap>
+TrialTokenValidator::GetValidTokensFromHeaders(
+ const url::Origin& origin,
+ const net::HttpResponseHeaders* headers) {
+ std::unique_ptr<FeatureToTokensMap> tokens(
+ base::MakeUnique<FeatureToTokensMap>());
+ if (!base::FeatureList::IsEnabled(features::kOriginTrials))
+ return tokens;
+
+ if (!IsOriginSecure(origin.GetURL()))
+ return tokens;
+
+ size_t iter = 0;
+ std::string token;
+ while (headers->EnumerateHeader(&iter, "Origin-Trial", &token)) {
+ std::string token_feature;
+ if (TrialTokenValidator::ValidateToken(token, origin, &token_feature) ==
+ blink::WebOriginTrialTokenStatus::Success) {
+ (*tokens)[token_feature].push_back(token);
+ }
+ }
+ return tokens;
+}
+
+std::unique_ptr<TrialTokenValidator::FeatureToTokensMap>
+TrialTokenValidator::GetValidTokens(const url::Origin& origin,
+ const FeatureToTokensMap& tokens) {
+ std::unique_ptr<FeatureToTokensMap> out_tokens(
+ base::MakeUnique<FeatureToTokensMap>());
+ if (!base::FeatureList::IsEnabled(features::kOriginTrials))
+ return out_tokens;
+
+ if (!IsOriginSecure(origin.GetURL()))
+ return out_tokens;
+
+ for (const auto& feature : tokens) {
+ for (const std::string& token : feature.second) {
+ std::string token_feature;
+ if (TrialTokenValidator::ValidateToken(token, origin, &token_feature) ==
+ blink::WebOriginTrialTokenStatus::Success) {
+ DCHECK_EQ(token_feature, feature.first);
+ (*out_tokens)[feature.first].push_back(token);
+ }
+ }
+ }
+ return out_tokens;
+}
+
} // namespace content
« no previous file with comments | « content/common/origin_trials/trial_token_validator.h ('k') | third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698