OLD | NEW |
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 |
OLD | NEW |