| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 pref_service_(pref_service), | 197 pref_service_(pref_service), |
| 198 suggestions_service_(suggestions_service), | 198 suggestions_service_(suggestions_service), |
| 199 application_language_code_(application_language_code), | 199 application_language_code_(application_language_code), |
| 200 scheduler_(scheduler), | 200 scheduler_(scheduler), |
| 201 snippets_fetcher_(std::move(snippets_fetcher)), | 201 snippets_fetcher_(std::move(snippets_fetcher)), |
| 202 image_fetcher_(std::move(image_fetcher)), | 202 image_fetcher_(std::move(image_fetcher)), |
| 203 image_decoder_(std::move(image_decoder)), | 203 image_decoder_(std::move(image_decoder)), |
| 204 database_(std::move(database)), | 204 database_(std::move(database)), |
| 205 snippets_status_service_(std::move(status_service)), | 205 snippets_status_service_(std::move(status_service)), |
| 206 fetch_after_load_(false) { | 206 fetch_after_load_(false) { |
| 207 // TODO(dgn) should be removed after branch point (https://crbug.com/617585). | |
| 208 ClearDeprecatedPrefs(); | |
| 209 | |
| 210 if (!enabled || database_->IsErrorState()) { | 207 if (!enabled || database_->IsErrorState()) { |
| 211 // Don't even bother loading the database. | 208 // Don't even bother loading the database. |
| 212 EnterState(State::SHUT_DOWN); | 209 EnterState(State::SHUT_DOWN); |
| 213 return; | 210 return; |
| 214 } | 211 } |
| 215 | 212 |
| 216 database_->SetErrorCallback(base::Bind(&NTPSnippetsService::OnDatabaseError, | 213 database_->SetErrorCallback(base::Bind(&NTPSnippetsService::OnDatabaseError, |
| 217 base::Unretained(this))); | 214 base::Unretained(this))); |
| 218 | 215 |
| 219 // We transition to other states while finalizing the initialization, when the | 216 // We transition to other states while finalizing the initialization, when the |
| 220 // database is done loading. | 217 // database is done loading. |
| 221 database_->LoadSnippets(base::Bind(&NTPSnippetsService::OnDatabaseLoaded, | 218 database_->LoadSnippets(base::Bind(&NTPSnippetsService::OnDatabaseLoaded, |
| 222 base::Unretained(this))); | 219 base::Unretained(this))); |
| 223 } | 220 } |
| 224 | 221 |
| 225 NTPSnippetsService::~NTPSnippetsService() { | 222 NTPSnippetsService::~NTPSnippetsService() { |
| 226 DCHECK(state_ == State::SHUT_DOWN); | 223 DCHECK(state_ == State::SHUT_DOWN); |
| 227 } | 224 } |
| 228 | 225 |
| 229 // static | 226 // static |
| 230 void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { | 227 void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
| 231 registry->RegisterListPref(prefs::kDeprecatedSnippets); | |
| 232 registry->RegisterListPref(prefs::kDeprecatedDiscardedSnippets); | |
| 233 registry->RegisterListPref(prefs::kSnippetHosts); | 228 registry->RegisterListPref(prefs::kSnippetHosts); |
| 234 } | 229 } |
| 235 | 230 |
| 236 // Inherited from KeyedService. | 231 // Inherited from KeyedService. |
| 237 void NTPSnippetsService::Shutdown() { | 232 void NTPSnippetsService::Shutdown() { |
| 238 EnterState(State::SHUT_DOWN); | 233 EnterState(State::SHUT_DOWN); |
| 239 } | 234 } |
| 240 | 235 |
| 241 void NTPSnippetsService::FetchSnippets() { | 236 void NTPSnippetsService::FetchSnippets() { |
| 242 if (ready()) | 237 if (ready()) |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 return; | 750 return; |
| 756 | 751 |
| 757 case State::SHUT_DOWN: | 752 case State::SHUT_DOWN: |
| 758 DVLOG(1) << "Entering state: SHUT_DOWN"; | 753 DVLOG(1) << "Entering state: SHUT_DOWN"; |
| 759 state_ = State::SHUT_DOWN; | 754 state_ = State::SHUT_DOWN; |
| 760 EnterStateShutdown(); | 755 EnterStateShutdown(); |
| 761 return; | 756 return; |
| 762 } | 757 } |
| 763 } | 758 } |
| 764 | 759 |
| 765 void NTPSnippetsService::ClearDeprecatedPrefs() { | |
| 766 pref_service_->ClearPref(prefs::kDeprecatedSnippets); | |
| 767 pref_service_->ClearPref(prefs::kDeprecatedDiscardedSnippets); | |
| 768 } | |
| 769 | |
| 770 } // namespace ntp_snippets | 760 } // namespace ntp_snippets |
| OLD | NEW |