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

Unified Diff: components/doodle/doodle_service.cc

Issue 2725143003: [Doodle] Pull time_to_live out of DoodleConfig (Closed)
Patch Set: mastiz review Created 3 years, 10 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_service.h ('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 fee586c6be958a007011c0d343cd303a16fd74a9..c5cb9137b253169c162b6b26898d5249f11512f5 100644
--- a/components/doodle/doodle_service.cc
+++ b/components/doodle/doodle_service.cc
@@ -7,6 +7,7 @@
#include <utility>
#include "base/bind.h"
+#include "base/time/time.h"
namespace doodle {
@@ -32,30 +33,19 @@ void DoodleService::Refresh() {
void DoodleService::DoodleFetched(
DoodleState state,
+ base::TimeDelta time_to_live,
const base::Optional<DoodleConfig>& doodle_config) {
- if (!cached_config_.has_value() && !doodle_config.has_value()) {
- // There was no config before and we didn't get a new one, so there's
- // nothing to do.
+ // If nothing changed, then there's nothing to do. Note that this checks both
+ // for existence changes as well as changes of the configs themselves.
+ if (cached_config_ == doodle_config) {
+ // TODO(treib): Once we support expiry, update the time to live here.
return;
}
- bool notify = false;
- if (cached_config_.has_value() != doodle_config.has_value()) {
- // We got a new config, or an existing one went away.
- notify = true;
- } else {
- // There was a config both before and after the update. Notify observers
- // only if something relevant changed.
- notify = !cached_config_.value().IsEquivalent(doodle_config.value());
- }
-
- // In any case, update the cache.
+ // Update the cache and notify observers.
cached_config_ = doodle_config;
-
- if (notify) {
- for (auto& observer : observers_) {
- observer.OnDoodleConfigUpdated(cached_config_);
- }
+ for (auto& observer : observers_) {
+ observer.OnDoodleConfigUpdated(cached_config_);
}
}
« no previous file with comments | « components/doodle/doodle_service.h ('k') | components/doodle/doodle_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698