| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 CHECK(printer_dict->GetString("printerModel", &printer_model)); | 197 CHECK(printer_dict->GetString("printerModel", &printer_model)); |
| 198 CHECK(printer_dict->GetString("printerAddress", &printer_address)); | 198 CHECK(printer_dict->GetString("printerAddress", &printer_address)); |
| 199 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); | 199 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); |
| 200 // printerQueue might be null for a printer whose protocol is not 'LPD'. | 200 // printerQueue might be null for a printer whose protocol is not 'LPD'. |
| 201 printer_dict->GetString("printerQueue", &printer_queue); | 201 printer_dict->GetString("printerQueue", &printer_queue); |
| 202 // printerPPDPath might be null for an auto-discovered printer. | 202 // printerPPDPath might be null for an auto-discovered printer. |
| 203 printer_dict->GetString("printerPPDPath", &printer_ppd_path); | 203 printer_dict->GetString("printerPPDPath", &printer_ppd_path); |
| 204 std::string printer_uri = | 204 std::string printer_uri = |
| 205 printer_protocol + "://" + printer_address + "/" + printer_queue; | 205 printer_protocol + "://" + printer_address + "/" + printer_queue; |
| 206 | 206 |
| 207 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(); | 207 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); |
| 208 printer->set_id(printer_id); | 208 printer_id = printer->id(); |
| 209 printer->set_display_name(printer_name); | 209 printer->set_display_name(printer_name); |
| 210 printer->set_description(printer_description); | 210 printer->set_description(printer_description); |
| 211 printer->set_manufacturer(printer_manufacturer); | 211 printer->set_manufacturer(printer_manufacturer); |
| 212 printer->set_model(printer_model); | 212 printer->set_model(printer_model); |
| 213 printer->set_uri(printer_uri); | 213 printer->set_uri(printer_uri); |
| 214 if (!printer_ppd_path.empty()) { |
| 215 printer->mutable_ppd_reference()->user_supplied_ppd_url = printer_ppd_path; |
| 216 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { |
| 217 Printer::PpdReference* ppd = printer->mutable_ppd_reference(); |
| 218 ppd->effective_manufacturer = printer_manufacturer; |
| 219 ppd->effective_model = printer_model; |
| 220 } |
| 214 | 221 |
| 215 chromeos::DebugDaemonClient* client = | 222 chromeos::DebugDaemonClient* client = |
| 216 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 223 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 217 client->CupsAddPrinter( | 224 client->CupsAddPrinter( |
| 218 printer_name, printer_uri, | 225 printer_id, // record id |
| 219 printer_ppd_path, | 226 printer_uri, // uri |
| 220 printer_ppd_path.empty() ? true : false, // ipp everywhere | 227 printer_ppd_path, // ppd location |
| 228 printer_ppd_path.empty() ? true : false, // ipp everywhere |
| 221 base::Bind(&CupsPrintersHandler::OnAddedPrinter, | 229 base::Bind(&CupsPrintersHandler::OnAddedPrinter, |
| 222 weak_factory_.GetWeakPtr(), base::Passed(std::move(printer))), | 230 weak_factory_.GetWeakPtr(), base::Passed(std::move(printer))), |
| 223 base::Bind(&CupsPrintersHandler::OnAddPrinterError, | 231 base::Bind(&CupsPrintersHandler::OnAddPrinterError, |
| 224 weak_factory_.GetWeakPtr())); | 232 weak_factory_.GetWeakPtr())); |
| 225 } | 233 } |
| 226 | 234 |
| 227 void CupsPrintersHandler::OnAddedPrinter(std::unique_ptr<Printer> printer, | 235 void CupsPrintersHandler::OnAddedPrinter(std::unique_ptr<Printer> printer, |
| 228 bool success) { | 236 bool success) { |
| 229 std::string printer_name = printer->display_name(); | 237 std::string printer_name = printer->display_name(); |
| 230 if (success) { | 238 if (success) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 *printers_list); | 372 *printers_list); |
| 365 } | 373 } |
| 366 | 374 |
| 367 void CupsPrintersHandler::OnDiscoveryDone() { | 375 void CupsPrintersHandler::OnDiscoveryDone() { |
| 368 CallJavascriptFunction("cr.webUIListenerCallback", | 376 CallJavascriptFunction("cr.webUIListenerCallback", |
| 369 base::StringValue("on-printer-discovery-done")); | 377 base::StringValue("on-printer-discovery-done")); |
| 370 } | 378 } |
| 371 | 379 |
| 372 } // namespace settings | 380 } // namespace settings |
| 373 } // namespace chromeos | 381 } // namespace chromeos |
| OLD | NEW |