blob: 7041edcb685e7a8fe577f64d76ec9dd31294d9e2 [file] [log] [blame]
Demetrios Papadopouloseec18702019-12-06 21:54:391// 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
Demetrios Papadopoulos4ba6c9a62019-12-07 03:26:015#ifndef CHROME_BROWSER_UI_WEBUI_COMPONENTS_COMPONENTS_HANDLER_H_
6#define CHROME_BROWSER_UI_WEBUI_COMPONENTS_COMPONENTS_HANDLER_H_
Demetrios Papadopouloseec18702019-12-06 21:54:397
8#include <memory>
9#include <string>
10
Dan Beam78c18c32020-01-04 02:49:1411#include "base/scoped_observer.h"
Demetrios Papadopouloseec18702019-12-06 21:54:3912#include "base/strings/string16.h"
13#include "components/component_updater/component_updater_service.h"
14#include "components/update_client/update_client.h"
Demetrios Papadopouloseec18702019-12-06 21:54:3915#include "content/public/browser/web_ui_message_handler.h"
16
17namespace base {
18class ListValue;
19}
20
21// The handler for Javascript messages for the chrome://components/ page.
22class 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
Dan Beam78c18c32020-01-04 02:49:1451 ScopedObserver<component_updater::ComponentUpdateService,
52 component_updater::ComponentUpdateService::Observer>
53 observer_{this};
Demetrios Papadopouloseec18702019-12-06 21:54:3954};
55
Demetrios Papadopoulos4ba6c9a62019-12-07 03:26:0156#endif // CHROME_BROWSER_UI_WEBUI_COMPONENTS_COMPONENTS_HANDLER_H_