1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/download/public/background_service/logger.h"
#include "content/public/browser/web_ui_message_handler.h"
namespace download {
class BackgroundDownloadService;
} // namespace download
namespace download_internals {
// Class acting as a controller of the chrome://download-internals WebUI.
class DownloadInternalsUIMessageHandler : public content::WebUIMessageHandler,
public download::Logger::Observer {
public:
DownloadInternalsUIMessageHandler();
DownloadInternalsUIMessageHandler(const DownloadInternalsUIMessageHandler&) =
delete;
DownloadInternalsUIMessageHandler& operator=(
const DownloadInternalsUIMessageHandler&) = delete;
~DownloadInternalsUIMessageHandler() override;
// content::WebUIMessageHandler implementation.
void RegisterMessages() override;
// download::Logger::Observer implementation.
void OnServiceStatusChanged(const base::Value::Dict& service_status) override;
void OnServiceDownloadsAvailable(
const base::Value::List& service_downloads) override;
void OnServiceDownloadChanged(
const base::Value::Dict& service_download) override;
void OnServiceDownloadFailed(
const base::Value::Dict& service_download) override;
void OnServiceRequestMade(const base::Value::Dict& service_request) override;
private:
// Get the current DownloadService and sub component statuses.
void HandleGetServiceStatus(const base::Value::List& args);
void HandleGetServiceDownloads(const base::Value::List& args);
// Starts a background download.
void HandleStartDownload(const base::Value::List& args);
raw_ptr<download::BackgroundDownloadService> download_service_;
base::WeakPtrFactory<DownloadInternalsUIMessageHandler> weak_ptr_factory_{
this};
};
} // namespace download_internals
#endif // CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_
|