| 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" |
| 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 Loading... |
| 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 |
| 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 |
| 47 void OnRemovedPrinter(bool success) {} | 56 void OnRemovedPrinter(bool success) {} |
| 48 | 57 |
| 49 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { | 58 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { |
| 50 std::unique_ptr<base::DictionaryValue> printer_info = | 59 std::unique_ptr<base::DictionaryValue> printer_info = |
| 51 base::MakeUnique<base::DictionaryValue>(); | 60 base::MakeUnique<base::DictionaryValue>(); |
| 52 printer_info->SetString("printerId", printer.id()); | 61 printer_info->SetString("printerId", printer.id()); |
| 53 printer_info->SetString("printerName", printer.display_name()); | 62 printer_info->SetString("printerName", printer.display_name()); |
| 54 printer_info->SetString("printerDescription", printer.description()); | 63 printer_info->SetString("printerDescription", printer.description()); |
| 55 printer_info->SetString("printerManufacturer", printer.manufacturer()); | 64 printer_info->SetString("printerManufacturer", printer.manufacturer()); |
| 56 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 Loading... |
| 218 | 227 |
| 219 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); | 228 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); |
| 220 printer->set_display_name(printer_name); | 229 printer->set_display_name(printer_name); |
| 221 printer->set_description(printer_description); | 230 printer->set_description(printer_description); |
| 222 printer->set_manufacturer(printer_manufacturer); | 231 printer->set_manufacturer(printer_manufacturer); |
| 223 printer->set_model(printer_model); | 232 printer->set_model(printer_model); |
| 224 printer->set_uri(printer_uri); | 233 printer->set_uri(printer_uri); |
| 225 | 234 |
| 226 // Verify a valid ppd path is present. | 235 // Verify a valid ppd path is present. |
| 227 if (!printer_ppd_path.empty()) { | 236 if (!printer_ppd_path.empty()) { |
| 237 RecordPpdSource(kUser); |
| 228 GURL tmp = net::FilePathToFileURL(base::FilePath(printer_ppd_path)); | 238 GURL tmp = net::FilePathToFileURL(base::FilePath(printer_ppd_path)); |
| 229 if (!tmp.is_valid()) { | 239 if (!tmp.is_valid()) { |
| 230 LOG(ERROR) << "Invalid ppd path: " << printer_ppd_path; | 240 LOG(ERROR) << "Invalid ppd path: " << printer_ppd_path; |
| 231 OnAddPrinterError(); | 241 OnAddPrinterError(); |
| 232 return; | 242 return; |
| 233 } | 243 } |
| 234 printer->mutable_ppd_reference()->user_supplied_ppd_url = tmp.spec(); | 244 printer->mutable_ppd_reference()->user_supplied_ppd_url = tmp.spec(); |
| 235 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { | 245 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { |
| 246 RecordPpdSource(kScs); |
| 236 // Using the manufacturer and model, get a ppd reference. | 247 // Using the manufacturer and model, get a ppd reference. |
| 237 if (!ppd_provider_->GetPpdReference(printer_manufacturer, printer_model, | 248 if (!ppd_provider_->GetPpdReference(printer_manufacturer, printer_model, |
| 238 printer->mutable_ppd_reference())) { | 249 printer->mutable_ppd_reference())) { |
| 239 LOG(ERROR) << "Failed to get ppd reference"; | 250 LOG(ERROR) << "Failed to get ppd reference"; |
| 240 OnAddPrinterError(); | 251 OnAddPrinterError(); |
| 241 return; | 252 return; |
| 242 } | 253 } |
| 243 } | 254 } |
| 244 | 255 |
| 245 // 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 |
| 246 // the receiver of the callback. | 257 // the receiver of the callback. |
| 247 const Printer printer_copy = *printer; | 258 const Printer printer_copy = *printer; |
| 248 printer_configurer_->SetUpPrinter( | 259 printer_configurer_->SetUpPrinter( |
| 249 printer_copy, | 260 printer_copy, |
| 250 base::Bind(&CupsPrintersHandler::OnAddedPrinter, | 261 base::Bind(&CupsPrintersHandler::OnAddedPrinter, |
| 251 weak_factory_.GetWeakPtr(), base::Passed(&printer))); | 262 weak_factory_.GetWeakPtr(), base::Passed(&printer))); |
| 252 } | 263 } |
| 253 | 264 |
| 254 void CupsPrintersHandler::OnAddedPrinter( | 265 void CupsPrintersHandler::OnAddedPrinter( |
| 255 std::unique_ptr<Printer> printer, | 266 std::unique_ptr<Printer> printer, |
| 256 chromeos::PrinterSetupResult result_code) { | 267 chromeos::PrinterSetupResult result_code) { |
| 257 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); |
| 258 switch (result_code) { | 271 switch (result_code) { |
| 259 case chromeos::PrinterSetupResult::kSuccess: { | 272 case chromeos::PrinterSetupResult::kSuccess: { |
| 260 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); | 273 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); |
| 261 manager->PrinterInstalled(*printer); | 274 manager->PrinterInstalled(*printer); |
| 262 manager->RegisterPrinter(std::move(printer)); | 275 manager->RegisterPrinter(std::move(printer)); |
| 263 break; | 276 break; |
| 264 } | 277 } |
| 265 case chromeos::PrinterSetupResult::kPpdNotFound: | 278 case chromeos::PrinterSetupResult::kPpdNotFound: |
| 266 LOG(WARNING) << "Could not locate requested PPD"; | 279 LOG(WARNING) << "Could not locate requested PPD"; |
| 267 break; | 280 break; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 425 |
| 413 FireWebUIListener("on-printer-discovered", *printers_list); | 426 FireWebUIListener("on-printer-discovered", *printers_list); |
| 414 } | 427 } |
| 415 | 428 |
| 416 void CupsPrintersHandler::OnDiscoveryInitialScanDone() { | 429 void CupsPrintersHandler::OnDiscoveryInitialScanDone() { |
| 417 FireWebUIListener("on-printer-discovery-done"); | 430 FireWebUIListener("on-printer-discovery-done"); |
| 418 } | 431 } |
| 419 | 432 |
| 420 } // namespace settings | 433 } // namespace settings |
| 421 } // namespace chromeos | 434 } // namespace chromeos |
| OLD | NEW |