1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "components/gcm_driver/features.h" 6 #include "base/metrics/field_trial_param_associator.h" 7 #include "base/metrics/field_trial_params.h" 8 #include "base/strings/string_number_conversions.h" 9 10 #include <algorithm> 11 #include <map> 12 13 namespace gcm { 14 15 namespace features { 16 17 const base::Feature kInvalidateTokenFeature{"GCMTokenInvalidAfterDays", 18 base::FEATURE_ENABLED_BY_DEFAULT}; 19 const char kParamNameTokenInvalidationPeriodDays[] = 20 "token_invalidation_period"; 21 // A token invalidation period of 0 means the feature is disabled, and the 22 // GCM token never becomes stale. 23 const int kDefaultTokenInvalidationPeriod = 7; 24 GetTokenInvalidationInterval()25base::TimeDelta GetTokenInvalidationInterval() { 26 if (!base::FeatureList::IsEnabled(kInvalidateTokenFeature)) 27 return base::TimeDelta(); 28 std::string override_value = base::GetFieldTrialParamValueByFeature( 29 kInvalidateTokenFeature, kParamNameTokenInvalidationPeriodDays); 30 31 if (!override_value.empty()) { 32 int override_value_days; 33 if (base::StringToInt(override_value, &override_value_days)) 34 return base::TimeDelta::FromDays(override_value_days); 35 } 36 return base::TimeDelta::FromDays(kDefaultTokenInvalidationPeriod); 37 } 38 39 } // namespace features 40 41 } // namespace gcm 42