Demetrios Papadopoulos | eec1870 | 2019-12-06 21:54:39 | [diff] [blame^] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_UI_WEBUI_COMPONENTS_HANDLER_H_ |
| 6 | #define CHROME_BROWSER_UI_WEBUI_COMPONENTS_HANDLER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/strings/string16.h" |
| 12 | #include "components/component_updater/component_updater_service.h" |
| 13 | #include "components/update_client/update_client.h" |
| 14 | #include "content/public/browser/notification_registrar.h" |
| 15 | #include "content/public/browser/web_ui_message_handler.h" |
| 16 | |
| 17 | namespace base { |
| 18 | class ListValue; |
| 19 | } |
| 20 | |
| 21 | // The handler for Javascript messages for the chrome://components/ page. |
| 22 | class ComponentsHandler : public content::WebUIMessageHandler, |
| 23 | public component_updater::ServiceObserver { |
| 24 | public: |
| 25 | ComponentsHandler(); |
| 26 | ComponentsHandler(const ComponentsHandler&) = delete; |
| 27 | ComponentsHandler& operator=(const ComponentsHandler&) = delete; |
| 28 | ~ComponentsHandler() override; |
| 29 | |
| 30 | // WebUIMessageHandler implementation. |
| 31 | void RegisterMessages() override; |
| 32 | void OnJavascriptAllowed() override; |
| 33 | void OnJavascriptDisallowed() override; |
| 34 | |
| 35 | // Callback for the "requestComponentsData" message. |
| 36 | void HandleRequestComponentsData(const base::ListValue* args); |
| 37 | |
| 38 | // Callback for the "checkUpdate" message. |
| 39 | void HandleCheckUpdate(const base::ListValue* args); |
| 40 | |
| 41 | // ServiceObserver implementation. |
| 42 | void OnEvent(Events event, const std::string& id) override; |
| 43 | |
| 44 | private: |
| 45 | static base::string16 ComponentEventToString(Events event); |
| 46 | static base::string16 ServiceStatusToString( |
| 47 | update_client::ComponentState state); |
| 48 | static std::unique_ptr<base::ListValue> LoadComponents(); |
| 49 | static void OnDemandUpdate(const std::string& component_id); |
| 50 | |
| 51 | content::NotificationRegistrar registrar_; |
| 52 | }; |
| 53 | |
| 54 | #endif // CHROME_BROWSER_UI_WEBUI_COMPONENTS_HANDLER_H_ |