Chromium Code Reviews| Index: components/ntp_snippets/ntp_snippets_service.cc |
| diff --git a/components/ntp_snippets/ntp_snippets_service.cc b/components/ntp_snippets/ntp_snippets_service.cc |
| index 02524508ceca77bf9620436e54bc6604c47ab25e..7d3cfdd3eafde7a339856b40fcf2ceb5b67e9c14 100644 |
| --- a/components/ntp_snippets/ntp_snippets_service.cc |
| +++ b/components/ntp_snippets/ntp_snippets_service.cc |
| @@ -126,7 +126,7 @@ std::set<std::string> GetSuggestionsHostsImpl( |
| } |
| std::unique_ptr<base::ListValue> SnippetsToListValue( |
| - const NTPSnippetsService::NTPSnippetStorage& snippets) { |
| + const NTPSnippet::PtrVector& snippets) { |
| std::unique_ptr<base::ListValue> list(new base::ListValue); |
| for (const auto& snippet : snippets) { |
| std::unique_ptr<base::DictionaryValue> dict = snippet->ToDictionary(); |
| @@ -135,7 +135,7 @@ std::unique_ptr<base::ListValue> SnippetsToListValue( |
| return list; |
| } |
| -bool ContainsSnippet(const NTPSnippetsService::NTPSnippetStorage& haystack, |
| +bool ContainsSnippet(const NTPSnippet::PtrVector& haystack, |
| const std::unique_ptr<NTPSnippet>& needle) { |
| const std::string& id = needle->id(); |
| return std::find_if(haystack.begin(), haystack.end(), |
| @@ -161,7 +161,8 @@ NTPSnippetsService::NTPSnippetsService( |
| NTPSnippetsScheduler* scheduler, |
| std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, |
| std::unique_ptr<ImageFetcher> image_fetcher) |
| - : enabled_(false), |
| + : state_(State::NOT_INITED), |
| + enabled_(false), |
| pref_service_(pref_service), |
| suggestions_service_(suggestions_service), |
| file_task_runner_(file_task_runner), |
| @@ -173,7 +174,9 @@ NTPSnippetsService::NTPSnippetsService( |
| &NTPSnippetsService::OnFetchFinished, base::Unretained(this))); |
| } |
| -NTPSnippetsService::~NTPSnippetsService() {} |
| +NTPSnippetsService::~NTPSnippetsService() { |
| + DCHECK(state_ == State::NOT_INITED || state_ == State::SHUT_DOWN); |
| +} |
| // static |
| void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
| @@ -183,6 +186,9 @@ void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
| } |
| void NTPSnippetsService::Init(bool enabled) { |
| + DCHECK(state_ == State::NOT_INITED); |
|
Marc Treib
2016/05/17 11:21:18
DCHECK_EQ etc don't work with enum class :(
(I gue
Bernhard Bauer
2016/05/17 12:38:13
Yuck. TBH, I'm less and less convinced that enum c
Marc Treib
2016/05/17 12:46:34
Yup, the missing operator<< is the reason DCHECK_E
|
| + state_ = State::INITED; |
| + |
| enabled_ = enabled; |
| if (enabled_) { |
| // |suggestions_service_| can be null in tests. |
| @@ -205,8 +211,12 @@ void NTPSnippetsService::Init(bool enabled) { |
| } |
| void NTPSnippetsService::Shutdown() { |
| + DCHECK(state_ == State::INITED); |
| + state_ = State::SHUT_DOWN; |
| + |
| FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, |
| NTPSnippetsServiceShutdown()); |
| + suggestions_service_subscription_.reset(); |
| enabled_ = false; |
| } |
| @@ -350,7 +360,7 @@ void NTPSnippetsService::OnFetchFinished( |
| LoadingSnippetsFinished(); |
| } |
| -void NTPSnippetsService::MergeSnippets(NTPSnippetStorage new_snippets) { |
| +void NTPSnippetsService::MergeSnippets(NTPSnippet::PtrVector new_snippets) { |
| // Remove new snippets that we already have, or that have been discarded. |
| new_snippets.erase( |
| std::remove_if(new_snippets.begin(), new_snippets.end(), |
| @@ -400,7 +410,7 @@ void NTPSnippetsService::MergeSnippets(NTPSnippetStorage new_snippets) { |
| } |
| void NTPSnippetsService::LoadSnippetsFromPrefs() { |
| - NTPSnippetStorage prefs_snippets; |
| + NTPSnippet::PtrVector prefs_snippets; |
| bool success = NTPSnippet::AddFromListValue( |
| *pref_service_->GetList(prefs::kSnippets), &prefs_snippets); |
| DCHECK(success) << "Failed to parse snippets from prefs"; |