Chromium Code Reviews| Index: chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc |
| diff --git a/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc b/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc |
| index 0a07cfacdb7c40c997af2f8f262a9bfcc2e7ef08..0170e533cf7ee8f4512d59c7be8614b07c4c47b8 100644 |
| --- a/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc |
| +++ b/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/files/file_util.h" |
| #include "base/json/json_string_value_serializer.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/path_service.h" |
| #include "base/strings/string_util.h" |
| #include "base/threading/sequenced_task_runner_handle.h" |
| @@ -44,7 +45,10 @@ namespace settings { |
| namespace { |
| -void OnRemovedPrinter(bool success) {} |
| +void OnRemovedPrinter(const Printer::PrinterProtocol& protocol, bool success) { |
| + UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterRemoved", protocol, |
| + Printer::PrinterProtocol::kProtocolMax); |
| +} |
| std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { |
| std::unique_ptr<base::DictionaryValue> printer_info = |
| @@ -175,12 +179,22 @@ void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) { |
| std::string printer_name; |
| CHECK(args->GetString(0, &printer_id)); |
| CHECK(args->GetString(1, &printer_name)); |
| - PrintersManagerFactory::GetForBrowserContext(profile_)->RemovePrinter( |
| - printer_id); |
| + PrintersManager* prefs = |
| + PrintersManagerFactory::GetForBrowserContext(profile_); |
| + auto printer = prefs->GetPrinter(printer_id); |
| + |
| + if (!printer) { |
| + LOG(WARNING) << "Tried to remove non-existant printer"; |
|
Dan Beam
2017/05/31 18:06:17
do we really need this LOG()?
Dan Beam
2017/05/31 18:06:17
existent
skau
2017/05/31 18:34:06
Now that you mention it, it's not that useful. Re
|
| + return; |
| + } |
| + Printer::PrinterProtocol protocol = printer->GetProtocol(); |
| + |
| + prefs->RemovePrinter(printer_id); |
| chromeos::DebugDaemonClient* client = |
| chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| - client->CupsRemovePrinter(printer_name, base::Bind(&OnRemovedPrinter), |
| + client->CupsRemovePrinter(printer_name, |
| + base::Bind(&OnRemovedPrinter, protocol), |
| base::Bind(&base::DoNothing)); |
| } |
| @@ -257,6 +271,8 @@ void CupsPrintersHandler::OnAddedPrinter( |
| std::string printer_name = printer->display_name(); |
| switch (result_code) { |
| case chromeos::PrinterSetupResult::kSuccess: { |
| + UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterAdded", |
| + printer->GetProtocol(), Printer::kProtocolMax); |
| auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); |
| manager->PrinterInstalled(*printer); |
| manager->RegisterPrinter(std::move(printer)); |