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

Unified Diff: third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp

Issue 1739163004: [Experimental Framework] Only log a console message for each feature once (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ef-state
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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
diff --git a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
index 788e2d8b6787d437219a8305eb8ce2e15ba49439..6d9cc0f2ebea3175a26ab5a9bd746130bf6dc4a2 100644
--- a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
+++ b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
@@ -28,6 +28,11 @@ String getDisabledMessage(const String& featureName)
return "The '" + featureName + "' feature is currently enabled in limited trials. Please see [Phosphor console URL] for information on enabling a trial for your site.";
}
+String getInvalidTokenMessage(const String& featureName)
+{
+ return "The provided token(s) are not valid for the '" + featureName + "' feature.";
+}
+
} // namespace
const char OriginTrialContext::kTrialHeaderName[] = "origin-trial";
@@ -78,13 +83,23 @@ bool OriginTrialContext::hasValidToken(Vector<String> tokens, const String& feat
}
}
- if (errorMessage) {
- if (tokens.size()) {
- *errorMessage = "The provided token(s) are not valid for the '" + featureName + "' feature.";
- } else {
- *errorMessage = getDisabledMessage(featureName);
- }
+ if (!errorMessage)
+ return false;
+
+ // If an error message has already been generated in this context, for this
+ // feature, do not generate another one. (This avoids cluttering the console
+ // with error messages on every attempt to access the feature.)
+ if (m_errorMessageGeneratedForFeature.contains(featureName)) {
+ *errorMessage = "";
+ return false;
+ }
+
+ if (tokens.size()) {
+ *errorMessage = getInvalidTokenMessage(featureName);
+ } else {
+ *errorMessage = getDisabledMessage(featureName);
}
+ m_errorMessageGeneratedForFeature.add(featureName);
return false;
}

Powered by Google App Engine
This is Rietveld 408576698