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/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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) { | 307 CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) { |
| 308 DCHECK(base::ContainsKey(categories_, category)); | 308 DCHECK(base::ContainsKey(categories_, category)); |
| 309 return categories_[category].status; | 309 return categories_[category].status; |
| 310 } | 310 } |
| 311 | 311 |
| 312 CategoryInfo NTPSnippetsService::GetCategoryInfo(Category category) { | 312 CategoryInfo NTPSnippetsService::GetCategoryInfo(Category category) { |
| 313 DCHECK(base::ContainsKey(categories_, category)); | 313 DCHECK(base::ContainsKey(categories_, category)); |
| 314 const CategoryContent& content = categories_[category]; | 314 const CategoryContent& content = categories_[category]; |
| 315 return CategoryInfo(content.localized_title, | 315 return CategoryInfo(content.localized_title, |
| 316 ContentSuggestionsCardLayout::FULL_CARD, | 316 ContentSuggestionsCardLayout::FULL_CARD, |
| 317 /* has_more_button */ false, | 317 /*has_more_button=*/false, |
| 318 /* show_if_empty */ true); | 318 /*show_if_empty=*/true); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void NTPSnippetsService::DismissSuggestion( | 321 void NTPSnippetsService::DismissSuggestion( |
| 322 const ContentSuggestion::ID& suggestion_id) { | 322 const ContentSuggestion::ID& suggestion_id) { |
| 323 if (!ready()) | 323 if (!ready()) |
| 324 return; | 324 return; |
| 325 | 325 |
| 326 DCHECK(base::ContainsKey(categories_, suggestion_id.category())); | 326 DCHECK(base::ContainsKey(categories_, suggestion_id.category())); |
| 327 | 327 |
| 328 CategoryContent* content = &categories_[suggestion_id.category()]; | 328 CategoryContent* content = &categories_[suggestion_id.category()]; |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 // TODO(jkrcal): Fetching snippets automatically upon creation of this | 829 // TODO(jkrcal): Fetching snippets automatically upon creation of this |
| 830 // lazily created service can cause troubles, e.g. in unit tests where | 830 // lazily created service can cause troubles, e.g. in unit tests where |
| 831 // network I/O is not allowed. | 831 // network I/O is not allowed. |
| 832 // Either add a DCHECK here that we actually are allowed to do network I/O | 832 // Either add a DCHECK here that we actually are allowed to do network I/O |
| 833 // or change the logic so that some explicit call is always needed for the | 833 // or change the logic so that some explicit call is always needed for the |
| 834 // network request. | 834 // network request. |
| 835 FetchSnippets(/*interactive_request=*/false); | 835 FetchSnippets(/*interactive_request=*/false); |
| 836 fetch_when_ready_ = false; | 836 fetch_when_ready_ = false; |
| 837 } | 837 } |
| 838 | 838 |
| 839 // FetchSnippets should set the status to |AVAILABLE_LOADING| if relevant, | 839 for (const auto& item : categories_) { |
|
Marc Treib
2016/10/14 13:47:14
This was the actual problem - I missed updating on
| |
| 840 // otherwise we transition to |AVAILABLE| here. | 840 Category category = item.first; |
| 841 if (categories_[articles_category_].status != | 841 const CategoryContent& content = item.second; |
| 842 CategoryStatus::AVAILABLE_LOADING) { | 842 // FetchSnippets has set the status to |AVAILABLE_LOADING| if relevant, |
| 843 UpdateCategoryStatus(articles_category_, CategoryStatus::AVAILABLE); | 843 // otherwise we transition to |AVAILABLE| here. |
| 844 if (content.status != CategoryStatus::AVAILABLE_LOADING) | |
| 845 UpdateCategoryStatus(category, CategoryStatus::AVAILABLE); | |
| 844 } | 846 } |
| 845 } | 847 } |
| 846 | 848 |
| 847 void NTPSnippetsService::EnterStateDisabled() { | 849 void NTPSnippetsService::EnterStateDisabled() { |
| 848 NukeAllSnippets(); | 850 NukeAllSnippets(); |
| 849 } | 851 } |
| 850 | 852 |
| 851 void NTPSnippetsService::EnterStateError() { | 853 void NTPSnippetsService::EnterStateError() { |
| 852 snippets_status_service_.reset(); | 854 snippets_status_service_.reset(); |
| 853 } | 855 } |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1100 } | 1102 } |
| 1101 | 1103 |
| 1102 NTPSnippetsService::CategoryContent::CategoryContent() = default; | 1104 NTPSnippetsService::CategoryContent::CategoryContent() = default; |
| 1103 NTPSnippetsService::CategoryContent::CategoryContent(CategoryContent&&) = | 1105 NTPSnippetsService::CategoryContent::CategoryContent(CategoryContent&&) = |
| 1104 default; | 1106 default; |
| 1105 NTPSnippetsService::CategoryContent::~CategoryContent() = default; | 1107 NTPSnippetsService::CategoryContent::~CategoryContent() = default; |
| 1106 NTPSnippetsService::CategoryContent& NTPSnippetsService::CategoryContent:: | 1108 NTPSnippetsService::CategoryContent& NTPSnippetsService::CategoryContent:: |
| 1107 operator=(CategoryContent&&) = default; | 1109 operator=(CategoryContent&&) = default; |
| 1108 | 1110 |
| 1109 } // namespace ntp_snippets | 1111 } // namespace ntp_snippets |
| OLD | NEW |