| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 10 #include <vector> |
| 9 | 11 |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 11 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
| 12 #include "components/ntp_snippets/category.h" | 15 #include "components/ntp_snippets/category.h" |
| 13 #include "components/ntp_snippets/category_status.h" | 16 #include "components/ntp_snippets/category_status.h" |
| 14 #include "components/ntp_snippets/content_suggestions_service.h" | 17 #include "components/ntp_snippets/content_suggestions_service.h" |
| 15 #include "components/ntp_snippets/ntp_snippets_service.h" | 18 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 16 #include "content/public/browser/web_ui_message_handler.h" | 19 #include "content/public/browser/web_ui_message_handler.h" |
| 17 | 20 |
| 18 namespace base { | 21 namespace base { |
| 19 class ListValue; | 22 class ListValue; |
| 20 } // namespace base | 23 } // namespace base |
| 21 | 24 |
| 22 // The implementation for the chrome://snippets-internals page. | 25 // The implementation for the chrome://snippets-internals page. |
| 23 class SnippetsInternalsMessageHandler | 26 class SnippetsInternalsMessageHandler |
| 24 : public content::WebUIMessageHandler, | 27 : public content::WebUIMessageHandler, |
| 25 public ntp_snippets::ContentSuggestionsService::Observer { | 28 public ntp_snippets::ContentSuggestionsService::Observer { |
| 26 public: | 29 public: |
| 27 SnippetsInternalsMessageHandler(); | 30 SnippetsInternalsMessageHandler(); |
| 28 ~SnippetsInternalsMessageHandler() override; | 31 ~SnippetsInternalsMessageHandler() override; |
| 29 | 32 |
| 30 private: | 33 private: |
| 34 enum class DismissedState { HIDDEN, LOADING, VISIBLE }; |
| 35 |
| 31 // content::WebUIMessageHandler: | 36 // content::WebUIMessageHandler: |
| 32 void RegisterMessages() override; | 37 void RegisterMessages() override; |
| 33 | 38 |
| 34 // ntp_snippets::ContentSuggestionsService::Observer: | 39 // ntp_snippets::ContentSuggestionsService::Observer: |
| 35 void OnNewSuggestions(ntp_snippets::Category category) override; | 40 void OnNewSuggestions(ntp_snippets::Category category) override; |
| 36 void OnCategoryStatusChanged( | 41 void OnCategoryStatusChanged( |
| 37 ntp_snippets::Category category, | 42 ntp_snippets::Category category, |
| 38 ntp_snippets::CategoryStatus new_status) override; | 43 ntp_snippets::CategoryStatus new_status) override; |
| 39 void OnSuggestionInvalidated(ntp_snippets::Category category, | 44 void OnSuggestionInvalidated(ntp_snippets::Category category, |
| 40 const std::string& suggestion_id) override; | 45 const std::string& suggestion_id) override; |
| 41 void ContentSuggestionsServiceShutdown() override; | 46 void ContentSuggestionsServiceShutdown() override; |
| 42 | 47 |
| 43 void HandleRefreshContent(const base::ListValue* args); | 48 void HandleRefreshContent(const base::ListValue* args); |
| 44 void HandleDownload(const base::ListValue* args); | 49 void HandleDownload(const base::ListValue* args); |
| 45 void HandleClearCachedSuggestions(const base::ListValue* args); | 50 void HandleClearCachedSuggestions(const base::ListValue* args); |
| 46 void HandleClearDismissedSuggestions(const base::ListValue* args); | 51 void HandleClearDismissedSuggestions(const base::ListValue* args); |
| 52 void HandleToggleDismissedSuggestions(const base::ListValue* args); |
| 47 | 53 |
| 48 void SendAllContent(); | 54 void SendAllContent(); |
| 49 void SendHosts(); | 55 void SendHosts(); |
| 50 void SendContentSuggestions(); | 56 void SendContentSuggestions(); |
| 51 void SendBoolean(const std::string& name, bool value); | 57 void SendBoolean(const std::string& name, bool value); |
| 52 void SendString(const std::string& name, const std::string& value); | 58 void SendString(const std::string& name, const std::string& value); |
| 53 | 59 |
| 60 void OnDismissedSuggestionsLoaded( |
| 61 ntp_snippets::Category category, |
| 62 std::vector<ntp_snippets::ContentSuggestion> dismissed_suggestions); |
| 63 |
| 54 ScopedObserver<ntp_snippets::ContentSuggestionsService, | 64 ScopedObserver<ntp_snippets::ContentSuggestionsService, |
| 55 ntp_snippets::ContentSuggestionsService::Observer> | 65 ntp_snippets::ContentSuggestionsService::Observer> |
| 56 content_suggestions_service_observer_; | 66 content_suggestions_service_observer_; |
| 57 | 67 |
| 58 // Tracks whether we can already send messages to the page. | 68 // Tracks whether we can already send messages to the page. |
| 59 bool dom_loaded_; | 69 bool dom_loaded_; |
| 60 | 70 |
| 61 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; | 71 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; |
| 62 ntp_snippets::ContentSuggestionsService* content_suggestions_service_; | 72 ntp_snippets::ContentSuggestionsService* content_suggestions_service_; |
| 63 | 73 |
| 74 std::map<ntp_snippets::Category, |
| 75 DismissedState, |
| 76 ntp_snippets::Category::CompareByID> |
| 77 dismissed_state_; |
| 78 std::map<ntp_snippets::Category, |
| 79 std::vector<ntp_snippets::ContentSuggestion>, |
| 80 ntp_snippets::Category::CompareByID> |
| 81 dismissed_suggestions_; |
| 82 |
| 83 base::WeakPtrFactory<SnippetsInternalsMessageHandler> weak_ptr_factory_; |
| 84 |
| 64 DISALLOW_COPY_AND_ASSIGN(SnippetsInternalsMessageHandler); | 85 DISALLOW_COPY_AND_ASSIGN(SnippetsInternalsMessageHandler); |
| 65 }; | 86 }; |
| 66 | 87 |
| 67 #endif // CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ | 88 #endif // CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ |
| OLD | NEW |