| 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/remote_suggestions_provider.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 return; | 478 return; |
| 479 } | 479 } |
| 480 CategoryContent* content = &content_it->second; | 480 CategoryContent* content = &content_it->second; |
| 481 if (content->snippets.empty()) | 481 if (content->snippets.empty()) |
| 482 return; | 482 return; |
| 483 | 483 |
| 484 database_->DeleteSnippets(GetSnippetIDVector(content->snippets)); | 484 database_->DeleteSnippets(GetSnippetIDVector(content->snippets)); |
| 485 database_->DeleteImages(GetSnippetIDVector(content->snippets)); | 485 database_->DeleteImages(GetSnippetIDVector(content->snippets)); |
| 486 content->snippets.clear(); | 486 content->snippets.clear(); |
| 487 | 487 |
| 488 NotifyNewSuggestions(category, *content); | 488 if (IsCategoryStatusAvailable(content->status)) |
| 489 NotifyNewSuggestions(category, *content); |
| 489 } | 490 } |
| 490 | 491 |
| 491 void RemoteSuggestionsProvider::GetDismissedSuggestionsForDebugging( | 492 void RemoteSuggestionsProvider::GetDismissedSuggestionsForDebugging( |
| 492 Category category, | 493 Category category, |
| 493 const DismissedSuggestionsCallback& callback) { | 494 const DismissedSuggestionsCallback& callback) { |
| 494 auto content_it = category_contents_.find(category); | 495 auto content_it = category_contents_.find(category); |
| 495 DCHECK(content_it != category_contents_.end()); | 496 DCHECK(content_it != category_contents_.end()); |
| 496 callback.Run( | 497 callback.Run( |
| 497 ConvertToContentSuggestions(category, content_it->second.dismissed)); | 498 ConvertToContentSuggestions(category, content_it->second.dismissed)); |
| 498 } | 499 } |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 // Note: Initializing the status service will run the callback right away with | 1035 // Note: Initializing the status service will run the callback right away with |
| 1035 // the current state. | 1036 // the current state. |
| 1036 snippets_status_service_->Init( | 1037 snippets_status_service_->Init( |
| 1037 base::Bind(&RemoteSuggestionsProvider::OnSnippetsStatusChanged, | 1038 base::Bind(&RemoteSuggestionsProvider::OnSnippetsStatusChanged, |
| 1038 base::Unretained(this))); | 1039 base::Unretained(this))); |
| 1039 | 1040 |
| 1040 // Always notify here even if we got nothing from the database, because we | 1041 // Always notify here even if we got nothing from the database, because we |
| 1041 // don't know how long the fetch will take or if it will even complete. | 1042 // don't know how long the fetch will take or if it will even complete. |
| 1042 for (const auto& item : category_contents_) { | 1043 for (const auto& item : category_contents_) { |
| 1043 Category category = item.first; | 1044 Category category = item.first; |
| 1044 NotifyNewSuggestions(category, item.second); | 1045 const CategoryContent& content = item.second; |
| 1046 // Note: We might be in a non-available status here, e.g. DISABLED due to |
| 1047 // enterprise policy. |
| 1048 if (IsCategoryStatusAvailable(content.status)) |
| 1049 NotifyNewSuggestions(category, content); |
| 1045 } | 1050 } |
| 1046 } | 1051 } |
| 1047 | 1052 |
| 1048 void RemoteSuggestionsProvider::OnSnippetsStatusChanged( | 1053 void RemoteSuggestionsProvider::OnSnippetsStatusChanged( |
| 1049 SnippetsStatus old_snippets_status, | 1054 SnippetsStatus old_snippets_status, |
| 1050 SnippetsStatus new_snippets_status) { | 1055 SnippetsStatus new_snippets_status) { |
| 1051 switch (new_snippets_status) { | 1056 switch (new_snippets_status) { |
| 1052 case SnippetsStatus::ENABLED_AND_SIGNED_IN: | 1057 case SnippetsStatus::ENABLED_AND_SIGNED_IN: |
| 1053 if (old_snippets_status == SnippetsStatus::ENABLED_AND_SIGNED_OUT) { | 1058 if (old_snippets_status == SnippetsStatus::ENABLED_AND_SIGNED_OUT) { |
| 1054 DCHECK(state_ == State::READY); | 1059 DCHECK(state_ == State::READY); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) = | 1285 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) = |
| 1281 default; | 1286 default; |
| 1282 | 1287 |
| 1283 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default; | 1288 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default; |
| 1284 | 1289 |
| 1285 RemoteSuggestionsProvider::CategoryContent& | 1290 RemoteSuggestionsProvider::CategoryContent& |
| 1286 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) = | 1291 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) = |
| 1287 default; | 1292 default; |
| 1288 | 1293 |
| 1289 } // namespace ntp_snippets | 1294 } // namespace ntp_snippets |
| OLD | NEW |