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

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

Issue 2911523002: Add metrics to printer setup flow. (Closed)
Patch Set: rebase Created 3 years, 6 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"
(...skipping 27 matching lines...) Expand all
38 #include "net/base/filename_util.h" 38 #include "net/base/filename_util.h"
39 #include "net/url_request/url_request_context_getter.h" 39 #include "net/url_request/url_request_context_getter.h"
40 #include "printing/backend/print_backend.h" 40 #include "printing/backend/print_backend.h"
41 #include "url/third_party/mozilla/url_parse.h" 41 #include "url/third_party/mozilla/url_parse.h"
42 42
43 namespace chromeos { 43 namespace chromeos {
44 namespace settings { 44 namespace settings {
45 45
46 namespace { 46 namespace {
47 47
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.
50 enum PpdSourceForHistogram { kUser = 0, kScs = 1, kPpdSourceMax };
51
52 void RecordPpdSource(const PpdSourceForHistogram& source) {
53 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PpdSource", source, kPpdSourceMax);
54 }
55
48 void OnRemovedPrinter(bool success) {} 56 void OnRemovedPrinter(bool success) {}
49 57
50 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { 58 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) {
51 std::unique_ptr<base::DictionaryValue> printer_info = 59 std::unique_ptr<base::DictionaryValue> printer_info =
52 base::MakeUnique<base::DictionaryValue>(); 60 base::MakeUnique<base::DictionaryValue>();
53 printer_info->SetString("printerId", printer.id()); 61 printer_info->SetString("printerId", printer.id());
54 printer_info->SetString("printerName", printer.display_name()); 62 printer_info->SetString("printerName", printer.display_name());
55 printer_info->SetString("printerDescription", printer.description()); 63 printer_info->SetString("printerDescription", printer.description());
56 printer_info->SetString("printerManufacturer", printer.manufacturer()); 64 printer_info->SetString("printerManufacturer", printer.manufacturer());
57 printer_info->SetString("printerModel", printer.model()); 65 printer_info->SetString("printerModel", printer.model());
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 227
220 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); 228 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id);
221 printer->set_display_name(printer_name); 229 printer->set_display_name(printer_name);
222 printer->set_description(printer_description); 230 printer->set_description(printer_description);
223 printer->set_manufacturer(printer_manufacturer); 231 printer->set_manufacturer(printer_manufacturer);
224 printer->set_model(printer_model); 232 printer->set_model(printer_model);
225 printer->set_uri(printer_uri); 233 printer->set_uri(printer_uri);
226 234
227 // Verify a valid ppd path is present. 235 // Verify a valid ppd path is present.
228 if (!printer_ppd_path.empty()) { 236 if (!printer_ppd_path.empty()) {
237 RecordPpdSource(kUser);
229 GURL tmp = net::FilePathToFileURL(base::FilePath(printer_ppd_path)); 238 GURL tmp = net::FilePathToFileURL(base::FilePath(printer_ppd_path));
230 if (!tmp.is_valid()) { 239 if (!tmp.is_valid()) {
231 LOG(ERROR) << "Invalid ppd path: " << printer_ppd_path; 240 LOG(ERROR) << "Invalid ppd path: " << printer_ppd_path;
232 OnAddPrinterError(); 241 OnAddPrinterError();
233 return; 242 return;
234 } 243 }
235 printer->mutable_ppd_reference()->user_supplied_ppd_url = tmp.spec(); 244 printer->mutable_ppd_reference()->user_supplied_ppd_url = tmp.spec();
236 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { 245 } else if (!printer_manufacturer.empty() && !printer_model.empty()) {
246 RecordPpdSource(kScs);
237 // Using the manufacturer and model, get a ppd reference. 247 // Using the manufacturer and model, get a ppd reference.
238 if (!ppd_provider_->GetPpdReference(printer_manufacturer, printer_model, 248 if (!ppd_provider_->GetPpdReference(printer_manufacturer, printer_model,
239 printer->mutable_ppd_reference())) { 249 printer->mutable_ppd_reference())) {
240 LOG(ERROR) << "Failed to get ppd reference"; 250 LOG(ERROR) << "Failed to get ppd reference";
241 OnAddPrinterError(); 251 OnAddPrinterError();
242 return; 252 return;
243 } 253 }
244 } 254 }
245 255
246 // Copy the printer for the configurer. Ownership needs to be transfered to 256 // Copy the printer for the configurer. Ownership needs to be transfered to
247 // the receiver of the callback. 257 // the receiver of the callback.
248 const Printer printer_copy = *printer; 258 const Printer printer_copy = *printer;
249 printer_configurer_->SetUpPrinter( 259 printer_configurer_->SetUpPrinter(
250 printer_copy, 260 printer_copy,
251 base::Bind(&CupsPrintersHandler::OnAddedPrinter, 261 base::Bind(&CupsPrintersHandler::OnAddedPrinter,
252 weak_factory_.GetWeakPtr(), base::Passed(&printer))); 262 weak_factory_.GetWeakPtr(), base::Passed(&printer)));
253 } 263 }
254 264
255 void CupsPrintersHandler::OnAddedPrinter( 265 void CupsPrintersHandler::OnAddedPrinter(
256 std::unique_ptr<Printer> printer, 266 std::unique_ptr<Printer> printer,
257 chromeos::PrinterSetupResult result_code) { 267 chromeos::PrinterSetupResult result_code) {
258 std::string printer_name = printer->display_name(); 268 std::string printer_name = printer->display_name();
269 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterSetupResult", result_code,
270 chromeos::PrinterSetupResult::kMaxValue);
259 switch (result_code) { 271 switch (result_code) {
260 case chromeos::PrinterSetupResult::kSuccess: { 272 case chromeos::PrinterSetupResult::kSuccess: {
261 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); 273 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_);
262 manager->PrinterInstalled(*printer); 274 manager->PrinterInstalled(*printer);
263 manager->RegisterPrinter(std::move(printer)); 275 manager->RegisterPrinter(std::move(printer));
264 break; 276 break;
265 } 277 }
266 case chromeos::PrinterSetupResult::kPpdNotFound: 278 case chromeos::PrinterSetupResult::kPpdNotFound:
267 LOG(WARNING) << "Could not locate requested PPD"; 279 LOG(WARNING) << "Could not locate requested PPD";
268 break; 280 break;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 FireWebUIListener("on-printer-discovered", *printers_list); 426 FireWebUIListener("on-printer-discovered", *printers_list);
415 } 427 }
416 428
417 void CupsPrintersHandler::OnDiscoveryInitialScanDone(int printer_count) { 429 void CupsPrintersHandler::OnDiscoveryInitialScanDone(int printer_count) {
418 UMA_HISTOGRAM_COUNTS_100("Printing.CUPS.PrintersDiscovered", printer_count); 430 UMA_HISTOGRAM_COUNTS_100("Printing.CUPS.PrintersDiscovered", printer_count);
419 FireWebUIListener("on-printer-discovery-done"); 431 FireWebUIListener("on-printer-discovery-done");
420 } 432 }
421 433
422 } // namespace settings 434 } // namespace settings
423 } // namespace chromeos 435 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/printing/printer_configurer.h ('k') | chromeos/printing/printer_configuration.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698