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