| 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 #ifndef CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_VALIDATOR_H_ | 5 #ifndef CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_VALIDATOR_H_ |
| 6 #define CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_VALIDATOR_H_ | 6 #define CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_VALIDATOR_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 8 #include <string> | 10 #include <string> |
| 11 #include <vector> |
| 9 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 10 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 11 #include "url/origin.h" | 14 #include "url/origin.h" |
| 12 | 15 |
| 13 namespace blink { | 16 namespace blink { |
| 14 enum class WebOriginTrialTokenStatus; | 17 enum class WebOriginTrialTokenStatus; |
| 15 } | 18 } |
| 16 | 19 |
| 17 namespace net { | 20 namespace net { |
| 18 class HttpResponseHeaders; | 21 class HttpResponseHeaders; |
| 19 class URLRequest; | 22 class URLRequest; |
| 20 } | 23 } |
| 21 | 24 |
| 22 namespace content { | 25 namespace content { |
| 23 | 26 |
| 24 namespace TrialTokenValidator { | 27 namespace TrialTokenValidator { |
| 25 | 28 |
| 29 using FeatureToTokensMap = std::map<std::string /* feature_name */, |
| 30 std::vector<std::string /* token */>>; |
| 31 |
| 26 // If token validates, |*feature_name| is set to the name of the feature the | 32 // If token validates, |*feature_name| is set to the name of the feature the |
| 27 // token enables. | 33 // token enables. |
| 28 // This method is thread-safe. | 34 // This method is thread-safe. |
| 29 CONTENT_EXPORT blink::WebOriginTrialTokenStatus ValidateToken( | 35 CONTENT_EXPORT blink::WebOriginTrialTokenStatus ValidateToken( |
| 30 const std::string& token, | 36 const std::string& token, |
| 31 const url::Origin& origin, | 37 const url::Origin& origin, |
| 32 std::string* feature_name); | 38 std::string* feature_name); |
| 33 | 39 |
| 34 CONTENT_EXPORT bool RequestEnablesFeature(const net::URLRequest* request, | 40 CONTENT_EXPORT bool RequestEnablesFeature(const net::URLRequest* request, |
| 35 base::StringPiece feature_name); | 41 base::StringPiece feature_name); |
| 36 | 42 |
| 37 CONTENT_EXPORT bool RequestEnablesFeature( | 43 CONTENT_EXPORT bool RequestEnablesFeature( |
| 38 const GURL& request_url, | 44 const GURL& request_url, |
| 39 const net::HttpResponseHeaders* response_headers, | 45 const net::HttpResponseHeaders* response_headers, |
| 40 base::StringPiece feature_name); | 46 base::StringPiece feature_name); |
| 41 | 47 |
| 48 // Returns all valid tokens in |headers|. |
| 49 CONTENT_EXPORT std::unique_ptr<FeatureToTokensMap> GetValidTokensFromHeaders( |
| 50 const url::Origin& origin, |
| 51 const net::HttpResponseHeaders* headers); |
| 52 |
| 53 // Returns all valid tokens in |tokens|. This method is used to re-validate |
| 54 // previously stored tokens. |
| 55 CONTENT_EXPORT std::unique_ptr<FeatureToTokensMap> GetValidTokens( |
| 56 const url::Origin& origin, |
| 57 const FeatureToTokensMap& tokens); |
| 58 |
| 42 } // namespace TrialTokenValidator | 59 } // namespace TrialTokenValidator |
| 43 | 60 |
| 44 } // namespace content | 61 } // namespace content |
| 45 | 62 |
| 46 #endif // CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_VALIDATOR_H_ | 63 #endif // CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_VALIDATOR_H_ |
| OLD | NEW |