OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.h" | 5 #include "chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 namespace { | 46 namespace { |
47 | 47 |
48 // These values are written to logs. New enum values can be added, but existing | 48 // These values are written to logs. New enum values can be added, but existing |
49 // enums must never be renumbered or deleted and reused. | 49 // enums must never be renumbered or deleted and reused. |
50 enum PpdSourceForHistogram { kUser = 0, kScs = 1, kPpdSourceMax }; | 50 enum PpdSourceForHistogram { kUser = 0, kScs = 1, kPpdSourceMax }; |
51 | 51 |
52 void RecordPpdSource(const PpdSourceForHistogram& source) { | 52 void RecordPpdSource(const PpdSourceForHistogram& source) { |
53 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PpdSource", source, kPpdSourceMax); | 53 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PpdSource", source, kPpdSourceMax); |
54 } | 54 } |
55 | 55 |
56 void OnRemovedPrinter(bool success) {} | 56 void OnRemovedPrinter(const Printer::PrinterProtocol& protocol, bool success) { |
| 57 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterRemoved", protocol, |
| 58 Printer::PrinterProtocol::kProtocolMax); |
| 59 } |
57 | 60 |
58 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { | 61 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { |
59 std::unique_ptr<base::DictionaryValue> printer_info = | 62 std::unique_ptr<base::DictionaryValue> printer_info = |
60 base::MakeUnique<base::DictionaryValue>(); | 63 base::MakeUnique<base::DictionaryValue>(); |
61 printer_info->SetString("printerId", printer.id()); | 64 printer_info->SetString("printerId", printer.id()); |
62 printer_info->SetString("printerName", printer.display_name()); | 65 printer_info->SetString("printerName", printer.display_name()); |
63 printer_info->SetString("printerDescription", printer.description()); | 66 printer_info->SetString("printerDescription", printer.description()); |
64 printer_info->SetString("printerManufacturer", printer.manufacturer()); | 67 printer_info->SetString("printerManufacturer", printer.manufacturer()); |
65 printer_info->SetString("printerModel", printer.model()); | 68 printer_info->SetString("printerModel", printer.model()); |
66 // Get protocol, ip address and queue from the printer's URI. | 69 // Get protocol, ip address and queue from the printer's URI. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 printer->set_display_name(printer_name); | 180 printer->set_display_name(printer_name); |
178 PrintersManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( | 181 PrintersManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( |
179 std::move(printer)); | 182 std::move(printer)); |
180 } | 183 } |
181 | 184 |
182 void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) { | 185 void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) { |
183 std::string printer_id; | 186 std::string printer_id; |
184 std::string printer_name; | 187 std::string printer_name; |
185 CHECK(args->GetString(0, &printer_id)); | 188 CHECK(args->GetString(0, &printer_id)); |
186 CHECK(args->GetString(1, &printer_name)); | 189 CHECK(args->GetString(1, &printer_name)); |
187 PrintersManagerFactory::GetForBrowserContext(profile_)->RemovePrinter( | 190 PrintersManager* prefs = |
188 printer_id); | 191 PrintersManagerFactory::GetForBrowserContext(profile_); |
| 192 auto printer = prefs->GetPrinter(printer_id); |
| 193 if (!printer) |
| 194 return; |
| 195 |
| 196 Printer::PrinterProtocol protocol = printer->GetProtocol(); |
| 197 prefs->RemovePrinter(printer_id); |
189 | 198 |
190 chromeos::DebugDaemonClient* client = | 199 chromeos::DebugDaemonClient* client = |
191 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 200 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
192 client->CupsRemovePrinter(printer_name, base::Bind(&OnRemovedPrinter), | 201 client->CupsRemovePrinter(printer_name, |
| 202 base::Bind(&OnRemovedPrinter, protocol), |
193 base::Bind(&base::DoNothing)); | 203 base::Bind(&base::DoNothing)); |
194 } | 204 } |
195 | 205 |
196 void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) { | 206 void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) { |
197 AllowJavascript(); | 207 AllowJavascript(); |
198 | 208 |
199 const base::DictionaryValue* printer_dict = nullptr; | 209 const base::DictionaryValue* printer_dict = nullptr; |
200 CHECK(args->GetDictionary(0, &printer_dict)); | 210 CHECK(args->GetDictionary(0, &printer_dict)); |
201 | 211 |
202 std::string printer_id; | 212 std::string printer_id; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 273 } |
264 | 274 |
265 void CupsPrintersHandler::OnAddedPrinter( | 275 void CupsPrintersHandler::OnAddedPrinter( |
266 std::unique_ptr<Printer> printer, | 276 std::unique_ptr<Printer> printer, |
267 chromeos::PrinterSetupResult result_code) { | 277 chromeos::PrinterSetupResult result_code) { |
268 std::string printer_name = printer->display_name(); | 278 std::string printer_name = printer->display_name(); |
269 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterSetupResult", result_code, | 279 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterSetupResult", result_code, |
270 chromeos::PrinterSetupResult::kMaxValue); | 280 chromeos::PrinterSetupResult::kMaxValue); |
271 switch (result_code) { | 281 switch (result_code) { |
272 case chromeos::PrinterSetupResult::kSuccess: { | 282 case chromeos::PrinterSetupResult::kSuccess: { |
| 283 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterAdded", |
| 284 printer->GetProtocol(), Printer::kProtocolMax); |
273 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); | 285 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); |
274 manager->PrinterInstalled(*printer); | 286 manager->PrinterInstalled(*printer); |
275 manager->RegisterPrinter(std::move(printer)); | 287 manager->RegisterPrinter(std::move(printer)); |
276 break; | 288 break; |
277 } | 289 } |
278 case chromeos::PrinterSetupResult::kPpdNotFound: | 290 case chromeos::PrinterSetupResult::kPpdNotFound: |
279 LOG(WARNING) << "Could not locate requested PPD"; | 291 LOG(WARNING) << "Could not locate requested PPD"; |
280 break; | 292 break; |
281 case chromeos::PrinterSetupResult::kPpdTooLarge: | 293 case chromeos::PrinterSetupResult::kPpdTooLarge: |
282 LOG(WARNING) << "PPD is too large"; | 294 LOG(WARNING) << "PPD is too large"; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 FireWebUIListener("on-printer-discovered", *printers_list); | 438 FireWebUIListener("on-printer-discovered", *printers_list); |
427 } | 439 } |
428 | 440 |
429 void CupsPrintersHandler::OnDiscoveryInitialScanDone(int printer_count) { | 441 void CupsPrintersHandler::OnDiscoveryInitialScanDone(int printer_count) { |
430 UMA_HISTOGRAM_COUNTS_100("Printing.CUPS.PrintersDiscovered", printer_count); | 442 UMA_HISTOGRAM_COUNTS_100("Printing.CUPS.PrintersDiscovered", printer_count); |
431 FireWebUIListener("on-printer-discovery-done"); | 443 FireWebUIListener("on-printer-discovery-done"); |
432 } | 444 } |
433 | 445 |
434 } // namespace settings | 446 } // namespace settings |
435 } // namespace chromeos | 447 } // namespace chromeos |
OLD | NEW |