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/memory/ptr_util.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 // Handle the case where the new config is already expired. | 186 // Handle the case where the new config is already expired. |
187 bool expired = time_to_live <= base::TimeDelta(); | 187 bool expired = time_to_live <= base::TimeDelta(); |
188 const base::Optional<DoodleConfig>& new_config = | 188 const base::Optional<DoodleConfig>& new_config = |
189 expired ? base::nullopt : doodle_config; | 189 expired ? base::nullopt : doodle_config; |
190 | 190 |
191 // Determine the download outcome *before* updating the cached config. | 191 // Determine the download outcome *before* updating the cached config. |
192 DownloadOutcome outcome = | 192 DownloadOutcome outcome = |
193 DetermineDownloadOutcome(cached_config_, new_config, state, expired); | 193 DetermineDownloadOutcome(cached_config_, new_config, state, expired); |
194 | 194 |
195 // If the config changed, update our cache and notify observers. | |
196 // Note that this checks both for existence changes as well as changes of the | 195 // Note that this checks both for existence changes as well as changes of the |
197 // configs themselves. | 196 // configs themselves. |
198 if (cached_config_ != new_config) { | 197 if (cached_config_ == new_config) { |
| 198 for (auto& observer : observers_) { |
| 199 observer.OnDoodleConfigRevalidated(); |
| 200 } |
| 201 } else { |
| 202 // The config changed. Update our cache and the prefs, and notify observers. |
| 203 cached_config_ = new_config; |
| 204 |
199 UpdateCachedConfig(time_to_live, new_config); | 205 UpdateCachedConfig(time_to_live, new_config); |
200 | 206 |
201 for (auto& observer : observers_) { | 207 for (auto& observer : observers_) { |
202 observer.OnDoodleConfigUpdated(cached_config_); | 208 observer.OnDoodleConfigUpdated(cached_config_); |
203 } | 209 } |
204 } | 210 } |
205 | 211 |
206 // Even if the configs are identical, the time-to-live might have changed. | 212 // Even if the configs are identical, the time-to-live might have changed. |
207 // (Re-)schedule the cache expiry. | 213 // (Re-)schedule the cache expiry. |
208 if (cached_config_.has_value()) { | 214 if (cached_config_.has_value()) { |
(...skipping 24 matching lines...) Expand all Loading... |
233 pref_service_->ClearPref(prefs::kCachedConfigExpiry); | 239 pref_service_->ClearPref(prefs::kCachedConfigExpiry); |
234 } | 240 } |
235 } | 241 } |
236 | 242 |
237 void DoodleService::DoodleExpired() { | 243 void DoodleService::DoodleExpired() { |
238 DCHECK(cached_config_.has_value()); | 244 DCHECK(cached_config_.has_value()); |
239 HandleNewConfig(DoodleState::NO_DOODLE, base::TimeDelta(), base::nullopt); | 245 HandleNewConfig(DoodleState::NO_DOODLE, base::TimeDelta(), base::nullopt); |
240 } | 246 } |
241 | 247 |
242 } // namespace doodle | 248 } // namespace doodle |
OLD | NEW |