Chromium Code Reviews| Index: chrome/browser/ui/webui/snippets_internals_message_handler.cc |
| diff --git a/chrome/browser/ui/webui/snippets_internals_message_handler.cc b/chrome/browser/ui/webui/snippets_internals_message_handler.cc |
| index c93e230c4dda7ab2ca8aa6f07fcf4f06a2914214..77737a4a5c9243d9ea7c6e134ef83cc905bc3b85 100644 |
| --- a/chrome/browser/ui/webui/snippets_internals_message_handler.cc |
| +++ b/chrome/browser/ui/webui/snippets_internals_message_handler.cc |
| @@ -112,6 +112,12 @@ void SnippetsInternalsMessageHandler::RegisterMessages() { |
| base::Bind( |
| &SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions, |
| base::Unretained(this))); |
| + |
| + web_ui()->RegisterMessageCallback( |
| + "toggleDismissedSuggestions", |
| + base::Bind( |
| + &SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions, |
| + base::Unretained(this))); |
| } |
| void SnippetsInternalsMessageHandler::OnNewSuggestions(Category category) { |
| @@ -144,6 +150,17 @@ void SnippetsInternalsMessageHandler::HandleRefreshContent( |
| dom_loaded_ = true; |
| + for (auto& it : dismissed_state_) { |
|
Marc Treib
2016/08/19 10:07:51
Please use the actual type, and a proper name - th
Philipp Keck
2016/08/19 12:11:53
Done.
|
| + if (it.second == DismissedState::VISIBLE) { |
| + it.second = DismissedState::LOADING; |
| + content_suggestions_service_->GetDismissedSuggestionsForDebugging( |
| + it.first, |
| + base::Bind( |
| + &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, |
| + base::Unretained(this))); |
|
Marc Treib
2016/08/19 10:07:51
I don't think Unretained is safe here - you'll pro
Philipp Keck
2016/08/19 12:11:53
Done.
|
| + } |
| + } |
| + |
| SendAllContent(); |
| } |
| @@ -192,6 +209,38 @@ void SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions( |
| category_id); |
| content_suggestions_service_->ClearDismissedSuggestionsForDebugging(category); |
| SendContentSuggestions(); |
| + dismissed_state_[category] = DismissedState::LOADING; |
| + content_suggestions_service_->GetDismissedSuggestionsForDebugging( |
| + category, |
| + base::Bind(&SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, |
| + base::Unretained(this))); |
|
Marc Treib
2016/08/19 10:07:51
Here too.
Philipp Keck
2016/08/19 12:11:53
Done.
|
| +} |
| + |
| +void SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions( |
| + const base::ListValue* args) { |
| + DCHECK_EQ(2u, args->GetSize()); |
| + |
| + int category_id; |
| + if (!args->GetInteger(0, &category_id)) |
| + return; |
| + bool dismissed_visible; |
| + if (!args->GetBoolean(1, &dismissed_visible)) |
| + return; |
| + |
| + Category category = |
| + content_suggestions_service_->category_factory()->FromIDValue( |
| + category_id); |
| + if (dismissed_visible) { |
| + dismissed_state_[category] = DismissedState::LOADING; |
| + content_suggestions_service_->GetDismissedSuggestionsForDebugging( |
| + category, |
| + base::Bind( |
| + &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, |
| + base::Unretained(this))); |
|
Marc Treib
2016/08/19 10:07:51
And here.
Philipp Keck
2016/08/19 12:11:53
Done.
|
| + } else { |
| + dismissed_state_[category] = DismissedState::HIDDEN; |
| + dismissed_suggestions_[category].clear(); |
| + } |
| } |
| void SnippetsInternalsMessageHandler::SendAllContent() { |
| @@ -271,9 +320,6 @@ void SnippetsInternalsMessageHandler::SendContentSuggestions() { |
| DCHECK(info); |
| const std::vector<ContentSuggestion>& suggestions = |
| content_suggestions_service_->GetSuggestionsForCategory(category); |
| - std::vector<ContentSuggestion> dismissed_suggestions = |
| - content_suggestions_service_->GetDismissedSuggestionsForDebugging( |
| - category); |
| std::unique_ptr<base::ListValue> suggestions_list(new base::ListValue); |
| for (const ContentSuggestion& suggestion : suggestions) { |
| @@ -281,7 +327,8 @@ void SnippetsInternalsMessageHandler::SendContentSuggestions() { |
| } |
| std::unique_ptr<base::ListValue> dismissed_list(new base::ListValue); |
| - for (const ContentSuggestion& suggestion : dismissed_suggestions) { |
| + for (const ContentSuggestion& suggestion : |
| + dismissed_suggestions_[category]) { |
| dismissed_list->Append(PrepareSuggestion(suggestion, index++)); |
| } |
| @@ -317,3 +364,13 @@ void SnippetsInternalsMessageHandler::SendString(const std::string& name, |
| web_ui()->CallJavascriptFunctionUnsafe( |
| "chrome.SnippetsInternals.receiveProperty", string_name, string_value); |
| } |
| + |
| +void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( |
| + Category category, |
| + std::vector<ContentSuggestion> dismissed_suggestions) { |
| + if (dismissed_state_[category] == DismissedState::HIDDEN) |
| + return; |
| + dismissed_suggestions_[category] = std::move(dismissed_suggestions); |
| + dismissed_state_[category] = DismissedState::VISIBLE; |
| + SendContentSuggestions(); |
| +} |