| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 const base::DictionaryValue* printer_dict = nullptr; | 321 const base::DictionaryValue* printer_dict = nullptr; |
| 322 CHECK(args->GetDictionary(0, &printer_dict)); | 322 CHECK(args->GetDictionary(0, &printer_dict)); |
| 323 | 323 |
| 324 std::string printer_id; | 324 std::string printer_id; |
| 325 std::string printer_name; | 325 std::string printer_name; |
| 326 std::string printer_description; | 326 std::string printer_description; |
| 327 std::string printer_manufacturer; | 327 std::string printer_manufacturer; |
| 328 std::string printer_model; | 328 std::string printer_model; |
| 329 std::string printer_address; | 329 std::string printer_address; |
| 330 std::string printer_protocol; | 330 std::string printer_protocol; |
| 331 std::string printer_ppd_path; | |
| 332 CHECK(printer_dict->GetString("printerId", &printer_id)); | 331 CHECK(printer_dict->GetString("printerId", &printer_id)); |
| 333 CHECK(printer_dict->GetString("printerName", &printer_name)); | 332 CHECK(printer_dict->GetString("printerName", &printer_name)); |
| 334 CHECK(printer_dict->GetString("printerDescription", &printer_description)); | 333 CHECK(printer_dict->GetString("printerDescription", &printer_description)); |
| 335 CHECK(printer_dict->GetString("printerManufacturer", &printer_manufacturer)); | 334 CHECK(printer_dict->GetString("printerManufacturer", &printer_manufacturer)); |
| 336 CHECK(printer_dict->GetString("printerModel", &printer_model)); | 335 CHECK(printer_dict->GetString("printerModel", &printer_model)); |
| 337 CHECK(printer_dict->GetString("printerAddress", &printer_address)); | 336 CHECK(printer_dict->GetString("printerAddress", &printer_address)); |
| 338 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); | 337 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); |
| 339 | 338 |
| 340 std::string printer_queue = GetPrinterQueue(*printer_dict); | 339 std::string printer_queue = GetPrinterQueue(*printer_dict); |
| 341 | 340 |
| 342 std::string printer_uri = | 341 std::string printer_uri = |
| 343 printer_protocol + url::kStandardSchemeSeparator + printer_address; | 342 printer_protocol + url::kStandardSchemeSeparator + printer_address; |
| 344 if (!printer_queue.empty()) { | 343 if (!printer_queue.empty()) { |
| 345 printer_uri += "/" + printer_queue; | 344 printer_uri += "/" + printer_queue; |
| 346 } | 345 } |
| 347 | 346 |
| 348 // printerPPDPath might be null for an auto-discovered printer. | 347 // Read PPD selection if it was used. |
| 348 std::string ppd_manufacturer; |
| 349 std::string ppd_model; |
| 350 printer_dict->GetString("ppdManufacturer", &ppd_manufacturer); |
| 351 printer_dict->GetString("ppdModel", &ppd_model); |
| 352 |
| 353 // Read user provided PPD if it was used. |
| 354 std::string printer_ppd_path; |
| 349 printer_dict->GetString("printerPPDPath", &printer_ppd_path); | 355 printer_dict->GetString("printerPPDPath", &printer_ppd_path); |
| 350 | 356 |
| 351 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); | 357 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); |
| 352 printer->set_display_name(printer_name); | 358 printer->set_display_name(printer_name); |
| 353 printer->set_description(printer_description); | 359 printer->set_description(printer_description); |
| 354 printer->set_manufacturer(printer_manufacturer); | 360 printer->set_manufacturer(printer_manufacturer); |
| 355 printer->set_model(printer_model); | 361 printer->set_model(printer_model); |
| 356 printer->set_uri(printer_uri); | 362 printer->set_uri(printer_uri); |
| 357 | 363 |
| 358 bool autoconf = false; | 364 bool autoconf = false; |
| 359 printer_dict->GetBoolean("printerAutoconf", &autoconf); | 365 printer_dict->GetBoolean("printerAutoconf", &autoconf); |
| 360 | 366 |
| 361 // Verify that the printer is autoconf or a valid ppd path is present. | 367 // Verify that the printer is autoconf or a valid ppd path is present. |
| 362 if (autoconf) { | 368 if (autoconf) { |
| 363 printer->mutable_ppd_reference()->autoconf = true; | 369 printer->mutable_ppd_reference()->autoconf = true; |
| 364 } else if (!printer_ppd_path.empty()) { | 370 } else if (!printer_ppd_path.empty()) { |
| 365 RecordPpdSource(kUser); | 371 RecordPpdSource(kUser); |
| 366 GURL tmp = net::FilePathToFileURL(base::FilePath(printer_ppd_path)); | 372 GURL tmp = net::FilePathToFileURL(base::FilePath(printer_ppd_path)); |
| 367 if (!tmp.is_valid()) { | 373 if (!tmp.is_valid()) { |
| 368 LOG(ERROR) << "Invalid ppd path: " << printer_ppd_path; | 374 LOG(ERROR) << "Invalid ppd path: " << printer_ppd_path; |
| 369 OnAddPrinterError(); | 375 OnAddPrinterError(); |
| 370 return; | 376 return; |
| 371 } | 377 } |
| 372 printer->mutable_ppd_reference()->user_supplied_ppd_url = tmp.spec(); | 378 printer->mutable_ppd_reference()->user_supplied_ppd_url = tmp.spec(); |
| 373 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { | 379 } else if (!ppd_manufacturer.empty() && !ppd_model.empty()) { |
| 374 RecordPpdSource(kScs); | 380 RecordPpdSource(kScs); |
| 375 // Using the manufacturer and model, get a ppd reference. | 381 // Using the manufacturer and model, get a ppd reference. |
| 376 if (!ppd_provider_->GetPpdReference(printer_manufacturer, printer_model, | 382 if (!ppd_provider_->GetPpdReference(ppd_manufacturer, ppd_model, |
| 377 printer->mutable_ppd_reference())) { | 383 printer->mutable_ppd_reference())) { |
| 378 LOG(ERROR) << "Failed to get ppd reference"; | 384 LOG(ERROR) << "Failed to get ppd reference"; |
| 379 OnAddPrinterError(); | 385 OnAddPrinterError(); |
| 380 return; | 386 return; |
| 381 } | 387 } |
| 388 |
| 389 if (printer->make_and_model().empty()) { |
| 390 // In lieu of more accurate information, populate the make and model |
| 391 // fields with the PPD information. |
| 392 printer->set_manufacturer(ppd_manufacturer); |
| 393 printer->set_model(ppd_model); |
| 394 // PPD Model names are actually make and model. |
| 395 printer->set_make_and_model(ppd_model); |
| 396 } |
| 397 } else { |
| 398 // TODO(crbug.com/738514): Support PPD guessing for non-autoconf printers. |
| 399 // i.e. !autoconf && !manufacturer.empty() && !model.empty() |
| 400 NOTREACHED() |
| 401 << "A configuration option must have been selected to add a printer"; |
| 382 } | 402 } |
| 383 | 403 |
| 384 // Copy the printer for the configurer. Ownership needs to be transfered to | 404 // Copy the printer for the configurer. Ownership needs to be transfered to |
| 385 // the receiver of the callback. | 405 // the receiver of the callback. |
| 386 const Printer printer_copy = *printer; | 406 const Printer printer_copy = *printer; |
| 387 printer_configurer_->SetUpPrinter( | 407 printer_configurer_->SetUpPrinter( |
| 388 printer_copy, | 408 printer_copy, |
| 389 base::Bind(&CupsPrintersHandler::OnAddedPrinter, | 409 base::Bind(&CupsPrintersHandler::OnAddedPrinter, |
| 390 weak_factory_.GetWeakPtr(), base::Passed(&printer))); | 410 weak_factory_.GetWeakPtr(), base::Passed(&printer))); |
| 391 } | 411 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 587 } |
| 568 | 588 |
| 569 void CupsPrintersHandler::OnPrinterScanComplete() { | 589 void CupsPrintersHandler::OnPrinterScanComplete() { |
| 570 UMA_HISTOGRAM_COUNTS_100("Printing.CUPS.PrintersDiscovered", | 590 UMA_HISTOGRAM_COUNTS_100("Printing.CUPS.PrintersDiscovered", |
| 571 printer_detector_->GetPrinters().size()); | 591 printer_detector_->GetPrinters().size()); |
| 572 FireWebUIListener("on-printer-discovery-done"); | 592 FireWebUIListener("on-printer-discovery-done"); |
| 573 } | 593 } |
| 574 | 594 |
| 575 } // namespace settings | 595 } // namespace settings |
| 576 } // namespace chromeos | 596 } // namespace chromeos |
| OLD | NEW |