| 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/remote/ntp_snippets_service.h" | 5 #include "components/ntp_snippets/remote/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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 EnterState(State::ERROR_OCCURRED); | 206 EnterState(State::ERROR_OCCURRED); |
| 207 UpdateAllCategoryStatus(CategoryStatus::LOADING_ERROR); | 207 UpdateAllCategoryStatus(CategoryStatus::LOADING_ERROR); |
| 208 return; | 208 return; |
| 209 } | 209 } |
| 210 | 210 |
| 211 database_->SetErrorCallback(base::Bind(&NTPSnippetsService::OnDatabaseError, | 211 database_->SetErrorCallback(base::Bind(&NTPSnippetsService::OnDatabaseError, |
| 212 base::Unretained(this))); | 212 base::Unretained(this))); |
| 213 | 213 |
| 214 // We transition to other states while finalizing the initialization, when the | 214 // We transition to other states while finalizing the initialization, when the |
| 215 // database is done loading. | 215 // database is done loading. |
| 216 database_load_start_ = base::TimeTicks::Now(); |
| 216 database_->LoadSnippets(base::Bind(&NTPSnippetsService::OnDatabaseLoaded, | 217 database_->LoadSnippets(base::Bind(&NTPSnippetsService::OnDatabaseLoaded, |
| 217 base::Unretained(this))); | 218 base::Unretained(this))); |
| 218 } | 219 } |
| 219 | 220 |
| 220 NTPSnippetsService::~NTPSnippetsService() = default; | 221 NTPSnippetsService::~NTPSnippetsService() = default; |
| 221 | 222 |
| 222 // static | 223 // static |
| 223 void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { | 224 void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
| 224 // TODO(treib): Add cleanup logic for prefs::kSnippetHosts, then remove it | 225 // TODO(treib): Add cleanup logic for prefs::kSnippetHosts, then remove it |
| 225 // completely after M56. | 226 // completely after M56. |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 // provided to |image_fetcher_| (OnSnippetImageDecodedFromNetwork()). | 466 // provided to |image_fetcher_| (OnSnippetImageDecodedFromNetwork()). |
| 466 database_->SaveImage(id_within_category, image_data); | 467 database_->SaveImage(id_within_category, image_data); |
| 467 } | 468 } |
| 468 | 469 |
| 469 void NTPSnippetsService::OnDatabaseLoaded(NTPSnippet::PtrVector snippets) { | 470 void NTPSnippetsService::OnDatabaseLoaded(NTPSnippet::PtrVector snippets) { |
| 470 if (state_ == State::ERROR_OCCURRED) | 471 if (state_ == State::ERROR_OCCURRED) |
| 471 return; | 472 return; |
| 472 DCHECK(state_ == State::NOT_INITED); | 473 DCHECK(state_ == State::NOT_INITED); |
| 473 DCHECK(base::ContainsKey(categories_, articles_category_)); | 474 DCHECK(base::ContainsKey(categories_, articles_category_)); |
| 474 | 475 |
| 476 base::TimeDelta database_load_time = |
| 477 base::TimeTicks::Now() - database_load_start_; |
| 478 UMA_HISTOGRAM_MEDIUM_TIMES("NewTabPage.Snippets.DatabaseLoadTime", |
| 479 database_load_time); |
| 480 |
| 475 NTPSnippet::PtrVector to_delete; | 481 NTPSnippet::PtrVector to_delete; |
| 476 for (std::unique_ptr<NTPSnippet>& snippet : snippets) { | 482 for (std::unique_ptr<NTPSnippet>& snippet : snippets) { |
| 477 Category snippet_category = | 483 Category snippet_category = |
| 478 category_factory()->FromRemoteCategory(snippet->remote_category_id()); | 484 category_factory()->FromRemoteCategory(snippet->remote_category_id()); |
| 479 // We should already know about the category. | 485 // We should already know about the category. |
| 480 if (!base::ContainsKey(categories_, snippet_category)) { | 486 if (!base::ContainsKey(categories_, snippet_category)) { |
| 481 DLOG(WARNING) << "Loaded a suggestion for unknown category " | 487 DLOG(WARNING) << "Loaded a suggestion for unknown category " |
| 482 << snippet_category << " from the DB; deleting"; | 488 << snippet_category << " from the DB; deleting"; |
| 483 to_delete.emplace_back(std::move(snippet)); | 489 to_delete.emplace_back(std::move(snippet)); |
| 484 continue; | 490 continue; |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 } | 1108 } |
| 1103 | 1109 |
| 1104 NTPSnippetsService::CategoryContent::CategoryContent() = default; | 1110 NTPSnippetsService::CategoryContent::CategoryContent() = default; |
| 1105 NTPSnippetsService::CategoryContent::CategoryContent(CategoryContent&&) = | 1111 NTPSnippetsService::CategoryContent::CategoryContent(CategoryContent&&) = |
| 1106 default; | 1112 default; |
| 1107 NTPSnippetsService::CategoryContent::~CategoryContent() = default; | 1113 NTPSnippetsService::CategoryContent::~CategoryContent() = default; |
| 1108 NTPSnippetsService::CategoryContent& NTPSnippetsService::CategoryContent:: | 1114 NTPSnippetsService::CategoryContent& NTPSnippetsService::CategoryContent:: |
| 1109 operator=(CategoryContent&&) = default; | 1115 operator=(CategoryContent&&) = default; |
| 1110 | 1116 |
| 1111 } // namespace ntp_snippets | 1117 } // namespace ntp_snippets |
| OLD | NEW |