Index: content/common/origin_trials/trial_token.h |
diff --git a/content/common/origin_trials/trial_token.h b/content/common/origin_trials/trial_token.h |
index fa05e3713b5b943cbd3f8fd774d09f1c5f8793cc..3471fa4eae78087963dc654935ad83b37d16011b 100644 |
--- a/content/common/origin_trials/trial_token.h |
+++ b/content/common/origin_trials/trial_token.h |
@@ -11,6 +11,7 @@ |
#include "base/strings/string_piece.h" |
#include "base/time/time.h" |
#include "content/common/content_export.h" |
+#include "content/common/origin_trials/trial_token_status.h" |
#include "url/origin.h" |
namespace content { |
@@ -32,19 +33,24 @@ class CONTENT_EXPORT TrialToken { |
public: |
~TrialToken(); |
- // Returns a token object if the string represents a signed well-formed token, |
- // or nullptr otherwise. (This does not mean that the token is currently |
- // valid, or appropriate for a given origin / feature, just that it is |
+ // If the string represents a signed well-formed token, a token object is |
+ // returned, and success is returned in the |out_status| parameter. Otherwise, |
+ // the |out_status| parameter indicates what was wrong with the string, and |
+ // nullptr is returned. |
+ // Note that success does not mean that the token is currently valid, or |
+ // appropriate for a given origin / feature. It only means that it is |
// correctly formatted and signed by the supplied public key, and can be |
- // parsed.) |
+ // parsed. |
static std::unique_ptr<TrialToken> From(const std::string& token_text, |
- base::StringPiece public_key); |
+ base::StringPiece public_key, |
+ TrialTokenStatus* out_status); |
- // Returns true if this token is appropriate for use by the given origin, |
- // for the given feature name, and has not yet expired. |
- bool IsValidForFeature(const url::Origin& origin, |
- base::StringPiece feature_name, |
- const base::Time& now) const; |
+ // Returns success if this token is appropriate for use by the given origin |
+ // and feature name, and has not yet expired. Otherwise, the return value |
+ // indicates why the token is not valid. |
+ TrialTokenStatus IsValidForFeature(const url::Origin& origin, |
+ base::StringPiece feature_name, |
+ const base::Time& now) const; |
url::Origin origin() { return origin_; } |
std::string feature_name() { return feature_name_; } |
@@ -53,10 +59,13 @@ class CONTENT_EXPORT TrialToken { |
protected: |
friend class TrialTokenTest; |
- // Returns the payload of a signed token, or nullptr if the token is not |
- // properly signed, or is not well-formed. |
- static std::unique_ptr<std::string> Extract(const std::string& token_text, |
- base::StringPiece public_key); |
+ // If the string represents a properly signed and well-formed token, the JSON |
+ // payload is returned in the |out_token_json| parameter and success is |
+ // returned. Otherwise,the return code indicates what was wrong with the |
+ // string, and |out_token_json| is unchanged. |
+ static TrialTokenStatus Extract(const std::string& token_text, |
+ base::StringPiece public_key, |
+ std::string* out_token_json); |
// Returns a token object if the string represents a well-formed JSON token |
// payload, or nullptr otherwise. |