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

Side by Side Diff: content/common/origin_trials/trial_token_validator.cc

Issue 1763943002: WIP add code to check http headers for origin trial tokens Base URL: https://chromium.googlesource.com/chromium/src.git@move-trial-token-code
Patch Set: rebase Created 4 years, 9 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
« no previous file with comments | « content/common/origin_trials/trial_token_validator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/time/time.h" 7 #include "base/time/time.h"
8 #include "content/common/origin_trials/trial_token.h" 8 #include "content/common/origin_trials/trial_token.h"
9 #include "content/public/common/content_client.h" 9 #include "content/public/common/content_client.h"
10 #include "net/http/http_response_headers.h"
11 #include "net/url_request/url_request.h"
10 12
11 namespace content { 13 namespace content {
12 14
13 bool TrialTokenValidator::ValidateToken(const std::string& token, 15 bool TrialTokenValidator::ValidateToken(const std::string& token,
14 const url::Origin& origin, 16 const url::Origin& origin,
15 base::StringPiece featureName) { 17 base::StringPiece featureName) {
16 scoped_ptr<TrialToken> trial_token = TrialToken::Parse(token); 18 scoped_ptr<TrialToken> trial_token = TrialToken::Parse(token);
17 19
18 ContentClient* content_client = GetContentClient(); 20 ContentClient* content_client = GetContentClient();
19 CHECK(content_client); 21 CHECK(content_client);
20 base::StringPiece public_key = content_client->GetOriginTrialPublicKey(); 22 base::StringPiece public_key = content_client->GetOriginTrialPublicKey();
21 return !public_key.empty() && trial_token && 23 return !public_key.empty() && trial_token &&
22 trial_token->IsAppropriate(origin, featureName) && 24 trial_token->IsAppropriate(origin, featureName) &&
23 trial_token->IsValid(base::Time::Now(), public_key); 25 trial_token->IsValid(base::Time::Now(), public_key);
24 } 26 }
25 27
28 bool TrialTokenValidator::RequestEnablesFeature(const net::URLRequest* request,
29 base::StringPiece featureName) {
30 url::Origin origin(request->url());
31 size_t iter = 0;
32 std::string token;
33 while (request->response_headers()->EnumerateHeader(&iter, "Origin-Trial",
34 &token)) {
35 if (ValidateToken(token, origin, featureName))
36 return true;
37 }
38 return false;
39 }
40
26 } // namespace content 41 } // namespace content
OLDNEW
« no previous file with comments | « content/common/origin_trials/trial_token_validator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698