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 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 bool TrialTokenValidator::ValidateToken(const std::string& token, | 13 TrialTokenStatus TrialTokenValidator::ValidateToken( |
14 const url::Origin& origin, | 14 const std::string& token, |
15 base::StringPiece feature_name) { | 15 const url::Origin& origin, |
| 16 base::StringPiece feature_name) { |
16 // TODO(iclelland): Allow for multiple signing keys, and iterate over all | 17 // TODO(iclelland): Allow for multiple signing keys, and iterate over all |
17 // active keys here. https://crbug.com/543220 | 18 // active keys here. https://crbug.com/543220 |
18 ContentClient* content_client = GetContentClient(); | 19 ContentClient* content_client = GetContentClient(); |
19 base::StringPiece public_key = content_client->GetOriginTrialPublicKey(); | 20 base::StringPiece public_key = content_client->GetOriginTrialPublicKey(); |
20 if (public_key.empty()) { | 21 if (public_key.empty()) { |
21 return false; | 22 return TRIAL_TOKEN_STATUS_NOT_SUPPORTED; |
22 } | 23 } |
23 std::unique_ptr<TrialToken> trial_token = TrialToken::From(token, public_key); | |
24 | 24 |
25 return trial_token && | 25 TrialTokenStatus status; |
26 trial_token->IsValidForFeature(origin, feature_name, | 26 std::unique_ptr<TrialToken> trial_token = |
| 27 TrialToken::From(token, public_key, &status); |
| 28 if (status != TRIAL_TOKEN_STATUS_SUCCESS) { |
| 29 return status; |
| 30 } |
| 31 |
| 32 return trial_token->IsValidForFeature(origin, feature_name, |
27 base::Time::Now()); | 33 base::Time::Now()); |
28 } | 34 } |
29 | 35 |
30 } // namespace content | 36 } // namespace content |
OLD | NEW |