Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc

Issue 2903883003: Log printer additions and removals by protocol. (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/json/json_string_value_serializer.h" 12 #include "base/json/json_string_value_serializer.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/threading/sequenced_task_runner_handle.h" 17 #include "base/threading/sequenced_task_runner_handle.h"
17 #include "base/values.h" 18 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/printing/ppd_provider_factory.h" 20 #include "chrome/browser/chromeos/printing/ppd_provider_factory.h"
20 #include "chrome/browser/chromeos/printing/printer_configurer.h" 21 #include "chrome/browser/chromeos/printing/printer_configurer.h"
21 #include "chrome/browser/chromeos/printing/printer_discoverer.h" 22 #include "chrome/browser/chromeos/printing/printer_discoverer.h"
22 #include "chrome/browser/chromeos/printing/printers_manager_factory.h" 23 #include "chrome/browser/chromeos/printing/printers_manager_factory.h"
23 #include "chrome/browser/download/download_prefs.h" 24 #include "chrome/browser/download/download_prefs.h"
(...skipping 13 matching lines...) Expand all
37 #include "net/base/filename_util.h" 38 #include "net/base/filename_util.h"
38 #include "net/url_request/url_request_context_getter.h" 39 #include "net/url_request/url_request_context_getter.h"
39 #include "printing/backend/print_backend.h" 40 #include "printing/backend/print_backend.h"
40 #include "url/third_party/mozilla/url_parse.h" 41 #include "url/third_party/mozilla/url_parse.h"
41 42
42 namespace chromeos { 43 namespace chromeos {
43 namespace settings { 44 namespace settings {
44 45
45 namespace { 46 namespace {
46 47
47 void OnRemovedPrinter(bool success) {} 48 void OnRemovedPrinter(const Printer::PrinterProtocol& protocol, bool success) {
49 if (success) {
50 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterRemoved", protocol,
51 Printer::PrinterProtocol::PROTOCOL_MAX);
52 }
53 }
48 54
49 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { 55 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) {
50 std::unique_ptr<base::DictionaryValue> printer_info = 56 std::unique_ptr<base::DictionaryValue> printer_info =
51 base::MakeUnique<base::DictionaryValue>(); 57 base::MakeUnique<base::DictionaryValue>();
52 printer_info->SetString("printerId", printer.id()); 58 printer_info->SetString("printerId", printer.id());
53 printer_info->SetString("printerName", printer.display_name()); 59 printer_info->SetString("printerName", printer.display_name());
54 printer_info->SetString("printerDescription", printer.description()); 60 printer_info->SetString("printerDescription", printer.description());
55 printer_info->SetString("printerManufacturer", printer.manufacturer()); 61 printer_info->SetString("printerManufacturer", printer.manufacturer());
56 printer_info->SetString("printerModel", printer.model()); 62 printer_info->SetString("printerModel", printer.model());
57 // Get protocol, ip address and queue from the printer's URI. 63 // Get protocol, ip address and queue from the printer's URI.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 printer->set_display_name(printer_name); 174 printer->set_display_name(printer_name);
169 PrintersManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( 175 PrintersManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter(
170 std::move(printer)); 176 std::move(printer));
171 } 177 }
172 178
173 void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) { 179 void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) {
174 std::string printer_id; 180 std::string printer_id;
175 std::string printer_name; 181 std::string printer_name;
176 CHECK(args->GetString(0, &printer_id)); 182 CHECK(args->GetString(0, &printer_id));
177 CHECK(args->GetString(1, &printer_name)); 183 CHECK(args->GetString(1, &printer_name));
178 PrintersManagerFactory::GetForBrowserContext(profile_)->RemovePrinter( 184 PrintersManager* prefs =
179 printer_id); 185 PrintersManagerFactory::GetForBrowserContext(profile_);
186 auto printer = prefs->GetPrinter(printer_id);
187
188 if (!printer) {
189 LOG(WARNING) << "Tried to remove non-existant printer";
190 return;
191 }
192 Printer::PrinterProtocol protocol = printer->GetProtocol();
193
194 prefs->RemovePrinter(printer_id);
180 195
181 chromeos::DebugDaemonClient* client = 196 chromeos::DebugDaemonClient* client =
182 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); 197 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
183 client->CupsRemovePrinter(printer_name, base::Bind(&OnRemovedPrinter), 198 client->CupsRemovePrinter(printer_name,
199 base::Bind(&OnRemovedPrinter, protocol),
184 base::Bind(&base::DoNothing)); 200 base::Bind(&base::DoNothing));
185 } 201 }
186 202
187 void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) { 203 void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) {
188 AllowJavascript(); 204 AllowJavascript();
189 205
190 const base::DictionaryValue* printer_dict = nullptr; 206 const base::DictionaryValue* printer_dict = nullptr;
191 CHECK(args->GetDictionary(0, &printer_dict)); 207 CHECK(args->GetDictionary(0, &printer_dict));
192 208
193 std::string printer_id; 209 std::string printer_id;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 base::Bind(&CupsPrintersHandler::OnAddedPrinter, 266 base::Bind(&CupsPrintersHandler::OnAddedPrinter,
251 weak_factory_.GetWeakPtr(), base::Passed(&printer))); 267 weak_factory_.GetWeakPtr(), base::Passed(&printer)));
252 } 268 }
253 269
254 void CupsPrintersHandler::OnAddedPrinter( 270 void CupsPrintersHandler::OnAddedPrinter(
255 std::unique_ptr<Printer> printer, 271 std::unique_ptr<Printer> printer,
256 chromeos::PrinterSetupResult result_code) { 272 chromeos::PrinterSetupResult result_code) {
257 std::string printer_name = printer->display_name(); 273 std::string printer_name = printer->display_name();
258 switch (result_code) { 274 switch (result_code) {
259 case chromeos::PrinterSetupResult::SUCCESS: { 275 case chromeos::PrinterSetupResult::SUCCESS: {
276 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterAdded",
277 printer->GetProtocol(), Printer::PROTOCOL_MAX);
260 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); 278 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_);
261 manager->PrinterInstalled(*printer); 279 manager->PrinterInstalled(*printer);
262 manager->RegisterPrinter(std::move(printer)); 280 manager->RegisterPrinter(std::move(printer));
263 break; 281 break;
264 } 282 }
265 case chromeos::PrinterSetupResult::PPD_NOT_FOUND: 283 case chromeos::PrinterSetupResult::PPD_NOT_FOUND:
266 LOG(WARNING) << "Could not locate requested PPD"; 284 LOG(WARNING) << "Could not locate requested PPD";
267 break; 285 break;
268 case chromeos::PrinterSetupResult::PPD_TOO_LARGE: 286 case chromeos::PrinterSetupResult::PPD_TOO_LARGE:
269 LOG(WARNING) << "PPD is too large"; 287 LOG(WARNING) << "PPD is too large";
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 427
410 FireWebUIListener("on-printer-discovered", *printers_list); 428 FireWebUIListener("on-printer-discovered", *printers_list);
411 } 429 }
412 430
413 void CupsPrintersHandler::OnDiscoveryInitialScanDone() { 431 void CupsPrintersHandler::OnDiscoveryInitialScanDone() {
414 FireWebUIListener("on-printer-discovery-done"); 432 FireWebUIListener("on-printer-discovery-done");
415 } 433 }
416 434
417 } // namespace settings 435 } // namespace settings
418 } // namespace chromeos 436 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698