Commit 77566471 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Add printer status backend for Chrome OS Print Preview

- Accepts a printer id, kicks off a printer status request, then
  once complete broadcasts the status to "printer-status-update".

Bug: 1059607
Change-Id: I91b30632a6682a4705616d714038a7826483753c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128236
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760330}
parent 9b390a4a
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/debug_daemon/debug_daemon_client.h" #include "chromeos/dbus/debug_daemon/debug_daemon_client.h"
#include "chromeos/printing/printer_configuration.h" #include "chromeos/printing/printer_configuration.h"
#include "chromeos/printing/printer_translator.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/printing/browser/printer_capabilities.h" #include "components/printing/browser/printer_capabilities.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
...@@ -238,6 +239,22 @@ void LocalPrinterHandlerChromeos::StartGetEulaUrl( ...@@ -238,6 +239,22 @@ void LocalPrinterHandlerChromeos::StartGetEulaUrl(
weak_factory_.GetWeakPtr(), std::move(cb))); weak_factory_.GetWeakPtr(), std::move(cb)));
} }
void LocalPrinterHandlerChromeos::StartPrinterStatusRequest(
const std::string& printer_id,
PrinterStatusRequestCallback callback) {
printers_manager_->FetchPrinterStatus(
printer_id,
base::BindOnce(&LocalPrinterHandlerChromeos::OnPrinterStatusUpdated,
weak_factory_.GetWeakPtr(), std::move(callback)));
}
void LocalPrinterHandlerChromeos::OnPrinterStatusUpdated(
PrinterStatusRequestCallback callback,
const chromeos::CupsPrinterStatus& cups_printers_status) {
std::move(callback).Run(
CreateCupsPrinterStatusDictionary(cups_printers_status));
}
void LocalPrinterHandlerChromeos::OnPrinterInstalled( void LocalPrinterHandlerChromeos::OnPrinterInstalled(
const chromeos::Printer& printer, const chromeos::Printer& printer,
GetCapabilityCallback cb, GetCapabilityCallback cb,
......
...@@ -54,6 +54,9 @@ class LocalPrinterHandlerChromeos : public PrinterHandler { ...@@ -54,6 +54,9 @@ class LocalPrinterHandlerChromeos : public PrinterHandler {
PrintCallback callback) override; PrintCallback callback) override;
void StartGetEulaUrl(const std::string& destination_id, void StartGetEulaUrl(const std::string& destination_id,
GetEulaUrlCallback cb) override; GetEulaUrlCallback cb) override;
void StartPrinterStatusRequest(
const std::string& printer_id,
PrinterStatusRequestCallback callback) override;
private: private:
FRIEND_TEST_ALL_PREFIXES(LocalPrinterHandlerChromeosTest, FRIEND_TEST_ALL_PREFIXES(LocalPrinterHandlerChromeosTest,
...@@ -83,6 +86,10 @@ class LocalPrinterHandlerChromeos : public PrinterHandler { ...@@ -83,6 +86,10 @@ class LocalPrinterHandlerChromeos : public PrinterHandler {
bool record_usb_setup_source, bool record_usb_setup_source,
chromeos::PrinterSetupResult result); chromeos::PrinterSetupResult result);
void OnPrinterStatusUpdated(
PrinterStatusRequestCallback callback,
const chromeos::CupsPrinterStatus& cups_printers_status);
Profile* const profile_; Profile* const profile_;
content::WebContents* const preview_web_contents_; content::WebContents* const preview_web_contents_;
chromeos::CupsPrintersManager* printers_manager_; chromeos::CupsPrintersManager* printers_manager_;
......
...@@ -649,6 +649,11 @@ void PrintPreviewHandler::RegisterMessages() { ...@@ -649,6 +649,11 @@ void PrintPreviewHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"getEulaUrl", base::BindRepeating(&PrintPreviewHandler::HandleGetEulaUrl, "getEulaUrl", base::BindRepeating(&PrintPreviewHandler::HandleGetEulaUrl,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"requestPrinterStatus",
base::BindRepeating(
&PrintPreviewHandler::HandleRequestPrinterStatusUpdate,
base::Unretained(this)));
#endif #endif
} }
...@@ -1586,4 +1591,23 @@ void PrintPreviewHandler::SendManipulateSettingsForTest( ...@@ -1586,4 +1591,23 @@ void PrintPreviewHandler::SendManipulateSettingsForTest(
FireWebUIListener("manipulate-settings-for-test", settings); FireWebUIListener("manipulate-settings-for-test", settings);
} }
#if defined(OS_CHROMEOS)
void PrintPreviewHandler::HandleRequestPrinterStatusUpdate(
const base::ListValue* args) {
CHECK_EQ(1U, args->GetList().size());
PrinterHandler* handler = GetPrinterHandler(PrinterType::kLocal);
handler->StartPrinterStatusRequest(
args->GetList()[0].GetString(),
base::BindOnce(&PrintPreviewHandler::OnPrinterStatusUpdated,
weak_factory_.GetWeakPtr()));
}
void PrintPreviewHandler::OnPrinterStatusUpdated(
const base::Value& cups_printer_status) {
// "printer-status-update" will also trigger non-PrintPreview UI for
// consuming fresh printer statuses.
FireWebUIListener("printer-status-update", cups_printer_status);
}
#endif
} // namespace printing } // namespace printing
...@@ -310,6 +310,14 @@ class PrintPreviewHandler : public content::WebUIMessageHandler, ...@@ -310,6 +310,14 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
void OnPrintResult(const std::string& callback_id, void OnPrintResult(const std::string& callback_id,
const base::Value& error); const base::Value& error);
#if defined(OS_CHROMEOS)
// Called to initiate a status request for a printer.
void HandleRequestPrinterStatusUpdate(const base::ListValue* args);
// Invokes Web UI Listener "printer-status-update" with new printer status.
void OnPrinterStatusUpdated(const base::Value& cups_printer_status);
#endif
// A count of how many requests received to regenerate preview data. // A count of how many requests received to regenerate preview data.
// Initialized to 0 then incremented and emitted to a histogram. // Initialized to 0 then incremented and emitted to a histogram.
int regenerate_preview_request_count_ = 0; int regenerate_preview_request_count_ = 0;
......
...@@ -70,6 +70,12 @@ void PrinterHandler::StartGetEulaUrl(const std::string& destination_id, ...@@ -70,6 +70,12 @@ void PrinterHandler::StartGetEulaUrl(const std::string& destination_id,
GetEulaUrlCallback callback) { GetEulaUrlCallback callback) {
NOTREACHED(); NOTREACHED();
} }
void PrinterHandler::StartPrinterStatusRequest(
const std::string& printer_id,
PrinterStatusRequestCallback callback) {
NOTREACHED();
}
#endif #endif
} // namespace printing } // namespace printing
...@@ -52,6 +52,8 @@ class PrinterHandler { ...@@ -52,6 +52,8 @@ class PrinterHandler {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
using GetEulaUrlCallback = using GetEulaUrlCallback =
base::OnceCallback<void(const std::string& license)>; base::OnceCallback<void(const std::string& license)>;
using PrinterStatusRequestCallback =
base::OnceCallback<void(const base::Value& cups_printer_status)>;
#endif #endif
// Creates an instance of a PrinterHandler for extension printers. // Creates an instance of a PrinterHandler for extension printers.
...@@ -121,6 +123,12 @@ class PrinterHandler { ...@@ -121,6 +123,12 @@ class PrinterHandler {
// |callback| should be called in response to the request. // |callback| should be called in response to the request.
virtual void StartGetEulaUrl(const std::string& destination_id, virtual void StartGetEulaUrl(const std::string& destination_id,
GetEulaUrlCallback callback); GetEulaUrlCallback callback);
// Initiates a status request for specified printer.
// |printer_id|: Printer id.
// |callback|: should be called in response to the request.
virtual void StartPrinterStatusRequest(const std::string& printer_id,
PrinterStatusRequestCallback callback);
#endif #endif
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment