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

Unified Diff: components/doodle/doodle_service.cc

Issue 2776973003: [Doodle] Move ttl clamping from fetcher to service (Closed)
Patch Set: Created 3 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
« no previous file with comments | « components/doodle/doodle_fetcher_impl_unittest.cc ('k') | components/doodle/doodle_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/doodle/doodle_service.cc
diff --git a/components/doodle/doodle_service.cc b/components/doodle/doodle_service.cc
index b005c277e974509e34c3b834cb91f01121a648d0..bb97e32d4175082c8a16e72e461ebe8355e1d4a3 100644
--- a/components/doodle/doodle_service.cc
+++ b/components/doodle/doodle_service.cc
@@ -17,6 +17,12 @@
namespace doodle {
+namespace {
+
+const int64_t kMaxTimeToLiveSecs = 30 * 24 * 60 * 60; // 30 days
+
+} // namespace
+
// static
void DoodleService::RegisterProfilePrefs(PrefRegistrySimple* pref_registry) {
pref_registry->RegisterDictionaryPref(prefs::kCachedConfig,
@@ -148,6 +154,12 @@ DoodleService::DownloadOutcome DoodleService::HandleNewConfig(
DoodleState state,
base::TimeDelta time_to_live,
const base::Optional<DoodleConfig>& doodle_config) {
+ // Clamp the time-to-live to some reasonable maximum.
+ if (time_to_live.InSeconds() > kMaxTimeToLiveSecs) {
+ time_to_live = base::TimeDelta::FromSeconds(kMaxTimeToLiveSecs);
+ DLOG(WARNING) << "Clamping TTL to " << kMaxTimeToLiveSecs << " seconds!";
+ }
+
// Handle the case where the new config is already expired.
bool expired = time_to_live <= base::TimeDelta();
const base::Optional<DoodleConfig>& new_config =
« no previous file with comments | « components/doodle/doodle_fetcher_impl_unittest.cc ('k') | components/doodle/doodle_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698