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