| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 13 #include "components/ntp_snippets/ntp_snippets_service.h" | 12 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 14 #include "content/public/browser/web_ui_message_handler.h" | 13 #include "content/public/browser/web_ui_message_handler.h" |
| 15 | 14 |
| 16 namespace base { | 15 namespace base { |
| 17 class ListValue; | 16 class ListValue; |
| 18 } // namespace base | 17 } // namespace base |
| 19 | 18 |
| 20 // The implementation for the chrome://snippets-internals page. | 19 // The implementation for the chrome://snippets-internals page. |
| 21 class SnippetsInternalsMessageHandler | 20 class SnippetsInternalsMessageHandler |
| 22 : public content::WebUIMessageHandler, | 21 : public content::WebUIMessageHandler, |
| 23 public ntp_snippets::NTPSnippetsServiceObserver { | 22 public ntp_snippets::NTPSnippetsServiceObserver { |
| 24 public: | 23 public: |
| 25 SnippetsInternalsMessageHandler(); | 24 SnippetsInternalsMessageHandler(); |
| 26 ~SnippetsInternalsMessageHandler() override; | 25 ~SnippetsInternalsMessageHandler() override; |
| 27 | 26 |
| 28 private: | 27 private: |
| 29 // content::WebUIMessageHandler: | 28 // content::WebUIMessageHandler: |
| 30 void RegisterMessages() override; | 29 void RegisterMessages() override; |
| 31 | 30 |
| 32 // ntp_snippets::NTPSnippetsServiceObserver: | 31 // ntp_snippets::NTPSnippetsServiceObserver: |
| 33 // Send everytime the service loads a new set of data. | |
| 34 void NTPSnippetsServiceLoaded() override; | 32 void NTPSnippetsServiceLoaded() override; |
| 35 // Send when the service is shutting down. | |
| 36 void NTPSnippetsServiceShutdown() override; | 33 void NTPSnippetsServiceShutdown() override; |
| 37 // Sent when the service is disabled. | |
| 38 void NTPSnippetsServiceDisabled() override; | 34 void NTPSnippetsServiceDisabled() override; |
| 39 | 35 |
| 40 void HandleLoaded(const base::ListValue* args); | 36 void HandleLoaded(const base::ListValue* args); |
| 41 void HandleClear(const base::ListValue* args); | 37 void HandleClear(const base::ListValue* args); |
| 42 void HandleDump(const base::ListValue* args); | |
| 43 void HandleClearDiscarded(const base::ListValue* args); | 38 void HandleClearDiscarded(const base::ListValue* args); |
| 44 void HandleDownload(const base::ListValue* args); | 39 void HandleDownload(const base::ListValue* args); |
| 45 | 40 |
| 46 void SendInitialData(); | 41 void SendInitialData(); |
| 47 void SendSnippets(); | 42 void SendSnippets(); |
| 48 void SendDiscardedSnippets(); | 43 void SendDiscardedSnippets(); |
| 49 void SendHosts(); | 44 void SendHosts(); |
| 50 void SendJson(const std::string& json); | |
| 51 void SendBoolean(const std::string& name, bool value); | 45 void SendBoolean(const std::string& name, bool value); |
| 52 void SendString(const std::string& name, const std::string& value); | 46 void SendString(const std::string& name, const std::string& value); |
| 53 | 47 |
| 54 ScopedObserver<ntp_snippets::NTPSnippetsService, | 48 ScopedObserver<ntp_snippets::NTPSnippetsService, |
| 55 ntp_snippets::NTPSnippetsServiceObserver> observer_; | 49 ntp_snippets::NTPSnippetsServiceObserver> observer_; |
| 56 | 50 |
| 57 // Tracks whether we can already send messages to the page. | 51 // Tracks whether we can already send messages to the page. |
| 58 bool dom_loaded_; | 52 bool dom_loaded_; |
| 59 | 53 |
| 60 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; | 54 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; |
| 61 | 55 |
| 62 DISALLOW_COPY_AND_ASSIGN(SnippetsInternalsMessageHandler); | 56 DISALLOW_COPY_AND_ASSIGN(SnippetsInternalsMessageHandler); |
| 63 }; | 57 }; |
| 64 | 58 |
| 65 #endif // CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ | 59 #endif // CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ |
| OLD | NEW |