| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/doodle/doodle_service.h" | 5 #include "components/doodle/doodle_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "components/doodle/pref_names.h" | 13 #include "components/doodle/pref_names.h" |
| 13 #include "components/prefs/pref_registry.h" | 14 #include "components/prefs/pref_registry.h" |
| 14 #include "components/prefs/pref_registry_simple.h" | 15 #include "components/prefs/pref_registry_simple.h" |
| 15 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 16 | 17 |
| 17 namespace doodle { | 18 namespace doodle { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // The maximum time-to-live we'll accept; any larger values will be clamped to | 22 // The maximum time-to-live we'll accept; any larger values will be clamped to |
| 22 // this one. This is a last resort in case the server sends bad data. | 23 // this one. This is a last resort in case the server sends bad data. |
| 23 const int64_t kMaxTimeToLiveSecs = 30 * 24 * 60 * 60; // 30 days | 24 const int64_t kMaxTimeToLiveSecs = 30 * 24 * 60 * 60; // 30 days |
| 24 | 25 |
| 25 // The default value for DoodleService::min_refresh_interval_. | 26 // The default value for DoodleService::min_refresh_interval_. |
| 26 const int64_t kDefaultMinRefreshIntervalSecs = 15 * 60; // 15 minutes | 27 const int64_t kDefaultMinRefreshIntervalSecs = 15 * 60; // 15 minutes |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 // static | 31 // static |
| 31 void DoodleService::RegisterProfilePrefs(PrefRegistrySimple* pref_registry) { | 32 void DoodleService::RegisterProfilePrefs(PrefRegistrySimple* pref_registry) { |
| 32 pref_registry->RegisterDictionaryPref(prefs::kCachedConfig, | 33 pref_registry->RegisterDictionaryPref( |
| 33 new base::DictionaryValue(), | 34 prefs::kCachedConfig, base::MakeUnique<base::DictionaryValue>(), |
| 34 PrefRegistry::LOSSY_PREF); | 35 PrefRegistry::LOSSY_PREF); |
| 35 pref_registry->RegisterInt64Pref(prefs::kCachedConfigExpiry, 0, | 36 pref_registry->RegisterInt64Pref(prefs::kCachedConfigExpiry, 0, |
| 36 PrefRegistry::LOSSY_PREF); | 37 PrefRegistry::LOSSY_PREF); |
| 37 } | 38 } |
| 38 | 39 |
| 39 DoodleService::DoodleService( | 40 DoodleService::DoodleService( |
| 40 PrefService* pref_service, | 41 PrefService* pref_service, |
| 41 std::unique_ptr<DoodleFetcher> fetcher, | 42 std::unique_ptr<DoodleFetcher> fetcher, |
| 42 std::unique_ptr<base::OneShotTimer> expiry_timer, | 43 std::unique_ptr<base::OneShotTimer> expiry_timer, |
| 43 std::unique_ptr<base::Clock> clock, | 44 std::unique_ptr<base::Clock> clock, |
| 44 std::unique_ptr<base::TickClock> tick_clock, | 45 std::unique_ptr<base::TickClock> tick_clock, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 pref_service_->ClearPref(prefs::kCachedConfigExpiry); | 233 pref_service_->ClearPref(prefs::kCachedConfigExpiry); |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 | 236 |
| 236 void DoodleService::DoodleExpired() { | 237 void DoodleService::DoodleExpired() { |
| 237 DCHECK(cached_config_.has_value()); | 238 DCHECK(cached_config_.has_value()); |
| 238 HandleNewConfig(DoodleState::NO_DOODLE, base::TimeDelta(), base::nullopt); | 239 HandleNewConfig(DoodleState::NO_DOODLE, base::TimeDelta(), base::nullopt); |
| 239 } | 240 } |
| 240 | 241 |
| 241 } // namespace doodle | 242 } // namespace doodle |
| OLD | NEW |