summaryrefslogtreecommitdiff
path: root/chromium/components/gcm_driver/features.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/gcm_driver/features.cc')
-rw-r--r--chromium/components/gcm_driver/features.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/chromium/components/gcm_driver/features.cc b/chromium/components/gcm_driver/features.cc
new file mode 100644
index 00000000000..9f6507687b1
--- /dev/null
+++ b/chromium/components/gcm_driver/features.cc
@@ -0,0 +1,41 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/gcm_driver/features.h"
+#include "base/metrics/field_trial_param_associator.h"
+#include "base/metrics/field_trial_params.h"
+#include "base/strings/string_number_conversions.h"
+
+#include <algorithm>
+#include <map>
+
+namespace gcm {
+
+namespace features {
+
+const base::Feature kInvalidateTokenFeature{"GCMTokenInvalidAfterDays",
+ base::FEATURE_ENABLED_BY_DEFAULT};
+const char kParamNameTokenInvalidationPeriodDays[] =
+ "token_invalidation_period";
+// A token invalidation period of 0 means the feature is disabled, and the
+// GCM token never becomes stale.
+const int kDefaultTokenInvalidationPeriod = 7;
+
+base::TimeDelta GetTokenInvalidationInterval() {
+ if (!base::FeatureList::IsEnabled(kInvalidateTokenFeature))
+ return base::TimeDelta();
+ std::string override_value = base::GetFieldTrialParamValueByFeature(
+ kInvalidateTokenFeature, kParamNameTokenInvalidationPeriodDays);
+
+ if (!override_value.empty()) {
+ int override_value_days;
+ if (base::StringToInt(override_value, &override_value_days))
+ return base::Days(override_value_days);
+ }
+ return base::Days(kDefaultTokenInvalidationPeriod);
+}
+
+} // namespace features
+
+} // namespace gcm