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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/common/origin_trials/trial_token_validator.h" 5 #include "content/common/origin_trials/trial_token_validator.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/memory/ptr_util.h"
8 #include "base/time/time.h" 9 #include "base/time/time.h"
9 #include "content/common/origin_trials/trial_token.h" 10 #include "content/common/origin_trials/trial_token.h"
10 #include "content/public/common/content_client.h" 11 #include "content/public/common/content_client.h"
11 #include "content/public/common/content_features.h" 12 #include "content/public/common/content_features.h"
12 #include "content/public/common/origin_trial_policy.h" 13 #include "content/public/common/origin_trial_policy.h"
13 #include "content/public/common/origin_util.h" 14 #include "content/public/common/origin_util.h"
14 #include "net/http/http_response_headers.h" 15 #include "net/http/http_response_headers.h"
15 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
16 #include "third_party/WebKit/public/platform/WebOriginTrialTokenStatus.h" 17 #include "third_party/WebKit/public/platform/WebOriginTrialTokenStatus.h"
17 18
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 std::string token_feature; 77 std::string token_feature;
77 // TODO(mek): Log the validation errors to histograms? 78 // TODO(mek): Log the validation errors to histograms?
78 if (ValidateToken(token, origin, &token_feature) == 79 if (ValidateToken(token, origin, &token_feature) ==
79 blink::WebOriginTrialTokenStatus::Success) 80 blink::WebOriginTrialTokenStatus::Success)
80 if (token_feature == feature_name) 81 if (token_feature == feature_name)
81 return true; 82 return true;
82 } 83 }
83 return false; 84 return false;
84 } 85 }
85 86
87 std::unique_ptr<TrialTokenValidator::FeatureToTokensMap>
88 TrialTokenValidator::GetValidTokensFromHeaders(
89 const url::Origin& origin,
90 const net::HttpResponseHeaders* headers) {
91 std::unique_ptr<FeatureToTokensMap> tokens(
92 base::MakeUnique<FeatureToTokensMap>());
93 if (!base::FeatureList::IsEnabled(features::kOriginTrials))
94 return tokens;
95
96 if (!IsOriginSecure(origin.GetURL()))
97 return tokens;
98
99 size_t iter = 0;
100 std::string token;
101 while (headers->EnumerateHeader(&iter, "Origin-Trial", &token)) {
102 std::string token_feature;
103 if (TrialTokenValidator::ValidateToken(token, origin, &token_feature) ==
104 blink::WebOriginTrialTokenStatus::Success) {
105 (*tokens)[token_feature].push_back(token);
106 }
107 }
108 return tokens;
109 }
110
111 std::unique_ptr<TrialTokenValidator::FeatureToTokensMap>
112 TrialTokenValidator::GetValidTokens(const url::Origin& origin,
113 const FeatureToTokensMap& tokens) {
114 std::unique_ptr<FeatureToTokensMap> out_tokens(
115 base::MakeUnique<FeatureToTokensMap>());
116 if (!base::FeatureList::IsEnabled(features::kOriginTrials))
117 return out_tokens;
118
119 if (!IsOriginSecure(origin.GetURL()))
120 return out_tokens;
121
122 for (const auto& feature : tokens) {
123 for (const std::string& token : feature.second) {
124 std::string token_feature;
125 if (TrialTokenValidator::ValidateToken(token, origin, &token_feature) ==
126 blink::WebOriginTrialTokenStatus::Success) {
127 DCHECK_EQ(token_feature, feature.first);
128 (*out_tokens)[feature.first].push_back(token);
129 }
130 }
131 }
132 return out_tokens;
133 }
134
86 } // namespace content 135 } // namespace content
OLDNEW
« 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