Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ntp_snippets/ntp_snippets_service.h" | 5 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 snippets_.erase( | 324 snippets_.erase( |
| 325 std::remove_if(snippets_.begin(), snippets_.end(), | 325 std::remove_if(snippets_.begin(), snippets_.end(), |
| 326 [&hosts](const std::unique_ptr<NTPSnippet>& snippet) { | 326 [&hosts](const std::unique_ptr<NTPSnippet>& snippet) { |
| 327 return !hosts.count(snippet->best_source().url.host()); | 327 return !hosts.count(snippet->best_source().url.host()); |
| 328 }), | 328 }), |
| 329 snippets_.end()); | 329 snippets_.end()); |
| 330 | 330 |
| 331 StoreSnippetsToPrefs(); | 331 StoreSnippetsToPrefs(); |
| 332 StoreSnippetHostsToPrefs(hosts); | 332 StoreSnippetHostsToPrefs(hosts); |
| 333 | 333 |
| 334 if (hosts.empty()) { | |
|
Marc Treib
2016/05/17 14:57:17
Post-commit drive-by comment: After https://codere
| |
| 335 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, | |
| 336 NTPSnippetsServiceCleared()); | |
| 337 } | |
| 338 | |
| 334 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, | 339 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, |
| 335 NTPSnippetsServiceLoaded()); | 340 NTPSnippetsServiceLoaded()); |
| 336 | 341 |
| 337 FetchSnippetsFromHosts(hosts); | 342 FetchSnippetsFromHosts(hosts); |
| 338 } | 343 } |
| 339 | 344 |
| 340 void NTPSnippetsService::OnFetchFinished( | 345 void NTPSnippetsService::OnFetchFinished( |
| 341 NTPSnippetsFetcher::OptionalSnippets snippets) { | 346 NTPSnippetsFetcher::OptionalSnippets snippets) { |
| 342 if (snippets) { | 347 if (snippets) { |
| 343 // Sparse histogram used because the number of snippets is small (bound by | 348 // Sparse histogram used because the number of snippets is small (bound by |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 if (snippet->expiry_date() < next_expiry) | 498 if (snippet->expiry_date() < next_expiry) |
| 494 next_expiry = snippet->expiry_date(); | 499 next_expiry = snippet->expiry_date(); |
| 495 } | 500 } |
| 496 DCHECK_GT(next_expiry, expiry); | 501 DCHECK_GT(next_expiry, expiry); |
| 497 expiry_timer_.Start(FROM_HERE, next_expiry - expiry, | 502 expiry_timer_.Start(FROM_HERE, next_expiry - expiry, |
| 498 base::Bind(&NTPSnippetsService::LoadingSnippetsFinished, | 503 base::Bind(&NTPSnippetsService::LoadingSnippetsFinished, |
| 499 base::Unretained(this))); | 504 base::Unretained(this))); |
| 500 } | 505 } |
| 501 | 506 |
| 502 } // namespace ntp_snippets | 507 } // namespace ntp_snippets |
| OLD | NEW |